Пример #1
0
        //public void DeleteMessage(string line_to_delete)
        //{
        //    try
        //    {
        //        string search_text = line_to_delete;
        //        string old;
        //        string n = "";
        //        System.IO.StreamWriter sr = new System.IO.StreamWriter();
        //        while ((old = sr.Write()) != null)
        //        {
        //        }
        //        sr.Close();
        //        System.IO.File.WriteAllText(Globals.Path_tweetMessagePath, n);
        //    }
        //    catch (Exception ex)
        //    {
        //    }
        //}
        public void ReTweet(string tweetMessage, int minDelay, int maxDelay)
        {
            try
            {
                if (!IsLoggedIn)
                {
                    Login();
                }

                if (IsNotSuspended)
                {
                    if (IsLoggedIn)
                    {

                        int counter_Retweet = 0;

                        TwitterDataScrapper.StructTweetIDs item = new TwitterDataScrapper.StructTweetIDs();
                        while (que_lst_Struct_TweetData.Count > 0)
                        {
                            //foreach (TwitterDataScrapper.StructTweetIDs item in static_lst_Struct_TweetData)
                            //{
                            if (!RetweetPerDay)
                            {
                                if (counter_Retweet >= noOfRetweets)
                                {
                                    Log("[ " + DateTime.Now + " ] => [ " + counter_Retweet + " ReTweets Done For " + Username + " ]");
                                    break;
                                }
                            }
                            else if (RetweetPerDay)
                            {
                                if (AlreadyRetweeted >= NoOFRetweetPerDay)
                                {
                                    Log("[ " + DateTime.Now + " ] => [ Already Tweeted " + AlreadyRetweeted + " ]");
                                    break;
                                }
                            }

                            lock (locker_qque_lst_Struct_TweetData)
                            {
                                if (que_lst_Struct_TweetData.Count > 0)
                                {
                                    item = que_lst_Struct_TweetData.Dequeue();
                                }
                                else
                                {

                                }
                            }

                            string tweetStatus;

                            int delay = 10 * 1000;

                            try
                            {
                                //delay = RandomNumberGenerator.GenerateRandom(minDelay, maxDelay);
                                if (Globals.IsGlobalDelay && Globals.IsCheckValueOfDelay)
                                {
                                    delay = RandomNumberGenerator.GenerateRandom(Globals.MinGlobalDelay, Globals.MaxGlobalDelay);
                                }
                                else
                                {
                                    delay = RandomNumberGenerator.GenerateRandom(minDelay, maxDelay);
                                }
                            }
                            catch (Exception ex)
                            {
                                delay = 10;
                                GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager --  ReTweet()  -- " + Username + " --> " + ex.Message, Globals.Path_TweetAccountManager);
                            }

                            tweeter.ReTweet(ref globusHttpHelper, pgSrc_Profile, postAuthenticityToken, item.ID_Tweet, "", out tweetStatus);

                            if (tweetStatus == "posted")
                            {
                                counter_Retweet++;
                                AlreadyRetweeted++;
                                clsDBQueryManager DataBase = new clsDBQueryManager();
                                string dbTweetMessage = StringEncoderDecoder.Encode(item.wholeTweetMessage);
                                DataBase.InsertMessageData(Username, "ReTweet", item.ID_Tweet, dbTweetMessage);
                                Log("[ " + DateTime.Now + " ] => [ Retweeted " + counter_Retweet + ": >> " + item.username__Tweet_User + " by " + Username + " ]");
                                GlobusFileHelper.AppendStringToTextfileNewLine( item.username__Tweet_User + " by " + Username , Globals.path_RetweetInformation);
                            }
                            else
                            {
                                Log("[ " + DateTime.Now + " ] => [ >>Couldn't Retweet >> " + item.ID_Tweet_User + " by " + Username + " ]");
                                //GlobusFileHelper.AppendStringToTextfileNewLine("Retweeted " + counter_Retweet + ": >> " + item.username__Tweet_User + " by " + Username, Globals.path_RetweetInformation);
                            }

                            Log("[ " + DateTime.Now + " ] => [ Retweet Delayed for " + delay + " Seconds ]");
                            Thread.Sleep(delay * 1000);
                        }

                        Log("[ " + DateTime.Now + " ] => [ Finished Retweeting with : " + Username + " ]");
                        Log("------------------------------------------------------------------------------------------------------------------------------------------");
                    }
                    else
                    {
                        Log("[ " + DateTime.Now + " ] => [ Couldn't log in with " + Username + " ]");
                        GlobusFileHelper.AppendStringToTextfileNewLine(Username + ":" + Password + ":" + proxyAddress + ":" + proxyPort + ":" + proxyUsername + ":" + proxyPassword, Globals.path_FailedLoginAccounts);
                    }
                }
                else
                {
                    clsDBQueryManager database = new clsDBQueryManager();
                    database.UpdateSuspendedAcc(Username);
                    Log("[ " + DateTime.Now + " ] => [ " + Username + ">>Account Suspended ]");

                    return;
                }
            }
            catch (Exception ex)
            {
                GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager() - retweet --> " + ex.Message, Globals.Path_TweetingErroLog);
                GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager --  ReTweet()  -- " + Username + " --> " + ex.Message, Globals.Path_TweetAccountManager);
            }
        }
