Exemplo n.º 1
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;
            }
        }
Exemplo n.º 2
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("---------------------------------------------------------------------------------------------------------------------------");

                        }));
                    }
                }
            }
        }