public void btn_FollowByKeyWordStart_Click(object sender, EventArgs e) { CheckNetConn = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable(); if (CheckNetConn) { if (!string.IsNullOrEmpty(txt_FollowBySearchKey.Text)) { objclsSettingDB.InsertOrUpdateSetting("Follower", "FollowBySearchKey", StringEncoderDecoder.Encode(txt_FollowBySearchKey.Text)); } if (IsFollowByKeyWordStart) { IsFollowByKeyWordStart = false; // new Thread(() => // { Dic_Thread.Clear(); Thread.CurrentThread.Name = "Thread_FollowByKeyword"; Dic_Thread.Add(Thread.CurrentThread.Name, Thread.CurrentThread); //TweetAccountManager TweetAccountManager = new TweetAccountManager(); //TwitterDataScrapper TwitterDataScrapper = new TwitterDataScrapper(); //int FollowLimitCounter = 0; //int AccountCounter = 0; FollowtweetKeywordList.ForEach(i => { searchkeywordqueue.Enqueue(i); }); int NoOfThreads = int.Parse(txtNoOfFollowThreads.Text); int DelayStart = 0; int DelayEnd = 0; bool _IsValue = false; _IsValue = int.TryParse((txtFollowMinDelay.Text), out DelayStart); if (!_IsValue) { IsFollowByKeyWordStart = true; return; } _IsValue = false; _IsValue = int.TryParse((txtFollowMaxDelay.Text), out DelayEnd); if (!_IsValue) { IsFollowByKeyWordStart = true; return; } string SeachKey = string.Empty; List<TwitterDataScrapper.StructTweetIDs> KeywordStructData = new List<TwitterDataScrapper.StructTweetIDs>(); TwitterDataScrapper TwitterDataScrapper = new TwitterDataScrapper(); if (FollowtweetKeywordList.Count != 0) { //TwitterDataScrapper.noOfRecords = int.Parse(txt_FollowByPerAccount.Text); txt_FollowByPerAccount.Invoke(new MethodInvoker(delegate { if (!string.IsNullOrEmpty(txt_FollowByPerAccount.Text)) { TwitterDataScrapper.noOfRecords = int.Parse(txt_FollowByPerAccount.Text); } else { TwitterDataScrapper.noOfRecords = 5; } })); if (!chk_followbysinglekeywordperaccount.Checked) { try { if (searchkeywordqueue.Count == 0) { return; } SeachKey = searchkeywordqueue.Dequeue().ToString();//FollowtweetKeywordList[counterThreadsFollowByKeyWord]; AddToLog_Follower("[ " + DateTime.Now + " ] => [ Start Scraping User for keyword= " + SeachKey + " ]"); KeywordStructData = TwitterDataScrapper.GetTweetData_New(SeachKey); if (KeywordStructData.Count == 0) { KeywordStructData = TwitterDataScrapper.NewKeywordStructData(SeachKey); } } catch (Exception) { } } else { //TwitterDataScrapper.logEvents.addToLogger += new EventHandler(logEvents_Follower_addToLogger); foreach (string SeachKey_item in FollowtweetKeywordList) { AddToLog_Follower("[ " + DateTime.Now + " ] => [ Start Scraping User for keyword= " + SeachKey_item + " . ]"); List<TwitterDataScrapper.StructTweetIDs> KeywordStructData1 = new List<TwitterDataScrapper.StructTweetIDs>(); int datacounter = 0; KeywordStructData1 = TwitterDataScrapper.NewKeywordStructData1(SeachKey_item); if (KeywordStructData1.Count == 0) { KeywordStructData1 = TwitterDataScrapper.KeywordStructData(SeachKey_item); } if (KeywordStructData1.Count == 0) { AddToLog_Follower("[ " + DateTime.Now + " ] => [ Key Word is not Exist/suspended. ]"); } foreach (var KeywordStructData1_item in KeywordStructData1) { if (datacounter == TwitterDataScrapper.noOfRecords) { break; } else { KeywordStructData.Add(KeywordStructData1_item); datacounter++; } } } } } else { MessageBox.Show("Please Upload Keywords"); //break; } List<List<TwitterDataScrapper.StructTweetIDs>> list_lstTargetUsers = new List<List<TwitterDataScrapper.StructTweetIDs>>(); int index = 0; if (chkUseDivide.Checked || IsUsingDivideData) { int splitNo = 0; if (rdBtnDivideEqually.Checked) { splitNo = KeywordStructData.Count / TweetAccountContainer.dictionary_TweetAccount.Count; } else if (rdBtnDivideByGivenNo.Checked) { if (!string.IsNullOrEmpty(txtScrapeNoOfUsers.Text) && NumberHelper.ValidateNumber(txtScrapeNoOfUsers.Text)) { int res = Convert.ToInt32(txtScrapeNoOfUsers.Text); splitNo = res;//listUserIDs.Count / res; } } if (splitNo == 0) { splitNo = RandomNumberGenerator.GenerateRandom(0, KeywordStructData.Count - 1); } list_lstTargetUsers = Split(KeywordStructData, splitNo); } if (TweetAccountContainer.dictionary_TweetAccount.Count > 0) { NoOfLoadAccount = TweetAccountContainer.dictionary_TweetAccount.Count; try { double Num; bool isNum = double.TryParse((txt_FollowByPerAccount.Text.Trim()), out Num); if (isNum) { AddToLog_Follower("[ " + DateTime.Now + " ] => [ Start process from follow by search keyword. ]"); ThreadPool.SetMaxThreads(NoOfThreads, 5); foreach (KeyValuePair<string, TweetAccountManager> item in TweetAccountContainer.dictionary_TweetAccount) { #region << Old Code >> //string profileUsername = string.Empty; //string profileUserpass = string.Empty; //profileUsername = item.Key; //profileUserpass = item.Value.Password; ////******search profile By keyWords //string SeachKey = string.Empty; //List<TwitterDataScrapper.StructTweetIDs> KeywordStructData = new List<TwitterDataScrapper.StructTweetIDs>(); //if (FollowtweetKeywordList.Count != 0) //{ // if (!chk_followbysinglekeywordperaccount.Checked) // { // try // { // SeachKey = FollowtweetKeywordList[AccountCounter]; // KeywordStructData = TwitterDataScrapper.GetTweetData_New(SeachKey); // if (KeywordStructData.Count == 0) // { // KeywordStructData = TwitterDataScrapper.NewKeywordStructData(SeachKey); // } // } // catch (Exception) // { // } // } // else // { // foreach (string SeachKey_item in FollowtweetKeywordList) // { // List<TwitterDataScrapper.StructTweetIDs> KeywordStructData1 = new List<TwitterDataScrapper.StructTweetIDs>(); // int datacounter = 0; // KeywordStructData1 = TwitterDataScrapper.NewKeywordStructData(SeachKey_item); // if (KeywordStructData1.Count == 0) // { // KeywordStructData1 = TwitterDataScrapper.KeywordStructData(SeachKey_item); // } // if (KeywordStructData1.Count == 0) // { // AddToLog_Follower("Key Word is not Exist/suspended."); // } // foreach (var KeywordStructData1_item in KeywordStructData1) // { // if (datacounter == int.Parse(txt_FollowByPerAccount.Text)) // { // break; // } // else // { // KeywordStructData.Add(KeywordStructData1_item); // datacounter++; // } // } // } // } //} //else //{ // MessageBox.Show("Please Upload Keywords"); // break; //} ////************* //try //{ // if (KeywordStructData.Count > 0) // { // TweetAccountManager AccountManager = (TweetAccountManager)item.Value; // AccountManager.logEvents.addToLogger += new EventHandler(logEvents_Follower_addToLogger); // int DelayStart = 0; // int DelayEnd = 0; // bool _IsValue = false; // _IsValue = int.TryParse((txtFollowMinDelay.Text), out DelayStart); // if (!_IsValue) // { // return; // } // _IsValue = false; // _IsValue = int.TryParse((txtFollowMaxDelay.Text), out DelayEnd); // if (!_IsValue) // { // return; // } // if (!AccountManager.IsLoggedIn) // { // AccountManager.Login(); // } // foreach (var item1 in KeywordStructData) // { // if (!chk_followbysinglekeywordperaccount.Checked) // { // //accordint to get Follow users limits // if (FollowLimitCounter >= (int.Parse(txt_FollowByPerAccount.Text))) // { // FollowLimitCounter = 0; // break; // } // else // { // FollowLimitCounter++; // } // } // //Get follow from user // string AccountId = item1.ID_Tweet_User; // ///Return if Suspended // if (AccountManager.AccountStatus == "Account Suspended") // { // AddToLog_Follower(profileUsername + " : Suspended"); // break; // } // else if ((AccountManager.globusHttpHelper.gResponse.ResponseUri.ToString().ToLower()).Contains("captcha")) // { // AddToLog_Follower(profileUsername + " : Asking for captcha."); // break; // } // getFollowUserBySearch(new object[] { AccountManager, AccountId }); // int Delay = RandomNumberGenerator.GenerateRandom(DelayStart, DelayEnd); // AddToLog_Follower("Delay :- " + Delay + " Seconds."); // Thread.Sleep(Delay); // } // } // else // { // //Message List is Empty // AddToLog_Follower("Key Word File is Empty or Wrong Formate"); // break; // } //} //catch (Exception) //{ //} //if (AccountCounter > TweetAccountContainer.dictionary_TweetAccount.Count) //{ // AccountCounter = 0; //} //else //{ // AccountCounter++; //} #endregion if (counterThreadsFollowByKeyWord >= NoOfThreads) { lock (lockerThreadsFollowByKeyWord) { Monitor.Wait(lockerThreadsFollowByKeyWord); } } if (chkUseDivide.Checked || IsUsingDivideData) { KeywordStructData = list_lstTargetUsers[index]; } //ThreadPool.QueueUserWorkItem(new WaitCallback(StartFollowByKeyWord), new object[] { item, DelayStart, DelayEnd }); Thread threadGetStartProcessForfollow = new Thread(StartFollowByKeyWord); threadGetStartProcessForfollow.Name = "Thread_FollowByKeyword" + "_" + item.Key; threadGetStartProcessForfollow.IsBackground = true; threadGetStartProcessForfollow.Start(new object[] { item, DelayStart, DelayEnd, KeywordStructData }); index++; Thread.Sleep(1000); } }//isNum If End else { MessageBox.Show("Please enter No of follow By per account"); AddToLog_Follower("[ " + DateTime.Now + " ] => [ Please enter No of follow By per account ]"); } } catch (Exception) { } finally { //if (FollowtweetKeywordList.Count == 0) //{ // AddToLog_Follower("Please Upload Keywords"); //} //else //{ // AddToLog_Follower("Follow By key Word Process is Finished."); //} } } else { MessageBox.Show("Please Upload Twitter Account"); AddToLog_Follower("[ " + DateTime.Now + " ] => [ Please Upload Twitter Account ]"); } IsFollowByKeyWordStart = true; // }).Start(); } } else { MessageBox.Show("Your Internet Connection is disabled ! or not working, Please Check Your Internet Connection..."); AddToLog_Follower("[ " + DateTime.Now + " ] => [ Your Internet Connection is disabled ! or not working, Please Check Your Internet Connection... ]"); } }