Пример #2
0
        public void Reply(string tweetMessage, int minDelay, int maxDelay)
        {
            //Login();
            List<string> lstTemp = new List<string>();
            //if (true)
            try
            {
                TwitterDataScrapper.StructTweetIDs TweeetData = new TwitterDataScrapper.StructTweetIDs();
                if (!IsLoggedIn)
                {
                    Login();
                }

                if (IsNotSuspended)
                {
                    if (IsLoggedIn)
                    {
                        int counter_Reply = 0;

                        //foreach (TwitterDataScrapper.StructTweetIDs item in static_lst_Struct_TweetData)
                        //{
                        //    List_of_struct_Keydatafrom_tweetData_list.Enqueue(item);

                        //TweeetData = List_of_struct_Keydatafrom_tweetData_list.Dequeue();

                        while (que_ReplyMessages.Count > 0)
                        {
                            int delay = 10 * 1000;
                            int counter = 0;

                            try
                            {
                                delay = RandomNumberGenerator.GenerateRandom(minDelay, maxDelay);
                            }
                            catch (Exception ex)
                            {
                                GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> Reply()-- delay  --> " + ex.Message, Globals.Path_TweetingErroLog);
                                GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager --  Reply()  -- " + Username + " --> " + ex.Message, Globals.Path_TweetAccountManager);
                            }
                            // Code for Sending unique Reply
                            // By Puja
                            lock (locker_que_ReplyTweetMessage)
                            {
                                //if (IsreplyUniqueTweet)
                                {
                                    if (que_ReplyMessages.Count > 0)
                                    {
                                        try
                                        {
                                            tweetMessage = que_ReplyMessages.Dequeue();
                                        }
                                        catch (Exception ex)
                                        {
                                            GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> Reply()-- locker_que_ReplyTweetMessage  --> " + ex.Message, Globals.Path_TweetingErroLog);
                                            GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager --  Reply()-- locker_que_ReplyTweetMessage -- " + Username + " --> " + ex.Message, Globals.Path_TweetAccountManager);
                                        }
                                    }
                                    else
                                    {
                                        Log("[ " + DateTime.Now + " ] => [ All Loaded Tweet Messages Used ]");
                                        //break;
                                    }
                                }

                                //Code by Puja
                                #region Code for Reply Per Tweet
                                //if (IsReplyPerTweet)
                                //{

                                //    if (lstTemp.Count == 0)
                                //    {
                                //        foreach (string item in que_ReplyMessages)
                                //        {
                                //            lstTemp.Add(item);

                                //        }
                                //    }
                                //    if (counter > lstTemp.Count - 1)
                                //    {
                                //        counter = 0;
                                //    }
                                //    tweetMessage = lstTemp[counter];
                                //    counter++;

                                //}
                                #endregion

                            }

                            lock (locker_que_keywyordStructData)
                            {
                                if (List_of_struct_Keydatafrom_tweetData_list.Count > 0)
                                {
                                    try
                                    {
                                        TweeetData = List_of_struct_Keydatafrom_tweetData_list.Dequeue();
                                    }
                                    catch (Exception ex)
                                    {
                                        GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> Reply()-- locker_que_ReplyTweetMessage  --> " + ex.Message, Globals.Path_TweetingErroLog);
                                        GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager --  Reply()-- locker_que_ReplyTweetMessage -- " + Username + " --> " + ex.Message, Globals.Path_TweetAccountManager);
                                    }
                                }
                                else
                                {

                                    TwitterDataScrapper tweetScrapper = new TwitterDataScrapper();
                                    TweetAccountManager.static_lst_Struct_TweetData = tweetScrapper.GetTweetData(ReplyKeyword);
                                    foreach (TwitterDataScrapper.StructTweetIDs item in TweetAccountManager.static_lst_Struct_TweetData)
                                    {
                                        TweetAccountManager.List_of_struct_Keydatafrom_tweetData_list.Enqueue(item);
                                    }
                                    TweeetData = List_of_struct_Keydatafrom_tweetData_list.Dequeue();

                                }
                            }

                            if (!ReplyPerDay)
                            {
                                if (counter_Reply >= noOfRetweets)
                                {
                                    Log("[ " + DateTime.Now + " ] => [ Finished Replying with : " + Username + " ]");
                                    Log("------------------------------------------------------------------------------------------------------------------------------------------");
                                    break;
                                }
                            }
                            else if (ReplyPerDay)
                            {
                                if (AlreadyReply >= NoOFReplyPerDay)
                                {
                                    Log("[ " + DateTime.Now + " ] => [ Already Replied " + AlreadyReply + " ]");
                                    break;
                                }
                            }

                            //if (counter_Reply >= noOfRetweets)
                            //{
                            //    //Log("Finished Replying with : " + Username);
                            //    break;
                            //}

                            string tweetStatus;

                            tweeter.Reply(ref globusHttpHelper, pgSrc_Profile, postAuthenticityToken, TweeetData.ID_Tweet, TweeetData.username__Tweet_User, tweetMessage, out tweetStatus);

                            if (tweetStatus == "posted")
                            {
                                counter_Reply++;
                                AlreadyReply++;
                                clsDBQueryManager DataBase = new clsDBQueryManager();
                                string dbTweetMessage = string.Empty;
                                try
                                {
                                     dbTweetMessage = StringEncoderDecoder.Encode(TweeetData.wholeTweetMessage);
                                }
                                catch { }
                                DataBase.InsertMessageData(Username, "Reply", TweeetData.ID_Tweet_User, dbTweetMessage);
                                Log("[ " + DateTime.Now + " ] => [ >> Replied : " + counter_Reply + " : " + tweetMessage + " by " + Username + " ]");
                                GlobusFileHelper.AppendStringToTextfileNewLine( tweetMessage + " by " + Username, Globals.path_ReplyInformation);
                            }
                            else
                            {
                                Log("[ " + DateTime.Now + " ] => [ >>Couldn't Reply >> " + tweetMessage + " by " + Username + " ]");
                                //GlobusFileHelper.AppendStringToTextfileNewLine(Username + ":" + Password + ":" + proxyAddress + ":" + proxyPort + ":" + proxyUsername + ":" + proxyPassword, Globals.path_FailedToFollowAccounts);
                            }

                            Log("[ " + DateTime.Now + " ] => [ Reply Delayed for " + delay + " Seconds ]");
                            Thread.Sleep(delay * 1000);

                            if (ReplyPerDay)
                            {
                                if (AlreadyReply >= NoOFReplyPerDay)
                                {
                                    Log("[ " + DateTime.Now + " ] => [ Finished Replying with : " + Username + " ]");
                                    Log("------------------------------------------------------------------------------------------------------------------------------------------");
                                    break;
                                }
                            }
                            else if (que_ReplyMessages.Count <= 0)
                            {
                                Log("[ " + DateTime.Now + " ] => [ Finished Replying with : " + Username + " ]");
                                Log("------------------------------------------------------------------------------------------------------------------------------------------");
                                break;
                            }
                        }

                        //Log("Finished Replying with : " + Username);
                    }

                    else
                    {
                        Log("[ " + DateTime.Now + " ] => [ Couldn't log in with " + Username + " ]");
                        GlobusFileHelper.AppendStringToTextfileNewLine(Username + ":" + Password + ":" + proxyAddress + ":" + proxyPort + ":" + proxyUsername + ":" + proxyPassword, Globals.path_FailedLoginAccounts);
                    }
                }
                else
                {
                    Log("[ " + DateTime.Now + " ] => [ " + Username + ">> Account Suspended ]");
                }
            }
            catch (Exception ex)
            {
                GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> Reply()  --> " + ex.Message, Globals.Path_TweetingErroLog);
                GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetAccountManager --  Reply() -- " + Username + " --> " + ex.Message, Globals.Path_TweetAccountManager);
            }
        }
