Esempio n. 1
0
        public void StartProcess(String CampaignName, String featurName, DataRow CampRow)
        {
            try
            {
                string val = string.Empty;
                try
                {
                    try
                    {
                        val = CampRow["indx"].ToString();
                    }
                    catch { }
                    if (string.IsNullOrEmpty(val))
                    {
                        DataRow[] drModelDetails = null;

                        DataSet CompaignsDataSet = cls_variables.LoadCampaignTemp();
                        drModelDetails = CompaignsDataSet.Tables[0].Select("CampaignName = '" + CampaignName + "'");
                        try
                        {
                            //if (drModelDetails.Count() > 3)
                            {
                                CampRow = drModelDetails[0];
                            }
                        }
                        catch { };
                    }
                }
                catch { }

                //DataRow[] drModelDetails = CompaignsDataSet.Tables[0].Select("CampaignName = '" + CampaignName + "'");

                //if (drModelDetails.Count() == 0)
                //{

                //}

                //Get 1st row from arrey
                DataRow DrCampaignDetails = CampRow;

                //Set all Details

                string   AcFilePath         = DrCampaignDetails.ItemArray[2].ToString();
                string   FollowFilePath     = DrCampaignDetails.ItemArray[3].ToString();
                bool     divideEql          = (Convert.ToInt32(DrCampaignDetails.ItemArray[5]) == 1) ? true : false;
                bool     dividebyUser       = (Convert.ToInt32(DrCampaignDetails.ItemArray[6]) == 1) ? true : false;
                int      NoOfUsersDivid     = Convert.ToInt32(DrCampaignDetails.ItemArray[7]);
                bool     IsfastFollow       = (Convert.ToInt32(DrCampaignDetails.ItemArray[8]) == 1) ? true : false;
                int      NoOfFollowPerAc    = Convert.ToInt32(DrCampaignDetails.ItemArray[9]);
                bool     IsSchedulDaily     = (Convert.ToInt32(DrCampaignDetails.ItemArray[12]) == 1) ? true : false;
                DateTime SchedulerStartTime = Convert.ToDateTime(DrCampaignDetails.ItemArray[13].ToString());
                DateTime SchedulerEndTime   = Convert.ToDateTime(DrCampaignDetails.ItemArray[14].ToString());
                int      DelayStar          = Convert.ToInt32(DrCampaignDetails.ItemArray[15]);
                int      DelayEnd           = Convert.ToInt32(DrCampaignDetails.ItemArray[16]);
                int      NoOfThreads        = Convert.ToInt32(DrCampaignDetails.ItemArray[17]);

                List <string>         _lstUserAccounts    = new List <string>();
                List <string>         _lstFollowersName   = new List <string>();
                List <List <string> > list_lstTargetUsers = new List <List <string> >();



                classes.Cls_AccountsManager Obj_AccManger = new Cls_AccountsManager();


                //Check Files is existing...
                if (!File.Exists(FollowFilePath))
                {
                    Log("[ " + DateTime.Now + " ] => [ Followers Users File Doesn't Exixst. Please change account File. ]");
                    if (cls_variables.lstCampaignStartShedular.Contains(CampaignName))
                    {
                        try
                        {
                            cls_variables.lstCampaignStartShedular.Remove(CampaignName);
                        }
                        catch { };
                    }
                    return;
                }
                else if (!File.Exists(AcFilePath))
                {
                    Log("[ " + DateTime.Now + " ] => [ Account File Doesn't Exixst. Please change account File. ]");
                    if (cls_variables.lstCampaignStartShedular.Contains(CampaignName))
                    {
                        try
                        {
                            cls_variables.lstCampaignStartShedular.Remove(CampaignName);
                        }
                        catch { };
                    }
                    return;
                }


                // Get User ID and pass from File ...

                _lstUserAccounts = Globussoft.GlobusFileHelper.ReadLargeFile(AcFilePath);

                Log("[ " + DateTime.Now + " ] => [ " + _lstUserAccounts.Count + " Accounts is uploaded. ]");

                //Get Followers Name
                _lstFollowersName = Globussoft.GlobusFileHelper.ReadLargeFile(FollowFilePath);
                _lstFollowersName = _lstFollowersName.Distinct().ToList();
                Log("[ " + DateTime.Now + " ] => [ " + _lstFollowersName.Count + " Followers uploaded. ]");

                if (_lstFollowersName.Count == 0)
                {
                    Log("[ " + DateTime.Now + " ] => [ Please Upload correct Followers File. ]");
                    if (cls_variables.lstCampaignStartShedular.Contains(CampaignName))
                    {
                        try
                        {
                            cls_variables.lstCampaignStartShedular.Remove(CampaignName);
                        }
                        catch { };
                    }
                    if (MixedCampaignManager.classes.cls_variables.Lst_WokingThreads.ContainsKey(CampaignName))
                    {
                        MixedCampaignManager.classes.cls_variables.Lst_WokingThreads.Remove(CampaignName);
                    }
                    return;
                }

                CampaignTweetAccountContainer objCampaignFollowAccountContainer = Obj_AccManger.AccountManager(_lstUserAccounts);

                if (dividebyUser || divideEql)
                {
                    int splitNo = 0;
                    if (divideEql)
                    {
                        splitNo = _lstFollowersName.Count / _lstUserAccounts.Count;
                    }
                    else if (dividebyUser)
                    {
                        if (NoOfUsersDivid != 0)
                        {
                            int res = Convert.ToInt32(NoOfUsersDivid);
                            splitNo = res;
                        }
                    }
                    if (splitNo == 0)
                    {
                        splitNo = RandomNumberGenerator.GenerateRandom(0, _lstFollowersName.Count - 1);
                    }
                    list_lstTargetUsers = Split(_lstFollowersName, splitNo);
                }


                //create logger Event object for accessing log MSG's ..
                CustomUserControls.followusecontrols.CampaignFollowerLogEvents.addToLogger += new EventHandler(logEvents_addToLogger);

                //set Max thread
                ThreadPool.SetMaxThreads(NoOfThreads, NoOfThreads);

                int LstCounter = 0;
                foreach (var item in objCampaignFollowAccountContainer.dictionary_CampaignAccounts)
                {
                    try
                    {
                        //check list for breaking loop
                        //if list of follow members list is completed.
                        if (LstCounter == list_lstTargetUsers.Count && (dividebyUser || divideEql))
                        {
                            Log("[ " + DateTime.Now + " ] => [ Account is grater than List of users. ]");
                            break;
                        }

                        List <string> list_lstTargetUsers_item = new List <string>();

                        if (dividebyUser || divideEql)
                        {
                            list_lstTargetUsers_item = list_lstTargetUsers[LstCounter];
                        }
                        else
                        {
                            list_lstTargetUsers_item = _lstFollowersName;
                        }

                        //get event from accountmanager class
                        // and create Event for printing log messages
                        ((CampaignAccountManager)item.Value).logEvents.addToLogger += new EventHandler(logEvents_addToLogger);


                        //Manage no of threads
                        if (counterThreadsCampaignFollow >= NoOfThreads)
                        {
                            lock (lockerThreadsCampaignFollow)
                            {
                                Monitor.Wait(lockerThreadsCampaignFollow);
                            }
                        }

                        #region New Licencing Feature Added by Sonu

                        try
                        {
                            if (Globals.IsBasicVersion || Globals.IsProVersion || Globals.IsFreeVersion)
                            {
                                string  queryCheckDataBaseEmpty = "select * from tb_FBAccount";
                                DataSet DS1 = DataBaseHandler.SelectQuery(queryCheckDataBaseEmpty, "tb_FBAccount");
                                if (!(DS1.Tables[0].Rows.Count == 0))
                                {
                                    DataTable DT    = DS1.Tables[0];
                                    bool      check = DT.Select().Any(x => x.ItemArray[0].ToString() == item.Key);
                                    if (!check)
                                    {
                                        System.Windows.Forms.MessageBox.Show("Please Upload this Account in Account Manager");
                                        return;
                                    }
                                    else
                                    {
                                        Thread threadGetStartProcessForFollow = new Thread(GetStartProcessForFollow);
                                        threadGetStartProcessForFollow.Name         = CampaignName + "_" + item.Key;
                                        threadGetStartProcessForFollow.IsBackground = true;
                                        threadGetStartProcessForFollow.Start(new object[] { item, list_lstTargetUsers_item, NoOfFollowPerAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime, divideEql, dividebyUser, FollowFilePath });
                                    }
                                }
                                else
                                {
                                    System.Windows.Forms.MessageBox.Show("Please Upload this Account in Account Manager");
                                    return;
                                }
                            }
                            else
                            {
                                Thread threadGetStartProcessForFollow = new Thread(GetStartProcessForFollow);
                                threadGetStartProcessForFollow.Name         = CampaignName + "_" + item.Key;
                                threadGetStartProcessForFollow.IsBackground = true;
                                threadGetStartProcessForFollow.Start(new object[] { item, list_lstTargetUsers_item, NoOfFollowPerAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime, divideEql, dividebyUser, FollowFilePath });
                            }
                        }
                        catch { };

                        #endregion

                        #region Old Code
                        //Thread threadGetStartProcessForFollow = new Thread(GetStartProcessForFollow);
                        //threadGetStartProcessForFollow.Name = CampaignName + "_" + item.Key;
                        //threadGetStartProcessForFollow.IsBackground = true;
                        //threadGetStartProcessForFollow.Start(new object[] { item, list_lstTargetUsers_item, NoOfFollowPerAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime, divideEql, dividebyUser, FollowFilePath });

                        #endregion

                        Thread.Sleep(1000);

                        LstCounter++;
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
            }
        }
Esempio n. 2
0
        public void StartProcess(DataSet CompaignsDataSet, string CampaignName)
        {
            DataRow[] drModelDetails = CompaignsDataSet.Tables[0].Select("CampaignName = '" + CampaignName + "'");

            if (drModelDetails.Count() == 0)
            {
            }

            //Get 1st row from arrey
            DataRow DrCampaignDetails = drModelDetails[0];

            //get details from row
            string AcFilePath        = DrCampaignDetails.ItemArray[2].ToString();
            string _ReplyMsgfilePath = DrCampaignDetails.ItemArray[3].ToString();
            string _ReplyKeyword     = DrCampaignDetails.ItemArray[4].ToString();
            bool   _IsUsername       = (Convert.ToInt32(DrCampaignDetails.ItemArray[5]) == 1) ? true : false;
            bool   _IsUniqueMessage  = (Convert.ToInt32(DrCampaignDetails.ItemArray[19]) == 1) ? true : false;
            bool   _IsReplyParDay    = (Convert.ToInt32(DrCampaignDetails.ItemArray[8]) == 1) ? true : false;
            int    _NoofReplyParDay  = Convert.ToInt32(DrCampaignDetails.ItemArray[9]);
            int    _NoofReplyParAc   = Convert.ToInt32(DrCampaignDetails.ItemArray[10]);
            bool   IsSchedulDaily    = (Convert.ToInt32(DrCampaignDetails.ItemArray[12]) == 1) ? true : false;
            //bool IsSchedulDaily = (Convert.ToInt32(DrCampaignDetails.ItemArray[11]) == 1) ? true : false;
            DateTime SchedulerStartTime = Convert.ToDateTime(DrCampaignDetails.ItemArray[13].ToString());
            DateTime SchedulerEndTime   = Convert.ToDateTime(DrCampaignDetails.ItemArray[14].ToString());
            //int DelayStar = Convert.ToInt32(DrCampaignDetails.ItemArray[14]);
            //int DelayEnd = Convert.ToInt32(DrCampaignDetails.ItemArray[15]);
            //int NoOfThreads = Convert.ToInt32(DrCampaignDetails.ItemArray[16]);

            int  DelayStar          = Convert.ToInt32(DrCampaignDetails.ItemArray[15]);
            int  DelayEnd           = Convert.ToInt32(DrCampaignDetails.ItemArray[16]);
            int  NoOfThreads        = Convert.ToInt32(DrCampaignDetails.ItemArray[17]);
            bool IsDuplicateMessage = (Convert.ToInt32(DrCampaignDetails.ItemArray[22]) == 1) ? true : false;

            List <string> _lstUserAccounts = new List <string>();
            List <List <CampTwitterDataScrapper.StructTweetIDs> > list_lstTargetMessages = new List <List <CampTwitterDataScrapper.StructTweetIDs> >();

            classes.Cls_AccountsManager Obj_AccManger = new Cls_AccountsManager();

            //checking files
            if (!File.Exists(AcFilePath))
            {
                Log("[ " + DateTime.Now + " ] => [ Account file doesn't exist. Please Update new file in campaign " + CampaignName + " ]");
                return;
            }
            else if (!File.Exists(_ReplyMsgfilePath))
            {
                Log("[ " + DateTime.Now + " ] => [ reply Message file doesn't exist. Please Update new file in campaign " + CampaignName + " ]");
                return;
            }
            else if (!File.Exists(_ReplyKeyword))
            {
                Log("[ " + DateTime.Now + " ] => [ reply Keyword file doesn't exist. Please Update new file in campaign " + CampaignName + " ]");
                return;
            }

            // Get User ID and pass from File ...
            _lstUserAccounts = Globussoft.GlobusFileHelper.ReadLargeFile(AcFilePath);

            _lstUserAccounts = _lstUserAccounts.Distinct().ToList();

            if (_lstUserAccounts.Count == 0)
            {
                MessageBox.Show("Account File is Empty.");
                return;
            }

            if (string.IsNullOrEmpty(_ReplyKeyword))
            {
                MessageBox.Show("Reply keyword File is not mention.");
                return;
            }

            CampaignManager.CampaignTweetAccountContainer objCampaignReTweetAccountContainer = Obj_AccManger.AccountManager(_lstUserAccounts);

            Log("[ " + DateTime.Now + " ] => [ " + objCampaignReTweetAccountContainer.dictionary_CampaignAccounts.Count + " Accounts Uploaded. ]");


            //Get the Reply Messages from File path

            List <string> _lst_ReplyMessages    = new List <string>();
            List <string> _lst_ReplyKeywordFile = new List <string>();

            _lst_ReplyMessages = Globussoft.GlobusFileHelper.ReadLargeFile(_ReplyMsgfilePath);

            //_lst_ReplyMessages = _lst_ReplyMessages.Distinct().ToList();
            if (!IsDuplicateMessage)
            {
                _lst_ReplyMessages = _lst_ReplyMessages.Distinct().ToList();
            }


            if (IsDuplicateMessage == true)
            {
                #region
                int countDifference = _lstUserAccounts.Count - _lst_ReplyMessages.Count;

                if (countDifference != 0)
                {
                    List <string> TemList = new List <string>();
                    for (int i = 0; i < countDifference; i++)
                    {
                        try
                        {
                            TemList.Add(_lst_ReplyMessages[i]);
                        }
                        catch (Exception ex)
                        {
                            if (ex.Message.Contains("Index was out of range"))
                            {
                                i = 0;
                            }
                        }
                        if (TemList.Count == countDifference)
                        {
                            Log("[ " + DateTime.Now + " ] => [ " + countDifference + " Duplicate Messages Uploaded. ]");
                            _lst_ReplyMessages.AddRange(TemList);
                            break;
                        }
                    }
                }
                #endregion
            }
            else if ((!IsDuplicateMessage == true) && _lstUserAccounts.Count > _lst_ReplyMessages.Count)
            {
                if (_lst_ReplyMessages.Count > 0)
                {
                    //Log("[ " + DateTime.Now + " ] => [ Message is less than accounts ]");
                    //DialogResult dialogResult = MessageBox.Show("Message is less than accounts. Do you want to repeat remaining Messages.", "Warning", MessageBoxButtons.YesNo);
                    //if (dialogResult == DialogResult.Yes)
                    {
                        #region
                        int countDifference = _lstUserAccounts.Count - _lst_ReplyMessages.Count;

                        if (countDifference != 0)
                        {
                            List <string> TemList = new List <string>();
                            for (int i = 0; i < countDifference; i++)
                            {
                                try
                                {
                                    TemList.Add(_lst_ReplyMessages[i]);
                                }
                                catch (Exception ex)
                                {
                                    if (ex.Message.Contains("Index was out of range"))
                                    {
                                        // i = 0;
                                    }
                                }
                                if (TemList.Count == countDifference)
                                {
                                    Log("[ " + DateTime.Now + " ] => [ " + countDifference + " Duplicate Messages Uploaded. ]");
                                    _lst_ReplyMessages.AddRange(TemList);
                                    break;
                                }
                            }
                        }
                        #endregion
                    }
                    //else
                    //{
                    //}
                }
            }


            _lst_ReplyKeywordFile = Globussoft.GlobusFileHelper.ReadLargeFile(_ReplyKeyword);
            _lst_ReplyKeywordFile = _lst_ReplyKeywordFile.Distinct().ToList();

            if (_lst_ReplyKeywordFile.Count == 0)
            {
                MessageBox.Show("Reply Keyword File is Empty.");
                return;
            }

            if (_lst_ReplyMessages.Count == 0)
            {
                MessageBox.Show("Tweet Message File is Empty.");
                return;
            }


            //Add remaining messages
            if (_lstUserAccounts.Count > _lst_ReplyMessages.Count)
            {
                Log("[ " + DateTime.Now + " ] => [ Message is less than accounts ]");
                DialogResult dialogResult = MessageBox.Show("Message is less than accounts. Do you want to repeat remaining Messages.", "Warning", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    #region
                    int countDifference = _lstUserAccounts.Count - _lst_ReplyMessages.Count;

                    if (countDifference != 0)
                    {
                        List <string> TemList = new List <string>();
                        for (int i = 0; i < countDifference; i++)
                        {
                            try
                            {
                                TemList.Add(_lst_ReplyMessages[i]);
                            }
                            catch (Exception ex)
                            {
                                if (ex.Message.Contains("Index was out of range"))
                                {
                                    i = 0;
                                }
                            }
                            if (TemList.Count == countDifference)
                            {
                                Log("[ " + DateTime.Now + " ] => [ " + countDifference + " Duplicate Messages Uploaded. ]");
                                _lst_ReplyMessages.AddRange(TemList);
                                break;
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    #region Puja
                    //int count = _lst_ReplyMessages.Count;
                    //Queue<string> queUserAccount = new Queue<string>();
                    //Queue<string> queReplyMessages = new Queue<string>();
                    //for (int i = 0; i < count; i++)
                    //{
                    //    try
                    //    {
                    //        queUserAccount.Enqueue(_lstUserAccounts[i].ToString());
                    //    }
                    //    catch { }
                    //}
                    //foreach (string item in _lst_ReplyMessages)
                    //{
                    //    try
                    //    {
                    //        queReplyMessages.Enqueue(item);
                    //    }
                    //    catch
                    //    { }
                    //}

                    //_lstUserAccounts.Clear();

                    ////  queUserAccount.Dequeue(_lstUserAccounts(_item));



                    //foreach (string _item in queUserAccount)
                    //{
                    //    try
                    //    {
                    //        _lstUserAccounts.Add(queUserAccount.Dequeue());
                    //    }
                    //    catch
                    //    { }
                    //}
                    #endregion
                }
            }

            Log("[ " + DateTime.Now + " ] => [ " + _lst_ReplyMessages.Count + " Reply Messages uploaded. ]");

            //get All tweets from entered user name
            //Scrap Tweets using Username

            List <CampTwitterDataScrapper.StructTweetIDs> lst_Struct_ReplyData = new List <CampTwitterDataScrapper.StructTweetIDs>();

            List <CampTwitterDataScrapper.StructTweetIDs> lst_Struct_ReplyDataTemp = new List <CampTwitterDataScrapper.StructTweetIDs>();

            CampTwitterDataScrapper CamptweetScrapper = new CampTwitterDataScrapper();

            int noOfRecordsForUniqueMessage = (_NoofReplyParAc * (objCampaignReTweetAccountContainer.dictionary_CampaignAccounts.Count));
            //List<string> _lstTweetMessageForUnique = new List<string>();
            int splitNo = 0;
            //Get details according to enter keyword is user name or keyword

            CamptweetScrapper.noOfRecords = (_NoofReplyParAc * (objCampaignReTweetAccountContainer.dictionary_CampaignAccounts.Count));

            Log("[ " + DateTime.Now + " ] => [ Getting  tweets. ]");
            foreach (string _ReplyKeywordTemp in _lst_ReplyKeywordFile)
            {
                if (_IsUsername)
                {
                    lst_Struct_ReplyDataTemp = CamptweetScrapper.TweetExtractor_ByUserName_New(_ReplyKeywordTemp);
                }

                else
                {
                    lst_Struct_ReplyDataTemp = CamptweetScrapper.GetTweetData_New_ForCampaign(_ReplyKeywordTemp, _NoofReplyParAc);
                }

                lst_Struct_ReplyData.AddRange(lst_Struct_ReplyDataTemp);
            }

            if (_IsUniqueMessage)
            {
                // lst_Struct_ReplyDataTemp = CamptweetScrapper.GetTweetData_New_ForCampaign(_ReplyKeywordTemp, noOfRecordsForUniqueMessage);

                splitNo = lst_Struct_ReplyData.Count / _lstUserAccounts.Count;
                if (splitNo == 0)
                {
                    splitNo = RandomNumberGenerator.GenerateRandom(0, lst_Struct_ReplyData.Count - 1);
                }
                list_lstTargetMessages = Split(lst_Struct_ReplyData, splitNo);
            }


            Log("[ " + DateTime.Now + " ] => [ Tweet found process completed. ]");
            if (lst_Struct_ReplyData.Count == 0)
            {
                Log("[ " + DateTime.Now + " ] => [ " + lst_Struct_ReplyData.Count + " Tweet Founded. ]");
                MessageBox.Show("No records Found from " + _ReplyKeyword + " Keywords.");
                return;
            }
            else
            {
                Log("[ " + DateTime.Now + " ] => [ " + lst_Struct_ReplyData.Count + " Tweet Founded. ]");
            }


            int LstCounter = 0;
            foreach (var Account in objCampaignReTweetAccountContainer.dictionary_CampaignAccounts)
            {
                ((CampaignAccountManager)Account.Value).logEvents.addToLogger += new EventHandler(logEvents_addToLogger);

                //ThreadPool.QueueUserWorkItem(new WaitCallback(GetStartReply), new object[] { Account, lst_Struct_ReplyData, _lst_ReplyMessages, _IsReplyParDay, _NoofReplyParDay, _NoofReplyParAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime });
                //GetStartReply(new object[] { Account, lst_Struct_ReplyData, _lst_ReplyMessages, _IsReplyParDay, _NoofReplyParDay, _NoofReplyParAc, DelayStar, DelayEnd, CampaignName });
                if (LstCounter == list_lstTargetMessages.Count && (_IsUniqueMessage))
                {
                    Log("[ " + DateTime.Now + " ] => [ Account is greater than List of tweets. ]");
                    break;
                }

                if (_IsUniqueMessage)
                {
                    lst_Struct_ReplyData = list_lstTargetMessages[LstCounter];
                }


                if (counterThreadsCampaignReply >= NoOfThreads)
                {
                    lock (lockerThreadsCampaignReply)
                    {
                        Monitor.Wait(lockerThreadsCampaignReply);
                    }
                }

                #region New Licensing Feature Added By Sonu
                try
                {
                    if (Globals.IsBasicVersion || Globals.IsProVersion || Globals.IsFreeVersion)
                    {
                        string  queryCheckDataBaseEmpty = "select * from tb_FBAccount";
                        DataSet DS1 = DataBaseHandler.SelectQuery(queryCheckDataBaseEmpty, "tb_FBAccount");
                        if (!(DS1.Tables[0].Rows.Count == 0))
                        {
                            DataTable DT    = DS1.Tables[0];
                            bool      check = DT.Select().Any(x => x.ItemArray[0].ToString() == Account.Key);
                            if (!check)
                            {
                                System.Windows.Forms.MessageBox.Show("Please Upload this Account in Account Manager");
                                return;
                            }
                            else
                            {
                                Thread threadGetStartProcessForReply = new Thread(GetStartReply);
                                threadGetStartProcessForReply.Name         = CampaignName + "_" + Account.Key;
                                threadGetStartProcessForReply.IsBackground = true;
                                threadGetStartProcessForReply.Start(new object[] { Account, lst_Struct_ReplyData, _lst_ReplyMessages, _IsReplyParDay, _NoofReplyParDay, _NoofReplyParAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime });
                            }
                        }
                        else
                        {
                            System.Windows.Forms.MessageBox.Show("Please Upload this Account in Account Manager");
                            return;
                        }
                    }
                    else
                    {
                        Thread threadGetStartProcessForReply = new Thread(GetStartReply);
                        threadGetStartProcessForReply.Name         = CampaignName + "_" + Account.Key;
                        threadGetStartProcessForReply.IsBackground = true;
                        threadGetStartProcessForReply.Start(new object[] { Account, lst_Struct_ReplyData, _lst_ReplyMessages, _IsReplyParDay, _NoofReplyParDay, _NoofReplyParAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime });
                    }
                }
                catch { };
                #endregion

                #region old Code
                //Thread threadGetStartProcessForReply = new Thread(GetStartReply);
                //threadGetStartProcessForReply.Name = CampaignName + "_" + Account.Key;
                //threadGetStartProcessForReply.IsBackground = true;
                //threadGetStartProcessForReply.Start(new object[] { Account, lst_Struct_ReplyData, _lst_ReplyMessages, _IsReplyParDay, _NoofReplyParDay, _NoofReplyParAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime });
                #endregion

                Thread.Sleep(1000);
                LstCounter++;
            }
        }
        public void startTweeting(String CampaignName, String featurName, DataRow CampRow)
        {
            //Get 1st row from arrey

            try
            {

                string val = string.Empty;
                try
                {
                    try
                    {
                        val = CampRow["indx"].ToString();
                    }
                    catch { }
                    if (string.IsNullOrEmpty(val))
                    {

                        DataRow[] drModelDetails = null;

                        DataSet CompaignsDataSet = cls_variables.LoadCampaignTemp();
                        drModelDetails = CompaignsDataSet.Tables[0].Select("CampaignName = '" + CampaignName + "'");
                        try
                        {
                            //if (drModelDetails.Count() > 3)
                            {
                                CampRow = drModelDetails[0];
                            }
                        }
                        catch { };
                    }

                }
                catch { };
                DataRow DrCampaignDetails = CampRow;

                //Get all Details from Row
                string AcFilePath = DrCampaignDetails.ItemArray[2].ToString();
                string TweetFilePath = DrCampaignDetails.ItemArray[3].ToString();
                string TweetImageFolderPath = DrCampaignDetails.ItemArray[4].ToString();
                bool IsDuplicatMsg = (Convert.ToInt32(DrCampaignDetails.ItemArray[5]) == 1) ? true : false;
                bool IsAllTweetParAc = (Convert.ToInt32(DrCampaignDetails.ItemArray[6]) == 1) ? true : false;
                bool IsHashTag = (Convert.ToInt32(DrCampaignDetails.ItemArray[7]) == 1) ? true : false;
                bool IsTweetParDey = (Convert.ToInt32(DrCampaignDetails.ItemArray[8]) == 1) ? true : false;
                int NoOfTweetPerday = Convert.ToInt32(DrCampaignDetails.ItemArray[9]);
                int NoOfTweetPerAc = Convert.ToInt32(DrCampaignDetails.ItemArray[10]);
                bool IsTweetWithImage = (Convert.ToInt32(DrCampaignDetails.ItemArray[11]) == 1) ? true : false;
                bool IsSchedulDaily = (Convert.ToInt32(DrCampaignDetails.ItemArray[12]) == 1) ? true : false;
                DateTime SchedulerStartTime = Convert.ToDateTime(DrCampaignDetails.ItemArray[13].ToString());
                DateTime SchedulerEndTime = Convert.ToDateTime(DrCampaignDetails.ItemArray[14].ToString());
                int DelayStar = Convert.ToInt32(DrCampaignDetails.ItemArray[15]);
                int DelayEnd = Convert.ToInt32(DrCampaignDetails.ItemArray[16]);
                int NoOfThreads = Convert.ToInt32(DrCampaignDetails.ItemArray[17]);
                string UserListFilePath = DrCampaignDetails.ItemArray[20].ToString();
                bool IsUserList = (Convert.ToInt32(DrCampaignDetails.ItemArray[21]) == 1) ? true : false;

                bool IsTweetMentionUserScrapedList = (Convert.ToInt32(DrCampaignDetails.ItemArray[23]) == 1) ? true : false;
                string TweetMentionUserNameScrapedList = DrCampaignDetails.ItemArray[24].ToString();
                bool IsTweetFollowerScrapedList = (Convert.ToInt32(DrCampaignDetails.ItemArray[25]) == 1) ? true : false;
                bool IsTweetFollowingScrapedList = (Convert.ToInt32(DrCampaignDetails.ItemArray[26]) == 1) ? true : false;
                int NoOfTweetMentionUserScrapedList = Convert.ToInt32(DrCampaignDetails.ItemArray[27]);
                int NoOfTweetScrapedUserScrapedLIst = Convert.ToInt32(DrCampaignDetails.ItemArray[28]);

                List<string> _lstTweetMsg = new List<string>();
                List<string> _lstTweetImages = new List<string>();
                List<string> _lstUserAccounts = new List<string>();
                List<string> _lstUserListForMsg = new List<string>();
                List<string> lst_structTweetFollowersIDs = new List<string>();
                List<string> lst_structTweetFollowingsIds = new List<string>();
                GlobusHttpHelper globusHttpHelper = new GlobusHttpHelper();

                classes.Cls_AccountsManager Obj_AccManger = new Cls_AccountsManager();

                //Check Files is existing...
                //if (File.Exists(TweetFilePath))
                //if (!File.Exists(TweetFilePath))
                //{
                //    Log("[ " + DateTime.Now + " ] => [ Tweet Message File Doesn't Exixst. Please change account File. ]");
                //    return;
                //}
                lock (this)
                {
                    if (IsHashTag)
                    {
                        if (Globals.HashTags.Count == 0)
                        {
                            Log("[ " + DateTime.Now + " ] => [ No Hash Tags In List. To get Hash Tags Please check Use Hash tags Checkbox and Click getHashTag button ]");
                            MessageBox.Show("No Hash Tags In List. To get Hash Tags Please check Use Hash tags Checkbox and Click getHashTag button");
                            return;
                        }
                    }

                    if (!File.Exists(AcFilePath))
                    {
                        Log("[ " + DateTime.Now + " ] => [ Account File Doesn't Exixst. Please change account File. ]");
                        return;
                    }

                    ///Get Followers and Follwing from scraping
                    ///

                    #region Follwers and following
                    if (IsTweetMentionUserScrapedList && !string.IsNullOrEmpty(TweetMentionUserNameScrapedList))
                    {
                        CampTwitterDataScrapper CamptweetScrapper = new CampTwitterDataScrapper();
                        string ReturnStatus = string.Empty;
                        CamptweetScrapper.CounterDataNo = NoOfTweetScrapedUserScrapedLIst;
                        Globals.IsMobileVersion = true;
                        if (IsTweetFollowerScrapedList)
                        {
                            Log("[ " + DateTime.Now + " ] => [ Scraping Followers ]");
                            lst_structTweetFollowersIDs = CamptweetScrapper.GetFollowers_New_ForMobileVersion(TweetMentionUserNameScrapedList.Trim(), out ReturnStatus);
                            Log("[ " + DateTime.Now + " ] => [ Followers Scrapped  : " + lst_structTweetFollowersIDs.Count + "]");

                            if (lst_structTweetFollowersIDs.Count > 0)
                            {
                                foreach (string item in lst_structTweetFollowersIDs)
                                {
                                    string userid = item.Split(':')[1];
                                    _lstUserListForMsg.Add(userid);
                                }

                                if (lst_structTweetFollowersIDs.Count > 0)
                                {
                                    //listUserIDs.AddRange(lst_structTweetFollowersIDs);
                                    Log("[ " + DateTime.Now + " ] => [ Added " + lst_structTweetFollowersIDs.Count + " Followers from User: "******" ]");
                                    Log("[ " + DateTime.Now + " ] => [ Data Exported to " + Globals.Path_ScrapedFollowersList);
                                }

                            }
                        }
                        if (IsTweetFollowingScrapedList)
                        {
                            Log("[ " + DateTime.Now + " ] => [ Scraping Following ]");
                            lst_structTweetFollowersIDs = CamptweetScrapper.GetFollowings_NewForMobileVersion(TweetMentionUserNameScrapedList.Trim(), out ReturnStatus);
                            Log("[ " + DateTime.Now + " ] => [ Following Scrapped : " + lst_structTweetFollowersIDs.Count + "]");
                            if (lst_structTweetFollowersIDs.Count > 0)
                            {
                                foreach (string item in lst_structTweetFollowersIDs)
                                {
                                    string userid = item.Split(':')[1];
                                    _lstUserListForMsg.Add(userid);
                                }

                                if (lst_structTweetFollowersIDs.Count > 0)
                                {
                                    //listUserIDs.AddRange(lst_structTweetFollowersIDs);
                                    Log("[ " + DateTime.Now + " ] => [ Added " + lst_structTweetFollowersIDs.Count + " Followers from User: "******" ]");
                                    Log("[ " + DateTime.Now + " ] => [ Data Exported to " + Globals.Path_ScrapedFollowersList);
                                }

                            }
                        }
                        Globals.IsMobileVersion = false;
                        if (_lstUserListForMsg.Count == 0)
                        {
                            Log("[ " + DateTime.Now + " ] => [ Failed to Scrap Following or Followers ]");
                            if (cls_variables.lstCampaignStartShedular.Contains(CampaignName))
                            {
                                try
                                {
                                    cls_variables.lstCampaignStartShedular.Remove(CampaignName);
                                }
                                catch { };
                                if (MixedCampaignManager.classes.cls_variables.Lst_WokingThreads.ContainsKey(CampaignName))
                                {
                                    MixedCampaignManager.classes.cls_variables.Lst_WokingThreads.Remove(CampaignName);
                                }
                                RaiseCampaignFineshedEvent(CampaignName);
                            }
                            return;
                        }

                    }
                    #endregion

                    /// Get User ID and pass from File ...
                    _lstUserAccounts = Globussoft.GlobusFileHelper.ReadLargeFile(AcFilePath);

                    _lstUserAccounts = _lstUserAccounts.Distinct().ToList();
                    countTweetMessageAccount = _lstUserAccounts.Count;

                    if (_lstUserAccounts.Count == 0)
                    {
                        MessageBox.Show("Account File is Empty.");
                        if (cls_variables.lstCampaignStartShedular.Contains(CampaignName))
                        {
                            try
                            {
                                cls_variables.lstCampaignStartShedular.Remove(CampaignName);
                            }
                            catch { };

                        }
                        return;
                    }

                    ///Get Followers Name
                    if (File.Exists(TweetFilePath))
                    {
                        _lstTweetMsg = Globussoft.GlobusFileHelper.ReadLargeFileForSpinnedMessage(TweetFilePath);

                        //_lstTweetMsg = _lstTweetMsg.Distinct().ToList();

                        if (_lstTweetMsg.Count == 0)
                        {
                            MessageBox.Show("Tweet Message File is Empty.");
                            if (cls_variables.lstCampaignStartShedular.Contains(CampaignName))
                            {
                                try
                                {
                                    cls_variables.lstCampaignStartShedular.Remove(CampaignName);
                                }
                                catch { };
                            }
                            return;
                        }
                    }

                    if (IsUserList)
                    {
                        if (File.Exists(UserListFilePath))
                        {
                            _lstUserListForMsg = Globussoft.GlobusFileHelper.ReadLargeFileForSpinnedMessage(UserListFilePath);

                        }
                    }

                    if (!IsDuplicatMsg)
                    {
                        _lstTweetMsg = _lstTweetMsg.Distinct().ToList();
                    }
                    ///Add remaining messages
                    if (IsDuplicatMsg == true)
                    {
                        #region
                        int countDifference = _lstUserAccounts.Count - _lstTweetMsg.Count;

                        if (countDifference != 0)
                        {
                            List<string> TemList = new List<string>();
                            for (int i = 0; i < countDifference; i++)
                            {
                                try
                                {
                                    TemList.Add(_lstTweetMsg[i]);
                                }
                                catch (Exception ex)
                                {
                                    if (ex.Message.Contains("Index was out of range"))
                                    {
                                        i = 0;
                                    }
                                }
                                if (TemList.Count == countDifference)
                                {
                                    Log("[ " + DateTime.Now + " ] => [ " + countDifference + " Duplicate Messages Uploaded. ]");
                                    _lstTweetMsg.AddRange(TemList);
                                    break;
                                }
                            }
                        }
                        #endregion
                    }
                    else if ((!IsDuplicatMsg == true) && _lstUserAccounts.Count > _lstTweetMsg.Count)
                    {
                        if (_lstTweetMsg.Count > 0)
                        {
                            //Log("[ " + DateTime.Now + " ] => [ Message is less than accounts ]");
                            //DialogResult dialogResult = MessageBox.Show("Message is less than accounts. Do you want to repeat remaining Messages.", "Warning", MessageBoxButtons.YesNo);
                            //if (dialogResult == DialogResult.Yes)
                            {
                                #region
                                int countDifference = _lstUserAccounts.Count - _lstTweetMsg.Count;

                                if (countDifference != 0)
                                {
                                    List<string> TemList = new List<string>();
                                    for (int i = 0; i < countDifference; i++)
                                    {
                                        try
                                        {
                                            TemList.Add(_lstTweetMsg[i]);
                                        }
                                        catch (Exception ex)
                                        {
                                            if (ex.Message.Contains("Index was out of range"))
                                            {
                                                // i = 0;
                                            }
                                        }
                                        if (TemList.Count == countDifference)
                                        {
                                            Log("[ " + DateTime.Now + " ] => [ " + countDifference + " Duplicate Messages Uploaded. ]");
                                            _lstTweetMsg.AddRange(TemList);
                                            break;
                                        }
                                    }
                                }
                                #endregion
                            }
                            //else
                            //{
                            //}
                        }
                    }

                    //If userlist  is uploaded
                    if (IsUserList && _lstUserListForMsg.Count > 0)
                    {
                        List<string> TempMsgList = new List<string>();
                        TempMsgList.Clear();
                        bool _RepeatusernameForAllMsg = false;
                        try
                        {
                            if (_lstUserListForMsg.Count < _lstTweetMsg.Count)
                            {
                                if (false)  //for client eric
                                {
                                    DialogResult dialogResult = MessageBox.Show("Do you want to repeat mention user name for remaining Messages.", "", MessageBoxButtons.YesNo);
                                    if (dialogResult == DialogResult.Yes)
                                    {
                                        _RepeatusernameForAllMsg = true;
                                    }
                                    else
                                    {
                                    }
                                }
                            }
                        }
                        catch { };

                        //
                        int UsernameCounter = 0;
                        int MsgListCounter = 0;
                        int CatchCounter = 0;
                        while (true)
                        {
                            try
                            {
                                string NewMSg = "@" + _lstUserListForMsg[UsernameCounter] + " " + _lstTweetMsg[MsgListCounter];
                                TempMsgList.Add(NewMSg);
                                UsernameCounter++;
                                MsgListCounter++;
                            }
                            catch
                            {
                                if (_RepeatusernameForAllMsg)
                                {
                                    UsernameCounter = 0;
                                }
                                if (!_RepeatusernameForAllMsg && CatchCounter >= 1)
                                {
                                    break;
                                }
                                CatchCounter++;
                            };

                            if (MsgListCounter >= _lstTweetMsg.Count)
                            {
                                break;
                            }
                        }

                        // Check if Mention adding is Succesfull.
                        if (TempMsgList.Count > 0)
                        {
                            _lstTweetMsg.Clear();
                            _lstTweetMsg.AddRange(TempMsgList);
                        }
                        else
                        {
                            if (false) //for eric client
                            {
                                MessageBox.Show("mention Message creation is Failure.");
                            }
                            else
                            {
                                Log("[ " + DateTime.Now + " ] => [ mention Message creation is Failure. ]");
                            }
                        }
                    }

                    else
                    {
                        if (IsTweetMentionUserScrapedList)
                        {
                            List<string> TempMsgList = new List<string>();
                            TempMsgList.Clear();
                            bool _RepeatusernameForAllMsg = false;
                            try
                            {
                                if (_lstUserListForMsg.Count < _lstTweetMsg.Count)
                                {
                                    if (false) //for client eric
                                    {
                                        DialogResult dialogResult = MessageBox.Show("Do you want to repeat mention user name for remaining Messages.", "", MessageBoxButtons.YesNo);
                                        if (dialogResult == DialogResult.Yes)
                                        {
                                            _RepeatusernameForAllMsg = true;
                                        }
                                        else
                                        {
                                        }
                                    }
                                }
                            }
                            catch { };

                            //
                            int UsernameCounter = 0;
                            int MsgListCounter = 0;
                            int CatchCounter = 0;
                            while (true)
                            {
                                try
                                {
                                    //string NewMSg = "@" + _lstUserListForMsg[UsernameCounter] + " " + _lstTweetMsg[MsgListCounter];
                                    //TempMsgList.Add(NewMSg);
                                    //UsernameCounter++;
                                    //MsgListCounter++;

                                    string NewMSg = string.Empty;
                                    int i = 1;
                                    //try
                                    {
                                        while (i <= NoOfTweetMentionUserScrapedList)
                                        {
                                            NewMSg += "@" + _lstUserListForMsg[UsernameCounter] + " ";
                                            UsernameCounter++;
                                            i++;
                                        }
                                        NewMSg = NewMSg + _lstTweetMsg[MsgListCounter];
                                        TempMsgList.Add(NewMSg);
                                        MsgListCounter++;
                                    }
                                    //catch
                                    //{
                                    //}
                                }
                                catch
                                {
                                    if (_RepeatusernameForAllMsg)
                                    {
                                        UsernameCounter = 0;
                                    }
                                    if (!_RepeatusernameForAllMsg && CatchCounter >= 1)
                                    {
                                        break;
                                    }
                                    CatchCounter++;
                                };

                                if (MsgListCounter >= _lstTweetMsg.Count)
                                {
                                    break;
                                }
                            }

                            // Check if Mention adding is Succesfull.
                            if (TempMsgList.Count > 0)
                            {
                                _lstTweetMsg.Clear();
                                _lstTweetMsg.AddRange(TempMsgList);
                            }
                            else
                            {
                                if (false)  //for client eric
                                {
                                    MessageBox.Show("mention Message creation is Failure.");
                                }
                                else
                                {
                                    Log("[ " + DateTime.Now + " ] => [ mention Message creation is Failure. ]");
                                }
                            }
                        }
                    }

                    //Check When User Wants to post tweet message with image
                    if (IsTweetWithImage)
                    {
                        #region << Load Images>>
                        if (!Directory.Exists(TweetImageFolderPath))
                        {
                            Log("[ " + DateTime.Now + " ] => [ Image Folder Does't Exist. ]");
                            return;
                        }
                        ///Load Image ...
                        _lstTweetImages = GetImagePathFromFolder(TweetImageFolderPath);

                        if (_lstTweetImages.Count != 0)
                        {
                            if (_lstTweetImages.Count < _lstTweetMsg.Count)
                            {
                                ///If Images is less than messages
                                ///its asking for repeat images.
                                //Log("[ " + DateTime.Now + " ] => [ Message is less than accounts ]");
                                Log("[ " + DateTime.Now + " ] => [ images is less than message ]");
                                if (false) //for client eric
                                {
                                    DialogResult dialogResult = MessageBox.Show("Images is less than Messages. Do you want to repeat remaining images.", "Warning", MessageBoxButtons.YesNo);
                                    if (dialogResult == DialogResult.Yes)
                                    {
                                        int remaining = _lstTweetMsg.Count - _lstTweetImages.Count;

                                        for (int i = 0; i < remaining; i++)
                                        {
                                            string Imagepath = string.Empty;

                                            try
                                            {
                                                Imagepath = _lstTweetImages[i];
                                            }
                                            catch (Exception ex)
                                            {
                                                i = 0;
                                                Imagepath = _lstTweetImages[i];
                                            }
                                            _lstTweetImages.Add(Imagepath);
                                        }
                                    }
                                    else
                                    {
                                    }
                                }
                            }
                            else
                            {
                                ///if  images is greater than messages.
                            }
                        }
                        else
                        {
                            Log("[ " + DateTime.Now + " ] => [ Please Folder is Empty. Please add images in :-  " + TweetImageFolderPath + " ]");
                            return;
                        }

                        ///print number of Images ...
                        Log("[ " + DateTime.Now + " ] => [ " + _lstTweetImages.Count() + " Images uploaded. ]");

                        #endregion
                    }

                }

                //Queue<string> QtweetMsg = new Queue<string>();
                //Upload account in account Container..
                CampaignTweetAccountContainer objCampaignTweetAccountContainer = Obj_AccManger.AccountManager(_lstUserAccounts);

                Log("[ " + DateTime.Now + " ] => [ " + objCampaignTweetAccountContainer.dictionary_CampaignAccounts.Count + " Accounts Uploaded. ]");

                Log("[ " + DateTime.Now + " ] => [ " + _lstTweetMsg.Count + " Tweet Messages Uploaded. ]");

                //IF user want to add hash tage from start of all MSG's ..
                if (IsHashTag)
                {
                    //List<string> temp_lstTweetMsg = new List<string>();
                    //_lstTweetMsg.ForEach(TMsg => temp_lstTweetMsg.Add("# " + TMsg));

                    //if (temp_lstTweetMsg.Count != 0)
                    //{
                    //    _lstTweetMsg.Clear();
                    //    _lstTweetMsg.AddRange(temp_lstTweetMsg);
                    //}
                    IsHashTag = true;
                    foreach (string Data in Globals.HashTags)
                    {
                       que_TweetMessages_Campaign_Hashtags.Enqueue(Data);
                    }

                }
                else
                {
                   IsHashTag = false;
                }

                if (!IsAllTweetParAc && QtweetMsg.Count == 0)
                {
                    _lstTweetMsg.ForEach(abc => { QtweetMsg.Enqueue(abc); });
                }

                if (IsTweetWithImage && _lstTweetImages.Count != 0)
                {
                    _lstTweetImages.ForEach(img => { QtweetImagePath.Enqueue(img); });
                }

                ThreadPool.SetMaxThreads(NoOfThreads, NoOfThreads);

                foreach (var Account in objCampaignTweetAccountContainer.dictionary_CampaignAccounts)

                    try
                    {
                        {

                            //ThreadPool.QueueUserWorkItem(new WaitCallback(StartCampaignTweeting), new object[] { Account, _lstTweetMsg, IsAllTweetParAc, DelayStar, DelayEnd, NoOfTweetPerAc, CampaignName, IsSchedulDaily, SchedulerEndTime });

                            if (counterThreadsCamapignTweet >= NoOfThreads)
                            {
                                lock (lockerThreadsCampaignTweet)
                                {
                                    Monitor.Wait(lockerThreadsCampaignTweet);
                                }
                            }

                            ((CampaignAccountManager)Account.Value).logEvents.addToLogger += new EventHandler(logEvents_addToLogger);

                            if (IsTweetWithImage)
                            {
                                ///Tweet message With Image
                                Thread threadGetStartProcessForTweet = new Thread(StartTweetingWithImages);
                                threadGetStartProcessForTweet.Name = CampaignName + "_" + Account.Key;
                                threadGetStartProcessForTweet.IsBackground = true;
                                threadGetStartProcessForTweet.Start(new object[] { Account, _lstTweetMsg, _lstTweetImages, IsTweetWithImage, IsAllTweetParAc, IsHashTag, DelayStar, DelayEnd, NoOfTweetPerAc, CampaignName, IsSchedulDaily, SchedulerEndTime, TweetFilePath, IsUserList, UserListFilePath });
                            }
                            else
                            {
                                /// Tweet Only Messages
                                Thread threadGetStartProcessForTweet = new Thread(StartCampaignTweeting);
                                threadGetStartProcessForTweet.Name = CampaignName + "_" + Account.Key;
                                threadGetStartProcessForTweet.IsBackground = true;
                                threadGetStartProcessForTweet.Start(new object[] { Account, _lstTweetMsg, IsAllTweetParAc, DelayStar, DelayEnd, NoOfTweetPerAc, CampaignName, IsSchedulDaily, SchedulerEndTime, IsHashTag, TweetFilePath, IsUserList, UserListFilePath });
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Write(ex.Message);
                    }
                    finally
                    {
                        countTweetMessageAccount--;
                        if (countTweetMessageAccount == 0)
                        {

                           // Log("[ " + DateTime.Now + " ] => [ Process complete ]");
                        }
                    }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }
Esempio n. 4
0
        public void StartRetweetProcess(DataSet CompaignsDataSet, String CampaignName)
        {
            try
            {
                DataRow[] drModelDetails = CompaignsDataSet.Tables[0].Select("CampaignName = '" + CampaignName + "'");

                if (drModelDetails.Count() == 0)
                {

                }

                //Get 1st row from arrey 
                DataRow DrCampaignDetails = drModelDetails[0];


                string AcFilePath = DrCampaignDetails.ItemArray[2].ToString();
                string _retweetKeyword = DrCampaignDetails.ItemArray[3].ToString();
                bool _IsUsername = (Convert.ToInt32(DrCampaignDetails.ItemArray[5]) == 1) ? true : false;
                bool _IsUniqueMessage = (Convert.ToInt32(DrCampaignDetails.ItemArray[19]) == 1) ? true : false;
                bool _IsRetweetParDay = (Convert.ToInt32(DrCampaignDetails.ItemArray[8]) == 1) ? true : false;
                int _NoofRetweetParDay = Convert.ToInt32(DrCampaignDetails.ItemArray[9]);
                int _NoofRetweetParAc = Convert.ToInt32(DrCampaignDetails.ItemArray[10]);
                bool IsSchedulDaily = (Convert.ToInt32(DrCampaignDetails.ItemArray[12]) == 1) ? true : false;
                DateTime SchedulerStartTime = Convert.ToDateTime(DrCampaignDetails.ItemArray[13].ToString());
                DateTime SchedulerEndTime = Convert.ToDateTime(DrCampaignDetails.ItemArray[14].ToString());
                int DelayStar = Convert.ToInt32(DrCampaignDetails.ItemArray[15]);
                int DelayEnd = Convert.ToInt32(DrCampaignDetails.ItemArray[16]);
                int NoOfThreads = Convert.ToInt32(DrCampaignDetails.ItemArray[17]);

                List<string> _lstUserAccounts = new List<string>();
                List<List<CampTwitterDataScrapper.StructTweetIDs>> list_lstTargetTweetMessages = new List<List<CampTwitterDataScrapper.StructTweetIDs>>();
                classes.Cls_AccountsManager Obj_AccManger = new Cls_AccountsManager();

                //Checking Account File is Exist or not 
                if (!File.Exists(AcFilePath))
                {
                    ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ Account File Doesn't Exist. Please Update Account File of Campaign " + CampaignName + " ]");
                    return;
                }
                // Get User ID and pass from File ...
                _lstUserAccounts = Globussoft.GlobusFileHelper.ReadLargeFile(AcFilePath);

                _lstUserAccounts = _lstUserAccounts.Distinct().ToList();

                if (_lstUserAccounts.Count == 0)
                {
                    MessageBox.Show("Account File is Empty.");
                    return;
                }

                if (string.IsNullOrEmpty(_retweetKeyword))
                {
                    MessageBox.Show("Re-Tweet key word is not mention.");
                    return;
                }

                CampaignTweetAccountContainer objCampaignReTweetAccountContainer = Obj_AccManger.AccountManager(_lstUserAccounts);

                ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ " + objCampaignReTweetAccountContainer.dictionary_CampaignAccounts.Count + " Accounts Uploaded. ]");


                //get All tweets from entered user name 
                //Scrap Tweets using Username
                List<CampTwitterDataScrapper.StructTweetIDs> lst_Struct_TweetData = new List<CampTwitterDataScrapper.StructTweetIDs>();
                CampTwitterDataScrapper CamptweetScrapper = new CampTwitterDataScrapper();
                int noOfRecordsForUniqueMessage = (_NoofRetweetParAc * (objCampaignReTweetAccountContainer.dictionary_CampaignAccounts.Count));
                //List<string> _lstTweetMessageForUnique = new List<string>();
                int splitNo = 0;

                //Get details according to enter keyword is user name or keyword
                ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ Getting Tweets from " + _retweetKeyword + " KeyWord. ]");
                CamptweetScrapper.noOfRecords = (_NoofRetweetParAc * (objCampaignReTweetAccountContainer.dictionary_CampaignAccounts.Count));
                if (_IsUsername)
                {
                    lst_Struct_TweetData = CamptweetScrapper.TweetExtractor_ByUserName_New(_retweetKeyword);
                }
                else if (_IsUniqueMessage)
                {
                    lst_Struct_TweetData = CamptweetScrapper.GetTweetData_New_ForCampaign(_retweetKeyword, noOfRecordsForUniqueMessage);

                    splitNo = lst_Struct_TweetData.Count / _lstUserAccounts.Count;
                    if (splitNo == 0)
                    {
                        splitNo = RandomNumberGenerator.GenerateRandom(0, lst_Struct_TweetData.Count - 1);
                    }
                    list_lstTargetTweetMessages = Split(lst_Struct_TweetData, splitNo);

                }
                else
                {
                    lst_Struct_TweetData = CamptweetScrapper.GetTweetData_New_ForCampaign(_retweetKeyword, _NoofRetweetParAc);

                }

                ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ " + lst_Struct_TweetData.Count + " Tweet Founded. ]");

                if (lst_Struct_TweetData.Count == 0)
                {
                    ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ " + lst_Struct_TweetData.Count + " Tweet Founded. ]");
                    MessageBox.Show("No records Found from " + _retweetKeyword + " Keywored.");
                    return;
                }

                MixedCampaignManager.CustomUserControls.retweetusercontrols Objretweetusercontrol = new CustomUserControls.retweetusercontrols();
                Objretweetusercontrol.retweetusercontrolslogEvents.addToLogger += new EventHandler(logEvents_addToLogger);


                ThreadPool.SetMaxThreads(NoOfThreads, NoOfThreads);
                int LstCounter = 0;
                foreach (var Account in objCampaignReTweetAccountContainer.dictionary_CampaignAccounts)
                {
                    ((CampaignAccountManager)Account.Value).logEvents.addToLogger += new EventHandler(logEvents_addToLogger);

                    if (_IsUniqueMessage)
                    {
                        lst_Struct_TweetData = list_lstTargetTweetMessages[LstCounter];
                    }

                    if (counterThreadsCampaignRetweet >= NoOfThreads)
                    {
                        lock (lockerThreadsCamapignRetweet)
                        {
                            Monitor.Wait(lockerThreadsCamapignRetweet);
                        }
                    }



                    #region New Licensing Feature Added by Sonu
                    try
                    {
                        if (Globals.IsBasicVersion || Globals.IsProVersion || Globals.IsFreeVersion)
                        {
                            string queryCheckDataBaseEmpty = "select * from tb_FBAccount";
                            DataSet DS1 = DataBaseHandler.SelectQuery(queryCheckDataBaseEmpty, "tb_FBAccount");
                            if (!(DS1.Tables[0].Rows.Count == 0))
                            {
                                DataTable DT = DS1.Tables[0];
                                bool check = DT.Select().Any(x => x.ItemArray[0].ToString() == Account.Key);
                                if (!check)
                                {
                                    System.Windows.Forms.MessageBox.Show("Please Upload this Account in Account Manager");
                                    return;
                                }
                                else
                                {
                                    Thread threadGetStartProcessForRetweet = new Thread(startRetweeting);
                                    threadGetStartProcessForRetweet.Name = CampaignName + "_" + Account.Key;
                                    threadGetStartProcessForRetweet.IsBackground = true;
                                    threadGetStartProcessForRetweet.Start(new object[] { Account, lst_Struct_TweetData, _IsRetweetParDay, _NoofRetweetParDay, _NoofRetweetParAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime });
                                }
                            }
                            else
                            {
                                System.Windows.Forms.MessageBox.Show("Please Upload this Account in Account Manager");
                                return;
                            }
                        }
                        else
                        {
                            Thread threadGetStartProcessForRetweet = new Thread(startRetweeting);
                            threadGetStartProcessForRetweet.Name = CampaignName + "_" + Account.Key;
                            threadGetStartProcessForRetweet.IsBackground = true;
                            threadGetStartProcessForRetweet.Start(new object[] { Account, lst_Struct_TweetData, _IsRetweetParDay, _NoofRetweetParDay, _NoofRetweetParAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime });
                        }
                    }
                    catch { };


                    #endregion

                    #region old Code
                    //Thread threadGetStartProcessForRetweet = new Thread(startRetweeting);
                    //threadGetStartProcessForRetweet.Name = CampaignName + "_" + Account.Key;
                    //threadGetStartProcessForRetweet.IsBackground = true;
                    //threadGetStartProcessForRetweet.Start(new object[] { Account, lst_Struct_TweetData, _IsRetweetParDay, _NoofRetweetParDay, _NoofRetweetParAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime }); 
                    #endregion

                    Thread.Sleep(1000);
                    LstCounter++;
                }
            }
            catch (Exception Err)
            {
                ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ There is some error,Retweet Process cannot be started ]");
            }
        }
Esempio n. 5
0
        public void StartProcess(String CampaignName, String featurName, DataRow CampRow)
        {
            try
            {
                string val = string.Empty;
                try
                {
                    try
                    {
                        val = CampRow["indx"].ToString();
                    }
                    catch { }
                    if (string.IsNullOrEmpty(val))
                    {

                        DataRow[] drModelDetails = null;

                        DataSet CompaignsDataSet = cls_variables.LoadCampaignTemp();
                        drModelDetails = CompaignsDataSet.Tables[0].Select("CampaignName = '" + CampaignName + "'");
                        try
                        {
                            //if (drModelDetails.Count() > 3)
                            {
                                CampRow = drModelDetails[0];
                            }
                        }
                        catch { };
                    }
                }
                catch { }

                //DataRow[] drModelDetails = CompaignsDataSet.Tables[0].Select("CampaignName = '" + CampaignName + "'");

                //if (drModelDetails.Count() == 0)
                //{

                //}

                //Get 1st row from arrey
                DataRow DrCampaignDetails = CampRow;

                //Set all Details

                string AcFilePath = DrCampaignDetails.ItemArray[2].ToString();
                string FollowFilePath = DrCampaignDetails.ItemArray[3].ToString();
                bool divideEql = (Convert.ToInt32(DrCampaignDetails.ItemArray[5]) == 1) ? true : false;
                bool dividebyUser = (Convert.ToInt32(DrCampaignDetails.ItemArray[6]) == 1) ? true : false;
                int NoOfUsersDivid = Convert.ToInt32(DrCampaignDetails.ItemArray[7]);
                bool IsfastFollow = (Convert.ToInt32(DrCampaignDetails.ItemArray[8]) == 1) ? true : false;
                int NoOfFollowPerAc = Convert.ToInt32(DrCampaignDetails.ItemArray[9]);
                bool IsSchedulDaily = (Convert.ToInt32(DrCampaignDetails.ItemArray[12]) == 1) ? true : false;
                DateTime SchedulerStartTime = Convert.ToDateTime(DrCampaignDetails.ItemArray[13].ToString());
                DateTime SchedulerEndTime = Convert.ToDateTime(DrCampaignDetails.ItemArray[14].ToString());
                int DelayStar = Convert.ToInt32(DrCampaignDetails.ItemArray[15]);
                int DelayEnd = Convert.ToInt32(DrCampaignDetails.ItemArray[16]);
                int NoOfThreads = Convert.ToInt32(DrCampaignDetails.ItemArray[17]);

                List<string> _lstUserAccounts = new List<string>();
                List<string> _lstFollowersName = new List<string>();
                List<List<string>> list_lstTargetUsers = new List<List<string>>();

                classes.Cls_AccountsManager Obj_AccManger = new Cls_AccountsManager();

                //Check Files is existing...
                if (!File.Exists(FollowFilePath))
                {
                    Log("[ " + DateTime.Now + " ] => [ Followers Users File Doesn't Exixst. Please change account File. ]");
                    if (cls_variables.lstCampaignStartShedular.Contains(CampaignName))
                    {
                        try
                        {
                            cls_variables.lstCampaignStartShedular.Remove(CampaignName);
                        }
                        catch { };
                    }
                    return;
                }
                else if (!File.Exists(AcFilePath))
                {

                    Log("[ " + DateTime.Now + " ] => [ Account File Doesn't Exixst. Please change account File. ]");
                    if (cls_variables.lstCampaignStartShedular.Contains(CampaignName))
                    {
                        try
                        {
                            cls_variables.lstCampaignStartShedular.Remove(CampaignName);
                        }
                        catch { };
                    }
                    return;
                }

                // Get User ID and pass from File ...

                _lstUserAccounts = Globussoft.GlobusFileHelper.ReadLargeFile(AcFilePath);

                Log("[ " + DateTime.Now + " ] => [ " + _lstUserAccounts.Count + " Accounts is uploaded. ]");

                //Get Followers Name
                _lstFollowersName = Globussoft.GlobusFileHelper.ReadLargeFile(FollowFilePath);
                _lstFollowersName = _lstFollowersName.Distinct().ToList();
                Log("[ " + DateTime.Now + " ] => [ " + _lstFollowersName.Count + " Followers uploaded. ]");

                if (_lstFollowersName.Count == 0)
                {
                    Log("[ " + DateTime.Now + " ] => [ Please Upload correct Followers File. ]");
                    if (cls_variables.lstCampaignStartShedular.Contains(CampaignName))
                    {
                        try
                        {
                            cls_variables.lstCampaignStartShedular.Remove(CampaignName);
                        }
                        catch { };
                    }
                    if (MixedCampaignManager.classes.cls_variables.Lst_WokingThreads.ContainsKey(CampaignName))
                    {
                        MixedCampaignManager.classes.cls_variables.Lst_WokingThreads.Remove(CampaignName);
                    }
                    return;
                }

                CampaignTweetAccountContainer objCampaignFollowAccountContainer = Obj_AccManger.AccountManager(_lstUserAccounts);

                if (dividebyUser || divideEql)
                {
                    int splitNo = 0;
                    if (divideEql)
                    {
                        splitNo = _lstFollowersName.Count / _lstUserAccounts.Count;
                    }
                    else if (dividebyUser)
                    {
                        if (NoOfUsersDivid != 0)
                        {
                            int res = Convert.ToInt32(NoOfUsersDivid);
                            splitNo = res;
                        }
                    }
                    if (splitNo == 0)
                    {
                        splitNo = RandomNumberGenerator.GenerateRandom(0, _lstFollowersName.Count - 1);
                    }
                    list_lstTargetUsers = Split(_lstFollowersName, splitNo);
                }

                //create logger Event object for accessing log MSG's ..
                CustomUserControls.followusecontrols.CampaignFollowerLogEvents.addToLogger += new EventHandler(logEvents_addToLogger);

                //set Max thread
                ThreadPool.SetMaxThreads(NoOfThreads, NoOfThreads);

                int LstCounter = 0;
                foreach (var item in objCampaignFollowAccountContainer.dictionary_CampaignAccounts)
                {
                    try
                    {
                        //check list for breaking loop
                        //if list of follow members list is completed.
                        if (LstCounter == list_lstTargetUsers.Count && (dividebyUser || divideEql))
                        {
                            Log("[ " + DateTime.Now + " ] => [ Account is grater than List of users. ]");
                            break;
                        }

                        List<string> list_lstTargetUsers_item = new List<string>();

                        if (dividebyUser || divideEql)
                        {
                            list_lstTargetUsers_item = list_lstTargetUsers[LstCounter];
                        }
                        else
                        {
                            list_lstTargetUsers_item = _lstFollowersName;
                        }

                        //get event from accountmanager class
                        // and create Event for printing log messages
                        ((CampaignAccountManager)item.Value).logEvents.addToLogger += new EventHandler(logEvents_addToLogger);

                        //Manage no of threads
                        if (counterThreadsCampaignFollow >= NoOfThreads)
                        {
                            lock (lockerThreadsCampaignFollow)
                            {
                                Monitor.Wait(lockerThreadsCampaignFollow);
                            }
                        }

                        Thread threadGetStartProcessForFollow = new Thread(GetStartProcessForFollow);
                        threadGetStartProcessForFollow.Name = CampaignName + "_" + item.Key;
                        threadGetStartProcessForFollow.IsBackground = true;
                        threadGetStartProcessForFollow.Start(new object[] { item, list_lstTargetUsers_item, NoOfFollowPerAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime, divideEql, dividebyUser, FollowFilePath });

                        Thread.Sleep(1000);

                        LstCounter++;
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {

            }
        }
Esempio n. 6
0
        public void StartRetweetProcess(DataSet CompaignsDataSet, String CampaignName)
        {
            try
            {
                DataRow[] drModelDetails = CompaignsDataSet.Tables[0].Select("CampaignName = '" + CampaignName + "'");

                if (drModelDetails.Count() == 0)
                {
                }

                //Get 1st row from arrey
                DataRow DrCampaignDetails = drModelDetails[0];


                string   AcFilePath         = DrCampaignDetails.ItemArray[2].ToString();
                string   _retweetKeyword    = DrCampaignDetails.ItemArray[3].ToString();
                bool     _IsUsername        = (Convert.ToInt32(DrCampaignDetails.ItemArray[5]) == 1) ? true : false;
                bool     _IsUniqueMessage   = (Convert.ToInt32(DrCampaignDetails.ItemArray[19]) == 1) ? true : false;
                bool     _IsRetweetParDay   = (Convert.ToInt32(DrCampaignDetails.ItemArray[8]) == 1) ? true : false;
                int      _NoofRetweetParDay = Convert.ToInt32(DrCampaignDetails.ItemArray[9]);
                int      _NoofRetweetParAc  = Convert.ToInt32(DrCampaignDetails.ItemArray[10]);
                bool     IsSchedulDaily     = (Convert.ToInt32(DrCampaignDetails.ItemArray[12]) == 1) ? true : false;
                DateTime SchedulerStartTime = Convert.ToDateTime(DrCampaignDetails.ItemArray[13].ToString());
                DateTime SchedulerEndTime   = Convert.ToDateTime(DrCampaignDetails.ItemArray[14].ToString());
                int      DelayStar          = Convert.ToInt32(DrCampaignDetails.ItemArray[15]);
                int      DelayEnd           = Convert.ToInt32(DrCampaignDetails.ItemArray[16]);
                int      NoOfThreads        = Convert.ToInt32(DrCampaignDetails.ItemArray[17]);

                List <string> _lstUserAccounts = new List <string>();
                List <List <CampTwitterDataScrapper.StructTweetIDs> > list_lstTargetTweetMessages = new List <List <CampTwitterDataScrapper.StructTweetIDs> >();
                classes.Cls_AccountsManager Obj_AccManger = new Cls_AccountsManager();

                //Checking Account File is Exist or not
                if (!File.Exists(AcFilePath))
                {
                    ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ Account File Doesn't Exist. Please Update Account File of Campaign " + CampaignName + " ]");
                    return;
                }
                // Get User ID and pass from File ...
                _lstUserAccounts = Globussoft.GlobusFileHelper.ReadLargeFile(AcFilePath);

                _lstUserAccounts = _lstUserAccounts.Distinct().ToList();

                if (_lstUserAccounts.Count == 0)
                {
                    MessageBox.Show("Account File is Empty.");
                    return;
                }

                if (string.IsNullOrEmpty(_retweetKeyword))
                {
                    MessageBox.Show("Re-Tweet key word is not mention.");
                    return;
                }

                CampaignTweetAccountContainer objCampaignReTweetAccountContainer = Obj_AccManger.AccountManager(_lstUserAccounts);

                ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ " + objCampaignReTweetAccountContainer.dictionary_CampaignAccounts.Count + " Accounts Uploaded. ]");


                //get All tweets from entered user name
                //Scrap Tweets using Username
                List <CampTwitterDataScrapper.StructTweetIDs> lst_Struct_TweetData = new List <CampTwitterDataScrapper.StructTweetIDs>();
                CampTwitterDataScrapper CamptweetScrapper = new CampTwitterDataScrapper();
                int noOfRecordsForUniqueMessage           = (_NoofRetweetParAc * (objCampaignReTweetAccountContainer.dictionary_CampaignAccounts.Count));
                //List<string> _lstTweetMessageForUnique = new List<string>();
                int splitNo = 0;

                //Get details according to enter keyword is user name or keyword
                ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ Getting Tweets from " + _retweetKeyword + " KeyWord. ]");
                CamptweetScrapper.noOfRecords = (_NoofRetweetParAc * (objCampaignReTweetAccountContainer.dictionary_CampaignAccounts.Count));
                if (_IsUsername)
                {
                    lst_Struct_TweetData = CamptweetScrapper.TweetExtractor_ByUserName_New(_retweetKeyword);
                }
                else if (_IsUniqueMessage)
                {
                    lst_Struct_TweetData = CamptweetScrapper.GetTweetData_New_ForCampaign(_retweetKeyword, noOfRecordsForUniqueMessage);

                    splitNo = lst_Struct_TweetData.Count / _lstUserAccounts.Count;
                    if (splitNo == 0)
                    {
                        splitNo = RandomNumberGenerator.GenerateRandom(0, lst_Struct_TweetData.Count - 1);
                    }
                    list_lstTargetTweetMessages = Split(lst_Struct_TweetData, splitNo);
                }
                else
                {
                    lst_Struct_TweetData = CamptweetScrapper.GetTweetData_New_ForCampaign(_retweetKeyword, _NoofRetweetParAc);
                }

                ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ " + lst_Struct_TweetData.Count + " Tweet Founded. ]");

                if (lst_Struct_TweetData.Count == 0)
                {
                    ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ " + lst_Struct_TweetData.Count + " Tweet Founded. ]");
                    MessageBox.Show("No records Found from " + _retweetKeyword + " Keywored.");
                    return;
                }

                MixedCampaignManager.CustomUserControls.retweetusercontrols Objretweetusercontrol = new CustomUserControls.retweetusercontrols();
                Objretweetusercontrol.retweetusercontrolslogEvents.addToLogger += new EventHandler(logEvents_addToLogger);


                ThreadPool.SetMaxThreads(NoOfThreads, NoOfThreads);
                int LstCounter = 0;
                foreach (var Account in objCampaignReTweetAccountContainer.dictionary_CampaignAccounts)
                {
                    ((CampaignAccountManager)Account.Value).logEvents.addToLogger += new EventHandler(logEvents_addToLogger);

                    if (_IsUniqueMessage)
                    {
                        lst_Struct_TweetData = list_lstTargetTweetMessages[LstCounter];
                    }

                    if (counterThreadsCampaignRetweet >= NoOfThreads)
                    {
                        lock (lockerThreadsCamapignRetweet)
                        {
                            Monitor.Wait(lockerThreadsCamapignRetweet);
                        }
                    }



                    #region New Licensing Feature Added by Sonu
                    try
                    {
                        if (Globals.IsBasicVersion || Globals.IsProVersion || Globals.IsFreeVersion)
                        {
                            string  queryCheckDataBaseEmpty = "select * from tb_FBAccount";
                            DataSet DS1 = DataBaseHandler.SelectQuery(queryCheckDataBaseEmpty, "tb_FBAccount");
                            if (!(DS1.Tables[0].Rows.Count == 0))
                            {
                                DataTable DT    = DS1.Tables[0];
                                bool      check = DT.Select().Any(x => x.ItemArray[0].ToString() == Account.Key);
                                if (!check)
                                {
                                    System.Windows.Forms.MessageBox.Show("Please Upload this Account in Account Manager");
                                    return;
                                }
                                else
                                {
                                    Thread threadGetStartProcessForRetweet = new Thread(startRetweeting);
                                    threadGetStartProcessForRetweet.Name         = CampaignName + "_" + Account.Key;
                                    threadGetStartProcessForRetweet.IsBackground = true;
                                    threadGetStartProcessForRetweet.Start(new object[] { Account, lst_Struct_TweetData, _IsRetweetParDay, _NoofRetweetParDay, _NoofRetweetParAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime });
                                }
                            }
                            else
                            {
                                System.Windows.Forms.MessageBox.Show("Please Upload this Account in Account Manager");
                                return;
                            }
                        }
                        else
                        {
                            Thread threadGetStartProcessForRetweet = new Thread(startRetweeting);
                            threadGetStartProcessForRetweet.Name         = CampaignName + "_" + Account.Key;
                            threadGetStartProcessForRetweet.IsBackground = true;
                            threadGetStartProcessForRetweet.Start(new object[] { Account, lst_Struct_TweetData, _IsRetweetParDay, _NoofRetweetParDay, _NoofRetweetParAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime });
                        }
                    }
                    catch { };


                    #endregion

                    #region old Code
                    //Thread threadGetStartProcessForRetweet = new Thread(startRetweeting);
                    //threadGetStartProcessForRetweet.Name = CampaignName + "_" + Account.Key;
                    //threadGetStartProcessForRetweet.IsBackground = true;
                    //threadGetStartProcessForRetweet.Start(new object[] { Account, lst_Struct_TweetData, _IsRetweetParDay, _NoofRetweetParDay, _NoofRetweetParAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime });
                    #endregion

                    Thread.Sleep(1000);
                    LstCounter++;
                }
            }
            catch (Exception Err)
            {
                ReTweetUserControlLog("[ " + DateTime.Now + " ] => [ There is some error,Retweet Process cannot be started ]");
            }
        }
Esempio n. 7
0
        public void StartProcess(DataSet CompaignsDataSet, string CampaignName)
        {

            DataRow[] drModelDetails = CompaignsDataSet.Tables[0].Select("CampaignName = '" + CampaignName + "'");

            if (drModelDetails.Count() == 0)
            {

            }

            //Get 1st row from arrey 
            DataRow DrCampaignDetails = drModelDetails[0];

            //get details from row
            string AcFilePath = DrCampaignDetails.ItemArray[2].ToString();
            string _ReplyMsgfilePath = DrCampaignDetails.ItemArray[3].ToString();
            string _ReplyKeyword = DrCampaignDetails.ItemArray[4].ToString();
            bool _IsUsername = (Convert.ToInt32(DrCampaignDetails.ItemArray[5]) == 1) ? true : false;
            bool _IsUniqueMessage = (Convert.ToInt32(DrCampaignDetails.ItemArray[19]) == 1) ? true : false;
            bool _IsReplyParDay = (Convert.ToInt32(DrCampaignDetails.ItemArray[8]) == 1) ? true : false;
            int _NoofReplyParDay = Convert.ToInt32(DrCampaignDetails.ItemArray[9]);
            int _NoofReplyParAc = Convert.ToInt32(DrCampaignDetails.ItemArray[10]);
            bool IsSchedulDaily = (Convert.ToInt32(DrCampaignDetails.ItemArray[12]) == 1) ? true : false;
            //bool IsSchedulDaily = (Convert.ToInt32(DrCampaignDetails.ItemArray[11]) == 1) ? true : false;
            DateTime SchedulerStartTime = Convert.ToDateTime(DrCampaignDetails.ItemArray[13].ToString());
            DateTime SchedulerEndTime = Convert.ToDateTime(DrCampaignDetails.ItemArray[14].ToString());
            //int DelayStar = Convert.ToInt32(DrCampaignDetails.ItemArray[14]);
            //int DelayEnd = Convert.ToInt32(DrCampaignDetails.ItemArray[15]);
            //int NoOfThreads = Convert.ToInt32(DrCampaignDetails.ItemArray[16]);

            int DelayStar = Convert.ToInt32(DrCampaignDetails.ItemArray[15]);
            int DelayEnd = Convert.ToInt32(DrCampaignDetails.ItemArray[16]);
            int NoOfThreads = Convert.ToInt32(DrCampaignDetails.ItemArray[17]);
            bool IsDuplicateMessage = (Convert.ToInt32(DrCampaignDetails.ItemArray[22]) == 1) ? true : false;

            List<string> _lstUserAccounts = new List<string>();
            List<List<CampTwitterDataScrapper.StructTweetIDs>> list_lstTargetMessages = new List<List<CampTwitterDataScrapper.StructTweetIDs>>();

            classes.Cls_AccountsManager Obj_AccManger = new Cls_AccountsManager();

            //checking files 
            if (!File.Exists(AcFilePath))
            {
                Log("[ " + DateTime.Now + " ] => [ Account file doesn't exist. Please Update new file in campaign " + CampaignName + " ]");
                return;
            }
            else if (!File.Exists(_ReplyMsgfilePath))
            {
                Log("[ " + DateTime.Now + " ] => [ reply Message file doesn't exist. Please Update new file in campaign " + CampaignName + " ]");
                return;
            }
            else if (!File.Exists(_ReplyKeyword))
            {
                Log("[ " + DateTime.Now + " ] => [ reply Keyword file doesn't exist. Please Update new file in campaign " + CampaignName + " ]");
                return;
            }

            // Get User ID and pass from File ...
            _lstUserAccounts = Globussoft.GlobusFileHelper.ReadLargeFile(AcFilePath);

            _lstUserAccounts = _lstUserAccounts.Distinct().ToList();

            if (_lstUserAccounts.Count == 0)
            {
                MessageBox.Show("Account File is Empty.");
                return;
            }

            if (string.IsNullOrEmpty(_ReplyKeyword))
            {
                MessageBox.Show("Reply keyword File is not mention.");
                return;
            }

            CampaignManager.CampaignTweetAccountContainer objCampaignReTweetAccountContainer = Obj_AccManger.AccountManager(_lstUserAccounts);

            Log("[ " + DateTime.Now + " ] => [ " + objCampaignReTweetAccountContainer.dictionary_CampaignAccounts.Count + " Accounts Uploaded. ]");


            //Get the Reply Messages from File path 

            List<string> _lst_ReplyMessages = new List<string>();
            List<string> _lst_ReplyKeywordFile = new List<string>();

            _lst_ReplyMessages = Globussoft.GlobusFileHelper.ReadLargeFile(_ReplyMsgfilePath);

            //_lst_ReplyMessages = _lst_ReplyMessages.Distinct().ToList();
            if (!IsDuplicateMessage)
            {
                _lst_ReplyMessages = _lst_ReplyMessages.Distinct().ToList();
            }


            if (IsDuplicateMessage == true)
            {
                #region
                int countDifference = _lstUserAccounts.Count - _lst_ReplyMessages.Count;

                if (countDifference != 0)
                {
                    List<string> TemList = new List<string>();
                    for (int i = 0; i < countDifference; i++)
                    {
                        try
                        {
                            TemList.Add(_lst_ReplyMessages[i]);
                        }
                        catch (Exception ex)
                        {
                            if (ex.Message.Contains("Index was out of range"))
                            {
                                i = 0;
                            }
                        }
                        if (TemList.Count == countDifference)
                        {
                            Log("[ " + DateTime.Now + " ] => [ " + countDifference + " Duplicate Messages Uploaded. ]");
                            _lst_ReplyMessages.AddRange(TemList);
                            break;
                        }
                    }
                }
                #endregion
            }
            else if ((!IsDuplicateMessage == true) && _lstUserAccounts.Count > _lst_ReplyMessages.Count)
            {
                if (_lst_ReplyMessages.Count > 0)
                {
                    //Log("[ " + DateTime.Now + " ] => [ Message is less than accounts ]");
                    //DialogResult dialogResult = MessageBox.Show("Message is less than accounts. Do you want to repeat remaining Messages.", "Warning", MessageBoxButtons.YesNo);
                    //if (dialogResult == DialogResult.Yes)
                    {
                        #region
                        int countDifference = _lstUserAccounts.Count - _lst_ReplyMessages.Count;

                        if (countDifference != 0)
                        {
                            List<string> TemList = new List<string>();
                            for (int i = 0; i < countDifference; i++)
                            {
                                try
                                {
                                    TemList.Add(_lst_ReplyMessages[i]);
                                }
                                catch (Exception ex)
                                {
                                    if (ex.Message.Contains("Index was out of range"))
                                    {
                                        // i = 0;
                                    }
                                }
                                if (TemList.Count == countDifference)
                                {
                                    Log("[ " + DateTime.Now + " ] => [ " + countDifference + " Duplicate Messages Uploaded. ]");
                                    _lst_ReplyMessages.AddRange(TemList);
                                    break;
                                }
                            }
                        }
                        #endregion
                    }
                    //else
                    //{
                    //}
                }
            }


            _lst_ReplyKeywordFile = Globussoft.GlobusFileHelper.ReadLargeFile(_ReplyKeyword);
            _lst_ReplyKeywordFile = _lst_ReplyKeywordFile.Distinct().ToList();

            if (_lst_ReplyKeywordFile.Count == 0)
            {
                MessageBox.Show("Reply Keyword File is Empty.");
                return;
            }

            if (_lst_ReplyMessages.Count == 0)
            {
                MessageBox.Show("Tweet Message File is Empty.");
                return;
            }


            //Add remaining messages
            if (_lstUserAccounts.Count > _lst_ReplyMessages.Count)
            {
                Log("[ " + DateTime.Now + " ] => [ Message is less than accounts ]");
                DialogResult dialogResult = MessageBox.Show("Message is less than accounts. Do you want to repeat remaining Messages.", "Warning", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    #region
                    int countDifference = _lstUserAccounts.Count - _lst_ReplyMessages.Count;

                    if (countDifference != 0)
                    {
                        List<string> TemList = new List<string>();
                        for (int i = 0; i < countDifference; i++)
                        {
                            try
                            {
                                TemList.Add(_lst_ReplyMessages[i]);
                            }
                            catch (Exception ex)
                            {
                                if (ex.Message.Contains("Index was out of range"))
                                {
                                    i = 0;
                                }
                            }
                            if (TemList.Count == countDifference)
                            {
                                Log("[ " + DateTime.Now + " ] => [ " + countDifference + " Duplicate Messages Uploaded. ]");
                                _lst_ReplyMessages.AddRange(TemList);
                                break;
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    #region Puja
                    //int count = _lst_ReplyMessages.Count;
                    //Queue<string> queUserAccount = new Queue<string>();
                    //Queue<string> queReplyMessages = new Queue<string>();
                    //for (int i = 0; i < count; i++)
                    //{
                    //    try
                    //    {
                    //        queUserAccount.Enqueue(_lstUserAccounts[i].ToString());
                    //    }
                    //    catch { }
                    //}
                    //foreach (string item in _lst_ReplyMessages)
                    //{
                    //    try
                    //    {
                    //        queReplyMessages.Enqueue(item);
                    //    }
                    //    catch
                    //    { }
                    //}

                    //_lstUserAccounts.Clear();

                    ////  queUserAccount.Dequeue(_lstUserAccounts(_item));



                    //foreach (string _item in queUserAccount)
                    //{
                    //    try
                    //    {
                    //        _lstUserAccounts.Add(queUserAccount.Dequeue());
                    //    }
                    //    catch
                    //    { }
                    //} 
                    #endregion

                   
                }
            }

            Log("[ " + DateTime.Now + " ] => [ " + _lst_ReplyMessages.Count + " Reply Messages uploaded. ]");

            //get All tweets from entered user name 
            //Scrap Tweets using Username

            List<CampTwitterDataScrapper.StructTweetIDs> lst_Struct_ReplyData = new List<CampTwitterDataScrapper.StructTweetIDs>();

            List<CampTwitterDataScrapper.StructTweetIDs> lst_Struct_ReplyDataTemp = new List<CampTwitterDataScrapper.StructTweetIDs>();

            CampTwitterDataScrapper CamptweetScrapper = new CampTwitterDataScrapper();

           int noOfRecordsForUniqueMessage = (_NoofReplyParAc * (objCampaignReTweetAccountContainer.dictionary_CampaignAccounts.Count));
           //List<string> _lstTweetMessageForUnique = new List<string>();
           int splitNo = 0;
            //Get details according to enter keyword is user name or keyword

            CamptweetScrapper.noOfRecords = (_NoofReplyParAc * (objCampaignReTweetAccountContainer.dictionary_CampaignAccounts.Count));

            Log("[ " + DateTime.Now + " ] => [ Getting  tweets. ]");
            foreach (string _ReplyKeywordTemp in _lst_ReplyKeywordFile)
            {
                if (_IsUsername)
                {
                    lst_Struct_ReplyDataTemp = CamptweetScrapper.TweetExtractor_ByUserName_New(_ReplyKeywordTemp);

                }
                
                else
                {
                    lst_Struct_ReplyDataTemp = CamptweetScrapper.GetTweetData_New_ForCampaign(_ReplyKeywordTemp, _NoofReplyParAc);

                    
                }

                lst_Struct_ReplyData.AddRange(lst_Struct_ReplyDataTemp);
            }

            if (_IsUniqueMessage)
            {
               // lst_Struct_ReplyDataTemp = CamptweetScrapper.GetTweetData_New_ForCampaign(_ReplyKeywordTemp, noOfRecordsForUniqueMessage);

                splitNo = lst_Struct_ReplyData.Count / _lstUserAccounts.Count;
                if (splitNo == 0)
                {
                    splitNo = RandomNumberGenerator.GenerateRandom(0, lst_Struct_ReplyData.Count - 1);
                }
                list_lstTargetMessages = Split(lst_Struct_ReplyData, splitNo);

            }


            Log("[ " + DateTime.Now + " ] => [ Tweet found process completed. ]");
            if (lst_Struct_ReplyData.Count == 0)
            {
                Log("[ " + DateTime.Now + " ] => [ " + lst_Struct_ReplyData.Count + " Tweet Founded. ]");
                MessageBox.Show("No records Found from " + _ReplyKeyword + " Keywords.");
                return;
            }
            else
                Log("[ " + DateTime.Now + " ] => [ " + lst_Struct_ReplyData.Count + " Tweet Founded. ]");


            int LstCounter = 0;
            foreach (var Account in objCampaignReTweetAccountContainer.dictionary_CampaignAccounts)
            {
                ((CampaignAccountManager)Account.Value).logEvents.addToLogger += new EventHandler(logEvents_addToLogger);

                //ThreadPool.QueueUserWorkItem(new WaitCallback(GetStartReply), new object[] { Account, lst_Struct_ReplyData, _lst_ReplyMessages, _IsReplyParDay, _NoofReplyParDay, _NoofReplyParAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime });
                //GetStartReply(new object[] { Account, lst_Struct_ReplyData, _lst_ReplyMessages, _IsReplyParDay, _NoofReplyParDay, _NoofReplyParAc, DelayStar, DelayEnd, CampaignName });
                if (LstCounter == list_lstTargetMessages.Count && (_IsUniqueMessage))
                {
                    Log("[ " + DateTime.Now + " ] => [ Account is greater than List of tweets. ]");
                    break;
                }

                if (_IsUniqueMessage)
                {
                    lst_Struct_ReplyData = list_lstTargetMessages[LstCounter];
                }
                

                if (counterThreadsCampaignReply >= NoOfThreads)
                {
                    lock (lockerThreadsCampaignReply)
                    {
                        Monitor.Wait(lockerThreadsCampaignReply);
                    }
                }

                #region New Licensing Feature Added By Sonu
                try
                {
                    if (Globals.IsBasicVersion || Globals.IsProVersion || Globals.IsFreeVersion)
                    {
                        string queryCheckDataBaseEmpty = "select * from tb_FBAccount";
                        DataSet DS1 = DataBaseHandler.SelectQuery(queryCheckDataBaseEmpty, "tb_FBAccount");
                        if (!(DS1.Tables[0].Rows.Count == 0))
                        {
                            DataTable DT = DS1.Tables[0];
                            bool check = DT.Select().Any(x => x.ItemArray[0].ToString() == Account.Key);
                            if (!check)
                            {
                                System.Windows.Forms.MessageBox.Show("Please Upload this Account in Account Manager");
                                return;
                            }
                            else
                            {
                                Thread threadGetStartProcessForReply = new Thread(GetStartReply);
                                threadGetStartProcessForReply.Name = CampaignName + "_" + Account.Key;
                                threadGetStartProcessForReply.IsBackground = true;
                                threadGetStartProcessForReply.Start(new object[] { Account, lst_Struct_ReplyData, _lst_ReplyMessages, _IsReplyParDay, _NoofReplyParDay, _NoofReplyParAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime });
                            }
                        }
                        else
                        {
                            System.Windows.Forms.MessageBox.Show("Please Upload this Account in Account Manager");
                            return;
                        }
                    }
                    else
                    {
                        Thread threadGetStartProcessForReply = new Thread(GetStartReply);
                        threadGetStartProcessForReply.Name = CampaignName + "_" + Account.Key;
                        threadGetStartProcessForReply.IsBackground = true;
                        threadGetStartProcessForReply.Start(new object[] { Account, lst_Struct_ReplyData, _lst_ReplyMessages, _IsReplyParDay, _NoofReplyParDay, _NoofReplyParAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime });
                    }
                }
                catch { };
                #endregion

                #region old Code
                //Thread threadGetStartProcessForReply = new Thread(GetStartReply);
                //threadGetStartProcessForReply.Name = CampaignName + "_" + Account.Key;
                //threadGetStartProcessForReply.IsBackground = true;
                //threadGetStartProcessForReply.Start(new object[] { Account, lst_Struct_ReplyData, _lst_ReplyMessages, _IsReplyParDay, _NoofReplyParDay, _NoofReplyParAc, DelayStar, DelayEnd, CampaignName, IsSchedulDaily, SchedulerEndTime });
                #endregion

                Thread.Sleep(1000);
                LstCounter++;
            }
        }