Exemple #1
0
        private IEnumerable <string> GetUserFeed(Entities.Twitterer user)
        {
            var feedData = new List <Tweet>();

            feedData.AddRange(user.Tweets);
            foreach (var follows in user.Follows)
            {
                var followUser = Users.FirstOrDefault(c => c.Name == follows);

                if (followUser != null)
                {
                    feedData.AddRange(followUser.Tweets);
                }
            }
            var sorted = feedData.OrderBy(o => o.Sequence).ToList();

            return(sorted.Select(x => x.Message).ToList());
        }
Exemple #2
0
        private void LoadUsers(StreamReader srUser)
        {
            var userDataRaw = srUser.ReadToEnd();
            var lines       = userDataRaw.Split(
                new[] { "\r\n", "\r", "\n" },
                StringSplitOptions.RemoveEmptyEntries
                ).ToList();

            lines = lines.Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();

            foreach (var line in lines)
            {
                var fileLineData = line.Split(
                    new[] { " follows " },
                    StringSplitOptions.None
                    ).ToList();

                var userName = fileLineData[0];
                fileLineData.Remove(fileLineData[0]);
                var lineData = string.Join(" follows ", fileLineData.ToArray());

                var user    = Users.FirstOrDefault(c => c.Name == userName);
                var follows = lineData.Split(
                    new[] { "," },
                    StringSplitOptions.None
                    ).ToList();

                follows = follows.Select(s => s.Trim()).ToList();

                if (user != null)
                {
                    user.Follows.AddRange(follows);
                }
                else
                {
                    user = new Entities.Twitterer
                    {
                        Name    = userName,
                        Follows = follows,
                        Tweets  = new List <Tweet>()
                    };
                    Users.Add(user);
                }
                user.Follows = user.Follows.Distinct().ToList();

                foreach (var follower in follows)
                {
                    var followUser = Users.FirstOrDefault(c => c.Name == follower);
                    if (followUser != null)
                    {
                        continue;
                    }
                    followUser = new Entities.Twitterer
                    {
                        Name    = follower,
                        Follows = new List <string>(),
                        Tweets  = new List <Tweet>()
                    };
                    Users.Add(followUser);
                }
            }
        }