Пример #3
0
        private void ThreadpoolMethod_Retweet(object parameters)
        {
            TweetAccountManager tweetAccountManager = new TweetAccountManager();
            try
            {
                Array paramsArray = new object[1];

                paramsArray = (Array)parameters;

                KeyValuePair<string, TweetAccountManager> keyValue = (KeyValuePair<string, TweetAccountManager>)paramsArray.GetValue(0);
                List<TwitterDataScrapper.StructTweetIDs> lst_DivideTweets = new List<TwitterDataScrapper.StructTweetIDs>();
                if (TweetAccountManager.IsRetweetDivideRetweet)
                {
                     lst_DivideTweets = (List<TwitterDataScrapper.StructTweetIDs>)paramsArray.GetValue(1);
                }
                tweetAccountManager = keyValue.Value;

                AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Starting ReTweet For Account : " + keyValue.Key + " ]");

                //Add to Threads Dictionary
                AddThreadToDictionary(strModule(Module.Retweet), tweetAccountManager.Username);
                try
                {
                    //Thread.CurrentThread.Name = "ReTweet_" + tweetAccountManager.Username;
                    //Thread.CurrentThread.IsBackground = true;
                    //dictionary_Threads.Add("ReTweet_" + tweetAccountManager.Username, Thread.CurrentThread);
                    AddThreadToDictionary(strModule(Module.Retweet), tweetAccountManager.Username);
                }
                catch { }

                //Create logger Event for lof MSg's .
                tweetAccountManager.logEvents.addToLogger += new EventHandler(logEvents_Tweet_addToLogger);
                //tweetAccountManager.logEvents.addToLogger += logEvents_Tweet_addToLogger;
                tweetAccountManager.tweeter.logEvents.addToLogger += logEvents_Tweet_addToLogger;

                if (GlobusRegex.ValidateNumber(txtMinDelay_Tweet.Text))
                {
                    retweetMinDealy = Convert.ToInt32(txtMinDelay_Tweet.Text);
                }
                if (GlobusRegex.ValidateNumber(txtMaxDelay_Tweet.Text))
                {
                    retweetMaxDealy = Convert.ToInt32(txtMaxDelay_Tweet.Text);
                }

                if (chkboxRetweetPerDay.Checked)
                {
                    TweetAccountManager.RetweetPerDay = true;
                    if (!string.IsNullOrEmpty(txtMaximumNoRetweet.Text) && NumberHelper.ValidateNumber(txtMaximumNoRetweet.Text))
                    {
                        TweetAccountManager.NoOFRetweetPerDay = Convert.ToInt32(txtMaximumNoRetweet.Text);
                    }
                    else
                    {
                        TweetAccountManager.NoOFRetweetPerDay = 10;
                        AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Setting Maximum No Of ReTweets Per Day as 10 ]");
                    }

                    clsDBQueryManager DbQueryManager = new clsDBQueryManager();
                    DataSet Ds = DbQueryManager.SelectMessageData(keyValue.Key, "ReTweet");

                    int TodayReTweet = Ds.Tables["tb_MessageRecord"].Rows.Count;
                    tweetAccountManager.AlreadyRetweeted = TodayReTweet;

                    if (TodayReTweet >= TweetAccountManager.NoOFRetweetPerDay)
                    {
                        AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Already Retweeted " + tweetAccountManager.AlreadyRetweeted + " ]");
                        return;
                    }
                }

                if (chkCheckDatabaseInEvery2Minutes.Checked == true || chkAutoFavorite.Checked == true)
                {
                    while (true)
                    {
                        try
                        {
                            string count_tweet = string.Empty;
                            string count_tweet1 = string.Empty;

                            TwitterDataScrapper tweetScrapper = new TwitterDataScrapper();
                            TwitterDataScrapper.StructTweetIDs item1 = new TwitterDataScrapper.StructTweetIDs();
                            TweetAccountManager.que_lst_Struct_TweetData.Clear();
                            Queue<TwitterDataScrapper.StructTweetIDs> tempQueue = new Queue<TwitterDataScrapper.StructTweetIDs>();
                            TwitterDataScrapper.noOfRecords = 1;
                            AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Searching tweets for  " + keyValue.Key + " ]");
                            count_tweet = tweetScrapper.countNoOfTweet(txtTweetKeyword.Text.Trim());

                        startAgain:

                            TweetAccountManager.static_lst_Struct_TweetData = tweetScrapper.TweetExtractor_ByUserName_New_New(txtTweetKeyword.Text.Trim());

                            int count = TweetAccountContainer.dictionary_TweetAccount.Count();
                            foreach (TwitterDataScrapper.StructTweetIDs item in TweetAccountManager.static_lst_Struct_TweetData)
                            {
                                //for (int i = 1; i <= count * TweetAccountManager.static_lst_Struct_TweetData.Count(); i++)
                                {
                                    TweetAccountManager.que_lst_Struct_TweetData.Enqueue(item);
                                    tempQueue.Enqueue(item);
                                }

                            }
                            try
                            {
                                if (TweetAccountManager.que_lst_Struct_TweetData.Count > 0)

                                {
                                    item1 = tempQueue.Dequeue();
                                }
                            }
                            catch (Exception ex)
                            {
                                ErrorLogger.AddToErrorLogText(ex.Message);
                                GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> ThreadpoolMethod_Retweet() --> " + ex.Message, Globals.Path_TweetingErroLog);
                                GlobusFileHelper.AppendStringToTextfileNewLine("Error --> ThreadpoolMethod_Retweet() --> " + ex.Message, Globals.Path_TwtErrorLogs);
                            }

                            try
                            {
                                clsDBQueryManager DbQueryManager = new clsDBQueryManager();
                                DataSet Ds = DbQueryManager.SelectMessageDataForRetweet(keyValue.Key, item1.ID_Tweet, "ReTweet");
                                int count_NO_RoWs = Ds.Tables[0].Rows.Count;
                                if (count_NO_RoWs == 0)
                                {
                                    if (chkCheckDatabaseInEvery2Minutes.Checked)
                                    {
                                        tweetAccountManager.ReTweet("", retweetMinDealy, retweetMaxDealy);
                                    }
                                    if (chkAutoFavorite.Checked && tweetAccountManager.IsNotSuspended && tweetAccountManager.IsLoggedIn)
                                    {
                                        string TUri = item1.ID_Tweet.ToString();
                                        AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Added To Favorite : " + TUri + " from " + tweetAccountManager.Username + " ]");
                                        FavoriteOfUrl(new object[] { TUri, keyValue, tweetAccountManager });
                                    }
                                }

                                AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Searching new tweets will start after 3 minutes from " + tweetAccountManager.Username + " ]");
                                Thread.Sleep(3 * 60 * 1000);
                                count_tweet1 = tweetScrapper.countNoOfTweet(txtTweetKeyword.Text.Trim());
                                if (Convert.ToInt32(count_tweet) == Convert.ToInt32(count_tweet1))
                                {
                                    TwitterDataScrapper.noOfRecords = 1;
                                }
                                else if (Convert.ToInt32(count_tweet1) > Convert.ToInt32(count_tweet))
                                {
                                    TwitterDataScrapper.noOfRecords = Convert.ToInt32(count_tweet1) - Convert.ToInt32(count_tweet);
                                }
                                else
                                {
                                    TwitterDataScrapper.noOfRecords = 1;
                                }
                                TweetAccountManager.static_lst_Struct_TweetData.Clear();
                                TweetAccountManager.que_lst_Struct_TweetData.Clear();
                                tempQueue.Clear();
                                count_tweet = count_tweet1;
                            }
                            catch (Exception ex)
                            {
                                ErrorLogger.AddToErrorLogText(ex.Message);
                                GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> ThreadpoolMethod_Retweet() --> " + ex.Message, Globals.Path_TweetingErroLog);
                                GlobusFileHelper.AppendStringToTextfileNewLine("Error --> ThreadpoolMethod_Retweet() --> " + ex.Message, Globals.Path_TwtErrorLogs);
                            }
                            goto startAgain;
                        }
                        catch (Exception ex)
                        {
                            ErrorLogger.AddToErrorLogText(ex.Message);
                            GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> ThreadpoolMethod_Retweet() --> " + ex.Message, Globals.Path_TweetingErroLog);
                            GlobusFileHelper.AppendStringToTextfileNewLine("Error --> ThreadpoolMethod_Retweet() --> " + ex.Message, Globals.Path_TwtErrorLogs);
                        }
                    }
                }
                else
                {

                    if (TweetAccountManager.IsRetweetDivideRetweet)
                    {
                        tweetAccountManager.ReTweetDivideRetweet(lst_DivideTweets, retweetMinDealy, retweetMaxDealy);
                    }
                    else
                    {
                        tweetAccountManager.ReTweet("", retweetMinDealy, retweetMaxDealy);
                    }
                }

                tweetAccountManager.logEvents.addToLogger -= logEvents_Tweet_addToLogger;
                tweetAccountManager.tweeter.logEvents.addToLogger -= logEvents_Tweet_addToLogger;
            }
            catch (Exception ex)
            {
                ErrorLogger.AddToErrorLogText(ex.Message);
                GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> ThreadpoolMethod_Retweet() --> " + ex.Message, Globals.Path_TweetingErroLog);
                GlobusFileHelper.AppendStringToTextfileNewLine("Error --> ThreadpoolMethod_Retweet() --> " + ex.Message, Globals.Path_TwtErrorLogs);
            }

            finally
            {
                tweetAccountManager.logEvents.addToLogger -= logEvents_Tweet_addToLogger;
                tweetAccountManager.tweeter.logEvents.addToLogger -= logEvents_Tweet_addToLogger;
            }
        }
