protected void submitsearch_Click(object sender, EventArgs e) { //remove unwanted chars Utility util = new Utility(); string srch1 = util.CleanInput(search1.Text); string srch2 = util.CleanInput(search2.Text); //search twitter MyTwitterObj MyTwitter = new MyTwitterObj(); MyTwitter.search_1 = srch1; MyTwitter.search_2 = srch2; Twitter twitter = new Twitter(); MyTwitter = twitter.GetData(MyTwitter); //store in DB DBInteractions DBI = new DBInteractions(); DBI.StoreInDB(search1.Text, MyTwitter.tweets_1, search2.Text, MyTwitter.tweets_2, MyTwitter.seconds_1, MyTwitter.seconds_2); //go to next page HttpContext CurrContext = HttpContext.Current; CurrContext.Items.Add("srch1", search1.Text); CurrContext.Items.Add("srch2", search2.Text); CurrContext.Items.Add("tweets1", MyTwitter.tweets_1); CurrContext.Items.Add("tweets2", MyTwitter.tweets_2); CurrContext.Items.Add("seconds1", MyTwitter.seconds_1); CurrContext.Items.Add("seconds2", MyTwitter.seconds_2); Server.Transfer("Results.aspx"); }
public MyTwitterObj GetData(MyTwitterObj myTwitter) { DateTime dtm = new DateTime(); dtm = DateTime.Now; //first search: TwitterHelper helper1 = new TwitterHelper { search = myTwitter.search_1, max_id = 0, since_id = 0, count = 0 }; RootObject root = new RootObject(); root = GetTweets(helper1); while (root.statuses.Count > 0) { if (root.statuses.Count == Int32.Parse(ConfigurationManager.AppSettings["TwitterMaxResults"])) { // there are more tweets than we can process in one batch -- loop foreach (Status value in root.statuses) { helper1.count = helper1.count + value.retweet_count + 1; } helper1.max_id = root.statuses[99].id; // oldest tweet in collection root = GetTweets(helper1); } else { // there is less than the maximum amount of tweets -- no need to loop foreach (Status value in root.statuses) { helper1.count = helper1.count + value.retweet_count + 1; helper1.created = value.created_at; } break; } } //second search: TwitterHelper helper2 = new TwitterHelper { search = myTwitter.search_2, max_id = 0, since_id = 0, count = 0 }; root = new RootObject(); root = GetTweets(helper2); while (root.statuses.Count > 0) { if (root.statuses.Count == Int32.Parse(ConfigurationManager.AppSettings["TwitterMaxResults"])) { // there are more tweets than we can process in one batch -- loop foreach (Status value in root.statuses) { helper2.count = helper2.count + value.retweet_count + 1; } helper2.max_id = root.statuses[99].id; // oldest tweet in collection root = GetTweets(helper2); } else { // there is less than the maximum amount of tweets -- no need to loop foreach (Status value in root.statuses) { helper2.count = helper2.count + value.retweet_count + 1; helper2.created = value.created_at; } break; } } //return data MyTwitterObj RetTwitterObj = new MyTwitterObj(); RetTwitterObj.search_1 = myTwitter.search_1; RetTwitterObj.search_2 = myTwitter.search_2; RetTwitterObj.tweets_1 = helper1.count; RetTwitterObj.tweets_2 = helper2.count; if (helper1.created == null) { RetTwitterObj.seconds_1 = 0; } else { DateTime date1 = DateTime.ParseExact(helper1.created, "ddd MMM dd HH:mm:ss zzz yyyy", System.Globalization.CultureInfo.InvariantCulture); RetTwitterObj.seconds_1 = Convert.ToInt32((dtm - date1).TotalSeconds); } if (helper2.created == null) { RetTwitterObj.seconds_2 = 0; } else { DateTime date2 = DateTime.ParseExact(helper2.created, "ddd MMM dd HH:mm:ss zzz yyyy", System.Globalization.CultureInfo.InvariantCulture); RetTwitterObj.seconds_2 = Convert.ToInt32((dtm - date2).TotalSeconds); } return(RetTwitterObj); }