public void GetStartReply(Object parameters) { string CampaignName = string.Empty; try { Interlocked.Increment(ref counterThreadsCampaignReply); Tweeter.Tweeter tweeter = new Tweeter.Tweeter(); tweeter.logEvents.addToLogger += new EventHandler(logEvents_addToLogger); Array paramsArray = new object[10]; paramsArray = (Array)parameters; //get value from param KeyValuePair <string, MixedCampaignManager.classes.CampaignAccountManager> keyValue = (KeyValuePair <string, MixedCampaignManager.classes.CampaignAccountManager>)paramsArray.GetValue(0); string accKey = keyValue.Key; MixedCampaignManager.classes.CampaignAccountManager ReplyAccountManager = keyValue.Value; List <MixedCampaignManager.classes.CampTwitterDataScrapper.StructTweetIDs> lst_ReplyData = (List <MixedCampaignManager.classes.CampTwitterDataScrapper.StructTweetIDs>)paramsArray.GetValue(1); List <string> lst_ReplyMsgs = (List <string>)paramsArray.GetValue(2); bool _IsReplyParDay = (bool)paramsArray.GetValue(3); int _NoofReplyParDay = (int)paramsArray.GetValue(4); int _NoofReplyParAc = (int)paramsArray.GetValue(5); int DelayStar = (int)paramsArray.GetValue(6); int DelayEnd = (int)paramsArray.GetValue(7); CampaignName = (string)paramsArray.GetValue(8); //Get scheduler time and status if task is scheduled bool IsSchedulDaily = (bool)paramsArray.GetValue(9); DateTime SchedulerEndTime = (DateTime)paramsArray.GetValue(10); int MsgCounter = 0; //Add List Of Working thread //we are using this list when we stop/abort running camp processes.. try { MixedCampaignManager.classes.cls_variables.Lst_WokingThreads.Add(CampaignName + "_" + ReplyAccountManager.Username, Thread.CurrentThread); } catch (Exception) { } //get account logging if (!(CampaignManager.CampaignAccountsList.dictionary_CampaignAccounts).Keys.Contains(accKey)) { ReplyAccountManager.Login(); try { CampaignManager.CampaignAccountsList.dictionary_CampaignAccounts.Add(accKey, ReplyAccountManager); } catch { }; } else { try { ReplyAccountManager = null; bool values = (CampaignManager.CampaignAccountsList.dictionary_CampaignAccounts).TryGetValue(accKey, out ReplyAccountManager); } catch (Exception) { } } count_AccountForReply_CompleteMessage = CampaignManager.CampaignAccountsList.dictionary_CampaignAccounts.Count(); if (!ReplyAccountManager.IsLoggedIn || !ReplyAccountManager.IsNotSuspended) { return; } foreach (var lst_ReplyData_item in lst_ReplyData) { //Check Scheduled Task end time //If task is scheduled if (IsSchedulDaily) { if (SchedulerEndTime.Hour == DateTime.Now.Hour && DateTime.Now.Minute >= SchedulerEndTime.Minute) { _IsReplyProcessStart = true; new Thread(() => { frm_mixcampaignmanager frmcamp = new frm_mixcampaignmanager(); frmcamp.StoprunningCampaign(CampaignName); }).Start(); break; } } // foreach (string Msg in lst_ReplyMsgs) { string tweetId = lst_ReplyData_item.ID_Tweet; string tweetUsername = lst_ReplyData_item.username__Tweet_User; if (MsgCounter == lst_ReplyMsgs.Count) { MsgCounter = 0; } string Msg = lst_ReplyMsgs[MsgCounter]; string _wholeTweetMessage = lst_ReplyData_item.wholeTweetMessage; string tweetStatus; tweeter.Reply(ref ReplyAccountManager.globusHttpHelper, "", ReplyAccountManager.postAuthenticityToken, tweetId, tweetUsername, Msg, out tweetStatus); if (tweetStatus == "posted") { Log("[ " + DateTime.Now + " ] => [ Message :- " + Msg + " Tweet :- " + _wholeTweetMessage + " by " + keyValue.Key + " ]"); try { RepositoryClasses.ReportTableRepository.InsertReport(CampaignName, accKey, "", 0, tweetId, "", "", Msg); } catch (Exception) { } } else { Log("[ " + DateTime.Now + " ] => [ Status :- " + tweetStatus + " by " + keyValue.Key + " ]"); } int delay = BaseLib.RandomNumberGenerator.GenerateRandom(DelayStar * 1000, DelayEnd * 1000); Log("[ " + DateTime.Now + " ] => [ Delay :- " + TimeSpan.FromMilliseconds(delay).Seconds + " Seconds. ]"); Thread.Sleep(delay); MsgCounter++; } } } catch (Exception) { } finally { count_AccountForReply_CompleteMessage--; Interlocked.Decrement(ref counterThreadsCampaignReply); lock (lockerThreadsCampaignReply) { Monitor.Pulse(lockerThreadsCampaignReply); if (counterThreadsCampaignReply == 0) { RaiseCampaignFineshedEvent(CampaignName); Log("[ " + DateTime.Now + " ] => [ Process completed. ]"); Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(CampaignName + ": " + DateTime.Now, Globals.path_LogCampaignCompleted); } } } }
public void startRetweeting(object parameters) { Tweeter.Tweeter tweeter = new Tweeter.Tweeter(); tweeter.logEvents.addToLogger += new EventHandler(logEvents_addToLogger); string CampaignName = string.Empty; try { Interlocked.Increment(ref counterThreadsCampaignRetweet); Queue <MixedCampaignManager.classes.CampTwitterDataScrapper.StructTweetIDs> Queue_Struct_TweetData = new Queue <MixedCampaignManager.classes.CampTwitterDataScrapper.StructTweetIDs>(); int Tweetcounter = 0; //get all parems from object Array paramsArray = new object[2]; paramsArray = (Array)parameters; //get value from param KeyValuePair <string, MixedCampaignManager.classes.CampaignAccountManager> keyValue = (KeyValuePair <string, MixedCampaignManager.classes.CampaignAccountManager>)paramsArray.GetValue(0); string accKey = keyValue.Key; MixedCampaignManager.classes.CampaignAccountManager RetweetAccountManager = keyValue.Value; List <MixedCampaignManager.classes.CampTwitterDataScrapper.StructTweetIDs> lst_Struct_TweetData1 = (List <MixedCampaignManager.classes.CampTwitterDataScrapper.StructTweetIDs>)paramsArray.GetValue(1); bool IsRetweetParDay = (bool)paramsArray.GetValue(2); int NoofRetweetParDay = (int)paramsArray.GetValue(3); int NoofRetweetParAc = (int)paramsArray.GetValue(4); int minDelay = (int)paramsArray.GetValue(5); int maxDelay = (int)paramsArray.GetValue(6); CampaignName = (string)paramsArray.GetValue(7); //Get scheduler time and status if task is scheduled bool IsSchedulDaily = (bool)paramsArray.GetValue(8); DateTime SchedulerEndTime = (DateTime)paramsArray.GetValue(9); // Add list Value in Queue list ... lst_Struct_TweetData1.ForEach(acc => { Queue_Struct_TweetData.Enqueue(acc); }); //Add List Of Working thread //we are using this list when we stop/abort running camp processes.. try { MixedCampaignManager.classes.cls_variables.Lst_WokingThreads.Add(CampaignName + "_" + RetweetAccountManager.Username, Thread.CurrentThread); } catch (Exception) { } //get account logging if (!(CampaignManager.CampaignAccountsList.dictionary_CampaignAccounts).Keys.Contains(accKey)) { RetweetAccountManager.Login(); try { CampaignManager.CampaignAccountsList.dictionary_CampaignAccounts.Add(accKey, RetweetAccountManager); } catch { }; } else { try { RetweetAccountManager = null; bool values = (CampaignManager.CampaignAccountsList.dictionary_CampaignAccounts).TryGetValue(accKey, out RetweetAccountManager); } catch (Exception) { } } if (RetweetAccountManager.IsLoggedIn) { if (RetweetAccountManager.IsNotSuspended) { while (Queue_Struct_TweetData.Count > 0) { string tweetStatus = string.Empty; int delay = 0; if (Queue_Struct_TweetData.Count == 0) { break; } if (Tweetcounter == NoofRetweetParAc) { ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ Per account re-tweet limit has exceeded from " + keyValue.Key + " ]"); break; } //Check Scheduled Task end time //If task is scheduled if (IsSchedulDaily) { if (SchedulerEndTime.Hour == DateTime.Now.Hour && DateTime.Now.Minute >= SchedulerEndTime.Minute) { _IsReTweetProcessStart = true; new Thread(() => { frm_mixcampaignmanager frmcamp = new frm_mixcampaignmanager(); frmcamp.StoprunningCampaign(CampaignName); }).Start(); break; } } try { delay = RandomNumberGenerator.GenerateRandom((minDelay), (maxDelay)); } catch (Exception ex) { delay = 10; } MixedCampaignManager.classes.CampTwitterDataScrapper.StructTweetIDs TweetDetails = Queue_Struct_TweetData.Dequeue(); tweeter.ReTweet(ref RetweetAccountManager.globusHttpHelper, "", RetweetAccountManager.postAuthenticityToken, TweetDetails.ID_Tweet, "", out tweetStatus); if (tweetStatus == "posted") { Tweetcounter++; ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ >> Retweeted : >> " + TweetDetails.wholeTweetMessage + " by " + keyValue.Key + " ]"); try { RepositoryClasses.ReportTableRepository.InsertReport(CampaignName, accKey, "", 0, TweetDetails.ID_Tweet, "", TweetDetails.wholeTweetMessage, ""); } catch (Exception) { } } else { ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ >> Couldn't Retweet : >> " + TweetDetails.wholeTweetMessage + " by " + keyValue.Key + " ]"); } //ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ Delay :- " + TimeSpan.FromMilliseconds(delay).Seconds + " seconds ] "); ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ Delay :- " + delay + " seconds ]"); Thread.Sleep(delay * 1000); } } } } catch (Exception ex) { Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> startRetweeting() --> " + ex.Message, Globals.Path_TweetingErroLog); Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> startRetweeting() --> " + ex.Message, Globals.Path_TwtErrorLogs); } finally { tweeter.logEvents.addToLogger -= new EventHandler(logEvents_addToLogger); Interlocked.Decrement(ref counterThreadsCampaignRetweet); lock (lockerThreadsCamapignRetweet) { Monitor.Pulse(lockerThreadsCamapignRetweet); } if (counterThreadsCampaignRetweet == 0) { RaiseCampaignFineshedEvent(CampaignName); ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ PROCESS COMPLETED for Campaign " + CampaignName + " ]"); Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(CampaignName + ": " + DateTime.Now, Globals.path_LogCampaignCompleted); } } }
public void startRetweeting(object parameters) { Tweeter.Tweeter tweeter = new Tweeter.Tweeter(); tweeter.logEvents.addToLogger += new EventHandler(logEvents_addToLogger); string CampaignName = string.Empty; try { Interlocked.Increment(ref counterThreadsCampaignRetweet); Queue<MixedCampaignManager.classes.CampTwitterDataScrapper.StructTweetIDs> Queue_Struct_TweetData = new Queue<MixedCampaignManager.classes.CampTwitterDataScrapper.StructTweetIDs>(); int Tweetcounter = 0; //get all parems from object Array paramsArray = new object[2]; paramsArray = (Array)parameters; //get value from param KeyValuePair<string, MixedCampaignManager.classes.CampaignAccountManager> keyValue = (KeyValuePair<string, MixedCampaignManager.classes.CampaignAccountManager>)paramsArray.GetValue(0); string accKey = keyValue.Key; MixedCampaignManager.classes.CampaignAccountManager RetweetAccountManager = keyValue.Value; List<MixedCampaignManager.classes.CampTwitterDataScrapper.StructTweetIDs> lst_Struct_TweetData1 = (List<MixedCampaignManager.classes.CampTwitterDataScrapper.StructTweetIDs>)paramsArray.GetValue(1); bool IsRetweetParDay = (bool)paramsArray.GetValue(2); int NoofRetweetParDay = (int)paramsArray.GetValue(3); int NoofRetweetParAc = (int)paramsArray.GetValue(4); int minDelay = (int)paramsArray.GetValue(5); int maxDelay = (int)paramsArray.GetValue(6); CampaignName = (string)paramsArray.GetValue(7); //Get scheduler time and status if task is scheduled bool IsSchedulDaily = (bool)paramsArray.GetValue(8); DateTime SchedulerEndTime = (DateTime)paramsArray.GetValue(9); // Add list Value in Queue list ... lst_Struct_TweetData1.ForEach(acc => { Queue_Struct_TweetData.Enqueue(acc); }); //Add List Of Working thread //we are using this list when we stop/abort running camp processes.. try { MixedCampaignManager.classes.cls_variables.Lst_WokingThreads.Add(CampaignName + "_" + RetweetAccountManager.Username, Thread.CurrentThread); } catch (Exception) { } //get account logging if (!(CampaignManager.CampaignAccountsList.dictionary_CampaignAccounts).Keys.Contains(accKey)) { RetweetAccountManager.Login(); try { CampaignManager.CampaignAccountsList.dictionary_CampaignAccounts.Add(accKey, RetweetAccountManager); } catch { }; } else { try { RetweetAccountManager = null; bool values = (CampaignManager.CampaignAccountsList.dictionary_CampaignAccounts).TryGetValue(accKey, out RetweetAccountManager); } catch (Exception) { } } if (RetweetAccountManager.IsLoggedIn) { if (RetweetAccountManager.IsNotSuspended) { while (Queue_Struct_TweetData.Count > 0) { string tweetStatus = string.Empty; int delay = 0; if (Queue_Struct_TweetData.Count == 0) { break; } if (Tweetcounter == NoofRetweetParAc) { ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ Per account re-tweet limit has exceeded from " + keyValue.Key + " ]"); break; } //Check Scheduled Task end time //If task is scheduled if (IsSchedulDaily) { if (SchedulerEndTime.Hour == DateTime.Now.Hour && DateTime.Now.Minute >= SchedulerEndTime.Minute) { _IsReTweetProcessStart = true; new Thread(() => { frm_mixcampaignmanager frmcamp = new frm_mixcampaignmanager(); frmcamp.StoprunningCampaign(CampaignName); }).Start(); break; } } try { delay = RandomNumberGenerator.GenerateRandom((minDelay), (maxDelay)); } catch (Exception ex) { delay = 10; } MixedCampaignManager.classes.CampTwitterDataScrapper.StructTweetIDs TweetDetails = Queue_Struct_TweetData.Dequeue(); tweeter.ReTweet(ref RetweetAccountManager.globusHttpHelper, "", RetweetAccountManager.postAuthenticityToken, TweetDetails.ID_Tweet, "", out tweetStatus); if (tweetStatus == "posted") { Tweetcounter++; ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ >> Retweeted : >> " + TweetDetails.wholeTweetMessage + " by " + keyValue.Key + " ]"); try { RepositoryClasses.ReportTableRepository.InsertReport(CampaignName, accKey, "", 0, TweetDetails.ID_Tweet, "", TweetDetails.wholeTweetMessage, ""); } catch (Exception) { } } else { ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ >> Couldn't Retweet : >> " + TweetDetails.wholeTweetMessage + " by " + keyValue.Key + " ]"); } //ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ Delay :- " + TimeSpan.FromMilliseconds(delay).Seconds + " seconds ] "); ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ Delay :- " + delay + " seconds ]"); Thread.Sleep(delay * 1000); } } } } catch (Exception ex) { Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> startRetweeting() --> " + ex.Message, Globals.Path_TweetingErroLog); Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> startRetweeting() --> " + ex.Message, Globals.Path_TwtErrorLogs); } finally { tweeter.logEvents.addToLogger -= new EventHandler(logEvents_addToLogger); Interlocked.Decrement(ref counterThreadsCampaignRetweet); lock (lockerThreadsCamapignRetweet) { Monitor.Pulse(lockerThreadsCamapignRetweet); } if (counterThreadsCampaignRetweet == 0) { RaiseCampaignFineshedEvent(CampaignName); ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ PROCESS COMPLETED for Campaign "+CampaignName +" ]"); Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(CampaignName + ": " + DateTime.Now, Globals.path_LogCampaignCompleted); } } }
public void GetStartReply(Object parameters) { string CampaignName = string.Empty; try { Interlocked.Increment(ref counterThreadsCampaignReply); Tweeter.Tweeter tweeter = new Tweeter.Tweeter(); tweeter.logEvents.addToLogger += new EventHandler(logEvents_addToLogger); Array paramsArray = new object[10]; paramsArray = (Array)parameters; //get value from param KeyValuePair<string, MixedCampaignManager.classes.CampaignAccountManager> keyValue = (KeyValuePair<string, MixedCampaignManager.classes.CampaignAccountManager>)paramsArray.GetValue(0); string accKey = keyValue.Key; MixedCampaignManager.classes.CampaignAccountManager ReplyAccountManager = keyValue.Value; List<MixedCampaignManager.classes.CampTwitterDataScrapper.StructTweetIDs> lst_ReplyData = (List<MixedCampaignManager.classes.CampTwitterDataScrapper.StructTweetIDs>)paramsArray.GetValue(1); List<string> lst_ReplyMsgs = (List<string>)paramsArray.GetValue(2); bool _IsReplyParDay = (bool)paramsArray.GetValue(3); int _NoofReplyParDay = (int)paramsArray.GetValue(4); int _NoofReplyParAc = (int)paramsArray.GetValue(5); int DelayStar = (int)paramsArray.GetValue(6); int DelayEnd = (int)paramsArray.GetValue(7); CampaignName = (string)paramsArray.GetValue(8); //Get scheduler time and status if task is scheduled bool IsSchedulDaily = (bool)paramsArray.GetValue(9); DateTime SchedulerEndTime = (DateTime)paramsArray.GetValue(10); int MsgCounter = 0; //Add List Of Working thread //we are using this list when we stop/abort running camp processes.. try { MixedCampaignManager.classes.cls_variables.Lst_WokingThreads.Add(CampaignName + "_" + ReplyAccountManager.Username, Thread.CurrentThread); } catch (Exception) { } //get account logging if (!(CampaignManager.CampaignAccountsList.dictionary_CampaignAccounts).Keys.Contains(accKey)) { ReplyAccountManager.Login(); try { CampaignManager.CampaignAccountsList.dictionary_CampaignAccounts.Add(accKey, ReplyAccountManager); } catch { }; } else { try { ReplyAccountManager = null; bool values = (CampaignManager.CampaignAccountsList.dictionary_CampaignAccounts).TryGetValue(accKey, out ReplyAccountManager); } catch (Exception) { } } count_AccountForReply_CompleteMessage = CampaignManager.CampaignAccountsList.dictionary_CampaignAccounts.Count(); if (!ReplyAccountManager.IsLoggedIn || !ReplyAccountManager.IsNotSuspended) { return; } foreach (var lst_ReplyData_item in lst_ReplyData) { //Check Scheduled Task end time //If task is scheduled if (IsSchedulDaily) { if (SchedulerEndTime.Hour == DateTime.Now.Hour && DateTime.Now.Minute >= SchedulerEndTime.Minute) { _IsReplyProcessStart = true; new Thread(() => { frm_mixcampaignmanager frmcamp = new frm_mixcampaignmanager(); frmcamp.StoprunningCampaign(CampaignName); }).Start(); break; } } // foreach (string Msg in lst_ReplyMsgs) { string tweetId = lst_ReplyData_item.ID_Tweet; string tweetUsername = lst_ReplyData_item.username__Tweet_User; if (MsgCounter == lst_ReplyMsgs.Count) { MsgCounter = 0; } string Msg = lst_ReplyMsgs[MsgCounter]; string _wholeTweetMessage = lst_ReplyData_item.wholeTweetMessage; string tweetStatus; tweeter.Reply(ref ReplyAccountManager.globusHttpHelper, "", ReplyAccountManager.postAuthenticityToken, tweetId, tweetUsername, Msg, out tweetStatus); if (tweetStatus == "posted") { Log("[ " + DateTime.Now + " ] => [ Message :- " + Msg + " Tweet :- " + _wholeTweetMessage + " by " + keyValue.Key + " ]"); try { RepositoryClasses.ReportTableRepository.InsertReport(CampaignName, accKey, "", 0, tweetId, "", "", Msg); } catch (Exception) { } } else { Log("[ " + DateTime.Now + " ] => [ Status :- " + tweetStatus + " by " + keyValue.Key + " ]"); } int delay = BaseLib.RandomNumberGenerator.GenerateRandom(DelayStar * 1000, DelayEnd * 1000); Log("[ " + DateTime.Now + " ] => [ Delay :- " + TimeSpan.FromMilliseconds(delay).Seconds + " Seconds. ]"); Thread.Sleep(delay); MsgCounter++; } } } catch (Exception) { } finally { count_AccountForReply_CompleteMessage--; Interlocked.Decrement(ref counterThreadsCampaignReply); lock (lockerThreadsCampaignReply) { Monitor.Pulse(lockerThreadsCampaignReply); if (counterThreadsCampaignReply == 0) { RaiseCampaignFineshedEvent(CampaignName); Log("[ " + DateTime.Now + " ] => [ Process completed. ]"); Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(CampaignName + ": " + DateTime.Now, Globals.path_LogCampaignCompleted); } } } }