Пример #4
0
        private void btnReplyBySpecificTweet_Click(object sender, EventArgs e)
        {
            try
            {
                using (System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog())
                {
                    ofd.Filter = "Text Files (*.txt)|*.txt";
                    ofd.InitialDirectory = Application.StartupPath;
                    if (ofd.ShowDialog() == DialogResult.OK)
                    {
                        txtTweetKeyword.Text = ofd.FileName;
                        lst_structTweetIDs = new List<TwitterDataScrapper.StructTweetIDs>();

                        lstReplyBySpecificTweet = GlobusFileHelper.ReadFiletoStringList(ofd.FileName);
                        TwitterDataScrapper.StructTweetIDs structTweetIDs = new TwitterDataScrapper.StructTweetIDs();
                        foreach (string item in lstReplyBySpecificTweet)
                        {
                            string _item = item + "@@@";

                            string tweetResult = getBetween(_item, "status/", "@@@");
                            string userResult = getBetween(_item, "twitter.com/", "/");
                            structTweetIDs.ID_Tweet = tweetResult;
                            structTweetIDs.username__Tweet_User = userResult;
                            lst_structTweetIDs.Add(structTweetIDs);
                        }

                        Console.WriteLine(lstReplyBySpecificTweet.Count + " Tweets loaded");
                        AddToLog_Tweet("[ " + DateTime.Now + " ] => [ " + lstReplyBySpecificTweet.Count + " Tweets loaded ]");
                    }
                }
            }
            catch
            {
            }
        }
