// GET: UserHome public ActionResult Home(User user) { UserHomeModel um = new UserHomeModel(); um.user = user; TweetHandler twtHandlr = new TweetHandler(); um.tweetDetails = twtHandlr.GetAllTweets(user.ID); UsersHandler usrHandlr = new UsersHandler(); um.FollowersList = usrHandlr.GetFollowersList(user.ID); um.FollowingList = usrHandlr.GetFollowingList(user.ID); return(View(um)); }
//**************************************************************************************** // Public method: ShowAllTweets() // Arguments: None // Returns: None // Description: Display a list to the console of all tweets send tweets of followed tweets // Revision: 1.01a // Revision date: 2016/05/25 // *************************************************************************************** public void ShowAllTweets() { // Initilize instance of AllTweets List <AllTweets> allTweets = new List <AllTweets>(); // Initilize instance of TweetHandler TweetHandler tweetHandler = new TweetHandler(); // Get a List of all the tweets allTweets = tweetHandler.GetAllTweets(); try { // Iterate through all the tweets stored in AllTweets foreach (AllTweets tweets in allTweets) { // Output the user name to the console Console.WriteLine(tweets.Owner); Console.WriteLine(); // Check if the any tweets for this user if (tweets.Tweet.Count > 0) { // Output all tweets associated with this user for (int tweetCount = 0; tweetCount < tweets.Tweet.Count; tweetCount++) { Console.WriteLine(tweets.Tweet.ElementAt(tweetCount)); Console.WriteLine(); } } } } catch (Exception ex) // Exception ecountered { Console.WriteLine("HelpLink = {0}", ex.HelpLink); Console.WriteLine("Message = {0}", ex.Message); Console.WriteLine("Source = {0}", ex.Source); Console.WriteLine("StackTrace = {0}", ex.StackTrace); Console.WriteLine("TargetSite = {0}", ex.TargetSite); } // After outputing the tweets ask user to press a key to exit console application Console.WriteLine(); Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
static void Main(string[] args) { var handler1 = new TweetHandler(TweetHandleMethod1); var handler2 = new TweetHandler(TweetHandleMethod2); var source = new TweetSource(); source.NewTweetEvent += handler1.AddTweetToQueue; source.NewTweetEvent += handler2.AddTweetToQueue; // start up the task threads (2 of them)! var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; var taskFactory = new TaskFactory(token); var task1 = taskFactory.StartNew(() => handler1.HandleTweets(token)); var task2 = taskFactory.StartNew(() => handler2.HandleTweets(token)); // fire up the source source.Start(); Thread.Sleep(10000); tokenSource.Cancel(); }
public ActionResult UserHomeOperations(System.Web.Mvc.FormCollection frmCollection, string submitButton) { try { int ID = 0; string tweetMsg; string errmsg = ""; TweetHandler twtHandlr = new TweetHandler(); if (submitButton == "share") { ID = Convert.ToInt32(frmCollection["UsrID"]); tweetMsg = frmCollection["msgTweet"]; if (ID != 0) { twtHandlr.PostTweet(ID, tweetMsg); } else { errmsg = "Could not read user properly"; } } else if (submitButton.Contains("Save")) { ID = Convert.ToInt32(frmCollection["TweetID"].Split(',')[0]); tweetMsg = frmCollection["msgEdtTweet"]; if (ID != 0) { twtHandlr.UpdateTweet(ID, tweetMsg); } else { errmsg = "Could not read tweet properly"; } } else if (submitButton == "Delete") { ID = Convert.ToInt32(frmCollection["TweetID"].Split(',')[0]); if (ID != 0) { twtHandlr.DeleteTweet(ID); } else { errmsg = "Could not read tweet properly"; } } else if (submitButton == "Cancel") { Redirect(Request.UrlReferrer.ToString()); } else if (submitButton == "Search") { if (string.IsNullOrEmpty(frmCollection["txtSearch"])) { throw new Exception("Search criteria cannot by empty"); } else { UserSearch srchUser = new UserSearch(); UsersHandler usrHandlr = new UsersHandler(); srchUser = usrHandlr.GetUserDetails(frmCollection["txtSearch"]); if (srchUser != null) { srchUser.sourceUsrID = Convert.ToInt32(frmCollection["UsrID"]); //SearchPage(srchUser); return(RedirectToAction("SearchPage", "Search", srchUser)); } } } return(Redirect(Request.UrlReferrer.ToString())); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); return(Redirect(Request.UrlReferrer.ToString())); } }