Inheritance: IComparable
Exemplo n.º 1
0
 public bool AddPost(Post post, string subforum)
 {
     try
     {
         subforumsList[subforum].TotalPosts++;
         return subforumsList[subforum].AddPost(post);
     }
     catch (Exception)
     {
         throw new SubforumNotFoundException();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// This method is called when controller invoked its OnUpdate event
        /// </summary>
        /// <param name="text"></param>
        public void controller_OnUpdateFromServer(Post p)
        {
            try
            {
                Console.Beep();
            }
            catch (Exception)
            {

                throw;
            }
        }
Exemplo n.º 3
0
 public void setWinProperties(Post parentPost, string subforum)
 {
     currentPost = parentPost;
     if (currentPost != null)
     {
         postTitleTextbox.Text = "RE:" + currentPost.Title;
     }
     else
     {
         postTitleTextbox.Text = "";
     }
     postContentTextBox.Text = "";
     currentSubforum = subforum;
     currentSubforumLabel.Content = currentSubforum;
 }
Exemplo n.º 4
0
        public ClientFormUI()
        {
            InitializeComponent();

            controller = new ClientController(true);
            controller.OnUpdateFromController += new ForumClientCore.NetworkLayer.ClientNetworkAdaptor.OnUpdate(controller_OnUpdateFromServer);

            currentPost = null;
            currentSubforumPosts = new List<Post>();

            postsGrid.Dock = DockStyle.Fill;
            subforumsGrid.Dock = DockStyle.Fill;
            postPanel.Dock = DockStyle.Fill;
            newPostPanel.Dock = DockStyle.Fill;

            GetSubforums();
        }
Exemplo n.º 5
0
 public void AddPostServerTests()
 {
     DataManager target = new DataManager();
     target.CleanForumData();
     User user = new User("user", "user");
     target.AddUser(user);
     target.AddSubforum(new Subforum("subforumName"));
     Postkey pk = new Postkey("user", DateTime.Now);
     Post p = new Post(pk, "Post", "body", null, "subforumName");
     bool actual = target.AddPost(p, "subforumName");
     Post p2 = target.GetPost(pk);
     Assert.IsTrue(actual);
     Assert.AreEqual(p.Key.Time, p2.Key.Time);
     Assert.AreEqual(p.Key.Username, p2.Key.Username);
     Assert.AreEqual(p.Title, p2.Title);
     Assert.AreEqual(p.Body, p2.Body);
     target.RemoveSubforum("subforumName");
 }
Exemplo n.º 6
0
 public bool AddReply(Post reply, Postkey originalPost)
 {
     Post post;
     GetPost(originalPost, out post);
     if (post == null)
         throw new PostNotFoundException();
     try
     {
         post.HasReplies = true;
         subforumsList[post.Subforum].TotalPosts++;
         post.Replies.Add(reply.Key, reply);
         return true;
         //return UpdatePost(oldPost);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 7
0
        //  private List<PostControl> repliesList;
        public PostControl(Post p, bool isReply)
        {
            InitializeComponent();
            isExpended = false;
            currentPost = p;
            setGUI(isReply);
            isExpended = true;
            expandIndicator_MouseLeftButtonDown(null, null);
               // repliesList = new List<PostControl>();
               // repliesList.Add(new PostControl());
            repliesList = new PostControlList();

            StaticObjects.newPostWin.cancelled += new AddPostWin.LoginEventHandler(newPostWin_closed);
            //Thread worker = new Thread(getReplies);
            //worker.Start();

            //repliesListBox.DataContext = repliesListBox;
              //  currentHeight = 50;
              //  grid.Height = currentHeight;
              //  this.Height = currentHeight;
        }
Exemplo n.º 8
0
        public Result Post(string subforum, Post post)
        {
            try
            {
                log.Info("got request to post in sub forum: " + subforum);
                if (!CheckPost(post))
                    return Result.ILLEGAL_POST;

                Result res = securityManager.IsAuthorizedToPost(post.Key.Username, subforum);
                if (res == Result.OK)
                    if (dataManager.AddPost(post, subforum.ToString()))
                    {
                        this.posted = post;
                        Notify();
                        return Result.OK;
                    }
                    else return Result.SUB_FORUM_NOT_FOUND;
                else return res;
            }
            catch (Exception e)
            {
                log.Error("failed to post in sub forum: " + subforum, e);
                throw e;
            }
        }
Exemplo n.º 9
0
        public Result Reply(Postkey currPost, Post post)
        {
            try
            {
                log.Info("got request to reply to post " + currPost);
                if (!CheckPost(post))
                    return Result.ILLEGAL_POST;

                Result res = securityManager.IsAuthorizedToPost(post.Key.Username, post.Subforum) ;
                if (res == Result.OK)
                    if (dataManager.AddReply(post, currPost))
                    {
                        this.posted = post;
                        Notify();
                        return Result.OK;
                    }
                    else return Result.POST_NOT_FOUND;
                else return res;
            }
            catch (Exception e)
            {
                log.Error("failed to reply to post " + currPost, e);
                throw e;
            }
        }
Exemplo n.º 10
0
        public Result Reply(Postkey current, Post toPost)
        {
            try
            {
                toPost.Replies = new Dictionary<Postkey, Post>();
                return controller.Reply(current, toPost);

            }
            catch (Exception e)
            {
                throw new FaultException<Exception>(e, e.Message);
            }
        }
Exemplo n.º 11
0
 public Result EditPost(Postkey currPost, Post post, string username, string password)
 {
     try
     {
         log.Info("got request to edit post " + currPost);
         if (!CheckPost(post))
             return Result.ILLEGAL_POST;
         Result res = securityManager.IsAuthorizedToEdit(username, currPost, password);
         if (res == Result.OK)
             if (dataManager.EditPost(post, currPost))
                 return Result.OK;
             else return Result.POST_NOT_FOUND;
         else return res;
     }
     catch (Exception e)
     {
         log.Error("failed to edit post " + currPost, e);
         throw e;
     }
 }
Exemplo n.º 12
0
        public bool AddPost(Post post, string subforum)
        {
            //Getting last id:
            IEnumerable<int> postKeysList = (from m in ForumContext.PostKeyEntities
                                             select m.PostKeyId);
            int lastId = 0;
            if (postKeysList.Count() != 0)
            {
                lastId = postKeysList.Max();
            }
            currentPostKeyId = lastId + 1;

            PostKeyEntity pke = new PostKeyEntity();
            pke.PostKeyId = currentPostKeyId;
            pke.Username = post.Key.Username;
            pke.Time = post.Key.Time;

            PostEntity pe = new PostEntity();
            pe.PostKeyId = currentPostKeyId;
            pe.ParentPostKeyId = -1;
            pe.Title = post.Title;
            pe.Body = post.Body;
            pe.SubforumName = subforum; //TODO - Why do we need 'subforum'?
            try
            {
                ForumContext.AddToPostKeyEntities(pke);
                ForumContext.AddToPostEntities(pe);
                ForumContext.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                //TODO
                throw;
            }
        }
Exemplo n.º 13
0
 public Post(Post postToCopy)
 {
     this.postToUpdate = postToCopy;
 }
Exemplo n.º 14
0
 private void GetRepliesOfUser(Post post, string username, List<Post> listOfUserPosts, out List<Post> returnedReplies)
 {
     returnedReplies = listOfUserPosts;
     foreach (Post reply in post.Replies.Values)
     {
         if (reply.Key.Username == username)
         {
             returnedReplies.Add(reply);
             GetRepliesOfUser(reply, username, listOfUserPosts.Union(returnedReplies).ToList(), out returnedReplies);
         }
     }
 }
Exemplo n.º 15
0
 public bool EditPost(Post postToUpdate, Postkey oldPostKey)
 {
     try
     {
         PostEntity post = GetPostEntity(oldPostKey).First();
         post.Title = postToUpdate.Title;
         post.Body = postToUpdate.Body;
         //TODO - Do username & datetime (Postkey) change on update?
         ForumContext.SaveChanges();
         return true;
     }
     catch (Exception)
     {
         //TODO
         throw;
     }
 }
Exemplo n.º 16
0
 private List<Post> GetAllReplyOfPost(Post post)
 {
     List<Post> allReplies = new List<Post>();
     allReplies = allReplies.Union(post.Replies.Values).ToList<Post>();
     foreach (Post PostToReturn in post.Replies.Values)
     {
         allReplies = allReplies.Union(GetAllReplyOfPost(PostToReturn)).ToList<Post>();
     }
     return allReplies;
 }
Exemplo n.º 17
0
        private void GetPost(Postkey postkey, out Post returnedPost)
        {
            returnedPost = null;
            foreach (KeyValuePair<string, Subforum> subforumEntry in subforumsList)
            {
                if (returnedPost != null)
                {
                    break;
                }
                try
                {
                    foreach (Post PostToReturn in subforumEntry.Value.Posts.Values)
                    {
                        if (PostToReturn.Key.CompareTo(postkey) == 0)
                        {
                            returnedPost = PostToReturn;
                            break;

                        }
                    }
                    if (returnedPost != null)
                    {
                        break;
                    }
                    else
                    {

                    //if (subforumEntry.Value.Posts.ContainsKey(postkey))    // If oldPost is main oldPost in subforumName
                    //{
                    //    returnedPost = subforumsList[subforumEntry.Key].Posts[postkey];
                    //    break;
                    //}
                    //else    // If oldPost is not main oldPost, search oldPost in replies & update

                    //{
                        GetReply(postkey, subforumsList[subforumEntry.Key].Posts, out returnedPost);
                        if (returnedPost != null)
                            break;
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 18
0
 public bool EditPost(Post postToUpdate, Postkey originalPost)
 {
     Post oldPost;
     GetPost(originalPost, out oldPost);
     if (oldPost == null)
         throw new PostNotFoundException();
     try
     {
         oldPost.Body = postToUpdate.Body;
         oldPost.Title = postToUpdate.Title;
         return true;
         //return UpdatePost(oldPost);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 19
0
 /// <summary>
 /// Will be called when controller will invoke update event
 /// </summary>
 /// <param name="text"></param>
 public void controller_OnUpdateFromServer(Post postUpdated)
 {
     onUpdatePictureBox.Visible = true;
     updatedPost = postUpdated;
     //richTextBox1.Text = richTextBox1.Text + text + '\n';    // Update textBox with the message from server
 }
Exemplo n.º 20
0
        private void ShowPost(Post p)
        {
            currentPost = p;

            // Switch Panels
            postsGrid.Visible = false;
            subforumsGrid.Visible = false;
            postPanel.Visible = true;
            newPostPanel.Visible = false;

            // Update panel data:
            repliesIndicator.Visible = true;
            postTitleLabel.Text = p.Title;
            postUserLabel.Text = p.Key.Username;
            postDateLabel.Text = p.Key.Time.ToShortDateString();
            postBody.Text = p.Body;
            ShowRepliesIndicator(p.HasReplies);
        }
Exemplo n.º 21
0
 private bool CheckPost(Post post)
 {
     return ((post.Body != null && post.Body.Length != 0)
            || (post.Title != null && post.Title.Length != 0));
 }
Exemplo n.º 22
0
        public Result Post(string currentSubforum, Post toPost)
        {
            try
            {
                toPost.Replies = new Dictionary<Postkey, Post>();
                return controller.Post(currentSubforum, toPost);

            }
            catch (Exception e)
            {
                throw new FaultException<Exception>(e, e.Message);
            }
        }
Exemplo n.º 23
0
        public bool AddReply(Post reply, Postkey postKey)
        {
            try
            {
                // Find parent postkey:
                IEnumerable<PostKeyEntity> postkeyQuery = GetPostKeyEntity(postKey);
                IEnumerable<PostEntity> postQuery = GetPostEntity(postKey);

                //Getting last id:
                IEnumerable<int> postKeysList = (from m in ForumContext.PostKeyEntities
                                                 select m.PostKeyId);
                int lastId = 0;
                if (postKeysList.Count() != 0)
                {
                    lastId = postKeysList.Max();
                }
                currentPostKeyId = lastId + 1;

                PostKeyEntity pke = new PostKeyEntity();
                pke.PostKeyId = currentPostKeyId;
                pke.Username = reply.Key.Username;
                pke.Time = reply.Key.Time;
                ForumContext.AddToPostKeyEntities(pke);
                PostEntity pe = new PostEntity();

                pe.PostKeyId = currentPostKeyId;
                //currentPostKeyId++;
                pe.ParentPostKeyId = postkeyQuery.ElementAt(0).PostKeyId;
                pe.Title = reply.Title;
                pe.Body = reply.Body;
                pe.SubforumName = postQuery.ElementAt(0).SubforumName;

                ForumContext.AddToPostEntities(pe);
                ForumContext.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                //TODO
                throw;
            }
        }
Exemplo n.º 24
0
 public string SerializePost(Post toSerialize)
 {
     return serializer.Serialize(toSerialize);
 }
Exemplo n.º 25
0
        private Post PostEntityToPost(PostEntity pe)
        {
            Postkey parentPostKey = null;

            // Finding parent`s postkey:
            if (pe.ParentPostKeyId != -1)
            {
                IEnumerable<PostKeyEntity> parentPostkeyQuery = from pk in ForumContext.PostKeyEntities
                                                                where pk.PostKeyId == pe.ParentPostKeyId
                                                                select pk;
                PostKeyEntity pke = parentPostkeyQuery.ElementAt<PostKeyEntity>(0);
                parentPostKey = new Postkey(pke.Username, pke.Time);
            }

            // Finding PostKey:
            IEnumerable<PostKeyEntity> PostkeyQuery = from pk in ForumContext.PostKeyEntities
                                                      where pk.PostKeyId == pe.PostKeyId
                                                      select pk;
            PostKeyEntity postkeyEntity = PostkeyQuery.First();
            Postkey postkey = new Postkey(postkeyEntity.Username, postkeyEntity.Time);

            Post PostToReturn = new Post(postkey, pe.Title, pe.Body, parentPostKey, pe.SubforumName);

            // Replies:
            IEnumerable<PostEntity> repliesList = from r in ForumContext.PostEntities
                                                  where r.ParentPostKeyId == pe.PostKeyId
                                                  select r;
            Dictionary<Postkey, Post> repliesDictionary = new Dictionary<Postkey, Post>();
            if (repliesList.Count() != 0)
            {
                foreach (PostEntity reply in repliesList)
                {
                    Post p = PostEntityToPost(reply);
                    repliesDictionary.Add(p.Key, p);
                }
                PostToReturn.HasReplies = true;
            }
            else
            {
                PostToReturn.HasReplies = false;
            }
            PostToReturn.Replies = repliesDictionary;
            return PostToReturn;
        }
Exemplo n.º 26
0
 private bool UpdateReply(Post replyToUpdate, Dictionary<Postkey, Post> postsList)
 {
     bool ans = false;
     if (postsList.ContainsKey(replyToUpdate.Key))
     {
         postsList[replyToUpdate.Key] = replyToUpdate;
         return true;
     }
     else
     {
         foreach (Post reply in postsList.Values)
         {
             ans = UpdateReply(replyToUpdate, reply.Replies);
             if (ans == true)
             {
                 return ans;
             }
         }
         return false;
     }
 }
Exemplo n.º 27
0
 public bool AddReply(Post reply)
 {
     try
     {
         this.replies.Add(reply.Key, reply);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return true;
 }
Exemplo n.º 28
0
 /// <summary>
 /// Add a reply to a post.
 /// </summary>
 /// <param name="originalPost">The post being replied</param>
 /// <param name="newReply">The new reply post</param>
 /// <returns>Returns true if reply succeeded, false otherwise</returns>
 internal Result Reply(Postkey originalPost, Post newReply)
 {
     return webService.Reply(originalPost, newReply);
 }
Exemplo n.º 29
0
 private void GetReply(Postkey postkey, Dictionary<Postkey, Post> postsList, out Post returnedPost)
 {
     returnedPost = null;
     foreach (Post PostToReturn in postsList.Values)
     {
         if (PostToReturn.Key.CompareTo(postkey) == 0)
         {
             returnedPost = PostToReturn;
             break;
         }
     }
     if (returnedPost != null)
     {
         return;
     }
     //if (postsList.ContainsKey(postkey))
     //{
     //    returnedPost = postsList[postkey];
     //    return;
     //}
     //else
     //{
         foreach (Post reply in postsList.Values)
         {
             if (returnedPost == null)
             {
                 GetReply(postkey, reply.Replies, out returnedPost);
             }
         }
     //}
 }
Exemplo n.º 30
0
 public Result EditPost(Postkey oldPost, Post newPost, string username, string password)
 {
     try
     {
         return controller.EditPost(oldPost, newPost, username, password);
     }
     catch (Exception e)
     {
         throw new FaultException<Exception>(e, e.Message);
     }
 }