Пример #5
0
        private void ThreadPoolMethod_Reply(object parameters)
        {
            try
            {
                Array paramsArray = new object[2];

                paramsArray = (Array)parameters;

                TweetAccountManager keyValue = (TweetAccountManager)paramsArray.GetValue(0);

                TweetAccountManager tweetAccountManager = keyValue;//keyValue.Value;

                //try
                //{
                //    dictionary_Threads.Add(tweetAccountManager.Username, Thread.CurrentThread);
                //}
                //catch { };

                //Add to Threads Dictionary
                AddThreadToDictionary(strModule(Module.Reply), tweetAccountManager.Username);

                tweetAccountManager.logEvents.addToLogger += new EventHandler(logEvents_Tweet_addToLogger);
                //tweetAccountManager.logEvents.addToLogger += logEvents_Tweet_addToLogger;
                tweetAccountManager.tweeter.logEvents.addToLogger += logEvents_Tweet_addToLogger;

                if (GlobusRegex.ValidateNumber(txtMinDelay_Tweet.Text))
                {
                    replyMinDealy = Convert.ToInt32(txtMinDelay_Tweet.Text);
                }
                if (GlobusRegex.ValidateNumber(txtMaxDelay_Tweet.Text))
                {
                    replyMaxDealy = Convert.ToInt32(txtMaxDelay_Tweet.Text);
                }

                if (chkboxReplyPerDay.Checked)
                {
                    TweetAccountManager.ReplyPerDay = true;
                    if (!string.IsNullOrEmpty(txtMaximumNoRetweet.Text) && NumberHelper.ValidateNumber(txtMaximumNoRetweet.Text))
                    {
                        TweetAccountManager.NoOFReplyPerDay = Convert.ToInt32(txtMaximumNoRetweet.Text);
                    }
                    else
                    {
                        TweetAccountManager.NoOFReplyPerDay = 10;
                        AddToTweetCreatorLogs("[ " + DateTime.Now + " ] => [ Adding Default Maximum No Of Retweet 10 ]");
                    }

                    clsDBQueryManager DbQueryManager = new clsDBQueryManager();
                    DataSet Ds = DbQueryManager.SelectMessageData(keyValue.Username, "Reply");

                    int TodayReply = Ds.Tables["tb_MessageRecord"].Rows.Count;
                    tweetAccountManager.AlreadyReply = TodayReply;
                    if (TodayReply >= TweetAccountManager.NoOFReplyPerDay)
                    {
                        AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Already Replied " + TodayReply + " ]");
                        return;
                    }
                }

                if (chkCheckDatabaseInEvery2Minutes.Checked == true)
                {
                    while (true)
                    {

                        TwitterDataScrapper tweetScrapper = new TwitterDataScrapper();
                        TwitterDataScrapper.StructTweetIDs item1 = new TwitterDataScrapper.StructTweetIDs();
                        TweetAccountManager.que_lst_Struct_TweetData.Clear();
                        Queue<TwitterDataScrapper.StructTweetIDs> tempQueue = new Queue<TwitterDataScrapper.StructTweetIDs>();
                        TwitterDataScrapper.noOfRecords = 1;
                        AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Searching tweets for  " + keyValue.Username + " ]");
                        TweetAccountManager.static_lst_Struct_TweetData = tweetScrapper.TweetExtractor_ByUserName_New_New(txtTweetKeyword.Text.Trim());

                        int count = TweetAccountContainer.dictionary_TweetAccount.Count();
                        foreach (TwitterDataScrapper.StructTweetIDs item in TweetAccountManager.static_lst_Struct_TweetData)
                        {
                            for (int i = 1; i <= count; i++)
                            {
                                TweetAccountManager.que_lst_Struct_TweetData.Enqueue(item);
                                tempQueue.Enqueue(item);
                            }

                        }
                        if (TweetAccountManager.que_lst_Struct_TweetData.Count > 0)
                        {
                            item1 = tempQueue.Dequeue();
                        }
                        clsDBQueryManager DbQueryManager = new clsDBQueryManager();
                        DataSet Ds = DbQueryManager.SelectMessageDataForRetweet(keyValue.Username, item1.ID_Tweet, "Reply");
                        int count_NO_RoWs = Ds.Tables[0].Rows.Count;
                        if (count_NO_RoWs == 0)
                        {
                            tweetAccountManager.Reply(listTweetMessages, replyMinDealy, replyMaxDealy);
                        }

                        AddToLog_Tweet("[ " + DateTime.Now + " ] => [ Search tweets after 3 minutes ");
                        Thread.Sleep(3 * 60 * 1000);

                    }
                }
                else
                {

                    tweetAccountManager.Reply("", replyMinDealy, replyMaxDealy);
                }

                tweetAccountManager.Reply("", replyMinDealy, replyMaxDealy);
                //tweetAccountManager.getmentions();
                tweetAccountManager.logEvents.addToLogger -= logEvents_Tweet_addToLogger;
                tweetAccountManager.tweeter.logEvents.addToLogger -= logEvents_Tweet_addToLogger;
            }
            catch (Exception ex)
            {
                ErrorLogger.AddToErrorLogText(ex.Message);
                GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> ThreadPoolMethod_Reply()  --> " + ex.Message, Globals.Path_TweetingErroLog);
                GlobusFileHelper.AppendStringToTextfileNewLine("Error --> ThreadPoolMethod_Reply() --> " + ex.Message, Globals.Path_TwtErrorLogs);
            }
            finally
            {
                counter_AccountFollwer--;

                if (counter_AccountFollwer == 0)
                {
                    if (btnStartFollowing.InvokeRequired)
                    {
                        btnStartReplying.Invoke(new MethodInvoker(delegate
                        {
                            AddToLog_Tweet("[ " + DateTime.Now + " ] => [ PROCESS COMPLETED ]");
                            AddToLog_Tweet("---------------------------------------------------------------------------------------------------------------------------");

                        }));
                    }
                }
            }
        }