public List <ActiveCommentator> GetActiveCommentatorsList(FacebookObjectCollection <Post> i_Posts)
        {
            List <ActiveCommentator> activeCommentatorsList = new List <ActiveCommentator>();

            foreach (Post post in i_Posts)
            {
                foreach (Comment comment in post.Comments)
                {
                    bool ifExists = false;
                    foreach (ActiveCommentator activeCommentator in activeCommentatorsList)
                    {
                        if (comment.From.Id.Equals(activeCommentator.UserId))
                        {
                            ifExists = true;
                            encreaseNumber(activeCommentator);
                            break;
                        }
                    }

                    if (!ifExists)
                    {
                        IActiveUser activeUser = ActiveUserCreator.CreateActiveUser(comment.GetType());
                        activeUser.UserName = comment.From.Name;
                        activeUser.UserId   = comment.From.Id;
                        activeCommentatorsList.Add(activeUser as ActiveCommentator);
                    }
                }
            }

            return(activeCommentatorsList);
        }
        public List <ActiveLiker> GetActiveLikersList(FacebookObjectCollection <Post> i_Posts)
        {
            List <ActiveLiker> activeLikersList = new List <ActiveLiker>();

            foreach (Post post in i_Posts)
            {
                foreach (User liker in post.LikedBy)
                {
                    bool ifExists = false;
                    foreach (ActiveLiker activeLiker in activeLikersList)
                    {
                        if (liker.Id.Equals(activeLiker.UserId))
                        {
                            ifExists = true;
                            encreaseNumber(activeLiker);
                            break;
                        }
                    }

                    if (!ifExists)
                    {
                        IActiveUser activeUser = ActiveUserCreator.CreateActiveUser(liker.GetType());
                        activeUser.UserName = liker.Name;
                        activeUser.UserId   = liker.Id;
                        activeLikersList.Add(activeUser as ActiveLiker);
                    }
                }
            }

            return(activeLikersList);
        }
 private void encreaseNumber(IActiveUser activeUser)
 {
     if (activeUser is ActiveCommentator)
     {
         (activeUser as ActiveCommentator).NumOfComments++;
     }
     else if (activeUser is ActiveLiker)
     {
         (activeUser as ActiveLiker).NumOfLikes++;
     }
 }
Exemple #4
0
        public static IActiveUser CreateActiveUser(Type i_Type)
        {
            IActiveUser activeUser = null;

            if (i_Type == typeof(User))
            {
                activeUser = new ActiveLiker();
            }
            else if (i_Type == typeof(Comment))
            {
                activeUser = new ActiveCommentator();
            }

            return(activeUser);
        }
Exemple #5
0
        public void LoadUsers_OneUser()
        {
            IAutorization autorization = new Autorization();
            string        examplefile  = "1" + "\r\n" + "Admin" + "\r\n" + "AdminPwd" + "\r\n" + "1";
            StreamWriter  sw           = new StreamWriter("tempSaveUser.txt");

            sw.WriteLine(examplefile);
            sw.Close();

            StreamReader sr = new StreamReader("tempSaveUser.txt");

            autorization.LoadUsers(sr);
            sr.Close();
            new FileInfo("tempSaveUser.txt").Delete();

            IActiveUser ActiveUser = autorization.AutorizeUser("Admin", "AdminPwd");

            Assert.AreEqual("Admin", ActiveUser.Login);
            Assert.AreEqual("AdminPwd", ActiveUser.Password);
            Assert.AreEqual(EUserPrivileges.Admin, ActiveUser.UserPrivilages);
        }
 /// <summary>
 /// Const.
 /// </summary>
 /// <param name="peopleRepository">Repository for obtaining people.</param>
 /// <param name="activeUser">Servis for obtaining active user.</param>
 public PeopleController(IPeopleRepository peopleRepository, IActiveUser activeUser)
 {
     _peopleRepository = Check.NotNull(peopleRepository, nameof(peopleRepository));
     _activeUser       = Check.NotNull(activeUser, nameof(activeUser));
 }