public static IPostStrategy CreatePostStrategy(string i_PostStrategy) { IPostStrategy postStrategy = null; switch (i_PostStrategy) { case "Post": postStrategy = new PostStrategy(); break; case "Likes": postStrategy = new LikesStrategy(); break; case "Comments": postStrategy = new CommentsStrategy(); break; case "Date": postStrategy = new DateStrategy(); break; } return(postStrategy); }
private void executeBlast(int i_Year, string i_BlastType) { IList <Post> postList = createPostYearList(i_Year); if (i_BlastType == "Random") { PostStrategy = new RandomPostStrategy(); } else if (i_BlastType == "Most Liked") { PostStrategy = new MostLikedPostStrategy(); } if (!string.IsNullOrEmpty(i_BlastType) && i_Year > 0) { PostResult = PostStrategy.GetPost(postList); } }
private void performFilterPosts() { buttonPostKeywordSearch.Invoke(new Action(() => buttonPostKeywordSearch.Enabled = false)); FilterPostStrategy = PostStrategyFactory.CreatePostStrategy(comboBoxPosts.SelectedItem.ToString()); foreach (Post post in m_LoggedInUser.WallPosts) { if (post.Type == Post.eType.status && !string.IsNullOrEmpty(post.Message)) { if (FilterPostStrategy.FilterPosts(post).ToLower().Contains(searchTextBox.Text.ToLower())) { dataGridViewPosts.Invoke(new Action(() => r_PostsAdapter.Add(new PostsAdapter(post)))); } } } dataGridViewPosts.Invoke(new Action(() => dataGridViewPosts.Refresh())); buttonPostKeywordSearch.Invoke(new Action(() => buttonPostKeywordSearch.Enabled = true)); }
/// <summary> /// Post Status method using the Strategy pattern /// </summary> /// <param name="i_StatusToPost">Status to post</param> /// <param name="i_PostStrategy">Posting Strategy</param> /// <returns></returns> internal bool PostStatus(string i_StatusToPost, IPostStrategy i_PostStrategy) { // Executing the strategy method return i_PostStrategy.excecute(m_LoggedInUserFriends, i_StatusToPost); }