private void btn_ScrapeUser_MentionUser_BrowseMessageorURL_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.DefaultExt = ".txt";
                dlg.Filter     = "Text documents (.txt)|*.txt";
                Nullable <bool> result = dlg.ShowDialog();
                string          Path   = dlg.ToString().Replace("Microsoft.Win32.OpenFileDialog: Title: , FileName", "");
                if (result == true)
                {
                    this.Dispatcher.Invoke(new Action(delegate
                    {
                        txt_ScrapeUsers_MentionUser_LoadPhotoIDOrUrlsPath.Text = dlg.FileName;
                    }));

                    List <string> lstTemp = Globussoft.GlobusFileHelper.ReadFiletoStringList(dlg.FileName);
                    GlobalDeclration.objScrapeUser.listOfMessageToComment = lstTemp.Distinct().ToList();

                    GlobusLogHelper.log.Info(lstTemp.Count + " Message Loaded ");
                }
            }
            catch (Exception ex)
            {
                GlobusLogHelper.log.Error("Error ==> " + ex.StackTrace);
            }
        }
        private void btn_ScrapeUser_MentionUser_BrowseMessageorURL_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.DefaultExt = ".txt";
                dlg.Filter = "Text documents (.txt)|*.txt";
                Nullable<bool> result = dlg.ShowDialog();
                string Path = dlg.ToString().Replace("Microsoft.Win32.OpenFileDialog: Title: , FileName", "");
                if (result == true)
                {
                    this.Dispatcher.Invoke(new Action(delegate
                    {
                        txt_ScrapeUsers_MentionUser_LoadPhotoIDOrUrlsPath.Text = dlg.FileName;
                    }));

                    List<string> lstTemp = Globussoft.GlobusFileHelper.ReadFiletoStringList(dlg.FileName);
                    GlobalDeclration.objScrapeUser.listOfMessageToComment = lstTemp.Distinct().ToList();

                    GlobusLogHelper.log.Info(lstTemp.Count + " Message Loaded ");
                }
            }
            catch (Exception ex)
            {
                GlobusLogHelper.log.Error("Error ==> " + ex.StackTrace);
            }
        }
        public void LoadAccounts()
        {
            try
            {
               
                DataSet ds;

                DataTable dt = new DataTable();

                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.DefaultExt = ".txt";
                dlg.Filter = "Text documents (.txt)|*.txt";
                Nullable<bool> result = dlg.ShowDialog();
                string Path = dlg.ToString().Replace("Microsoft.Win32.OpenFileDialog: Title: , FileName", "");
                if (result == true)
                {
                    DateTime sTime = DateTime.Now;

                    dt.Columns.Add("UserName");
                    dt.Columns.Add("Password");
                    dt.Columns.Add("Niches");
                    dt.Columns.Add("ProxyAddress");
                    dt.Columns.Add("ProxyPort");
                    dt.Columns.Add("ProxyUserName");
                    dt.Columns.Add("ProxyPassword");
                    //dt.Columns.Add("Useragent");
                   // dt.Columns.Add("BoardsName");
                    dt.Columns.Add("ScreenName");
                    dt.Columns.Add("LoginStatus");

                    ds = new DataSet();
                    ds.Tables.Add(dt);

                    List<string> templist = GlobusFileHelper.ReadFile(dlg.FileName);

                    if (templist.Count > 0)
                    {
                        PDGlobals.loadedAccountsDictionary.Clear();
                        PDGlobals.listAccounts.Clear();
                    }

                    if (Globals.IsBasicVersion)
                    {
                        try
                        {
                            string selectQuery = "select count(UserName) from tb_emails";
                            DataSet DS = DataBaseHandler.SelectQuery(selectQuery, "tb_emails");
                            int countLoadedAccounts = Convert.ToInt32(DS.Tables[0].Rows[0].ItemArray[0].ToString());

                            if (countLoadedAccounts >= 5)
                            {
                                AccounLoad();
                                MessageBox.Show("You Are Using PD Basic Version 5 Accounts allready loaded..");
                                return;
                            }
                            else
                            {
                                int RemainingAccount = 5 - countLoadedAccounts;

                                templist.RemoveRange(RemainingAccount, templist.Count - RemainingAccount);

                            }
                        }
                        catch { }
                    }
                    if (Globals.IsProVersion)
                    {
                        try
                        {
                            string selectQuery = "select count(UserName) from tb_emails";
                            DataSet DS = DataBaseHandler.SelectQuery(selectQuery, "tb_emails");
                            int countLoadedAccounts = Convert.ToInt32(DS.Tables[0].Rows[0].ItemArray[0].ToString());

                            if (countLoadedAccounts >= 15)
                            {
                                AccounLoad();
                                MessageBox.Show("You Are Using PD Pro Version 15 Accounts allready loaded..");
                                return;
                            }
                            else
                            {
                                int RemainingAccount = 15 - countLoadedAccounts;

                                templist.RemoveRange(RemainingAccount, templist.Count - RemainingAccount);

                            }
                        }
                        catch { }
                    }
                    int counter = 0;

                    foreach (string item in templist)
                    {
                        //if (Globals.CheckLicenseManager == "fdfreetrial" && counter == 5)
                        //{
                        //    break;
                        //}
                        counter = counter + 1;
                        try
                        {
                            string account = item;
                            string[] AccArr = account.Split(':');
                            if (AccArr.Count() > 1)
                            {
                                string accountUser = account.Split(':')[0];
                                string accountPass = account.Split(':')[1];
                                string niches = string.Empty;
                                string proxyAddress = string.Empty;
                                string proxyPort = string.Empty;
                                string proxyUserName = string.Empty;
                                string proxyPassword = string.Empty;
                                //string Useragent = string.Empty;
                                string Followers = string.Empty;
                                string Following = string.Empty;
                                // string Boards = string.Empty;
                                string BoardsName = string.Empty;
                                string ScreenName = string.Empty;
                                string LoginStatus = string.Empty;

                                int DataCount = account.Split(':').Length;
                                if (DataCount == 3)
                                {
                                    niches = account.Split(':')[2];

                                }
                                else if (DataCount == 5)
                                {
                                    niches = account.Split(':')[2];
                                    proxyAddress = account.Split(':')[3];
                                    proxyPort = account.Split(':')[4];
                                }
                                else if (DataCount == 7)
                                {
                                    niches = account.Split(':')[2];
                                    proxyAddress = account.Split(':')[3];
                                    proxyPort = account.Split(':')[4];
                                    proxyUserName = account.Split(':')[5];
                                    proxyPassword = account.Split(':')[6];
                                    //BoardsName = account.Split(':')[7];

                                }

                                dt.Rows.Add(accountUser, accountPass, proxyAddress, proxyPort, proxyUserName, proxyPassword);
                                //Qm.DeleteAccounts(accountUser);
                                LoginStatus = "NotChecked";

                                Qm.AddAccountInDataBase(accountUser, accountPass, niches, proxyAddress, proxyPort, proxyUserName, proxyPassword, ScreenName, LoginStatus);

                                try
                                {
                                    AccountNotifyPropertyChanged objAccountNotifyPropertyChanged = new AccountNotifyPropertyChanged();

                                    objAccountNotifyPropertyChanged.Username = accountUser;
                                    objAccountNotifyPropertyChanged.Password = accountPass;
                                    objAccountNotifyPropertyChanged.Niche = niches;
                                    objAccountNotifyPropertyChanged.ScreenName = ScreenName;
                                    objAccountNotifyPropertyChanged.FollowerCount = Followers;
                                    objAccountNotifyPropertyChanged.FollowingCount = Following;
                                    objAccountNotifyPropertyChanged.ProxyAddress = proxyAddress;
                                    objAccountNotifyPropertyChanged.ProxyPassword = proxyPassword;
                                    objAccountNotifyPropertyChanged.ProxyPort = proxyPort;
                                    objAccountNotifyPropertyChanged.ProxyUserName = proxyUserName;
                                    if (LoginStatus.Contains("Success"))
                                    {
                                        objAccountNotifyPropertyChanged.LoginStatus = "Success";
                                        objAccountNotifyPropertyChanged.BackgroundColor = "Green";
                                        this.Dispatcher.Invoke(new Action(delegate
                                             {
                                                 AccountViewModel._listOfAccount.Add(objAccountNotifyPropertyChanged);
                                             }));
                                    }
                                    else if (LoginStatus.Contains("Fail"))
                                    {
                                        objAccountNotifyPropertyChanged.LoginStatus = "Fail";
                                        objAccountNotifyPropertyChanged.BackgroundColor = "Red";
                                        this.Dispatcher.Invoke(new Action(delegate
                                            {
                                                AccountViewModel._listOfAccount.Add(objAccountNotifyPropertyChanged);
                                            }));                                      
                                    }
                                    else if (LoginStatus.Contains("Not"))
                                    {
                                        objAccountNotifyPropertyChanged.LoginStatus = "Not Checked";
                                        objAccountNotifyPropertyChanged.BackgroundColor = "";
                                        this.Dispatcher.Invoke(new Action(delegate
                                            {
                                                AccountViewModel._listOfAccount.Add(objAccountNotifyPropertyChanged);
                                            }));                                     
                                    }
                                }
                                catch (Exception ex)
                                {
                                    GlobusLogHelper.log.Error(" Error :" + ex.StackTrace);
                                }

                                try
                                {
                                    PinInterestUser objPinInterestUser = new PinInterestUser();
                                    objPinInterestUser.Username = accountUser;
                                    objPinInterestUser.Password = accountPass;
                                    objPinInterestUser.Niches = niches;
                                    objPinInterestUser.ProxyAddress = proxyAddress;
                                    objPinInterestUser.ProxyPort = proxyPort;
                                    objPinInterestUser.ProxyUsername = proxyUserName;
                                    objPinInterestUser.ProxyPassword = proxyPassword;
                                    //objPinInterestUser.UserAgent = Useragent;
                                    objPinInterestUser.BoardsName = BoardsName;
                                    objPinInterestUser.ScreenName = ScreenName;
                                    objPinInterestUser.LoginStatus = LoginStatus;
                                    PDGlobals.loadedAccountsDictionary.Add(objPinInterestUser.Username, objPinInterestUser);

                                    PDGlobals.listAccounts.Add(objPinInterestUser.Username + ":" + objPinInterestUser.Password + ":" + objPinInterestUser.Niches + ":" + objPinInterestUser.ProxyAddress + ":" + objPinInterestUser.ProxyPort + ":" + objPinInterestUser.ProxyUsername + ":" + objPinInterestUser.ProxyPassword);
                                }
                                catch (Exception ex)
                                {
                                    GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                                }

                                // Set this to "0" if loading unprofiled accounts;

                                string profileStatus = "0";
                            }
                            else
                            {
                                GlobusLogHelper.log.Info("Account has some problem : " + item);
                                GlobusLogHelper.log.Debug("Account has some problem : " + item);
                            }
                        }
                        catch (Exception ex)
                        {
                            GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                        }

                    }

                    DataView dv = dt.DefaultView;
                    dv.AllowNew = false;
                    try
                    {
                        AccounLoad();

                    }
                    catch (Exception ex)
                    {
                        GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                    }

                    try
                    {
                        DateTime eTime = DateTime.Now;

                        string timeSpan = (eTime - sTime).TotalSeconds.ToString();

                        Application.Current.Dispatcher.Invoke(new Action(() => { lblaccounts_ManageAccounts_LoadsAccountsCount.Content = dt.Rows.Count.ToString(); }));

                        GlobusLogHelper.log.Debug("Accounts Loaded : " + dt.Rows.Count.ToString() + " In " + timeSpan + " Seconds");

                        //GlobusLogHelper.log.Info("Accounts Loaded : " + dt.Rows.Count.ToString() + " In " + timeSpan + " Seconds");
                    }
                    catch (Exception ex)
                    {
                        GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                    }

                }
            }
            catch (Exception ex)
            {
                GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
            }
            Application.Current.Dispatcher.Invoke((Action)(() =>
            {
                LoadAccountProgressBar.IsIndeterminate = false;
            }));
        }
        public void LoadAccounts()
        {
            try
            {
                DataSet ds;

                DataTable dt = new DataTable();

                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.DefaultExt = ".txt";
                dlg.Filter     = "Text documents (.txt)|*.txt";
                Nullable <bool> result = dlg.ShowDialog();
                string          Path   = dlg.ToString().Replace("Microsoft.Win32.OpenFileDialog: Title: , FileName", "");
                if (result == true)
                {
                    DateTime sTime = DateTime.Now;

                    dt.Columns.Add("UserName");
                    dt.Columns.Add("Password");
                    dt.Columns.Add("Niches");
                    dt.Columns.Add("ProxyAddress");
                    dt.Columns.Add("ProxyPort");
                    dt.Columns.Add("ProxyUserName");
                    dt.Columns.Add("ProxyPassword");
                    //dt.Columns.Add("Useragent");
                    // dt.Columns.Add("BoardsName");
                    dt.Columns.Add("ScreenName");
                    dt.Columns.Add("LoginStatus");

                    ds = new DataSet();
                    ds.Tables.Add(dt);

                    List <string> templist = GlobusFileHelper.ReadFile(dlg.FileName);

                    if (templist.Count > 0)
                    {
                        PDGlobals.loadedAccountsDictionary.Clear();
                        PDGlobals.listAccounts.Clear();
                    }

                    if (Globals.IsBasicVersion)
                    {
                        try
                        {
                            string  selectQuery         = "select count(UserName) from tb_emails";
                            DataSet DS                  = DataBaseHandler.SelectQuery(selectQuery, "tb_emails");
                            int     countLoadedAccounts = Convert.ToInt32(DS.Tables[0].Rows[0].ItemArray[0].ToString());

                            if (countLoadedAccounts >= 5)
                            {
                                AccounLoad();
                                MessageBox.Show("You Are Using PD Basic Version 5 Accounts allready loaded..");
                                return;
                            }
                            else
                            {
                                int RemainingAccount = 5 - countLoadedAccounts;

                                templist.RemoveRange(RemainingAccount, templist.Count - RemainingAccount);
                            }
                        }
                        catch { }
                    }
                    if (Globals.IsProVersion)
                    {
                        try
                        {
                            string  selectQuery         = "select count(UserName) from tb_emails";
                            DataSet DS                  = DataBaseHandler.SelectQuery(selectQuery, "tb_emails");
                            int     countLoadedAccounts = Convert.ToInt32(DS.Tables[0].Rows[0].ItemArray[0].ToString());

                            if (countLoadedAccounts >= 15)
                            {
                                AccounLoad();
                                MessageBox.Show("You Are Using PD Pro Version 15 Accounts allready loaded..");
                                return;
                            }
                            else
                            {
                                int RemainingAccount = 15 - countLoadedAccounts;

                                templist.RemoveRange(RemainingAccount, templist.Count - RemainingAccount);
                            }
                        }
                        catch { }
                    }
                    int counter = 0;

                    foreach (string item in templist)
                    {
                        //if (Globals.CheckLicenseManager == "fdfreetrial" && counter == 5)
                        //{
                        //    break;
                        //}
                        counter = counter + 1;
                        try
                        {
                            string   account = item;
                            string[] AccArr  = account.Split(':');
                            if (AccArr.Count() > 1)
                            {
                                string accountUser   = account.Split(':')[0];
                                string accountPass   = account.Split(':')[1];
                                string niches        = string.Empty;
                                string proxyAddress  = string.Empty;
                                string proxyPort     = string.Empty;
                                string proxyUserName = string.Empty;
                                string proxyPassword = string.Empty;
                                //string Useragent = string.Empty;
                                string Followers = string.Empty;
                                string Following = string.Empty;
                                // string Boards = string.Empty;
                                string BoardsName  = string.Empty;
                                string ScreenName  = string.Empty;
                                string LoginStatus = string.Empty;

                                int DataCount = account.Split(':').Length;
                                if (DataCount == 3)
                                {
                                    niches = account.Split(':')[2];
                                }
                                else if (DataCount == 5)
                                {
                                    niches       = account.Split(':')[2];
                                    proxyAddress = account.Split(':')[3];
                                    proxyPort    = account.Split(':')[4];
                                }
                                else if (DataCount == 7)
                                {
                                    niches        = account.Split(':')[2];
                                    proxyAddress  = account.Split(':')[3];
                                    proxyPort     = account.Split(':')[4];
                                    proxyUserName = account.Split(':')[5];
                                    proxyPassword = account.Split(':')[6];
                                    //BoardsName = account.Split(':')[7];
                                }

                                dt.Rows.Add(accountUser, accountPass, proxyAddress, proxyPort, proxyUserName, proxyPassword);
                                //Qm.DeleteAccounts(accountUser);
                                LoginStatus = "NotChecked";

                                Qm.AddAccountInDataBase(accountUser, accountPass, niches, proxyAddress, proxyPort, proxyUserName, proxyPassword, ScreenName, LoginStatus);

                                try
                                {
                                    AccountNotifyPropertyChanged objAccountNotifyPropertyChanged = new AccountNotifyPropertyChanged();

                                    objAccountNotifyPropertyChanged.Username       = accountUser;
                                    objAccountNotifyPropertyChanged.Password       = accountPass;
                                    objAccountNotifyPropertyChanged.Niche          = niches;
                                    objAccountNotifyPropertyChanged.ScreenName     = ScreenName;
                                    objAccountNotifyPropertyChanged.FollowerCount  = Followers;
                                    objAccountNotifyPropertyChanged.FollowingCount = Following;
                                    objAccountNotifyPropertyChanged.ProxyAddress   = proxyAddress;
                                    objAccountNotifyPropertyChanged.ProxyPassword  = proxyPassword;
                                    objAccountNotifyPropertyChanged.ProxyPort      = proxyPort;
                                    objAccountNotifyPropertyChanged.ProxyUserName  = proxyUserName;
                                    if (LoginStatus.Contains("Success"))
                                    {
                                        objAccountNotifyPropertyChanged.LoginStatus     = "Success";
                                        objAccountNotifyPropertyChanged.BackgroundColor = "Green";
                                        this.Dispatcher.Invoke(new Action(delegate
                                        {
                                            AccountViewModel._listOfAccount.Add(objAccountNotifyPropertyChanged);
                                        }));
                                    }
                                    else if (LoginStatus.Contains("Fail"))
                                    {
                                        objAccountNotifyPropertyChanged.LoginStatus     = "Fail";
                                        objAccountNotifyPropertyChanged.BackgroundColor = "Red";
                                        this.Dispatcher.Invoke(new Action(delegate
                                        {
                                            AccountViewModel._listOfAccount.Add(objAccountNotifyPropertyChanged);
                                        }));
                                    }
                                    else if (LoginStatus.Contains("Not"))
                                    {
                                        objAccountNotifyPropertyChanged.LoginStatus     = "Not Checked";
                                        objAccountNotifyPropertyChanged.BackgroundColor = "";
                                        this.Dispatcher.Invoke(new Action(delegate
                                        {
                                            AccountViewModel._listOfAccount.Add(objAccountNotifyPropertyChanged);
                                        }));
                                    }
                                }
                                catch (Exception ex)
                                {
                                    GlobusLogHelper.log.Error(" Error :" + ex.StackTrace);
                                }

                                try
                                {
                                    PinInterestUser objPinInterestUser = new PinInterestUser();
                                    objPinInterestUser.Username      = accountUser;
                                    objPinInterestUser.Password      = accountPass;
                                    objPinInterestUser.Niches        = niches;
                                    objPinInterestUser.ProxyAddress  = proxyAddress;
                                    objPinInterestUser.ProxyPort     = proxyPort;
                                    objPinInterestUser.ProxyUsername = proxyUserName;
                                    objPinInterestUser.ProxyPassword = proxyPassword;
                                    //objPinInterestUser.UserAgent = Useragent;
                                    objPinInterestUser.BoardsName  = BoardsName;
                                    objPinInterestUser.ScreenName  = ScreenName;
                                    objPinInterestUser.LoginStatus = LoginStatus;
                                    PDGlobals.loadedAccountsDictionary.Add(objPinInterestUser.Username, objPinInterestUser);

                                    PDGlobals.listAccounts.Add(objPinInterestUser.Username + ":" + objPinInterestUser.Password + ":" + objPinInterestUser.Niches + ":" + objPinInterestUser.ProxyAddress + ":" + objPinInterestUser.ProxyPort + ":" + objPinInterestUser.ProxyUsername + ":" + objPinInterestUser.ProxyPassword);
                                }
                                catch (Exception ex)
                                {
                                    GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                                }

                                // Set this to "0" if loading unprofiled accounts;

                                string profileStatus = "0";
                            }
                            else
                            {
                                GlobusLogHelper.log.Info("Account has some problem : " + item);
                                GlobusLogHelper.log.Debug("Account has some problem : " + item);
                            }
                        }
                        catch (Exception ex)
                        {
                            GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                        }
                    }

                    DataView dv = dt.DefaultView;
                    dv.AllowNew = false;
                    try
                    {
                        AccounLoad();
                    }
                    catch (Exception ex)
                    {
                        GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                    }

                    try
                    {
                        DateTime eTime = DateTime.Now;

                        string timeSpan = (eTime - sTime).TotalSeconds.ToString();

                        Application.Current.Dispatcher.Invoke(new Action(() => { lblaccounts_ManageAccounts_LoadsAccountsCount.Content = dt.Rows.Count.ToString(); }));

                        GlobusLogHelper.log.Debug("Accounts Loaded : " + dt.Rows.Count.ToString() + " In " + timeSpan + " Seconds");

                        //GlobusLogHelper.log.Info("Accounts Loaded : " + dt.Rows.Count.ToString() + " In " + timeSpan + " Seconds");
                    }
                    catch (Exception ex)
                    {
                        GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                    }
                }
            }
            catch (Exception ex)
            {
                GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
            }
            Application.Current.Dispatcher.Invoke((Action)(() =>
            {
                LoadAccountProgressBar.IsIndeterminate = false;
            }));
        }
        private void LoadAccounts()
        {
            this.Dispatcher.Invoke(new Action(delegate
            {
                AccountViewModel._listOfAccount.Clear();
            }));
            DataSet ds;

            DataTable dt = new DataTable();

            DateTime sTime = DateTime.Now;
            try
            {


                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.DefaultExt = ".txt";
                dlg.Filter = "Text documents (.txt)|*.txt";
                Nullable<bool> result = dlg.ShowDialog();
                string Path = dlg.ToString().Replace("Microsoft.Win32.OpenFileDialog: Title: , FileName", "");

                if (result == true)
                {


                    dt.Columns.Add("UserName");
                    dt.Columns.Add("Password");
                    dt.Columns.Add("ProxyAddress");
                    dt.Columns.Add("ProxyPort");
                    dt.Columns.Add("ProxyUserName");
                    dt.Columns.Add("ProxyPassword");

                    ds = new DataSet();
                    ds.Tables.Add(dt);

                    List<string> templist = GlobusFileHelper.ReadFile(dlg.FileName);

                    if (templist.Count > 0)
                    {
                        IGGlobals.loadedAccountsDictionary.Clear();


                    }
                    if (Globals.IsBasicVersion)
                    {
                        try
                        {
                            string selectQuery = "select count(UserName) from AccountInfo";
                            DataSet DS = DataBaseHandler.SelectQuery(selectQuery, "AccountInfo");
                            int countLoadedAccounts = Convert.ToInt32(DS.Tables[0].Rows[0].ItemArray[0].ToString());

                            if (countLoadedAccounts >= 5)
                            {
                                LoadAccountsFromDataBase();
                                GlobusLogHelper.log.Info("You Are Using ID Basic Version 5 Accounts allready loaded..");
                              // MessageBox.Show("You Are Using ID Basic Version 5 Accounts allready loaded..");
                             //  AccounLoad();
                              // LoadAccountProgressBar.IsIndeterminate = false;
                              //  ModernDialog.ShowMessage("You Are Using ID Basic Version 5 Accounts allready loaded..", "Message", MessageBoxButton.OK);
                                this.Dispatcher.Invoke(new Action(delegate
                                    {
                                        LoadAccountProgressBar.IsIndeterminate = false;
                                    }));
                                return;
                            }
                            else
                            {
                                int RemainingAccount = 5 - countLoadedAccounts;

                                templist.RemoveRange(RemainingAccount, templist.Count - RemainingAccount);

                            }
                        }
                        catch { }
                    }
                    if (Globals.IsProVersion)
                    {
                        try
                        {
                            string selectQuery = "select count(UserName) from AccountInfo";
                            DataSet DS = DataBaseHandler.SelectQuery(selectQuery, "AccountInfo");
                            int countLoadedAccounts = Convert.ToInt32(DS.Tables[0].Rows[0].ItemArray[0].ToString());

                            if (countLoadedAccounts >= 15)
                            {
                                LoadAccountsFromDataBase();
                                MessageBox.Show("You Are Using ID Pro Version 15 Accounts allready loaded..");
                                AccounLoad();
                                LoadAccountProgressBar.IsIndeterminate = false;
                                return;
                            }
                            else
                            {
                                int RemainingAccount = 15 - countLoadedAccounts;

                                templist.RemoveRange(RemainingAccount, templist.Count - RemainingAccount);

                            }
                        }
                        catch { }
                    }
                    int counter = 0;

                    foreach (string item in templist)
                    {
                        if (Globals.CheckLicenseManager == "fdfreetrial" && counter == 5)
                        {
                            break;
                        }
                        counter = counter + 1;
                        try
                        {
                            string account = item;
                            string[] AccArr = account.Split(':');
                            if (AccArr.Count() > 1)
                            {
                                string accountUser = account.Split(':')[0];
                                string accountPass = account.Split(':')[1];
                                string proxyAddress = string.Empty;
                                string proxyPort = string.Empty;
                                string proxyUserName = string.Empty;
                                string proxyPassword = string.Empty;
                                string status = string.Empty;
                                string LogInStatus = string.Empty;

                                int DataCount = account.Split(':').Length;
                                LogInStatus = "Not Checked";
                                // new Thread(() =>
                                //{
                                if (DataCount == 2)
                                {
                                    //Globals.accountMode = AccountMode.NoProxy;

                                }
                                else if (DataCount == 4)
                                {

                                    proxyAddress = account.Split(':')[2];
                                    proxyPort = account.Split(':')[3];
                                }
                                else if (DataCount > 5 && DataCount < 7)
                                {

                                    proxyAddress = account.Split(':')[2];
                                    proxyPort = account.Split(':')[3];
                                    proxyUserName = account.Split(':')[4];
                                    proxyPassword = account.Split(':')[5];

                                }
                                else if (DataCount == 7)
                                {

                                    proxyAddress = account.Split(':')[2];
                                    proxyPort = account.Split(':')[3];
                                    proxyUserName = account.Split(':')[4];
                                    proxyPassword = account.Split(':')[5];

                                }

                                dt.Rows.Add(accountUser, accountPass, proxyAddress, proxyPort, proxyUserName, proxyPassword);
                                Qm.DeleteAccounts(accountUser);
                                Qm.AddAccountInDataBase(accountUser, accountPass, proxyAddress, proxyPort, proxyUserName, proxyPassword, Path, LogInStatus);
                                //   }).Start();
                                try
                                {
                                    GramDominator.ViewModule.AccountNotifyPropertyChanged objAccountNotifyPropertyChanged = new GramDominator.ViewModule.AccountNotifyPropertyChanged();

                                    objAccountNotifyPropertyChanged.Username = accountUser;
                                    objAccountNotifyPropertyChanged.Password = accountPass;
                                    objAccountNotifyPropertyChanged.LoginStatus = LogInStatus;                                   
                                    objAccountNotifyPropertyChanged.ProxyAddress = proxyAddress;
                                    objAccountNotifyPropertyChanged.ProxyPassword = proxyPassword;
                                    objAccountNotifyPropertyChanged.ProxyPort = proxyPort;
                                    objAccountNotifyPropertyChanged.ProxyUserName = proxyUserName;
                                    objAccountNotifyPropertyChanged.Status = status;
                                    
                                    if (LogInStatus.Contains("Success"))
                                    {
                                        objAccountNotifyPropertyChanged.LoginStatus = "Success";
                                        objAccountNotifyPropertyChanged.BackgroundColor = "Green";
                                        AccountViewModel._listOfAccount.Add(objAccountNotifyPropertyChanged);
                                    }
                                    else if (LogInStatus.Contains("Fail"))
                                    {
                                        objAccountNotifyPropertyChanged.LoginStatus = "Fail";
                                        objAccountNotifyPropertyChanged.BackgroundColor = "Red";
                                        AccountViewModel._listOfAccount.Add(objAccountNotifyPropertyChanged);
                                    }
                                    else if (LogInStatus.Contains("Not"))
                                    {
                                        objAccountNotifyPropertyChanged.LoginStatus = "Not Checked";
                                        objAccountNotifyPropertyChanged.BackgroundColor = "Red";
                                        this.Dispatcher.Invoke(new Action(delegate
             {
                 AccountViewModel._listOfAccount.Add(objAccountNotifyPropertyChanged);
             }));
                                    }
                                }
                                catch (Exception ex)
                                {

                                }

                                try
                                {
                                    InstagramUser objInstagramUser = new InstagramUser("", "", "", "");
                                    objInstagramUser.username = accountUser;
                                    objInstagramUser.password = accountPass;
                                    objInstagramUser.proxyip = proxyAddress;
                                    objInstagramUser.proxyport = proxyPort;
                                    objInstagramUser.proxyusername = proxyUserName;
                                    objInstagramUser.proxypassword = proxyPassword;
                                    objInstagramUser.globusHttpHelper = new GlobusHttpHelper();
                                    objInstagramUser.globusHttpHelper.proxyAddress = proxyAddress;
                                    try
                                    {
                                        objInstagramUser.globusHttpHelper.port = int.Parse(proxyPort);
                                    }
                                    catch 
                                    {
                                        objInstagramUser.globusHttpHelper.port = 80;
 
                                    };
                                    objInstagramUser.globusHttpHelper.proxyUsername = proxyUserName;
                                    objInstagramUser.globusHttpHelper.proxyPassword = proxyPassword;

                                    IGGlobals.loadedAccountsDictionary.Add(objInstagramUser.username, objInstagramUser);

                                    IGGlobals.listAccounts.Add(objInstagramUser.username + ":" + objInstagramUser.password + ":" + objInstagramUser.proxyip + ":" + objInstagramUser.proxyport + ":" + objInstagramUser.proxyusername + ":" + objInstagramUser.proxypassword);
                                }
                                catch (Exception ex)
                                {
                                    GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                                }

                                ///Set this to "0" if loading unprofiled accounts
                                ///
                                string profileStatus = "0";
                                GlobusLogHelper.log.Info("Account Inserted In Database : " + item);


                            }
                            else
                            {
                                GlobusLogHelper.log.Info("Account has some problem : " + item);
                                GlobusLogHelper.log.Debug("Account has some problem : " + item);
                            }

                        }
                        catch (Exception ex)
                        {
                            GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                        }

                    }


                }
            }
            catch (Exception ex)
            {
                GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
            }


            try
            {

                DateTime eTime = DateTime.Now;

                string timeSpan = (eTime - sTime).TotalSeconds.ToString();

                Application.Current.Dispatcher.Invoke(new Action(() => { lblaccounts_ManageAccounts_LoadsAccountsCount.Content = IGGlobals.listAccounts.Count; }));

                GlobusLogHelper.log.Debug("Accounts Loaded : " + IGGlobals.listAccounts.Count + " In " + timeSpan + " Seconds");

                GlobusLogHelper.log.Info("Accounts Loaded : " + dt.Rows.Count.ToString() + " In " + timeSpan + " Seconds");
            }
            catch (Exception ex)
            {
                GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
            }
            AccounLoad();
            Application.Current.Dispatcher.Invoke((Action)(() =>
            {
                LoadAccountProgressBar.IsIndeterminate = false;
            }));


        }
        private void LoadAccounts()
        {

            try
            {
                DataSet ds;
                
                DataTable dt = new DataTable();

                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.DefaultExt = ".txt";
                dlg.Filter = "Text documents (.txt)|*.txt";
                Nullable<bool> result = dlg.ShowDialog();
                string Path = dlg.ToString().Replace("Microsoft.Win32.OpenFileDialog: Title: , FileName","");
                if (result == true)
                {
                    DateTime sTime = DateTime.Now;

                    dt.Columns.Add("UserName");
                    dt.Columns.Add("Password");
                    dt.Columns.Add("ProxyAddress");
                    dt.Columns.Add("ProxyPort");
                    dt.Columns.Add("ProxyUserName");
                    dt.Columns.Add("ProxyPassword");

                    ds = new DataSet();
                    ds.Tables.Add(dt);

                    List<string> templist = GlobusFileHelper.ReadFile(dlg.FileName);

                    if (templist.Count > 0)
                    {
                        IGGlobals.loadedAccountsDictionary.Clear();
                      //  IGGlobals.listAccounts.Clear();
                       
                    }
                    int counter = 0;
                    
                    foreach (string item in templist)
                    {
                        if (Globals.CheckLicenseManager == "fdfreetrial" && counter == 5)
                        {
                            break;
                        }
                        counter = counter + 1;
                        try
                        {
                            string account = item;
                            string[] AccArr = account.Split(':');
                            if (AccArr.Count() > 1)
                            {
                                string accountUser = account.Split(':')[0];
                                string accountPass = account.Split(':')[1];
                                string proxyAddress = string.Empty;
                                string proxyPort = string.Empty;
                                string proxyUserName = string.Empty;
                                string proxyPassword = string.Empty;
                                string status = string.Empty;

                                int DataCount = account.Split(':').Length;
                                if (DataCount == 2)
                                {
                                    //Globals.accountMode = AccountMode.NoProxy;

                                }
                                else if (DataCount == 4)
                                {

                                    proxyAddress = account.Split(':')[2];
                                    proxyPort = account.Split(':')[3];
                                }
                                else if (DataCount > 5 && DataCount < 7)
                                {

                                    proxyAddress = account.Split(':')[2];
                                    proxyPort = account.Split(':')[3];
                                    proxyUserName = account.Split(':')[4];
                                    proxyPassword = account.Split(':')[5];

                                }
                                else if (DataCount == 7)
                                {

                                    proxyAddress = account.Split(':')[2];
                                    proxyPort = account.Split(':')[3];
                                    proxyUserName = account.Split(':')[4];
                                    proxyPassword = account.Split(':')[5];

                                }

                                dt.Rows.Add(accountUser, accountPass, proxyAddress, proxyPort, proxyUserName, proxyPassword);
                                Qm.DeleteAccounts(accountUser);
                                Qm.AddAccountInDataBase(accountUser, accountPass, proxyAddress, proxyPort, proxyUserName, proxyPassword, Path);
                             

                                try
                                {
                                    InstagramUser objInstagramUser = new InstagramUser("","","","");
                                    objInstagramUser.username = accountUser;
                                    objInstagramUser.password = accountPass;
                                    objInstagramUser.proxyip = proxyAddress;
                                    objInstagramUser.proxyport = proxyPort;
                                    objInstagramUser.proxyusername = proxyUserName;
                                    objInstagramUser.proxypassword = proxyPassword;

                                   IGGlobals.loadedAccountsDictionary.Add(objInstagramUser.username, objInstagramUser);

                           

                                    IGGlobals.listAccounts.Add(objInstagramUser.username + ":" + objInstagramUser.password + ":" + objInstagramUser.proxyip + ":" + objInstagramUser.proxyport + ":" + objInstagramUser.proxyusername + ":" + objInstagramUser.proxypassword);
                                }
                                catch (Exception ex)
                                {
                                    GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                                }

                                ///Set this to "0" if loading unprofiled accounts
                                ///
                                string profileStatus = "0";


                            }
                            else
                            {
                                GlobusLogHelper.log.Info("Account has some problem : " + item);
                                GlobusLogHelper.log.Debug("Account has some problem : " + item);
                            }
                        }
                        catch (Exception ex)
                        {
                            GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                        }

                    }

                  //  DataView dv = dt.DefaultView;
                 //   dv.AllowNew = false;

                    AccounLoad();



                    
                    
                    try
                    {


                
                        DateTime eTime = DateTime.Now;

                        string timeSpan = (eTime - sTime).TotalSeconds.ToString();

                        Application.Current.Dispatcher.Invoke(new Action(() => { lblaccounts_ManageAccounts_LoadsAccountsCount.Content = dt.Rows.Count.ToString(); }));

                        GlobusLogHelper.log.Debug("Accounts Loaded : " + dt.Rows.Count.ToString() + " In " + timeSpan + " Seconds");

                        GlobusLogHelper.log.Info("Accounts Loaded : " + dt.Rows.Count.ToString() + " In " + timeSpan + " Seconds");
                    }
                    catch (Exception ex)
                    {
                        GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                    }

                }
            }
            catch (Exception ex)
            {
                GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
            }
            Application.Current.Dispatcher.Invoke((Action)(() =>
            {
                LoadAccountProgressBar.IsIndeterminate = false;
            }));

        }
 public override string ToString()
 {
     return(fileDialog.ToString());
 }