public Dictionary<string, string> GetGroups(ref LinkedinUser objLinkedInUser)
        {
            string pageSource = string.Empty;
            GlobusHttpHelper HttpHelper = objLinkedInUser.globusHttpHelper;
            Dictionary<string, string> GroupName = new Dictionary<string, string>();
            try
            {
                string url = "https://www.linkedin.com";
                pageSource = HttpHelper.getHtmlfromUrl(new Uri(url));

                string[] arr = Regex.Split(pageSource, "<h3>");
                string profId = Utils.getBetween(arr[2], "<a href=\"", "\"");
                pageSource = HttpHelper.getHtmlfromUrl(new Uri(profId));

                string[] arr1 = Regex.Split(pageSource, "<h3>");
                string profileId = Utils.getBetween(arr1[2], "<a href=\"", "\"");
                pageSource = HttpHelper.getHtmlfromUrl(new Uri(profileId));

                string[] arr1_groups = Regex.Split(pageSource, "link_groups_settings");
                arr1_groups = arr1_groups.Skip(1).ToArray();

                if (arr1_groups.Length > 0)
                {
                    GlobusLogHelper.log.Info(arr1_groups.Length + " Groups Found");
                }

                foreach (string item in arr1_groups)
                {
                    string grpName = string.Empty;
                    string grpId = string.Empty;

                    grpName = Utils.getBetween(item, "name\":\"", "\",\"");
                    grpName = grpName.Replace(":", "");
                    grpId = Utils.getBetween(item, "&gid=", "&");

                    Thread.Sleep(500);
                    GlobusLogHelper.log.Info(grpName);

                    grpName = grpName + "<:><:>" + objLinkedInUser.username;
                    if (NumberHelper.ValidateNumber(grpId))
                    {
                        GroupName.Add(grpName, grpId);
                    }
                }

                if (GroupName.Count == 0)
                {
                    try
                    {
                        string url_to_get_Groups = string.Empty;
                        url_to_get_Groups = Utils.getBetween(pageSource, "<div id=\"groups-container", "</div>");
                        url_to_get_Groups = Utils.getBetween(url_to_get_Groups, "url\":\"", "\"})");

                        pageSource = HttpHelper.getHtmlfromUrl(new Uri(url_to_get_Groups));

                        arr1_groups = Regex.Split(pageSource, "link_groups_settings");
                        arr1_groups = arr1_groups.Skip(1).ToArray();

                        foreach (string item in arr1_groups)
                        {
                            try
                            {
                                string grpName = string.Empty;
                                string grpId = string.Empty;

                                grpName = Utils.getBetween(item, "name\":\"", "\",\"");
                                grpName = grpName.Replace(":", "");
                                grpId = Utils.getBetween(item, "&gid=", "&");

                                grpName = grpName + "<:><:>" + objLinkedInUser.username;
                                if (NumberHelper.ValidateNumber(grpId))
                                {
                                    GroupName.Add(grpName, grpId);
                                }
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return GroupName;
        }
        public Dictionary<string, string> AddSpecificGroupUser(ref GlobusHttpHelper HttpHelper, LinkedinUser objLinkedinUser, string gid)
        {
            string endName = string.Empty;
            string DeegreeConn = string.Empty;
            string endKey = string.Empty;
            string Locality = string.Empty;
            string Val_sourceAlias = string.Empty;
            string Val_key = string.Empty;
            string Val_defaultText = string.Empty;
            string Name = string.Empty;
            string Val_CsrToken = string.Empty;
            string Val_Subject = string.Empty;
            string Val_greeting = string.Empty;
            string Val_AuthToken = string.Empty;
            string Val_AuthType = string.Empty;
            string val_trk = string.Empty;
            string Val_lastName = string.Empty;
            string html = string.Empty;
            string Title = string.Empty;

            #region Data Initialization
            string GroupMemId = string.Empty;
            string GroupName = string.Empty;
            string Industry = string.Empty;
            string URLprofile = string.Empty;
            string firstname = string.Empty;
            string lastname = string.Empty;
            string location = string.Empty;
            string country = string.Empty;
            string postal = string.Empty;
            string phone = string.Empty;
            string USERemail = string.Empty;
            string code = string.Empty;
            string education1 = string.Empty;
            string education2 = string.Empty;
            string titlecurrent = string.Empty;
            string companycurrent = string.Empty;
            string titlepast1 = string.Empty;
            string companypast1 = string.Empty;
            string titlepast2 = string.Empty;
            string companypast2 = string.Empty;
            string titlepast3 = string.Empty;
            string companypast3 = string.Empty;
            string titlepast4 = string.Empty;
            string companypast4 = string.Empty;
            string Recommendations = string.Empty;
            string Connection = string.Empty;
            string Designation = string.Empty;
            string Website = string.Empty;
            string Contactsettings = string.Empty;
            string recomandation = string.Empty;

            string titleCurrenttitle = string.Empty;
            string titleCurrenttitle2 = string.Empty;
            string titleCurrenttitle3 = string.Empty;
            string titleCurrenttitle4 = string.Empty;
            string Skill = string.Empty;
            string TypeOfProfile = "Public";
            List<string> EducationList = new List<string>();
            string Finaldata = string.Empty;
            string EducationCollection = string.Empty;
            List<string> checkerlst = new List<string>();
            List<string> checkgrplist = new List<string>();
            string groupscollectin = string.Empty;
            string strFamilyName = string.Empty;
            string LDS_LoginID = string.Empty;
            string LDS_Websites = string.Empty;
            string LDS_UserProfileLink = string.Empty;
            string LDS_CurrentTitle = string.Empty;
            string LDS_Experience = string.Empty;
            string LDS_UserContact = string.Empty;
            string LDS_PastTitles = string.Empty;
            string LDS_BackGround_Summary = string.Empty;
            string LDS_Desc_AllComp = string.Empty;
            string Company = string.Empty;
            List<string> lstpasttitle = new List<string>();
            List<string> checkpasttitle = new List<string>();
            string csrfToken = string.Empty;
            string pageSource = string.Empty;
            string[] RgxSikValue = new string[] { };
            string[] RgxPageNo = new string[] { };
            string sikvalue = string.Empty;
            int pageno = 25;
            int counter = 0;

            string group_Url = string.Empty;
            string pagination_url = string.Empty;

            string groupId = string.Empty;
            string UserID = string.Empty;

            #endregion


            try
            {
                HttpHelper = objLinkedinUser.globusHttpHelper;
                UserID = objLinkedinUser.username;
                GroupSpecMem.Clear();
                GroupName = gid.Split('^')[0];
                groupId = gid.Split(':')[1];
                string pageSource1 = HttpHelper.getHtmlfromUrl(new Uri("https://www.linkedin.com/home?trk=hb_tab_home_top"));

                if (pageSource1.Contains("csrfToken"))
                {
                    csrfToken = pageSource1.Substring(pageSource1.IndexOf("csrfToken"), 50);
                    string[] Arr = csrfToken.Split('>');
                    csrfToken = Arr[0];
                    csrfToken = csrfToken.Replace(":", "%3A").Replace("csrfToken", "").Replace("\"", string.Empty).Replace("value", string.Empty).Replace("cs", string.Empty).Replace("id", string.Empty).Replace("=", string.Empty).Replace("\n", string.Empty).Replace(">", string.Empty).Replace("<script src", string.Empty);
                    csrfToken = csrfToken.Trim();
                }



                for (int i = 1; i <= pageno; i++)
                {
                    counter++;

                    string[] RgxGroupData = new string[] { };

                    #region with group search
                    if (WithGroupSearch == true)
                    {

                        string txid = (UnixTimestampFromDateTime(System.DateTime.Now) * 1000).ToString();

                        if (counter == 1)
                        {

                            //  pageSource = HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/groups?viewMembers=&gid=" + gid.Split(':')[2]));

                            pageSource = HttpHelper.getHtmlfromUrl(new Uri("https://www.linkedin.com/groups?viewMembers=&gid=" + gid.Split(':')[1]));

                            string Gid = string.Empty;
                            try
                            {
                                Gid = gid.Split(':')[1];
                            }
                            catch (Exception ex)
                            {
                            }
                            string URL = "https://www.linkedin.com/groups?viewMembers=&gid=" + Gid;
                            pageSource = HttpHelper.getHtmlfromUrl(new Uri(URL));

                            RgxSikValue = System.Text.RegularExpressions.Regex.Split(pageSource, "sik");
                            try
                            {
                                sikvalue = RgxSikValue[1].Split('&')[0].Replace("=", string.Empty);
                            }
                            catch { }

                            try
                            {
                                if (NumberHelper.ValidateNumber(sikvalue))
                                {
                                    sikvalue = sikvalue.Split('\"')[0];
                                }
                                else
                                {
                                    sikvalue = sikvalue.Split('\"')[0];
                                }
                            }
                            catch
                            {
                                sikvalue = sikvalue.Split('\"')[0];
                            }

                            //if (pageSource.Contains("<p class=\"paginate\">"))
                            //{
                            //    pagination_url = Utils.getBetween(pageSource, "<p class=\"paginate\">", "</a>");
                            //    pagination_url = Utils.getBetween(pagination_url, "href=\"", "\">").Replace("amp;", "");
                            //    pagination_url = "https://www.linkedin.com" + pagination_url;
                            //}

                            if (!string.IsNullOrEmpty(sikvalue))
                            {

                                //string postdata = "csrfToken=" + csrfToken + "&searchField=" + SearchKeyword + "&searchMembers=submit&searchMembers=Search&gid=" + gid.Split(':')[2] + "&goback=.gna_" + gid.Split(':')[2] + "";
                                //pageSource = HttpHelper.postFormDataRef(new Uri("https://www.linkedin.com/groups"), postdata, "http://www.linkedin.com/groups?viewMembers=&gid=" + gid.Split(':')[2] + "&sik=" + txid + "&split_page=" + i + "&goback=%2Egna_" + gid.Split(':')[2] + "", "", "");
                                #region Commented by sharan
                                string postdata = "csrfToken=" + csrfToken + "&searchField=" + SearchKeyword + "&searchMembers=submit&searchMembers=Search&gid=" + gid.Split(':')[1] + "&goback=.gna_" + gid.Split(':')[1] + "";
                                pageSource = HttpHelper.postFormDataRef(new Uri("https://www.linkedin.com/groups"), postdata, "http://www.linkedin.com/groups?viewMembers=&gid=" + gid.Split(':')[1] + "&sik=" + txid + "&split_page=" + i + "&goback=%2Egna_" + gid.Split(':')[1] + "", "", "");
                                #endregion

                                #region written by sharan
                                pageSource = HttpHelper.getHtmlfromUrl(new Uri("https://www.linkedin.com/grp/members?csrfToken=" + csrfToken + "&search=" + SearchKeyword.Replace(" ", "+") + "&gid=" + gid.Split(':')[1]));
                                #endregion
                                //string postdata = "csrfToken=" + csrfToken + "&searchField=" + SearchKeyword + "&searchMembers=submit&searchMembers=Search&gid=" + gid.Split(':')[1] + "&goback=.gna_" + gid.Split(':')[1] + "";
                                //pageSource = HttpHelper.postFormDataRef(new Uri("http://www.linkedin.com/groups"), postdata, "http://www.linkedin.com/groups?viewMembers=&gid=" + gid.Split(':')[1] + "&sik=" + txid + "&split_page=" + i + "&goback=%2Egna_" + gid.Split(':')[1] + "", "", "");

                            }
                            else
                            {

                                pageSource = HttpHelper.getHtmlfromUrl(new Uri("https://www.linkedin.com/grp/members?csrfToken=" + csrfToken + "&search=" + SearchKeyword.Replace(" ", "+") + "&gid=" + gid.Split(':')[1]));

                                // pageSource = HttpHelper.getHtmlfromUrl(new Uri("https://www.linkedin.com/grp/members?csrfToken=" + csrfToken + "&search=" + SearchKeyword.Replace(" ", "+") + "&gid=" + gid.Split(':')[1]));

                            }
                        }

                        if (!string.IsNullOrEmpty(sikvalue))
                        {
                            if (counter > 1)
                            {


                                // string getdata = "http://www.linkedin.com/groups?viewMembers=&gid=" + gid.Split(':')[2] + "&sik=" + txid + "&split_page=" + i + "&goback=%2Egna_" + gid.Split(':')[2] + "";
                                string getdata = "http://www.linkedin.com/groups?viewMembers=&gid=" + gid.Split(':')[1] + "&sik=" + txid + "&split_page=" + i + "&goback=%2Egna_" + gid.Split(':')[1] + "";
                                string new_pagination_url = pagination_url;
                                new_pagination_url = Utils.getBetween("###" + new_pagination_url, "###", "page=");
                                new_pagination_url = new_pagination_url + "page=" + counter;
                                pageSource = HttpHelper.getHtmlfromUrl(new Uri(new_pagination_url));
                                //   pageSource = HttpHelper.getHtmlfromUrl(new Uri(getdata));


                                // string getdata = "http://www.linkedin.com/groups?viewMembers=&gid=" + gid.Split(':')[1] + "&sik=" + txid + "&split_page=" + i + "&goback=%2Egna_" + gid.Split(':')[1] + "";
                                //  pageSource = HttpHelper.getHtmlfromUrl(new Uri(getdata));

                            }



                            RgxGroupData = System.Text.RegularExpressions.Regex.Split(pageSource, "<li class=\"member\">");


                            if (counter == 1)
                            {
                                try
                                {
                                    RgxPageNo = System.Text.RegularExpressions.Regex.Split(pageSource, "<h3 class=\"page-title\">Search Results: <span>");
                                    pageno = Convert.ToInt32(RgxPageNo[1].Split('<')[0].Replace("(", string.Empty).Replace(")", string.Empty).Replace("+", string.Empty).Trim());
                                    pageno = pageno / 20 + 1;
                                }
                                catch { }

                                if (pageno > 25)
                                {
                                    pageno = 25;
                                }

                                try
                                {
                                    if (pageSource.Contains("<p class=\"paginate\">"))
                                    {
                                        pagination_url = Utils.getBetween(pageSource, "<p class=\"paginate\">", "</a>");
                                        pagination_url = Utils.getBetween(pagination_url, "href=\"", "\">").Replace("amp;", "");
                                        pagination_url = "https://www.linkedin.com" + pagination_url;
                                        pagination_url = pagination_url.Replace("amp;", "");
                                    }
                                }
                                catch
                                { }
                            }
                        }
                        else
                        {
                            // RgxGroupData = System.Text.RegularExpressions.Regex.Split(pageSource, "<li class=\"member\">");
                            if (counter > 1)
                            {


                                //string getdata = "https://www.linkedin.com/grp/members?csrfToken=" + csrfToken + "&search=" + SearchKeyword.Replace(" ", "+") + "&gid=" + gid.Split(':')[2] + "&page="+i;

                                //string getdata = "https://www.linkedin.com/grp/members?csrfToken=" + csrfToken + "&search=" + SearchKeyword.Replace(" ", "+") + "&gid=" + gid.Split(':')[2] + "&page=" + i;

                                string new_pagination_url = pagination_url;
                                new_pagination_url = Utils.getBetween("###" + new_pagination_url, "###", "page=");
                                new_pagination_url = new_pagination_url + "page=" + counter;
                                pageSource = HttpHelper.getHtmlfromUrl(new Uri(new_pagination_url));

                                // pageSource = HttpHelper.getHtmlfromUrl(new Uri(getdata));
                            }


                            if (string.IsNullOrEmpty(sikvalue) && counter == 1)
                            {
                                try
                                {
                                    if (pageSource.Contains("<p class=\"paginate\">"))
                                    {
                                        pagination_url = Utils.getBetween(pageSource, "<p class=\"paginate\">", "</a>");
                                        pagination_url = Utils.getBetween(pagination_url, "href=\"", "\">").Replace("amp;", "");
                                        pagination_url = "https://www.linkedin.com" + pagination_url;
                                        pagination_url = pagination_url.Replace("amp;", "");
                                    }
                                }
                                catch
                                { }
                            }



                            RgxGroupData = System.Text.RegularExpressions.Regex.Split(pageSource, "<li class=\"member\">");

                            if (counter == 1)
                            {
                                try
                                {
                                    RgxPageNo = System.Text.RegularExpressions.Regex.Split(pageSource, "<h3 class=\"page-title\">Search Results <span>");
                                    pageno = Convert.ToInt32(RgxPageNo[1].Split('<')[0].Replace("(", string.Empty).Replace(")", string.Empty).Replace("+", string.Empty).Trim());
                                    pageno = pageno / 20 + 1;
                                }
                                catch { }

                                if (pageno > 25)
                                {
                                    pageno = 25;
                                }
                            }
                        }
                    }

                    #endregion

                    else
                    {
                        //pageSource = HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/groups?viewMembers=&gid=" + gid.Split(':')[2] + "&split_page=" + i + ""));
                        pageSource = HttpHelper.getHtmlfromUrl(new Uri("https://www.linkedin.com/grp/members?gid=" + gid.Split(':')[1] + "&page=" + i));

                        group_Url = "https://www.linkedin.com/grp/members?gid=" + gid.Split(':')[1];


                        RgxGroupData = System.Text.RegularExpressions.Regex.Split(pageSource, "<li class=\"member\" id=\"");
                        if (RgxGroupData.Length == 1)
                        {
                            RgxGroupData = Regex.Split(pageSource, "<span class=\"new-miniprofile-container\"");
                            if (RgxGroupData.Length == 1)
                            {
                                break;
                            }
                        }
                    }

                    #region for csv
                    if (WithCsvinAddFriend == true)
                    {
                        List<string> PageSerchUrl = ChilkatBasedRegex.GettingAllUrls(pageSource, "profile/view?id");
                        string FrnAcceptUrL = string.Empty;
                        foreach (string item in PageSerchUrl)
                        {
                            try
                            {
                                if (item.Contains("/profile/view?id"))
                                {
                                    FrnAcceptUrL = "http://www.linkedin.com" + item;
                                    string[] urll = Regex.Split(FrnAcceptUrL, "&authType");
                                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ " + FrnAcceptUrL + " ]");

                                    string stringSource = HttpHelper.getHtmlfromUrl(new Uri(FrnAcceptUrL));

                                    #region GroupMemId
                                    try
                                    {
                                        string[] gid1 = FrnAcceptUrL.Split('&');
                                        GroupMemId = gid1[0].Replace("http://www.linkedin.com/profile/view?id=", string.Empty);
                                    }
                                    catch { }
                                    #endregion

                                    #region Name
                                    try
                                    {
                                        try
                                        {
                                            strFamilyName = stringSource.Substring(stringSource.IndexOf("\"See Full Name\",\"i18n_Edit\":\"Edit\",\"fmt__full_name\":\""), (stringSource.IndexOf("i18n__expand_your_network_to_see_more", stringSource.IndexOf("\"See Full Name\",\"i18n_Edit\":\"Edit\",\"fmt__full_name\":\"")) - stringSource.IndexOf("\"See Full Name\",\"i18n_Edit\":\"Edit\",\"fmt__full_name\":\""))).Replace("\"See Full Name\",\"i18n_Edit\":\"Edit\",\"fmt__full_name\":\"", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Trim();
                                        }
                                        catch
                                        {
                                            try
                                            {
                                                strFamilyName = stringSource.Substring(stringSource.IndexOf("i18n__Overview_for_X"), (stringSource.IndexOf(",", stringSource.IndexOf("i18n__Overview_for_X")) - stringSource.IndexOf("i18n__Overview_for_X"))).Replace("i18n__Overview_for_X", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Replace(":Overview for", "").Trim();

                                            }
                                            catch { }
                                        }
                                    }
                                    catch { }

                                    #endregion

                                    #region Namesplitation
                                    string[] NameArr = new string[5];
                                    if (strFamilyName.Contains(" "))
                                    {
                                        try
                                        {
                                            NameArr = Regex.Split(strFamilyName, " ");
                                        }
                                        catch { }
                                    }
                                    #endregion

                                    #region FirstName
                                    try
                                    {
                                        firstname = NameArr[0];
                                    }
                                    catch { }
                                    #endregion

                                    #region LastName



                                    try
                                    {
                                        lastname = NameArr[1];

                                        if (NameArr.Count() == 3)
                                        {
                                            lastname = NameArr[1] + " " + NameArr[2];
                                        }

                                        if (lastname.Contains("}]"))
                                        {

                                            #region Name
                                            try
                                            {
                                                try
                                                {
                                                    strFamilyName = stringSource.Substring(stringSource.IndexOf("<span class=\"n fn\">")).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Trim();
                                                }
                                                catch
                                                {
                                                    try
                                                    {
                                                        strFamilyName = stringSource.Substring(stringSource.IndexOf("fmt__full_name\":"), (stringSource.IndexOf(",", stringSource.IndexOf("fmt__full_name\":")) - stringSource.IndexOf("fmt__full_name\":"))).Replace("fmt__full_name\":", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Trim();

                                                    }
                                                    catch { }
                                                }
                                            }
                                            catch { }
                                            #endregion
                                        }
                                    }
                                    catch { }
                                    #endregion

                                    #region Company
                                    Company = string.Empty;
                                    try
                                    {
                                        try
                                        {
                                            try
                                            {
                                                //Company = stringSource.Substring(stringSource.IndexOf("visible\":true,\"memberHeadline"), (stringSource.IndexOf("memberID", stringSource.IndexOf("visible\":true,\"memberHeadline")) - stringSource.IndexOf("visible\":true,\"memberHeadline"))).Replace("visible\":true,\"memberHeadline", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Replace(":", string.Empty).Replace("   ", string.Empty).Trim();
                                                Company = stringSource.Substring(stringSource.IndexOf("\"memberHeadline"), (stringSource.IndexOf("memberID", stringSource.IndexOf("\"memberHeadline")) - stringSource.IndexOf("\"memberHeadline"))).Replace("\"memberHeadline", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Replace(":", string.Empty).Replace("i18n__LocationLocationcompletenessLevel4", string.Empty).Replace("visibletrue", "").Replace("isPortfoliofalse", string.Empty).Replace("isLNLedtrue", string.Empty).Trim();
                                            }
                                            catch
                                            {
                                            }

                                            if (string.IsNullOrEmpty(Company))
                                            {
                                                try
                                                {
                                                    //memberHeadline
                                                    Company = stringSource.Substring(stringSource.IndexOf("memberHeadline\":"), (stringSource.IndexOf(",", stringSource.IndexOf("memberHeadline\":")) - stringSource.IndexOf("memberHeadline\":"))).Replace("memberHeadline\":", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Replace(":", string.Empty).Replace("   ", string.Empty).Replace(":", "").Replace("&dsh;", "").Replace("&amp", "").Replace(";", "").Replace("isPortfoliofalse", string.Empty).Replace("isLNLedtrue", string.Empty).Trim();
                                                }
                                                catch
                                                {
                                                }

                                            }

                                            titlecurrent = string.Empty;
                                            companycurrent = string.Empty;
                                            string[] strdesigandcompany = new string[4];
                                            if (Company.Contains(" at ") || Company.Contains(" of "))
                                            {
                                                try
                                                {
                                                    strdesigandcompany = Regex.Split(Company, " at ");

                                                    if (strdesigandcompany.Count() == 1)
                                                    {
                                                        strdesigandcompany = Regex.Split(Company, " of ");
                                                    }
                                                }
                                                catch { }

                                                #region Title
                                                try
                                                {
                                                    titlecurrent = strdesigandcompany[0];
                                                }
                                                catch { }
                                                #endregion

                                                #region Current Company
                                                try
                                                {
                                                    companycurrent = strdesigandcompany[1];
                                                }
                                                catch { }
                                                #endregion
                                            }

                                            if (titlecurrent == string.Empty)
                                            {
                                                titlecurrent = Company;
                                            }
                                        }
                                        catch { }

                                        #region PastCompany
                                        string[] companylist = Regex.Split(stringSource, "companyName\"");
                                        string AllComapny = string.Empty;

                                        string Companyname = string.Empty;
                                        checkerlst.Clear();
                                        foreach (string item1 in companylist)
                                        {
                                            try
                                            {
                                                if (!item1.Contains("<!DOCTYPE html>"))
                                                {
                                                    Companyname = item1.Substring(item1.IndexOf(":"), (item1.IndexOf(",", item1.IndexOf(":")) - item1.IndexOf(":"))).Replace(":", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Replace(":", string.Empty).Replace("]", string.Empty).Replace("}", string.Empty).Trim();
                                                    //Checklist.Add(item);
                                                    string items = item1;
                                                    checkerlst.Add(Companyname);
                                                    checkerlst = checkerlst.Distinct().ToList();
                                                }
                                            }
                                            catch { }
                                        }
                                        AllComapny = string.Empty;
                                        foreach (string item1 in checkerlst)
                                        {
                                            if (string.IsNullOrEmpty(AllComapny))
                                            {
                                                AllComapny = item1.Replace("}", "").Replace("]", "").Replace("&amp;", "&");
                                            }
                                            else
                                            {
                                                AllComapny = AllComapny + " : " + item1.Replace("}", "").Replace("]", "").Replace("&amp;", "&");
                                            }
                                        }

                                        if (companycurrent == string.Empty)
                                        {
                                            companycurrent = checkerlst[0].ToString();
                                        }
                                        #endregion

                                    #endregion Company

                                        #region Company Descripription

                                        try
                                        {
                                            string[] str_CompanyDesc = Regex.Split(stringSource, "showSummarySection");

                                            foreach (string item2 in str_CompanyDesc)
                                            {
                                                try
                                                {
                                                    string Current_Company = string.Empty;
                                                    if (!item2.Contains("<!DOCTYPE html>"))
                                                    {
                                                        int startindex = item2.IndexOf("specialties\":\"");

                                                        if (startindex > 0)
                                                        {
                                                            try
                                                            {
                                                                string start = item2.Substring(startindex).Replace("specialties\":", "");
                                                                int endindex = start.IndexOf("\",\"associatedWith\"");
                                                                string end = start.Substring(0, endindex);
                                                                Current_Company = end.Replace(",\"specialties_lb\":", string.Empty).Replace("\"", string.Empty).Replace("summary_lb", "Summary").Replace(",", ";").Replace("\"u002", "-");
                                                                LDS_BackGround_Summary = Current_Company;
                                                            }
                                                            catch { }
                                                        }

                                                    }

                                                    if (!item2.Contains("<!DOCTYPE html>"))
                                                    {
                                                        int startindex = item2.IndexOf("\"summary_lb\"");

                                                        if (startindex > 0)
                                                        {
                                                            try
                                                            {
                                                                string start = item2.Substring(startindex).Replace("\"summary_lb\"", "");
                                                                int endindex = start.IndexOf("\",\"associatedWith\"");
                                                                string end = start.Substring(0, endindex);
                                                                Current_Company = end.Replace(",\"specialties_lb\":", string.Empty).Replace("<br>", string.Empty).Replace("\n\"", string.Empty).Replace("\"", string.Empty).Replace("summary_lb", "Summary").Replace(",", ";").Replace("u002", "-").Replace(":", string.Empty);
                                                                LDS_BackGround_Summary = Current_Company;
                                                            }
                                                            catch { }
                                                        }

                                                    }

                                                }
                                                catch { }
                                            }
                                        }
                                        catch { }

                                        #endregion

                                        #region Education
                                        EducationCollection = string.Empty;
                                        try
                                        {
                                            try
                                            {
                                                EducationCollection = stringSource.Substring(stringSource.IndexOf("\"schoolName\":"), (stringSource.IndexOf(",", stringSource.IndexOf("\"schoolName\":")) - stringSource.IndexOf("\"schoolName\":"))).Replace("\"schoolName\":", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Trim();
                                            }
                                            catch
                                            {
                                                try
                                                {
                                                    //  education1 = stringSource.Substring(stringSource.IndexOf("i18n__Overview_for_X"), (stringSource.IndexOf(",", stringSource.IndexOf("i18n__Overview_for_X")) - stringSource.IndexOf("i18n__Overview_for_X"))).Replace("i18n__Overview_for_X", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Replace(":Overview for", "").Trim();

                                                }
                                                catch { }
                                            }
                                        }
                                        catch { }

                                        #endregion

                                        #region Email
                                        try
                                        {
                                            string[] str_Email = Regex.Split(stringSource, "email\"");
                                            USERemail = stringSource.Substring(stringSource.IndexOf("[{\"email\":"), (stringSource.IndexOf("}]", stringSource.IndexOf("[{\"email\":")) - stringSource.IndexOf("[{\"email\":"))).Replace("[{\"email\":", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Replace(":", string.Empty).Trim();
                                        }
                                        catch (Exception ex)
                                        {

                                        }
                                        #endregion Email

                                        #region Website
                                        Website = string.Empty;
                                        try
                                        {
                                            Website = stringSource.Substring(stringSource.IndexOf("[{\"URL\":"), (stringSource.IndexOf(",", stringSource.IndexOf("[{\"URL\":")) - stringSource.IndexOf("[{\"URL\":"))).Replace("[{\"URL\":", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Replace("}]", string.Empty).Trim();
                                        }
                                        catch { }
                                        #endregion Website

                                        #region location
                                        location = string.Empty;
                                        try
                                        {
                                            location = stringSource.Substring(stringSource.IndexOf("Country\",\"fmt__location\":"), (stringSource.IndexOf("i18n_no_location_matches", stringSource.IndexOf("Country\",\"fmt__location\":")) - stringSource.IndexOf("Country\",\"fmt__location\":"))).Replace("Country\",\"fmt__location\":", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(":", string.Empty).Replace(",", string.Empty).Trim();
                                        }
                                        catch (Exception ex)
                                        {
                                            try
                                            {
                                                if (string.IsNullOrEmpty(location))
                                                {
                                                    int startindex = stringSource.IndexOf("\"fmt_location\":\"");
                                                    if (startindex > 0)
                                                    {
                                                        string start = stringSource.Substring(startindex).Replace("\"fmt_location\":\"", "");
                                                        int endindex = start.IndexOf("\",");
                                                        string end = start.Substring(0, endindex);
                                                        country = end;
                                                    }
                                                }
                                            }
                                            catch (Exception ex1)
                                            {

                                            }
                                        }

                                        #endregion location

                                        #region Country
                                        try
                                        {
                                            int startindex = stringSource.IndexOf("\"locationName\":\"");
                                            if (startindex > 0)
                                            {
                                                string start = stringSource.Substring(startindex).Replace("\"locationName\":\"", "");
                                                int endindex = start.IndexOf("\",");
                                                string end = start.Substring(0, endindex);
                                                location = end;
                                            }
                                        }
                                        catch (Exception ex)
                                        {

                                        }
                                        #endregion

                                        #region Industry
                                        Industry = string.Empty;
                                        try
                                        {
                                            //Industry = stringSource.Substring(stringSource.IndexOf("fmt__industry_highlight\":"), (stringSource.IndexOf(",", stringSource.IndexOf("fmt__industry_highlight\":")) - stringSource.IndexOf("fmt__industry_highlight\":"))).Replace("fmt__industry_highlight\":", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Replace(":", string.Empty).Trim();
                                            int startindex = stringSource.IndexOf("\"industry_highlight\":\"");
                                            if (startindex > 0)
                                            {
                                                string start = stringSource.Substring(startindex).Replace("\"industry_highlight\":\"", "");
                                                int endindex = start.IndexOf("\",");
                                                string end = start.Substring(0, endindex).Replace("&amp;", "&");
                                                Industry = end;
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                        }
                                        #endregion Industry

                                        #region Connection
                                        Connection = string.Empty;
                                        try
                                        {
                                            //Connection = stringSource.Substring(stringSource.IndexOf("_count_string\":"), (stringSource.IndexOf(",", stringSource.IndexOf("_count_string\":")) - stringSource.IndexOf("_count_string\":"))).Replace("_count_string\":", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Replace(":", string.Empty).Trim();
                                            int startindex = stringSource.IndexOf("\"numberOfConnections\":");
                                            if (startindex > 0)
                                            {
                                                string start = stringSource.Substring(startindex).Replace("\"numberOfConnections\":", "");
                                                int endindex = start.IndexOf(",");
                                                string end = start.Substring(0, endindex).Replace("&amp;", "&").Replace("}", string.Empty);
                                                Connection = end;
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                        }
                                        #endregion Connection

                                        #region Recommendation
                                        try
                                        {
                                            //recomandation = stringSource.Substring(stringSource.IndexOf("i18n__Recommend_Query\":"), (stringSource.IndexOf(",", stringSource.IndexOf("i18n__Recommend_Query\":")) - stringSource.IndexOf("i18n__Recommend_Query\":"))).Replace("i18n__Recommend_Query\":", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Replace(":", string.Empty).Trim();         
                                            string PageSource = HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/profile/profile-v2-endorsements?id=" + GroupMemId + "&authType=OUT_OF_NETWORK&authToken=rXRG&goback=%2Efps_PBCK_*1_*1_*1_*1_*1_*1_tcs_*2_CP_I_us_*1_*1_false_1_R_*1_*51_*1_*51_true_*1_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2"));
                                            string[] arrayRecommendedName = Regex.Split(PageSource, "headline");
                                            List<string> ListRecommendationName = new List<string>();
                                            recomandation = string.Empty;
                                            foreach (var itemRecomName in arrayRecommendedName)
                                            {
                                                try
                                                {
                                                    if (!itemRecomName.Contains("Endorsements"))
                                                    {
                                                        try
                                                        {

                                                            int startindex = itemRecomName.IndexOf(":");
                                                            string start = itemRecomName.Substring(startindex);
                                                            int endIndex = start.IndexOf("\",");
                                                            string Heading = (start.Substring(0, endIndex).Replace("\"", string.Empty).Replace(":", string.Empty));

                                                            int startindex1 = itemRecomName.IndexOf("fmt__referrerfullName");
                                                            string start1 = itemRecomName.Substring(startindex1);
                                                            int endIndex1 = start1.IndexOf("\",");
                                                            Name = (start1.Substring(0, endIndex1).Replace("\"", string.Empty).Replace("fmt__referrerfullName", string.Empty).Replace(":", string.Empty));

                                                            ListRecommendationName.Add(Name + " : " + Heading);
                                                        }
                                                        catch { }
                                                    }
                                                }
                                                catch { }

                                            }

                                            foreach (var item5 in ListRecommendationName)
                                            {
                                                if (recomandation == string.Empty)
                                                {
                                                    recomandation = item5;
                                                }
                                                else
                                                {
                                                    recomandation += "  -  " + item5;
                                                }
                                            }

                                        }
                                        catch { }
                                        #endregion

                                        #region Experience
                                        LDS_Experience = string.Empty;
                                        if (LDS_Experience == string.Empty)
                                        {
                                            try
                                            {
                                                string[] array = Regex.Split(stringSource, "title_highlight");
                                                string exp = string.Empty;
                                                string comp = string.Empty;
                                                List<string> ListExperince = new List<string>();
                                                string SelItem = string.Empty;

                                                foreach (var itemGrps in array)
                                                {
                                                    try
                                                    {
                                                        if (itemGrps.Contains("title_pivot") && !itemGrps.Contains("<!DOCTYPE html")) //">Join
                                                        {
                                                            try
                                                            {

                                                                int startindex = itemGrps.IndexOf("\":\"");
                                                                string start = itemGrps.Substring(startindex);
                                                                int endIndex = start.IndexOf(",");
                                                                exp = (start.Substring(0, endIndex).Replace("\"", string.Empty).Replace(":", string.Empty).Replace("&amp", "&").Replace(";", string.Empty).Replace("\\u002d", "-").Replace("name:", string.Empty));

                                                            }
                                                            catch { }

                                                            try
                                                            {

                                                                int startindex1 = itemGrps.IndexOf("companyName");
                                                                string start1 = itemGrps.Substring(startindex1);
                                                                int endIndex1 = start1.IndexOf(",");
                                                                comp = (start1.Substring(0, endIndex1).Replace("\"", string.Empty).Replace("companyName", string.Empty).Replace(":", string.Empty).Replace(";", string.Empty).Replace("\\u002d", "-").Replace("name:", string.Empty));

                                                            }
                                                            catch { }

                                                            if (titlecurrent == string.Empty)
                                                            {
                                                                titlecurrent = exp;
                                                            }

                                                            if (companycurrent == string.Empty)
                                                            {
                                                                companycurrent = comp;
                                                            }

                                                            ListExperince.Add(exp + ":" + comp);

                                                        }
                                                    }
                                                    catch { }
                                                }

                                                foreach (var itemExp in ListExperince)
                                                {
                                                    if (LDS_Experience == string.Empty)
                                                    {
                                                        LDS_Experience = itemExp;
                                                    }
                                                    else
                                                    {
                                                        LDS_Experience += "  -  " + itemExp;
                                                    }
                                                }

                                            }
                                            catch { }
                                        }

                                        #endregion

                                        #region Group
                                        try
                                        {
                                            string PageSource = HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/profile/mappers?x-a=profile_v2_groups%2Cprofile_v2_follow%2Cprofile_v2_connections&x-p=profile_v2_discovery%2Erecords%3A4%2Ctop_card%2EprofileContactsIntegrationStatus%3A0%2Cprofile_v2_comparison_insight%2Edistance%3A1%2Cprofile_v2_right_fixed_discovery%2Eoffset%3A0%2Cprofile_v2_connections%2Edistance%3A1%2Cprofile_v2_right_fixed_discovery%2Erecords%3A4%2Cprofile_v2_network_overview_insight%2Edistance%3A1%2Cprofile_v2_right_top_discovery_teamlinkv2%2Eoffset%3A0%2Cprofile_v2_right_top_discovery_teamlinkv2%2Erecords%3A4%2Cprofile_v2_discovery%2Eoffset%3A0%2Cprofile_v2_summary_upsell%2EsummaryUpsell%3Atrue%2Cprofile_v2_network_overview_insight%2EnumConn%3A1668%2Ctop_card%2Etc%3Atrue&x-oa=bottomAliases&id=" + GroupMemId + "&locale=&snapshotID=&authToken=&authType=name&invAcpt=&notContactable=&primaryAction=&isPublic=false&sfd=true&_=1366115853014"));

                                            string[] array = Regex.Split(PageSource, "href=\"/groupRegistration?");
                                            string[] array1 = Regex.Split(PageSource, "groupRegistration?");
                                            List<string> ListGroupName = new List<string>();
                                            string SelItem = string.Empty;

                                            foreach (var itemGrps in array1)
                                            {
                                                try
                                                {
                                                    if (itemGrps.Contains("?gid=") && !itemGrps.Contains("<!DOCTYPE html")) //">Join
                                                    {
                                                        if (itemGrps.IndexOf("?gid=") == 0)
                                                        {
                                                            try
                                                            {
                                                                int startindex = itemGrps.IndexOf("\"name\":");
                                                                string start = itemGrps.Substring(startindex);
                                                                int endIndex = start.IndexOf(",");
                                                                ListGroupName.Add(start.Substring(0, endIndex).Replace("\"", string.Empty).Replace("amp", string.Empty).Replace("&", string.Empty).Replace(";", string.Empty).Replace("csrfToken", string.Empty).Replace("name:", string.Empty));
                                                            }
                                                            catch { }
                                                        }
                                                    }
                                                }
                                                catch { }
                                            }

                                            foreach (var item6 in ListGroupName)
                                            {
                                                if (groupscollectin == string.Empty)
                                                {
                                                    groupscollectin = item6;
                                                }
                                                else
                                                {
                                                    groupscollectin += "  -  " + item6;

                                                }
                                            }

                                        }
                                        catch { }

                                        #endregion

                                        #region skill and Expertise
                                        try
                                        {
                                            string[] strarr_skill = Regex.Split(stringSource, "endorse-item-name-text\"");
                                            string[] strarr_skill1 = Regex.Split(stringSource, "fmt__skill_name\"");
                                            if (strarr_skill.Count() >= 2)
                                            {
                                                foreach (string item7 in strarr_skill)
                                                {
                                                    try
                                                    {
                                                        if (!item7.Contains("!DOCTYPE html"))
                                                        {
                                                            try
                                                            {
                                                                string Grp = item7.Substring(item7.IndexOf("<"), (item7.IndexOf(">", item7.IndexOf("<")) - item7.IndexOf("<"))).Replace("<", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Replace(":", string.Empty).Trim();
                                                                checkgrplist.Add(Grp);
                                                                checkgrplist.Distinct().ToList();
                                                            }
                                                            catch { }
                                                        }

                                                    }
                                                    catch { }
                                                }

                                                foreach (string item8 in checkgrplist)
                                                {
                                                    if (string.IsNullOrEmpty(Skill))
                                                    {
                                                        Skill = item8;
                                                    }
                                                    else
                                                    {
                                                        Skill = Skill + "  -  " + item8;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (strarr_skill1.Count() >= 2)
                                                {
                                                    try
                                                    {
                                                        foreach (string skillitem in strarr_skill1)
                                                        {
                                                            if (!skillitem.Contains("!DOCTYPE html"))
                                                            {
                                                                try
                                                                {
                                                                    string Grp = skillitem.Substring(skillitem.IndexOf(":"), (skillitem.IndexOf("}", skillitem.IndexOf(":")) - skillitem.IndexOf(":"))).Replace(":", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Replace(":", string.Empty).Trim();
                                                                    checkgrplist.Add(Grp);
                                                                    checkgrplist.Distinct().ToList();
                                                                }
                                                                catch { }
                                                            }
                                                        }

                                                        foreach (string item9 in checkgrplist)
                                                        {
                                                            if (string.IsNullOrEmpty(Skill))
                                                            {
                                                                Skill = item9;
                                                            }
                                                            else
                                                            {
                                                                Skill = Skill + "  -  " + item9;
                                                            }
                                                        }
                                                    }
                                                    catch (Exception ex)
                                                    {

                                                    }
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {

                                        }

                                        #endregion

                                        #region Pasttitle and All Company Summary
                                        string[] pasttitles = Regex.Split(stringSource, "company_name");
                                        string pstTitlesitem = string.Empty;
                                        string pstDescCompitem = string.Empty;
                                        LDS_PastTitles = string.Empty;
                                        pasttitles = pasttitles.Skip(1).ToArray();
                                        foreach (string item10 in pasttitles)
                                        {
                                            if (item10.Contains("positionId"))
                                            {
                                                try
                                                {
                                                    int startindex = item10.IndexOf(":");
                                                    if (startindex > 0)
                                                    {
                                                        string start = item10.Substring(startindex).Replace(":\"", "");
                                                        int endindex = start.IndexOf("\",");
                                                        string end = start.Substring(0, endindex);
                                                        pstTitlesitem = end.Replace(",", ";");
                                                    }

                                                    if (string.IsNullOrEmpty(LDS_PastTitles))
                                                    {
                                                        LDS_PastTitles = pstTitlesitem;
                                                    }
                                                    else
                                                    {
                                                        LDS_PastTitles = LDS_PastTitles + "  :  " + pstTitlesitem;
                                                    }


                                                    int startindex1 = item10.IndexOf("summary_lb\":\"");
                                                    if (startindex > 0)
                                                    {
                                                        string start1 = item10.Substring(startindex1).Replace("summary_lb\":\"", "");
                                                        int endindex1 = 0;

                                                        if (start1.Contains("associatedWith"))
                                                        {
                                                            endindex1 = start1.IndexOf("\",\"associatedWith\"");

                                                            if (start1.Contains("\"}"))
                                                            {
                                                                endindex1 = start1.IndexOf("\"}");
                                                            }

                                                        }
                                                        else if (start1.Contains("\"}"))
                                                        {
                                                            endindex1 = start1.IndexOf("\"}");
                                                        }


                                                        string end1 = start1.Substring(0, endindex1);
                                                        pstDescCompitem = end1.Replace(",", ";").Replace("u002d", "-").Replace("<br>", string.Empty).Replace("\n\"", string.Empty);

                                                        if (pstDescCompitem.Contains("\";\"associatedWith"))
                                                        {
                                                            pstDescCompitem = Regex.Split(pstDescCompitem, "\";\"associatedWith")[0];
                                                        }
                                                    }

                                                    if (string.IsNullOrEmpty(LDS_Desc_AllComp))
                                                    {
                                                        LDS_Desc_AllComp = pstTitlesitem + "-" + pstDescCompitem + " ++ ";
                                                    }
                                                    else
                                                    {
                                                        LDS_Desc_AllComp = LDS_Desc_AllComp + pstTitlesitem + "-" + pstDescCompitem + " ++ ";
                                                    }
                                                }
                                                catch
                                                {
                                                }
                                            }

                                        }
                                        #endregion

                                        #region FullUrl
                                        try
                                        {
                                            string[] UrlFull = System.Text.RegularExpressions.Regex.Split(FrnAcceptUrL, "&authType");
                                            LDS_UserProfileLink = UrlFull[0];

                                            LDS_UserProfileLink = UrlFull[0];
                                            //  LDS_UserProfileLink = stringSource.Substring(stringSource.IndexOf("canonicalUrl\":"), (stringSource.IndexOf(",", stringSource.IndexOf("canonicalUrl\":")) - stringSource.IndexOf("canonicalUrl\":"))).Replace("canonicalUrl\":", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Replace(":", string.Empty).Trim();
                                        }
                                        catch { }
                                        #endregion

                                        LDS_LoginID = objLinkedinUser.username;

                                        if (string.IsNullOrEmpty(firstname))
                                        {
                                            firstname = "Linkedin Member";
                                        }

                                        LDS_BackGround_Summary = LDS_BackGround_Summary.Replace("\n", "").Replace("-", "").Replace("d", "").Replace("&#x2022", "").Replace(";", "").Replace("\n", "").Replace(",", "").Replace("&#x201", "").Trim();

                                        LDS_Desc_AllComp = "NA";
                                        Skill = "NA";

                                        string LDS_FinalData = TypeOfProfile + "," + LDS_UserProfileLink + "," + firstname + "," + lastname + "," + Company.Replace(",", ";") + "," + titlecurrent.Replace(",", ";") + "," + companycurrent.Replace(",", ";") + "," + LDS_Desc_AllComp + "," + LDS_BackGround_Summary.Replace(",", ";") + "," + Connection.Replace(",", ";") + "," + recomandation.Replace(",", string.Empty) + "," + Skill.Replace(",", ";") + "," + LDS_Experience.Replace(",", string.Empty) + "," + EducationCollection.Replace(",", ";") + "," + groupscollectin.Replace(",", ";") + "," + USERemail.Replace(",", ";") + "," + LDS_UserContact.Replace(",", ";") + "," + LDS_PastTitles + "," + AllComapny.Replace(",", ";") + "," + country.Replace(",", ";") + "," + location.Replace(",", ";") + "," + Industry.Replace(",", ";") + "," + Website.Replace(",", ";") + "," + LDS_LoginID.Replace(",", ";") + ",";
                                      //  AppFileHelper.AddingLinkedInGroupMemberDataToCSVFile(LDS_FinalData, SearchCriteria.FileName);

                                    }
                                    catch { }
                                }

                            }
                            catch { }
                        }
                    }
                    #endregion

                    foreach (var GrpUser in RgxGroupData)
                    {
                        try
                        {
                            if (GrpUser.Contains("member"))
                            {
                                if (GrpUser.Contains("title=\"YOU") || GrpUser.Contains("<!DOCTYPE html>"))
                                {
                                    if (GrpUser.Contains("title=\"YOU"))
                                    {

                                    }
                                    continue;
                                }
                                string profileUrl = string.Empty;
                                try
                                {
                                    profileUrl = Utils.getBetween(GrpUser, "<a href=\"", "\">");
                                }
                                catch
                                {
                                }
                                try
                                {
                                    //data-li-fullName="Kashish Arora">Send message</a>

                                    int startindex = GrpUser.IndexOf("fullName=");
                                    if (startindex > 0)
                                    {
                                        endName = string.Empty;
                                        string start = GrpUser.Substring(startindex);
                                        int endIndex = start.IndexOf(">Send message<");
                                        if (endIndex == -1)
                                        {
                                            endIndex = start.IndexOf(">");
                                        }
                                        endName = start.Substring(0, endIndex).Replace("fullName=", string.Empty).Replace("'", string.Empty).Replace(",", string.Empty).Replace("/", string.Empty).Replace("\"", string.Empty).Replace("&amp;", "&").Replace("&quot;", "'").Replace("tracking=anetppl_sendmsg", string.Empty).Replace("tracking=anetppl_invite", string.Empty).Replace("\\u00e9", "é").Trim();
                                    }
                                    else
                                    {
                                        endName = string.Empty;
                                        int startindex1 = GrpUser.IndexOf("alt=");
                                        string start = GrpUser.Substring(startindex1).Replace("alt=\"", "");
                                        int endIndex = start.IndexOf("\"");
                                        try
                                        {
                                            endName = start.Substring(0, endIndex).Replace("alt=", string.Empty).Replace("'", string.Empty).Replace(",", string.Empty).Replace(">", string.Empty).Replace("\"", string.Empty).Replace("&amp;", "&").Replace("&quot;", "'").Replace("tracking=anetppl_sendmsg", string.Empty).Replace("tracking=anetppl_invite", string.Empty).Replace("\\u00e9", "é").Trim();
                                        }
                                        catch { }
                                        try
                                        {
                                            if (string.IsNullOrEmpty(endName))
                                            {
                                                endName = start.Substring(start.IndexOf("alt="), start.IndexOf("class=", start.IndexOf("alt=")) - start.IndexOf("alt=")).Replace("alt=", string.Empty).Replace("alt=", string.Empty).Replace("\"", string.Empty).Replace("&quot;", "'").Replace("tracking=anetppl_sendmsg", string.Empty).Replace("tracking=anetppl_invite", string.Empty).Replace("\\u00e9", "é").Trim();
                                            }

                                        }
                                        catch { }
                                    }
                                }
                                catch
                                {

                                }

                                //Deegree connection
                                try
                                {
                                    int startindex = GrpUser.IndexOf("<span class=\"degree-icon\">");
                                    if (startindex > 0)
                                    {
                                        DeegreeConn = string.Empty;
                                        string start = GrpUser.Substring(startindex);
                                        int endIndex = start.IndexOf("<sup>");
                                        DeegreeConn = start.Substring(0, endIndex).Replace("<span class=\"degree-icon\">", string.Empty);

                                        if (DeegreeConn == "1")
                                        {
                                            DeegreeConn = DeegreeConn + "st";
                                        }
                                        else if (DeegreeConn == "2")
                                        {
                                            DeegreeConn = DeegreeConn + "nd";
                                        }
                                        else if (DeegreeConn == "3")
                                        {
                                            DeegreeConn = DeegreeConn + "rd";
                                        }
                                    }
                                    else
                                    {
                                        startindex = GrpUser.IndexOf("span class=\"degree-icon group\">");
                                        DeegreeConn = string.Empty;

                                        if (startindex > 0)
                                        {
                                            DeegreeConn = string.Empty;
                                            string start = GrpUser.Substring(startindex);
                                            int endIndex = start.IndexOf("</span>");
                                            DeegreeConn = start.Substring(0, endIndex).Replace("span class=\"degree-icon group\">", string.Empty);

                                        }

                                        if (DeegreeConn == string.Empty)
                                        {

                                            DeegreeConn = "3rd";
                                        }
                                    }

                                }

                                catch { }

                                try
                                {
                                    int startindex2 = GrpUser.IndexOf("memberId=");
                                    if (startindex2 > 0)
                                    {
                                        endKey = string.Empty;
                                        string start1 = GrpUser.Substring(startindex2);
                                        int endIndex1 = start1.IndexOf("data-li-fullName=");
                                        endKey = start1.Substring(0, endIndex1).Replace("memberId=", string.Empty).Replace("'", string.Empty).Replace(",", string.Empty).Replace("/", string.Empty).Replace("\"", string.Empty).Trim();
                                    }
                                    else
                                    {
                                        endKey = string.Empty;
                                        int startindex3 = GrpUser.IndexOf("member-");
                                        string start1 = GrpUser.Substring(startindex3);
                                        int endIndex1 = start1.IndexOf(">");
                                        endKey = start1.Substring(0, endIndex1).Replace("member-", string.Empty).Replace("'", string.Empty).Replace(",", string.Empty).Replace(">", string.Empty).Replace("\"", string.Empty).Trim();
                                    }
                                }
                                catch
                                {

                                }

                                try
                                {
                                    GroupSpecMem.Add(endKey, " [" + GroupName.Replace(",", string.Empty) + " ] " + endName + " (" + DeegreeConn.Replace(",", string.Empty) + ")");
                                    string item = UserID + "," + GroupName.Replace(",", string.Empty) + "," + group_Url.Replace("'", "").Replace("\r", "").Replace(" ", "").Replace("\n", " ") + "," + endName + "," + profileUrl.Replace("'", "").Replace("\r", "").Replace(" ", "").Replace("\n", " ") + "," + DeegreeConn.Replace(",", string.Empty);
                                   // AddingLinkedInDataToCSVFile1(item);
                                    if (WithGroupSearch == true)
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Added Group Member : " + endName + " (" + DeegreeConn + ") with Search keyword : " + SearchKeyword + " ]");
                                        //  objfrmMain.AddLoggerLoggerForGroupScraper("[ " + DateTime.Now + " ] => [ Added Group Member : " + endName + " (" + DeegreeConn + ") with Search keyword : " + SearchKeyword + " ]");
                                    }
                                    else
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Added Group Member : " + endName + " ]");
                                    }
                                }
                                catch { }
                            }
                            else
                            {

                            }
                        }
                        catch { }
                    }



                    return GroupSpecMem;
                }

                #region new code_11_26

                if (GroupSpecMem.Count <= 0)
                {
                    List<string> lstNewMembers = new List<string>();
                    bool gotScrapeUrl = false;
                    int startPage = 10;

                  string  url = "https://www.linkedin.com/communities-api/v1/memberships/community/" + groupId + "?projection=MINI&count=20&start=0";
                GetItemToScrapeUrls:
                    List<string> lstitemForScrap = new List<string>();
             //   pageSource = HttpHelper.getHtmlfromUrl(new Uri(url), "https://www.linkedin.com/groups/" + groupId + "", "", "");


                #region Cookie settings
              //  string CookieDaata = "bcookie=\"v=2&e456608f-798a-4a30-8111-4abf66a2a2d2\"; bscookie=\"v=1&201504281150112c2cb966-888b-44d4-8fe3-2bed850fc88eAQH5LeTYIub6nyWgnwTdMWl9XSSvnwsJ\"; visit=\"v=1&M\"; _chartbeat2=vnNg6xd-hkBwUPD5.1439389439450.1439994463832.10000001; VID=V_2015_08_19_07_4913; ELOQUA=GUID=28AF04F863BF45A78F3AA16B2C88EFBC; BKUT=1439994600; sessionid=\"eyJkamFuZ29fdGltZXpvbmUiOiJBc2lhL0tvbGthdGEifQ:1a1DwL:Z1TtuNNPyqGqvT1Pix66crqU9RA\"; csrftoken=fGdgb242nAkaqdDI0T72TptnHK9Fq9MM; _ga=GA1.2.1307723840.1448360766; L1c=5eba1285; oz_props_fetch_size1_125011638=9; wutan=YjukjFsDQIHEoN/VG0Nwwa8w7dzs308V6oAfSeVHCY8=; L1e=4a2dae59; oz_props_fetch_size1_394473043=5; oz_props_fetch_size1_394482147=1; sl=\"v=1&y7Ik2\"; li_at=AQEDAReDUeMB8eJnAAABUXFNV2wAAAFRcbs0bEsAw1uzWq20X7lGOtdsUgxs31vuFr1q74cnHL82GBdRUIVjbPbKccr0gJVqHj9mqczMKjWVA417H7gRrQeFQARUNssZqNTx0aZZR1hyEmdxvf4iYbF1; liap=true; JSESSIONID=\"ajax:7383772031323678847\"; share_setting=PUBLIC; sdsc=1%3A1SZM1shxDNbLt36wZwCgPgvN58iw%3D; _lipt=0_0MPCZKVCxoBpoHR17D_hDUfM2NiX0FG-oN1B8U9sDtgK_Ydwh1Gw2TGDG8LSwwC-BWGgocnwaixcQM_gvLFHZRCDaMOR9vUNoFFU7Pv4sekUOXFI9ys8jl6QfmKapvABKOlY89bVv5mqx58JvuF7NyP6lyWIckctWO6k6UG0iu1y6ABeq4BLdi4Hx_r4fhtEsbUgeBtzZHE00OAoBcpWzyBorypcrsvu10vjpfQ4JrlkZcgesHUL0zqxRmg6dwbDlfWnQT0C4hwhjEdaTEVNTp; lidc=\"b=LB47:g=319:u=13:i=1449305064:t=1449390866:s=AQG1xLWNXv_mwQpQa_XpXXydwVB0xggq\"; lang=\"v=2&lang=en-us\"; RT=s=1449305300845&r=https%3A%2F%2Fwww.linkedin.com%2Fgroups%2F47307%2Fmembers";


              //  string[] CookieDaatalst = Regex.Split(CookieDaata, ";");
              //  HttpHelper.gCookies = new System.Net.CookieCollection();
              //  System.Net.CookieCollection CookieCollection =   new System.Net.CookieCollection();
                
              //  foreach (string itemlst in CookieDaatalst)
              //  {

              //      try
              //      {
                        
              //          string[] namevalue = Regex.Split(itemlst, "=");

              //          string name = namevalue[0].Replace(" ","");
              //          string value = namevalue[1].Replace(" ", "");

              //          string Domain = "linkedin.com";

              //          System.Net.Cookie cookie = new System.Net.Cookie();
              //          cookie.Name = name;
              //          cookie.Value = value;
              //          cookie.Domain = Domain;
              //          bool IsFound = false;
              //          try
              //          {
                         
              //              foreach (System.Net.Cookie cokieitem in HttpHelper.gCookies)
              //              {

              //                  if (cookie == cokieitem)
              //                  {
              //                      IsFound = true;
              //                      break;
              //                  }
              //              }
              //              if (!IsFound)
              //              {
              //                  HttpHelper.gCookies.Add(cookie);
              //              }
              //          }
              //          catch { };
              //      }
              //      catch { };
              //  }

                #endregion


                pageSource = HttpHelper.getHtmlfromUrl(new Uri(url), "https://www.linkedin.com/groups/" + groupId + "", "", "");
                    string[] arr = Regex.Split(pageSource, ".jpg\",\"name\":");
                    foreach (var itemArr in arr)
                    {
                        if (itemArr.Contains("{\"data\":[{\"profileUrl\""))
                        {
                            continue;
                        }

                        string memberName = string.Empty;
                        string memberId = string.Empty;

                        memberName = Utils.getBetween(itemArr, "\"", "\",\"");
                        memberId = Utils.getBetween(itemArr, "id\":\"", "\",\"");
                        GroupName = GroupName.Replace(",", string.Empty);
                        try
                        {
                            if (!memberName.Contains("data\":[{\""))
                            {
                                GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Added Group Member : " + memberName + " ]");
                                GroupSpecMem.Add(memberId, " [" + GroupName + " ] " + memberName);
                            }

                        }
                        catch (Exception ex)
                        {
                            Console.Write(ex);
                        }


                        //string name = Utils.getBetween(itemArr, "\"", ",").Replace("\"", "");
                        //string memberId = Utils.getBetween(itemArr, "nonIterableMemberId\":", ",").Replace("\"", "");
                        string itemToScrapUrl = "https://www.linkedin.com/profile/view?id=" + memberId + "&authType=name&authToken=2ZLd";
                        if (!lstitemForScrap.Contains(itemToScrapUrl))
                        {
                            gotScrapeUrl = true;
                            lstitemForScrap.Add(itemToScrapUrl);
                        }
                    }
                    if (gotScrapeUrl)
                    {
                        //foreach (var itemForScrap in lstitemForScrap)
                        //{
                        //    if (!lstNewMembers.Contains(itemForScrap))
                        //    {
                        //        if (!obj_ClsScrapGroupMember.CrawlingLinkedInPage(itemForScrap, ref HttpHelper))
                        //        {
                        //            obj_ClsScrapGroupMember.CrawlingPageDataSource(itemForScrap, ref HttpHelper);
                        //        }
                        //        lstNewMembers.Add(itemForScrap);
                        //    }
                        //}

                        startPage = startPage + 10;
                        url = "https://www.linkedin.com/communities-api/v1/memberships/community/" + groupId + "?membershipStatus=MEMBER&start=" + startPage + "&projection=FULL";
                        gotScrapeUrl = false;
                        if (startPage <= 500)
                        {
                            goto GetItemToScrapeUrls;
                        }

                    }



                }
                #endregion
            }
            catch (Exception ex)
            {
            }
            return GroupSpecMem;
        }
        public void StartGroupStatus(ref LinkedinUser objLinkedinUser)
        {
            try
            {
                Dictionary<string, string> dicGroup = new Dictionary<string, string>();
                GlobusLogHelper.log.Info("Finding Groups...");
                dicGroup = GetGroups(ref objLinkedinUser);

                GlobalsGroups.lstGroups.Clear();

                foreach (var item in dicGroup)
                {
                    GlobalsGroups.lstGroups.Add(Regex.Split(item.Key, "<:><:>")[0]);
                }

                BindingGroupNames();
            }
            catch (Exception ex)
            {
            }
        }
        public void StartActionGetFirstConnection(ref LinkedinUser LdUser)
        {

            if(isExcelInput)
            {

                Dictionary<string, string> Result = PostaddMembersWithExcelInput_WithoutHittingUrl(ref LdUser.globusHttpHelper, LdUser.username);

                if (Result.Count == 0)
                {
                    if (Globals.MessageContacts.Count == 0)
                    {
                        string query = "select * from  tb_ComposeMessageExcelData where UserName='******'";
                        DataSet DS = DataBaseHandler.SelectQuery(query, "tb_ComposeMessageExcelData");
                        foreach (DataRow itemAccountData in DS.Tables[0].Rows)
                        {

                            string Account1 = itemAccountData["UserName"].ToString();
                            string ProfileUrl = itemAccountData["RecipientProfileUrl"].ToString();
                            Result.Add(Account1, ProfileUrl);

                        }
                    }


                }

               Globals.MessageContacts.Add(LdUser.username, Result);
            }
            else
            {

                Dictionary<string, string> Result = PostAddMembers(ref LdUser);
                Globals.MessageContacts.Add(LdUser.username, Result);

            }

            GlobusLogHelper.log.Info("[ Member Added Successfully : " + LdUser.username);
            GroupStatus.ComboBoxDataBind("jhkj");
            //ComboBoxDataBind("aaaa");



        }
        public Dictionary<string, string> PostAddMembers(ref LinkedinUser LDUser)
        {


            try
            {
                // MemberNameAndID.Add(MemId, MemFullName + ":" + Title);
                MemberNameAndID.Clear();
                string MemId = string.Empty;
                string MemFName = string.Empty;
                string MemLName = string.Empty;
                string MemFullName = string.Empty;
                string Memfullname1 = string.Empty;
                string memID1 = string.Empty;
                string MemId1 = string.Empty;
                string user = LDUser.username;
                GlobusHttpHelper HttpHelper = LDUser.globusHttpHelper;
                string pageSource = string.Empty;

                #region without_search
                if (!Globals.is_Searched_Compose_msg)
                {
                    pageSource = HttpHelper.getHtmlfromUrl(new Uri("https://www.linkedin.com/contacts/api/contacts/?&sortOrder=recent&source=LinkedIn"));   // if we url is getting redirected then comment this line


                    // if (!string.IsNullOrEmpty(pageSource)&&!pageSource.Contains("success")) // if we url is getting redirected then remove this comment
                    if (!pageSource.Contains("success"))
                    {
                        for (int i = 1; i <= 2; i++)
                        {
                            Thread.Sleep(4000);
                            pageSource = HttpHelper.getHtmlfromUrl(new Uri("https://www.linkedin.com/contacts/api/contacts/?&sortOrder=recent&source=LinkedIn"));
                            if (pageSource.Contains("success"))
                            {
                                break;
                            }

                        }
                    }
                    if (!string.IsNullOrEmpty(pageSource))
                    {

                        string[] RgxGroupData = System.Text.RegularExpressions.Regex.Split(pageSource, "{\"name\"");
                        foreach (var Members in RgxGroupData)
                        {
                            string Fname = string.Empty;
                            string Title = string.Empty;
                            string companyName = string.Empty;
                            if (Members.Contains("title"))
                            {
                                try
                                {
                                    try
                                    {
                                        companyName = Utils.getBetween(Members, "company\":", "name\":");
                                        companyName = Utils.getBetween(companyName, "\"li_", "\",");
                                    }
                                    catch
                                    { }
                                    try
                                    {
                                        string[] arr = Regex.Split(Members, "\"li_");
                                        MemId1 = Utils.getBetween("###" + arr[2], "###", "\"}");
                                        MemId = user + ':' + MemId1;
                                    }
                                    catch
                                    {

                                        string[] arr = Regex.Split(Members, "\"li_");
                                        MemId1 = Utils.getBetween("###" + arr[1], "###", "\"}");
                                        MemId = user + ':' + MemId1;
                                    }

                                    Fname = Utils.getBetween(Members, "\"", "\"");
                                    Title = Utils.getBetween(Members, "\"title\": \"", "\",");
                                }
                                catch (Exception ex)
                                {
                                    GlobusLogHelper.log.Info("Exception : " + ex);
                                }

                                try
                                {
                                    if (!string.IsNullOrEmpty(MemId1))
                                    {
                                        string MemUrl = "https://www.linkedin.com/contacts/view?id=" + MemId1; //"https://www.linkedin.com/profile/view?id=" + MemId1;

                                        MemberNameAndID.Add(MemId, Fname + ":" + Title + ":" + companyName);

                                        //GlobusFileHelper.AppendStringToTextfileNewLine(user + " : " + MemFullName, Globals.path_ComposeMessage_FriendList);
                                        GlobusLogHelper.log.Info(" Added member : " + Fname + " ");

                                        string tempFinalData = user + "," + Fname + "," + MemId1 + "," + MemUrl + "," + Title;
                                        AddingLinkedInDataToCSVFile(tempFinalData);

                                        string Query = "INSERT INTO tb_endorsement (FriendName, FriendId,Username,Status) VALUES ('" + MemFullName + "', '" + MemId1 + "','" + user + "','0')";
                                        DataBaseHandler.InsertQuery(Query, "tb_endorsement");

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

                    }
                }
                #endregion without_search


                #region with_search

                //if (Globals.is_Searched_Compose_msg)
                //{
                //    string pageSourceaAdvanceSearch = HttpHelper.getHtmlfromUrl1(new Uri("http://www.linkedin.com/search"));
                //    string rsid = Utils.getBetween(pageSourceaAdvanceSearch, "vsearch/g?rsid=", "&trk");

                //    string url_search = "https://www.linkedin.com/vsearch/p?orig=FCTD&rsid=" + rsid + "&keywords=" + GroupStatus.searchKeyword + "&trk=vsrp_people_sel&trkInfo=VSRPsearchId%3A4198823611434003376235,VSRPcmpt%3Atrans_nav&openFacets=N,G,CC&f_N=F";
                //    pageSource = HttpHelper.getHtmlfromUrl(new Uri(url_search));   // if we url is getting redirected then comment this line

                //    // if (!string.IsNullOrEmpty(pageSource)&&!pageSource.Contains("success")) // if we url is getting redirected then remove this comment

                //    string no_of_profiles = string.Empty;
                //    string pagination_url = string.Empty;
                //    int no_of_pages = 0;
                //    if (!string.IsNullOrEmpty(pageSource))
                //    {
                //        no_of_profiles = Utils.getBetween(pageSource, "i18n_results_count_capped_without_keywords", "/strong");
                //        no_of_profiles = Utils.getBetween(no_of_profiles, "003e", "+");

                //    }
                //    if (pageSource.Contains("isCurrentPage\":true,\"pageURL"))
                //    {
                //        pagination_url = Utils.getBetween(pageSource, "isCurrentPage", "pageNum");
                //        pagination_url = Utils.getBetween(pagination_url, "pageURL\":\"", "\",");
                //        pagination_url = "https://www.linkedin.com" + pagination_url;

                //        string s1 = "";




                //        //isCurrentPage":true,
                //    }
                //    if (string.IsNullOrEmpty(pageSource))
                //    {
                //        for (int i = 1; i <= 2; i++)
                //        {
                //            Thread.Sleep(4000);
                //            pageSource = HttpHelper.getHtmlfromUrl(new Uri(url_search));
                //            if (pageSource.Contains("<!DOCTYPE html>"))
                //            {
                //                break;
                //            }

                //        }
                //    }
                //    if (!string.IsNullOrEmpty(no_of_profiles))
                //    {
                //        no_of_pages = Convert.ToInt32(no_of_profiles);
                //        no_of_pages = (no_of_pages / 10) + 1;
                //    }

                //    for (int i = 1; i <= no_of_pages; i++)
                //    {
                //        if (i == 1)
                //        {

                //        }
                //        else
                //        {
                //            pagination_url = Utils.getBetween(pagination_url, "", "num=");
                //            pagination_url = pagination_url + "num=" + i;
                //            pageSource = HttpHelper.getHtmlfromUrl(new Uri(pagination_url));

                //        }


                //        if (!string.IsNullOrEmpty(pageSource))
                //        {
                //            string[] RgxGroupData = System.Text.RegularExpressions.Regex.Split(pageSource, "fmt_headline");

                //            foreach (var Members in RgxGroupData)
                //            {
                //                string Fname = string.Empty;
                //                string Title = string.Empty;

                //                if (!Members.Contains("<!DOCTYPE html>"))
                //                {
                //                    try
                //                    {
                //                        try
                //                        {

                //                            MemId1 = Utils.getBetween(Members, "&pid=", "&");




                //                            // int startindex = Members.IndexOf(", \"id\": \"li_");
                //                            // string start = Members.Substring(startindex).Replace(", \"id\": \"li_", string.Empty);
                //                            // int endIndex = start.IndexOf("\"}");
                //                            // MemId1 = start.Substring(0, endIndex).Replace("{[", string.Empty).Replace("}]", string.Empty).Trim();
                //                            MemId = user + ':' + MemId1;
                //                            Globals.groupStatusString = "withoutAPI because of li_";
                //                        }
                //                        catch
                //                        {
                //                            int startindex = Members.IndexOf(", \"id\":");
                //                            string start = Members.Substring(startindex).Replace(", \"id\":", string.Empty);
                //                            int endIndex = start.IndexOf("},");
                //                            MemId1 = start.Substring(0, endIndex).Replace("{[", string.Empty).Replace("},", string.Empty).Trim();
                //                            MemId = user + ':' + MemId1;

                //                            Globals.groupStatusString = "API";
                //                        }

                //                        try
                //                        {
                //                            Fname = Utils.getBetween(Members, "fmt_name\":\"", "\",\"");
                //                            //  if(Fname.Contains(""))


                //                            // string Start = Members.Substring(StartIndex1).Replace(": \"", string.Empty);
                //                            // int EndIndex = Start.IndexOf("\",");
                //                            //string End = Start.Substring(0, EndIndex);
                //                            //Fname = End.Replace(",", ";").Replace("&#xe3;", "ã").Replace("&#xe7;", "ç").Replace("&#xf4;", "ô").Replace("&#xe9;", "é").Replace("&#xba;", "º").Replace("&#xc1;", "Á").Replace("&#xb4;", "'").Replace("&#xed;", "í").Replace("&#xf5;", "õ").Replace("&#xf3;", "ó").Replace("&#xe1;", "á").Replace("&#xea;", "ê").Replace("&#xe0;", "à").Replace("&#xfc;", "ü").Replace("&#xe4;", "ä").Replace("&#xf6;", "ö").Replace("&#xfa;", "ú").Replace("&#xf4;", "ô").Replace("&#xc9;", "É").Replace("&#xe2;", "â").Replace("&#x113;", "ē").Replace("&#xd3;", "Ó").Replace("&#xf1;", "ñ").Replace("&#x20ac;", "€").Replace("&#xd1;", "Ñ").Replace("&#xe8;", "è").Replace("&#xd3;", "Ó").Replace("&#xaa;", "ª").Replace("&#x2605;", "★").Replace("&#x2606;", "☆").Replace("&#xf1;", "ñ").Replace("&#xc0;", "À").Replace("&#x263a;", "☺").Replace("&#xbf;", "¿").Replace("\\u00ae", "®").Replace("{[", string.Empty).Replace("}]", string.Empty);
                //                        }
                //                        catch
                //                        { }

                //                        try
                //                        {
                //                            Title = Utils.getBetween(Members, "\":\"", "\",\"");
                //                            // string Start = Members.Substring(StartIndextemp).Replace("title\":", string.Empty);
                //                            //int EndIndex = Start.IndexOf(",");
                //                            // string End = Start.Substring(0, EndIndex).Replace("\"", "").Trim();
                //                            // Title = End.Replace(",", ";").Replace("&#xe3;", "ã").Replace("&#xe7;", "ç").Replace("&#xf4;", "ô").Replace("&#xe9;", "é").Replace("&#xba;", "º").Replace("&#xc1;", "Á").Replace("&#xb4;", "'").Replace("&#xed;", "í").Replace("&#xf5;", "õ").Replace("&#xf3;", "ó").Replace("&#xe1;", "á").Replace("&#xea;", "ê").Replace("&#xe0;", "à").Replace("&#xfc;", "ü").Replace("&#xe4;", "ä").Replace("&#xf6;", "ö").Replace("&#xfa;", "ú").Replace("&#xf4;", "ô").Replace("&#xc9;", "É").Replace("&#xe2;", "â").Replace("&#x113;", "ē").Replace("&#xd3;", "Ó").Replace("&#xf1;", "ñ").Replace("&#x20ac;", "€").Replace("&#xd1;", "Ñ").Replace("&#xe8;", "è").Replace("&#xd3;", "Ó").Replace("&#xaa;", "ª").Replace("&#x2605;", "★").Replace("&#x2606;", "☆").Replace("&#xf1;", "ñ").Replace("&#xc0;", "À").Replace("&#x263a;", "☺").Replace("&#xbf;", "¿").Replace("\\u00ae", "®").Replace("{[", string.Empty).Replace("}]", string.Empty);
                //                            if (Title.Contains("u003e"))
                //                            {
                //                                Title = Utils.getBetween(Title + "##", "u003e", "#");
                //                            }
                //                            if (Title.Contains("\\u003c/strong\\u003e"))
                //                            {
                //                                Title = Title.Replace("\\u003c/strong\\u003e", "");
                //                            }


                //                            if (Title == "null")
                //                            {
                //                                Title = "N/A";
                //                            }
                //                        }
                //                        catch
                //                        { }
                //                    }
                //                    catch (Exception ex)
                //                    {
                //                        GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Error --> Add Friends Groups --> PostAddMembers() >> 1 >>>> " + ex.Message + "StackTrace --> >>>" + ex.StackTrace, Globals.Path_LinkedinErrorLogs);
                //                        GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Error --> Add Friends Groups --> PostAddMembers() >> 1 >>>> " + ex.Message + "StackTrace --> >>>" + ex.StackTrace, Globals.Path_LinkedinAddFriendsGroupErrorLogs);
                //                    }
                //                    //   #endregion

                //                    MemFullName = Fname;

                //                    try
                //                    {

                //                        if (!string.IsNullOrEmpty(MemId1))
                //                        {
                //                            #region WriteenByMe

                //                            // string MemUrl = "https://www.linkedin.com/profile/view?id=" + MemId1;

                //                            #endregion




                //                            string MemUrl = "https://www.linkedin.com/contacts/view?id=" + MemId1; //"https://www.linkedin.com/profile/view?id=" + MemId1;





                //                            //string memResponse = HttpHelper.getHtmlfromUrl(new Uri(MemUrl));
                //                            //if (memResponse.Contains("is your connection"))
                //                            //{

                //                            //if (!string.IsNullOrEmpty(Title))
                //                            {
                //                                MemberNameAndID.Add(MemId, MemFullName + ":" + Title);
                //                            }

                //                            GlobusFileHelper.AppendStringToTextfileNewLine(user + " : " + MemFullName, Globals.path_ComposeMessage_FriendList);
                //                            Logger("[ " + DateTime.Now + " ] => [ Added member : " + MemFullName + " ]");

                //                            string tempFinalData = user + "," + MemFullName + "," + MemId1 + "," + MemUrl + "," + Title;
                //                            AddingLinkedInDataToCSVFile(tempFinalData);

                //                            string Query = "INSERT INTO tb_endorsement (FriendName, FriendId,Username,Status) VALUES ('" + MemFullName + "', '" + MemId1 + "','" + user + "','0')";
                //                            DataBaseHandler.InsertQuery(Query, "tb_endorsement");

                //                            if (moduleLog == "endorsecamp")
                //                            {
                //                                Log_Endorse("[ " + DateTime.Now + " ] => [ Insert Member ID " + MemId1 + " of " + (MemFullName) + " ]");
                //                            }
                //                            // }
                //                        }
                //                    }
                //                    catch (Exception ex)
                //                    {
                //                        GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Error --> Add Friends Groups --> PostAddMembers() >> 2 >>>> " + ex.Message + "StackTrace --> >>>" + ex.StackTrace, Globals.Path_LinkedinErrorLogs);
                //                        GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Error --> Add Friends Groups --> PostAddMembers() >> 2 >>>> " + ex.Message + "StackTrace --> >>>" + ex.StackTrace, Globals.Path_LinkedinAddFriendsGroupErrorLogs);
                //                    }
                //                }
                //            }

                //        }
                //    }
                //}
                #endregion with_search


              

                return MemberNameAndID;
            }
            catch (Exception ex)
            {
                GlobusLogHelper.log.Info("Exception : " + ex);
                return MemberNameAndID;
            }
        }
 public void StartSalesNavigator(ref LinkedinUser objLinkedinUser)
 {
     try
     {
         GlobusHttpHelper objHttpHelper = objLinkedinUser.globusHttpHelper;
         string mainUrl = string.Empty;
         mainUrl = FormURL(ref objLinkedinUser);
        
         Pagination(ref objHttpHelper, mainUrl);
         //ScrapeProfileDetails(ref objHttpHelper);
         try
         {
             string[] profileUrls = lstProfileUrls.ToArray();
             System.IO.File.WriteAllLines(FilePath.profileUrlsSalesNavigatorScraper, profileUrls);
         }
         catch
         { }
     }
     catch (Exception ex)
     {
     }
 }
        public void LoadAccountsFromDataBase()
        {
            try
            {
                LDGlobals.loadedAccountsDictionary.Clear();
                LDGlobals.listAccounts.Clear();

                DataTable dt = new DataTable();

                dt.Columns.Add("UserName");
                dt.Columns.Add("Password");
               // dt.Columns.Add("ScreenName");
               //// dt.Columns.Add("FollowerCount");
               // dt.Columns.Add("FollwingCount");
                dt.Columns.Add("proxyAddress");
                dt.Columns.Add("proxyPort");
                dt.Columns.Add("ProxyUserName");
                dt.Columns.Add("ProxyPassword");
             //   dt.Columns.Add("GroupName");
              //  dt.Columns.Add("AccountStatus");



                int counter = 0;
                DataSet ds = null;
                try
                {
                    ds = Qm.SelectAccounts();
                }
                catch (Exception ex)
                {
                    GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                }


                foreach (DataRow ds_item in ds.Tables[0].Rows)
                {
                    if (Globals.CheckLicenseManager == "fdfreetrial" && counter == 5)
                    {
                        break;
                    }
                    counter = counter + 1;
                    try
                    {
                        string item = ds_item[0].ToString() + ":" + ds_item[1].ToString() + ":" + ds_item[2].ToString() + ":" + ds_item[3].ToString() + ":" + ds_item[4].ToString() + ":" + ds_item[5].ToString();
                        string account = item;
                        string[] AccArr = account.Split(':');
                        if (AccArr.Count() > 1)
                        {
                            string accountUser = account.Split(':')[0];
                            string accountPass = account.Split(':')[1];

                            string ScreenName = string.Empty;
                            string FollowerCount = string.Empty;
                            string FollwingCount = string.Empty;
                            string proxyAddress = string.Empty;
                            string proxyPort = string.Empty;
                            string proxyUserName = string.Empty;
                            string proxyPassword = string.Empty;
                            string GroupName = string.Empty;
                            string AccountStatus = string.Empty;
                            string status = string.Empty;

                            DataGridColumn newcolumn = new DataGridHyperlinkColumn();


                            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 ==6)
                            {

                                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);


                            try
                            {
                                LinkedinUser objLD_Users = new LinkedinUser();
                               // TWTUsers objTwtUser = new TWTUsers();
                                objLD_Users.username = accountUser;
                                objLD_Users.password = accountPass;
                                objLD_Users.proxyip = proxyAddress;
                                objLD_Users.proxyport = proxyPort;
                                objLD_Users.proxyusername = proxyUserName;
                                objLD_Users.proxypassword = proxyPassword;

                                LDGlobals.loadedAccountsDictionary.Add(objLD_Users.username, objLD_Users);
//                                TWTGlobals.loadedAccountsDictionary.Add(objTwtUser.username, objTwtUser);

                                #region MyRegion
                                //try
                                //{
                                //    if (cmbGroups_GroupCampaignManager_Accounts.InvokeRequired)
                                //    {
                                //        cmbScraper__fanscraper_Accounts.Invoke(new MethodInvoker(delegate
                                //        {
                                //            cmbScraper__fanscraper_Accounts.Items.Add(accountUser);
                                //        }));
                                //    }
                                //}
                                //catch (Exception ex)
                                //{
                                //    GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                                //}

                                //try
                                //{
                                //    if (cmbScraper__CustomAudiencesScraper_Accounts.InvokeRequired)
                                //    {
                                //        cmbScraper__CustomAudiencesScraper_Accounts.Invoke(new MethodInvoker(delegate
                                //        {
                                //            cmbScraper__CustomAudiencesScraper_Accounts.Items.Add(accountUser);
                                //        }));
                                //    }
                                //}
                                //catch (Exception ex)
                                //{
                                //    GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                                //}
                                //try
                                //{
                                //    //cmbCommentsOnPostSelectAccount
                                //    if (cmbCommentsOnPostSelectAccount.InvokeRequired)
                                //    {
                                //        cmbCommentsOnPostSelectAccount.Invoke(new MethodInvoker(delegate
                                //        {
                                //            cmbCommentsOnPostSelectAccount.Items.Add(accountUser + ":" + accountPass);
                                //        }));
                                //    }
                                //}
                                //catch (Exception ex)
                                //{
                                //    GlobusLogHelper.log.Error(ex.Message);
                                //}
                                //try
                                //{
                                //    if (cmbGroups_GroupCampaignManager_Accounts.InvokeRequired)
                                //    {
                                //        cmbGroups_GroupCampaignManager_Accounts.Invoke(new MethodInvoker(delegate
                                //        {
                                //            cmbGroups_GroupCampaignManager_Accounts.Items.Add(accountUser);
                                //        }));
                                //    }
                                //}
                                //catch (Exception ex)
                                //{
                                //    GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                                //}

                                //try
                                //{
                                //    if (cmbScraper__GroupMemberScraper_Accounts.InvokeRequired)
                                //    {
                                //        cmbScraper__GroupMemberScraper_Accounts.Invoke(new MethodInvoker(delegate
                                //        {
                                //            cmbScraper__GroupMemberScraper_Accounts.Items.Add(accountUser);
                                //        }));
                                //    }
                                //}
                                //catch (Exception ex)
                                //{
                                //    GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
                                //} 
                                #endregion

                                LDGlobals.listAccounts.Add(objLD_Users.username + ":" + objLD_Users.password + ":" + objLD_Users.proxyip + ":" + objLD_Users.proxyport + ":" + objLD_Users.proxyusername + ":" + objLD_Users.proxypassword);
                              //  TWTGlobals.listAccounts.Add(objTwtUser.username + ":" + objTwtUser.password + ":" + objTwtUser.proxyip + ":" + objTwtUser.proxyport + ":" + objTwtUser.proxyusername + ":" + objTwtUser.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;

           
                
                this.Dispatcher.Invoke(new Action(delegate
                {
                   // grvAccounts_AccountCreator_AccountDetails.ItemsSource = dv;

                }));

                try
                {
                    grvAccounts_AccountCreator_AccountDetails.ItemsSource = dt.DefaultView;
                }
                catch { }


                GlobusLogHelper.log.Debug("Accounts Loaded : " + dt.Rows.Count);
                GlobusLogHelper.log.Info("Accounts Loaded : " + dt.Rows.Count);

            }
            catch (Exception ex)
            {
                GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
            }
        }
        public bool CheckAccountDetailDB(string Username, string profileUrl, ref LinkedinUser objLinkedinUser)
        {
            bool checkStatus = true;
            try
            {
                var dateAndTime = DateTime.Now;
                var date = dateAndTime.Date;

                string Date = dateAndTime.ToString("dd/MM/yyyy");

                #region new code by sharan

                string LinkedinUrl = profileUrl.Split('&')[0];
                string selectQuery = "SELECT * FROM tb_ManageAddConnection WHERE Username ='******'and LinkedinUrl='" + LinkedinUrl + "'and DateTime='" + Date.Replace("/","-") + "' ";

                #endregion


                // string selectQuery = "SELECT * FROM tb_AccountsDetails WHERE Usename ='" + objLinkedinUser.username + "'and ProfileId='" + profileUrl + "'and Date='" + Date + "' ";
                DataSet ds = DataBaseHandler.SelectQuery(selectQuery, "tb_AccountsDetails");
                if (ds.Tables[0].Rows.Count != 0)
                {
                    return checkStatus = false;
                }
                else
                {
                    return checkStatus = true;
                }

            }
            catch
            {
                return checkStatus = false;
            };
            return checkStatus;
        }
 public void ConnectSearchUsingkeyword(ref LinkedinUser objLinkedinUser, int SearchMinDelay, int SearchMaxDelay)
 {
     try
     {
         ConnectionSearch(ref objLinkedinUser, SearchMinDelay, SearchMaxDelay);
     }
     catch
     {
     }
 }
        public void StartAddConn(ref LinkedinUser objLinkedinUser)
        {
            try
            {
                if (GlobalsAddConn.selectedManageConnKeyword&&!string.IsNullOrEmpty(GlobalsAddConn.requestPerKeyword.ToString()))
                {                    
                    foreach (string itemKeyword in GlobalsAddConn.lst_keyWords_for_AddConnection)
                    {
                        que_SearchKeywords.Enqueue(itemKeyword);
                    }

                    //ConnectUsing_Search ConnectUsing_Search = new ConnectUsing_Search(objLinkedinUser.username, objLinkedinUser.password, objLinkedinUser.proxyip, objLinkedinUser.proxyport, objLinkedinUser.proxyusername, objLinkedinUser.proxypassword, que_SearchKeywords);
                    ConnectSearchUsingkeyword(ref objLinkedinUser, GlobalsAddConn.minDelay, GlobalsAddConn.maxDelay);
                }
                if(GlobalsAddConn.selectedManageConnEmail)
                {
                    InviteFriendThroughEmail(ref objLinkedinUser, GlobalsAddConn.noOfUsers, GlobalsAddConn.maxDelay, GlobalsAddConn.minDelay);
                }
            }
            catch (Exception ex)
            {
            }
        }
        public void InviteFriendThroughEmail(ref LinkedinUser objLinkedinUser, int NoofemailRequest, int MaxDelay, int MinDelay)
        {
            try
            {
                int proxyport = 888;
                Regex PortCheck = new Regex("^[0-9]*$");

                string _ProxyPort = objLinkedinUser.proxyport;
                string _UserName = objLinkedinUser.username;
                string _Password = objLinkedinUser.password;
                string _ProxyAddress = objLinkedinUser.proxyip;
                string _ProxyUserName = objLinkedinUser.proxyusername;
                string _ProxyPassword = objLinkedinUser.proxypassword;
                GlobusHttpHelper HttpHelper = objLinkedinUser.globusHttpHelper;

                if (PortCheck.IsMatch(_ProxyPort) && !string.IsNullOrEmpty(_ProxyPort))
                {
                    proxyport = int.Parse(_ProxyPort);
                }

                string xMESSAGE = string.Empty;
                GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Logging In With Account : " + _UserName + " ]");

                if (objLinkedinUser.isloggedin)
                {
                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Logged in with " + _UserName + " ]");
                    //int CounterInvite = 1;

                    //if (UniqueEmailStatus == "False")
                    DataSet ds_bList = new DataSet();
                    foreach (string Email in GlobalsAddConn.lst_Emails_for_AddConnection)
                    {
                        string emailtosend = string.Empty;

                        try
                        {
                            string Querystring = "Select UserID From tb_BlackListAccount Where UserID ='" + Email + "'";
                            ds_bList = DataBaseHandler.SelectQuery(Querystring, "tb_BlackListAccount");
                        }
                        catch { }

                        if (ds_bList.Tables.Count > 0)
                        {
                            if (ds_bList.Tables[0].Rows.Count > 0)
                            {
                                GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ User: "******" is Added BalckListed List For Send Connection Pls Check ]");
                                return;
                            }
                        }
                        else
                        {
                            if (Email.Contains(":"))
                            {
                                emailtosend = Email.Split(':')[0];
                            }
                            else
                            {
                                emailtosend = Email;
                            }

                            try
                            {
                                GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Sending Invitation To :" + emailtosend + " ]");

                                string emailAddresses = string.Empty;
                                string csrfToken = string.Empty;
                                string sourceAlias = string.Empty;
                                string PostData = string.Empty;
                                string PgSrcInviteMessgae = string.Empty;
                                string postUrl = string.Empty;

                                // https://www.linkedin.com/fetch/manual-invite-create

                                PgSrcInviteMessgae = HttpHelper.getHtmlfromUrlProxy(new Uri("https://www.linkedin.com/fetch/importAndInviteEntry"), _ProxyAddress, proxyport, _ProxyUserName, _ProxyPassword);
                                emailAddresses = emailtosend;

                                // For csrfToken
                                string[] ArrCsrfToken = Regex.Split(PgSrcInviteMessgae, "input");
                                foreach (string item in ArrCsrfToken)
                                {
                                    try
                                    {
                                        if (!item.Contains("<!DOCTYPE"))
                                        {
                                            if (item.Contains("csrfToken") && item.Contains("value="))
                                            {
                                                csrfToken = item;
                                                break;
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                }
                                if (csrfToken.Contains("csrfToken"))
                                {
                                    try
                                    {
                                        csrfToken = csrfToken.Substring(csrfToken.IndexOf("csrfToken"), 44);
                                        string[] Arr = csrfToken.Split('&');
                                        csrfToken = Arr[0].Replace("csrfToken=", string.Empty);
                                        csrfToken = csrfToken.Replace(":", "%3A").Replace("\\", string.Empty).Replace("csrfToken", "").Replace("=", "").Replace("value", "").Replace("\"", "").Trim();
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                }

                                // For sourceAlias
                                if (PgSrcInviteMessgae.Contains("sourceAlias"))
                                {
                                    try
                                    {
                                        sourceAlias = PgSrcInviteMessgae.Substring(PgSrcInviteMessgae.IndexOf("sourceAlias"), 100);
                                        string[] Arr = sourceAlias.Split('"');
                                        sourceAlias = Arr[2].Replace("\\", string.Empty).Trim();
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                }
                                if(csrfToken.Contains(">"))
                                {
                                    csrfToken = Utils.getBetween("###"+csrfToken, "###", ">");

                                }

                                //Post Data for Invite Message 
                                PostData = "emailAddresses=" + Uri.EscapeDataString(emailAddresses) + "&subject=Invitation+to+connect+on+LinkedIn&csrfToken=" + csrfToken + "&sourceAlias=" + sourceAlias;
                                //Post Url for Invite Message 

                                postUrl = "https://www.linkedin.com/fetch/manual-invite-create";

                                string postResponse = HttpHelper.postFormDataRef(new Uri(postUrl), PostData, "https://www.linkedin.com/fetch/manual-invite-create", "", "", "", "", "");

                                if (postResponse.Contains("Your invitation has been sent.") && postResponse.Contains("alert success"))
                                {
                                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Invitation sent to :" + emailtosend + " from ID : " + _UserName + " ]");
                                    GlobusFileHelper.AppendStringToTextfileNewLine(_UserName + "-->" + emailtosend, FilePath.path_AddConnectionEmail);
                                }
                                else if (!postResponse.Contains("Your invitation has been sent.") && !postResponse.Contains("alert success"))
                                {
                                    int Delay = RandomNumberGenerator.GenerateRandom(GlobalsAddConn.minDelay, GlobalsAddConn.maxDelay);
                                    Thread.Sleep(Delay * 1000);
                                    postResponse = HttpHelper.postFormDataRef(new Uri(postUrl), PostData, "https://www.linkedin.com/fetch/manual-invite-create", "", "", "", "", "");
                                    if (postResponse.Contains("Your invitation has been sent.") && postResponse.Contains("alert success"))
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Invitation sent to :" + emailtosend + " from ID : " + _UserName + " ]");
                                        GlobusFileHelper.AppendStringToTextfileNewLine(_UserName + "-->" + emailtosend, FilePath.path_AddConnectionEmail);
                                    }
                                    else
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Invitation sent to :" + emailtosend + " from ID : " + _UserName + " ]");
                                        GlobusFileHelper.AppendStringToTextfileNewLine(_UserName + "-->" + emailtosend, FilePath.path_AddConnectionEmail);
                                        //LoggerManageConnection("[ " + DateTime.Now + " ] => [ Some Problem for sending Invitation :" + emailtosend + " from ID : " + _UserName + " ]");
                                        //GlobusFileHelper.AppendStringToTextfileNewLine(_UserName + "-->" + emailtosend, Globals.path_NonAddConnectionEmail);
                                    }
                                }
                                else
                                {
                                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Invitation sent to :" + emailtosend + " from ID : " + _UserName + " ]");
                                    GlobusFileHelper.AppendStringToTextfileNewLine(_UserName + "-->" + emailtosend, FilePath.path_AddConnectionEmail);
                                    //LoggerManageConnection("[ " + DateTime.Now + " ] => [ Some Problem for sending Invitation :" + emailtosend + " from ID : " + _UserName + " ]");
                                    //GlobusFileHelper.AppendStringToTextfileNewLine(_UserName + "-->" + emailtosend, Globals.path_NonAddConnectionEmail);
                                }

                                //MinimumDelay = MinDelay;
                                //MaximumDelay = MaxDelay;

                                int Delay1 = RandomNumberGenerator.GenerateRandom(GlobalsAddConn.minDelay, GlobalsAddConn.maxDelay);
                                GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Delay For : " + Delay1 + " Seconds ]");
                                Thread.Sleep(Delay1 * 1000);
                            }
                            catch (Exception ex)
                            {

                            }
                        }
                    }
                }
                else
                {
                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ " + xMESSAGE + " With Username >>> " + _UserName + " ]");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public void TestConnectPageSearchForUniqueUrl(string pageNumber, int SearchMinDelay, int SearchMaxDelay, ref LinkedinUser objLinkedinUser)
        {
            int proxyport = 888;
            string SummaryLink = string.Empty;
            GlobusHttpHelper HttpHelper = objLinkedinUser.globusHttpHelper;
            string _ProxyPort = objLinkedinUser.proxyport;
            string _ProxyAddress = objLinkedinUser.proxyip;
            string _ProxyUserName = objLinkedinUser.proxyusername;
            string _ProxyPassword = objLinkedinUser.proxypassword;

            Regex PortCheck = new Regex("^[0-9]*$");

            if (PortCheck.IsMatch(_ProxyPort) && !string.IsNullOrEmpty(_ProxyPort))
            {
                proxyport = int.Parse(_ProxyPort);
            }

            //recive the page number and then hit page wise and find the url in which we need to send the request.....

            string UrlConnectpage = "http://www.linkedin.com/search/fpsearch?keywords=" + _ConnectSearchKeyword + "&keepFacets=keepFacets&page_num=" + pageNumber + "&pplSearchOrigin=ADVS&viewCriteria=2&sortCriteria=R&redir=redir";
            string PgSrcMain1 = HttpHelper.getHtmlfromUrlProxy(new Uri(UrlConnectpage), _ProxyAddress, proxyport, _ProxyUserName, _ProxyPassword);

            string PostData = string.Empty;
            string page_num = string.Empty;
            string postUrl = string.Empty;
            string facetsOrder = string.Empty;

            if (PgSrcMain1.Contains("facetsOrder"))
            {
                facetsOrder = PgSrcMain1.Substring(PgSrcMain1.IndexOf("facetsOrder"), 200);
                string[] Arr = facetsOrder.Split('"');
                facetsOrder = Arr[2];
                string DecodedCharTest = Uri.UnescapeDataString(facetsOrder);
                string DecodedEmail = Uri.EscapeDataString(facetsOrder);
                facetsOrder = DecodedEmail;
            }

            page_num = pageNumber;

            PostData = "search=&viewCriteria=2&sortCriteria=C&facetsOrder=" + facetsOrder + "&page_num=" + page_num + "&openFacets=N%2CCC%2CG";

            //Post Url for Invite Message 
            postUrl = "http://www.linkedin.com/search/hits";

            //Diclaration For Post Add Connection For Keyword

            //Post Response
            string postResponse = HttpHelper.postFormDataProxy(new Uri(postUrl), PostData, _ProxyAddress, proxyport, _ProxyUserName, _ProxyPassword);
            //  List<string> PageSerchUrl = ChilkatBasedRegex.GettingAllUrls1(PgSrcMain1, "/profile/view?id"); 
            // List<string> PageSerchUrl = ChilkatBasedRegex.GettingAllUrls1_writtenBysharan(PgSrcMain1, "/profile/view?id");
            List<string> PageSerchUrl = ChilkatBasedRegex.GettingAllUrls1_writtenBysharan_fullUrl(PgSrcMain1);


            ///profile/view?id=22828991&authType=OUT_OF_NETWORK&authToken=pYz-&locale=en_US&srchid=2361660011371725230773&srchindex=1&srchtotal=3010&trk=vsrp_people_res_name&trkInfo=VSRPsearchId%3A2361660011371725230773%2CVSRPtargetId%3A22828991%2CVSRPcmpt%3Aprimary

            string FrnAcceptUrL = string.Empty;
            foreach (string item in PageSerchUrl)
            {
                string Val_firstName = string.Empty;
                string Val_lastName = string.Empty;
                string Val_key = string.Empty;
                string Val_goback = string.Empty;
                string Val_sourceAlias = string.Empty;
                string Val_defaultText = string.Empty;
                string Val_CsrToken = string.Empty;
                string Val_Subject = string.Empty;
                string Val_greeting = string.Empty;
                string Val_AuthToken = string.Empty;
                string Val_AuthType = string.Empty;
                string val_trk = string.Empty;

                string _UserName = objLinkedinUser.username;

                bool check = CheckAccountDetailDB(_UserName, item, ref objLinkedinUser);
                if (!check)
                {
                    GlobusLogHelper.log.Info("this Profile :" + item + "  has already been visited today with username : "******"/profile/view?id"))  //this key word can only seprate the Url with all common urls....
                    {
                        lock (LockerConnection)
                        {
                            //if (!item.Contains("http://www.linkedin.com"))
                            //{
                            //    FrnAcceptUrL = "http://www.linkedin.com" + item;
                            //}
                            // else
                            {
                                FrnAcceptUrL = item;
                            }
                            string[] urll = Regex.Split(FrnAcceptUrL, "&authType");
                            DataSet ds = new DataSet();
                            try
                            {
                                string Querystring = "Select * From tb_ManageAddConnection Where Keyword='" + _ConnectSearchKeyword + "' and LinkedinUrl='" + urll[0] + "'";//"Insert into tb_ManageAddConnection (Keyword,LinkedinUrl,Username,DateTime) Values('" + _ConnectSearchKeyword + "','" + url[0] + "','" + _UserName + "','" + DateTime.Now.ToString("dd-MM-yyyy") + "')";
                                ds = DataBaseHandler.SelectQuery(Querystring, "tb_ManageAddConnection");
                            }
                            catch { }
                            if (ds.Tables[0].Rows.Count < 1)
                            {
                                string FRNURLresponce = HttpHelper.getHtmlfromUrl1(new Uri(FrnAcceptUrL));

                                if (FRNURLresponce.Contains("memberId"))
                                {
                                    try
                                    {
                                        //Val_key = FrnAcceptUrL.Substring(FrnAcceptUrL.IndexOf("id="), (FrnAcceptUrL.IndexOf("&", FrnAcceptUrL.IndexOf("id=")) - FrnAcceptUrL.IndexOf("id="))).Replace("id=", string.Empty).Trim();

                                        Val_key = Utils.getBetween(FRNURLresponce, "memberId:\"", "\"}");
                                    }
                                    catch { }
                                }

                                if (FRNURLresponce.Contains("csrfToken"))
                                {
                                    try
                                    {
                                        Val_CsrToken = FRNURLresponce.Substring(FRNURLresponce.IndexOf("csrfToken"), 100);
                                        string[] Arr = Val_CsrToken.Split('>');
                                        Val_CsrToken = Arr[0].Replace("csrfToken=", "").Replace("\"", string.Empty).Trim();
                                    }
                                    catch { }
                                }

                                if (FRNURLresponce.Contains("authToken"))
                                {
                                    try
                                    {
                                        int startindex = FRNURLresponce.IndexOf("authToken");
                                        string start = FRNURLresponce.Substring(startindex);
                                        int endindex = start.IndexOf(",");
                                        string end = start.Substring(0, endindex);
                                        Val_AuthToken = end.Replace(",", string.Empty).Replace("authToken=", string.Empty).Replace("\"", string.Empty).Trim();
                                        if (Val_AuthToken.Contains("&"))
                                        {
                                            string[] Arr = Val_AuthToken.Split('&');
                                            Val_AuthToken = Arr[0].Replace("authToken=", string.Empty);
                                        }
                                        if (Val_AuthToken.Contains("</noscript>"))
                                        {
                                            try
                                            {
                                                string[] Val_Auth = Regex.Split(Val_AuthToken, ">");
                                                Val_AuthToken = Val_Auth[0].Replace("\"", string.Empty);
                                            }
                                            catch { }
                                        }
                                    }
                                    catch { }
                                }
                                if (FRNURLresponce.Contains("authType"))
                                {
                                    try
                                    {
                                        Val_AuthType = FRNURLresponce.Substring(FRNURLresponce.IndexOf("authType"), 50);
                                        string[] Arr = Val_AuthType.Split('&');
                                        Val_AuthType = Arr[0].Replace("authType=", "");
                                        if (Val_AuthType.Contains("</noscript>"))
                                        {
                                            Val_AuthType = Val_AuthType.Replace("</noscript>", string.Empty).Replace("\n", string.Empty).Replace(">", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Trim();
                                        }
                                        try
                                        {
                                            if (string.IsNullOrEmpty(Val_AuthType))
                                            {
                                                Val_AuthType = "OUT_OF_NETWORK";
                                            }
                                        }
                                        catch { }
                                    }
                                    catch { }
                                }


                                if (FRNURLresponce.Contains("goback"))
                                {
                                    try
                                    {
                                        Val_goback = FRNURLresponce.Substring(FRNURLresponce.IndexOf("goback"), 300);
                                        string[] Arr = Val_goback.Split('"');
                                        Val_goback = Arr[0].Replace("goback=", "");
                                    }
                                    catch { }
                                }
                                if (FRNURLresponce.Contains("trk"))
                                {
                                    try
                                    {
                                        val_trk = FRNURLresponce.Substring(FRNURLresponce.IndexOf("trk"), 100);
                                        string[] Arr = val_trk.Split(';');
                                        val_trk = Arr[0].Replace("trk=", "");
                                    }
                                    catch { }
                                }

                                if (FRNURLresponce.Contains("lastName"))
                                {
                                    try
                                    {
                                        Val_lastName = FRNURLresponce.Substring(FRNURLresponce.IndexOf("View Profile"), 300);
                                        try
                                        {
                                            string[] Arr = Val_lastName.Split(':');
                                            Val_lastName = Arr[2].Replace("firstName", "").Replace(",", "").Replace("\"", "").Replace("&#225;", string.Empty).Trim();
                                        }
                                        catch { }
                                    }
                                    catch { }
                                }

                                if (FRNURLresponce.Contains("firstName") || FRNURLresponce.Contains("ShortTitle"))
                                {
                                    try
                                    {
                                        if (FRNURLresponce.Contains("firstName"))
                                        {
                                            try
                                            {
                                                Val_firstName = FRNURLresponce.Substring(FRNURLresponce.IndexOf("View Profile"), 300);
                                                string[] Arrr = Val_firstName.Split(':');
                                                Val_firstName = Arrr[3].Replace("lastName=", "").Replace("i18n_HEADLINE", string.Empty).Replace("\"", "").Replace(",", string.Empty).Replace("}", string.Empty).Replace("link__endpoint", "").Trim();
                                            }
                                            catch { }
                                        }
                                        else if (FRNURLresponce.Contains("ShortTitle"))
                                        {
                                            Val_firstName = FRNURLresponce.Substring(FRNURLresponce.IndexOf("ShortTitle"), 30);
                                            string[] Arr = Val_firstName.Split('"');
                                            Val_firstName = Arr[2].Replace("ShortTitle=", "");
                                        }
                                    }
                                    catch { }

                                }

                                if (string.IsNullOrEmpty(Val_firstName))
                                {
                                    int startindex = FRNURLresponce.IndexOf("<title>");
                                    string start = FRNURLresponce.Substring(startindex).Replace("<title>", string.Empty);
                                    int endindex = start.IndexOf("</title>");
                                    string end = start.Substring(0, endindex).Replace("</title>", string.Empty);
                                    Val_firstName = end.Replace("| LinkedIn", "").Trim();
                                    string[] Arr = Regex.Split(Val_firstName, " ");
                                    try
                                    {
                                        Val_firstName = Arr[0];
                                        Val_lastName = Arr[1];
                                    }
                                    catch
                                    { }
                                    if (Arr.Count() == 2)
                                    {
                                        try
                                        {
                                            Val_lastName = Arr[1];
                                        }
                                        catch
                                        { }
                                    }
                                    if (Arr.Count() == 3)
                                    {
                                        try
                                        {
                                            Val_lastName = Arr[1] + " " + Arr[2];
                                        }
                                        catch
                                        { }
                                    }
                                    if (Arr.Count() == 4)
                                    {
                                        try
                                        {
                                            Val_lastName = Arr[1] + " " + Arr[2] + " " + Arr[3];
                                        }
                                        catch
                                        { }
                                    }
                                    if (Arr.Count() == 5)
                                    {
                                        try
                                        {
                                            Val_lastName = Arr[1] + " " + Arr[2] + " " + Arr[3] + " " + Arr[4];
                                        }
                                        catch
                                        { }
                                    }
                                    if (Arr.Count() == 6)
                                    {
                                        try
                                        {
                                            Val_lastName = Arr[1] + " " + Arr[2] + " " + Arr[3] + " " + Arr[4] + " " + Arr[5];
                                        }
                                        catch
                                        { }
                                    }
                                    if (Arr.Count() == 7)
                                    {
                                        try
                                        {
                                            Val_lastName = Arr[1] + " " + Arr[2] + " " + Arr[3] + " " + Arr[4] + " " + Arr[5] + " " + Arr[6];
                                        }
                                        catch
                                        { }
                                    }
                                }


                                try
                                {
                                    string[] Valuesss = Regex.Split(FRNURLresponce, "markAsReadOnClick");
                                    try
                                    {
                                        Val_goback = Valuesss[1].Substring(Valuesss[1].IndexOf("goback="), (Valuesss[1].IndexOf(",", Valuesss[1].IndexOf("goback=")) - Valuesss[1].IndexOf("goback="))).Replace("goback=", string.Empty).Trim();

                                    }
                                    catch { }
                                }
                                catch { }


                                //Check BlackListed Accounts
                                DataSet ds_bList = new DataSet();
                                try
                                {
                                    string Querystring = "Select ProfileID From tb_BlackListAccount Where ProfileID ='" + Val_key + "'";
                                    ds_bList = DataBaseHandler.SelectQuery(Querystring, "tb_BlackListAccount");
                                }
                                catch { }

                                string pageResponce2 = string.Empty;

                                if (ds_bList.Tables.Count > 0)
                                {
                                    if (ds_bList.Tables[0].Rows.Count > 0)
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ User: "******":", string.Empty).Trim() + " is Added BlackListed List For Send Invitation Pls Check ]");
                                        return;
                                    }
                                }
                                else
                                {
                                    string thiredResponce = "http://www.linkedin.com/people/invite?from=profile&key=" + Val_key + "&firstName=" + Val_firstName + "&lastName=" + Val_lastName + "&authToken=" + Val_AuthToken + "&authType=" + Val_AuthType + "&csrfToken=" + Val_CsrToken + "&goback=" + Val_goback;
                                    pageResponce2 = HttpHelper.getHtmlfromUrl1(new Uri(thiredResponce));
                                }

                                if (pageResponce2.Contains("You and this LinkedIn user don’t know anyone in common"))
                                {
                                    string CSVHeader = "UserName" + "," + "SearchKeyword" + "," + "Invitation Sent To" + "," + "InvitationUrl";
                                    string[] url = Regex.Split(FrnAcceptUrL, "&authType");
                                    string CSV_Content = _UserName + "," + _ConnectSearchKeyword + ", ," + url[0];
                                    CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_ConnectionThroughUnkonwPeopleLink);
                                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Failed To Send Invitation From " + _UserName + " ]");
                                    valid = false;
                                    Isaccountvalid = false;
                                    continue;
                                }
                                if (pageResponce2.Contains("sourceAlias"))
                                {
                                    try
                                    {
                                        Val_sourceAlias = pageResponce2.Substring(pageResponce2.IndexOf("sourceAlias"), 100);
                                        string[] Arr = Val_sourceAlias.Split('"');
                                        Val_sourceAlias = Arr[2];
                                    }
                                    catch { }
                                }
                                string[] strNameValue = Regex.Split(pageResponce2, "name=");

                                #region DecareVariable By Sanjeev
                                string iweReconnectSubmit = string.Empty;
                                string iweLimitReached = string.Empty;
                                string companyID0 = string.Empty;
                                string companyName0 = string.Empty;
                                //companyName.0
                                string companyID1 = string.Empty;
                                string schoolID = string.Empty;
                                string schoolcountryCode = string.Empty;
                                string schoolprovinceCode = string.Empty;
                                string subject = string.Empty;
                                string defaultText = string.Empty;
                                string csrfToken = string.Empty;
                                string sourceAlias = string.Empty;
                                string goback = string.Empty;
                                string titleIC0 = string.Empty;
                                string greeting = string.Empty;
                                string startYearIC0 = string.Empty;
                                string endYearIC0 = string.Empty;
                                string schoolText = string.Empty;
                                string titleIB0 = string.Empty;
                                string startYearIB0 = string.Empty;
                                string trk = string.Empty;
                                string authType = string.Empty;
                                string otheremail = string.Empty;
                                string firstName = string.Empty;
                                string lastName = string.Empty;
                                #endregion



                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"startYearIC.0");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    startYearIC0 = (strValue);

                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"authType");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    authType = (strValue);

                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"authType");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    authType = (strValue);

                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    //string[] ArrForValue = Regex.Split(pageResponce2, "name=\"trk");
                                    //string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    //trk = (strValue);

                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"trk");
                                    int tempstartIndex = ArrForValue[1].IndexOf("id=\"");
                                    string strValue = ArrForValue[1].Substring(tempstartIndex).Replace("id=\"", "");
                                    strValue = strValue.Substring(0, strValue.IndexOf("\""));
                                    trk = (strValue).Trim();

                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"endYearIC.0");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    endYearIC0 = (strValue);

                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"schoolText");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    schoolText = (strValue);

                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"startYearIB.0");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    startYearIB0 = (strValue);

                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"titleIB.0");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    titleIB0 = (strValue);

                                }
                                catch { }
                                #endregion
                                //schoolText titleIB.0=
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"companyID.0");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    companyID0 = (strValue);

                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"companyID.1");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    companyID1 = (strValue);

                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"schoolID");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    schoolID = (strValue);

                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"schoolcountryCode");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    schoolcountryCode = (strValue);

                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"schoolprovinceCode");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    schoolprovinceCode = (strValue);
                                    if (!string.IsNullOrEmpty(schoolprovinceCode))
                                    {

                                        schoolprovinceCode = "";
                                    }
                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"subject");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    subject = (strValue);
                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"defaultText");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    defaultText = (strValue);
                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"csrfToken");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    csrfToken = (strValue);
                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"sourceAlias");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    sourceAlias = (strValue);
                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    //string[] ArrForValue = Regex.Split(pageResponce2, "name=\"goback");
                                    //string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    //goback = (strValue);

                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"goback");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    goback = (strValue).Replace("&quot;", "%22").Replace(":", "%3A").Replace(",", "%2C").Replace("/", "%2F").Replace("{", "%7B").Replace(" ", "+");
                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"titleIC.0");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    titleIC0 = (strValue);
                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"otherEmail");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    otheremail = (strValue);
                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"iweLimitReached");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    iweLimitReached = (strValue);
                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    try
                                    {
                                        string[] ArrForValue = Regex.Split(pageResponce2, "name=\"iweReconnectSubmit");
                                        string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("class=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                        iweReconnectSubmit = (strValue);
                                    }
                                    catch { }
                                    try
                                    {
                                        if (iweReconnectSubmit.Contains(">") || iweReconnectSubmit.Contains(">"))
                                        {
                                            iweReconnectSubmit = "Send Invitation";
                                        }
                                    }
                                    catch { }
                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    try
                                    {
                                        string[] ArrForValue = Regex.Split(pageResponce2, "name=\"greeting");
                                        string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("class=\"message\">"), ArrForValue[1].IndexOf("<", ArrForValue[1].IndexOf("class=\"message\">")) - ArrForValue[1].IndexOf("class=\"message\">")).Replace("class=\"message\">", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                        greeting = (strValue);
                                        greeting = greeting.Replace("&#39;", "'");
                                        greeting = greeting.Replace(" ", "+");
                                        greeting = Uri.EscapeUriString(greeting);
                                        greeting = greeting.Remove(greeting.IndexOf("@"));
                                    }
                                    catch { }
                                    try
                                    {
                                        if (iweReconnectSubmit.Contains(">") || iweReconnectSubmit.Contains(">"))
                                        {
                                            //iweReconnectSubmit = "Send Invitation";
                                        }
                                    }
                                    catch { }
                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"companyName.0");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    companyName0 = (strValue);
                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"firstName");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    firstName = (strValue);
                                }
                                catch { }
                                #endregion
                                #region
                                try
                                {
                                    string[] ArrForValue = Regex.Split(pageResponce2, "name=\"lastName");
                                    string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                    lastName = (strValue);

                                    if (lastName.Contains("&quot"))
                                    {
                                        lastName = string.Empty;

                                    }
                                }
                                catch { }
                                #endregion


                                string lastPostUrl = "http://www.linkedin.com/people/iweReconnectAction";

                                //
                                //*********post request for last process of send request 

                                //existingPositionIC=&companyName.0=&titleIC.0=&startYearIC.0=&endYearIC.0=&schoolText=&schoolID=&existingPositionIB=&companyName.1=&titleIB.0=&startYearIB.0=&endYearIB.0=&reason=IF&otherEmail=&greeting=I%27d+like+to+add+you+to+my+professional+network+on+LinkedIn.%0D%0A%0D%0A-+gaurav+agrawal&iweReconnectSubmit=Send+Invitation&key=141450&firstName=Ron&lastName=Bates&authToken=d7Ir&authType=OPENLINK&trk=prof-0-sb-connect-button&iweLimitReached=false&companyID.0=&companyID.1=&schoolID=&schoolcountryCode=&schoolprovinceCode=&javascriptEnabled=false&subject=gaurav+agrawal+wants+to+connect+on+LinkedIn+&defaultText=a908b3ba18701677a5879c1955035d05&csrfToken=ajax%3A8096156173388039261&                                                            sourceAlias=0_0ZD1VB-f52hFxNsCjPZdLV&goback=.fps_PBCK_*1_*1_*1_*1_*1_*1_*1_*2_*1_Y_*1_*1_*1_false_1_C_*1_*51_*1_*51_true_CC%2CN%2CG%2CI%2CPC%2CED%2CL%2CFG%2CTE%2CFA%2CSE%2CP%2CCS%2CF%2CDR_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2.npv_141450_*1_*1_OPENLINK_d7Ir_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1;
                                string NameOfSender = _UserName.Remove(_UserName.IndexOf("@"));
                                // tab-name username">
                                string SenderName = string.Empty;
                                try
                                {
                                    SenderName = FRNURLresponce.Substring(FRNURLresponce.IndexOf("tab-name username\">"), (FRNURLresponce.IndexOf("<", FRNURLresponce.IndexOf("tab-name username\">")) - FRNURLresponce.IndexOf("tab-name username\">"))).Replace("tab-name username\">", string.Empty).Trim().Replace("tab-name username\">", string.Empty);
                                    NameOfSender = Uri.EscapeUriString(SenderName);
                                }
                                catch { }
                                //if(string.IsNullOrEmpty(SenderName))
                                //{
                                //SenderName=NameOfSender;
                                //}

                                // catch { }
                                //if (Val_AuthType.Contains("</noscript>"))
                                //{
                                //    Val_AuthType = Val_AuthType.Replace("</noscript>", string.Empty).Replace("\n",string.Empty).Replace(">",string.Empty).Replace("\\",string.Empty).Replace("\"",string.Empty).Trim();
                                //}
                                //   string LastPostData = "companyName.0=" + companyName0 + "titleIC.0=" + titleIC0 + "&startYearIC.0=" + startYearIC0 + "&endYearIC.0=" + endYearIC0 + "&schoolText=" + schoolText + "&schoolID=" + schoolID + "&companyName.1=" + companyName0 + "&titleIB.0=" + titleIB0 + "&startYearIB.0=" + startYearIB0 + "&endYearIB.0=" + endYearIC0 + "&reason=IF&otherEmail=" + otheremail + "&greeting=" + greeting + "&iweReconnectSubmit=" + iweReconnectSubmit.Replace(" ", "+") + "&key=" + Val_key + "&firstName=" + firstName + "&lastName=" + lastName + "&authToken=" + Val_AuthToken + "&authType=" + Val_AuthType + "&trk=" + trk + "&iweLimitReached=false&companyID.0=" + companyID0 + "&companyID.1=" + companyID1 + "&schoolID=" + schoolID + "&schoolcountryCode=" + schoolcountryCode + "&schoolprovinceCode=" + schoolprovinceCode + "&javascriptEnabled=false&subject=" + subject.Replace(" ", "+") + "&defaultText=" + defaultText + "&csrfToken=" + Val_CsrToken + "&sourceAlias=" + sourceAlias + "&goback=" + goback;
                                string LastPostData = "companyName.0=" + companyName0 + "titleIC.0=" + titleIC0 + "&startYearIC.0=" + startYearIC0 + "&endYearIC.0=" + endYearIC0 + "&schoolText=" + schoolText + "&schoolID=" + schoolID + "&companyName.1=" + companyName0 + "&titleIB.0=" + titleIB0 + "&startYearIB.0=" + startYearIB0 + "&endYearIB.0=" + endYearIC0 + "&reason=IF&otherEmail=" + otheremail + "&greeting=" + greeting + "&iweReconnectSubmit=" + iweReconnectSubmit.Replace(" ", "+") + "&key=" + Val_key + "&firstName=" + firstName + "&lastName=" + lastName + "&authToken=" + Val_AuthToken + "&authType=" + Val_AuthType + "&trk=" + trk + "&iweLimitReached=false&companyID.0=" + companyID0 + "&companyID.1=" + companyID1 + "&schoolID=" + schoolID + "&schoolcountryCode=" + schoolcountryCode + "&schoolprovinceCode=" + schoolprovinceCode + "&javascriptEnabled=false&subject=" + subject.Replace(" ", "+") + "&defaultText=" + defaultText + "&csrfToken=" + Val_CsrToken + "&sourceAlias=" + sourceAlias + "&goback=" + Val_goback;
                                //string LastPostData = "companyName.0=" + companyName0 + "titleIC.0=" + titleIC0 + "&startYearIC.0=" + startYearIC0 + "&endYearIC.0=" + endYearIC0 + "&schoolText=" + schoolText + "&schoolID=" + schoolID + "&companyName.1=" + companyName0 + "&titleIB.0=" + titleIB0 + "&startYearIB.0=" + startYearIB0 + "&endYearIB.0=" + endYearIC0 + "&reason=IF&otherEmail=" + otheremail + "&greeting=" + greeting + "&iweReconnectSubmit=" + iweReconnectSubmit.Replace(" ", "+") + "&key=" + Val_key + "&firstName=" + firstName + "&lastName=" + lastName + "&authToken=" + Val_AuthToken + "&authType=" + Val_AuthType + "&trk=" + trk + "&iweLimitReached=false&companyID.0=" + companyID0 + "&companyID.1=" + companyID1 + "&schoolID=" + schoolID + "&schoolcountryCode=" + schoolcountryCode + "&schoolprovinceCode=" + schoolprovinceCode + "&javascriptEnabled=false&subject=" + subject.Replace(" ", "+") + "&defaultText=" + defaultText + "&csrfToken=" + Val_CsrToken + "&sourceAlias=" + sourceAlias + "&goback=" + goback;
                                //string LastPostData = "existingPositionIC=&companyName.0=&titleIC.0=&startYearIC.0=&endYearIC.0=&schoolText=&schoolID=&existingPositionIB=&companyName.1=&titleIB.0=&startYearIB.0=&endYearIB.0=&reason=IF&otherEmail=&greeting=I%27d+like+to+add+you+to+my+professional+network+on+LinkedIn.%0D%0A%0D%0A-" + NameOfSender + "&iweReconnectSubmit=Send+Invitation&key=" + Val_key + "&firstName=" + Val_firstName + "&lastName=" + Val_lastName + "&authToken=" + Val_AuthToken + "&authType=" + Val_AuthType + "&trk=prof-0-sb-connect-button&iweLimitReached=false&companyID.0=&companyID.1=&schoolID=&schoolcountryCode=&schoolprovinceCode=&javascriptEnabled=false&subject=" + NameOfSender + "+wants+to+connect+on+LinkedIn+&defaultText=a908b3ba18701677a5879c1955035d05&csrfToken=" + Val_CsrToken + "&sourceAlias=" + Val_sourceAlias + "&goback=" + Val_goback.Replace("%2E", ".") + ".npv_" + Val_key + "_*1_*1_OPENLINK_d7Ir_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1";
                                string postResponse1 = HttpHelper.postFormDataProxy(new Uri(lastPostUrl), LastPostData, _ProxyAddress, proxyport, _ProxyUserName, _ProxyPassword);

                                // Here we getting captcha sometimes

                                #region captcha solving code

                                string ImageUrl = string.Empty;
                                string captchaText = string.Empty;
                                string captchachallengeid = string.Empty;
                                string dts = string.Empty;
                                string origActionAlias = string.Empty;
                                string origSourceAlias = string.Empty;
                                string irhf = string.Empty;
                                string submissionID = string.Empty;
                                string CAPTCHAfwdcsrftoken = string.Empty;
                                string CAPTCHAfwdsignin = string.Empty;
                                string CAPTCHAfwdsession_password = string.Empty;
                                string CAPTCHAfwdsession_key = string.Empty;
                                string CAPTCHAfwdisJsEnabled = string.Empty;
                                string CAPTCHAfwdloginCsrfParam = string.Empty;

                                string security_challenge_id = string.Empty;
                                string cyrpto_CAPTCHA_fwd_reason = string.Empty;
                                string cyrpto_CAPTCHA_fwd_lastName = string.Empty;
                                string cyrpto_CAPTCHA_fwd_goback = string.Empty;
                                string cyrpto_CAPTCHA_fwd_subject = string.Empty;
                                string cyrpto_CAPTCHA_fwd_greeting = string.Empty;
                                string cyrpto_CAPTCHA_fwd_authToken = string.Empty;
                                string cyrpto_CAPTCHA_fwd_connectionParam = string.Empty;
                                string cyrpto_CAPTCHA_fwd_iweReconnectSubmit = string.Empty;
                                string cyrpto_CAPTCHA_fwd_javascriptEnabled = string.Empty;
                                string cyrpto_CAPTCHA_fwd_authType = string.Empty;
                                string cyrpto_CAPTCHA_fwd_key = string.Empty;
                                string cyrpto_CAPTCHA_fwd_trk = string.Empty;
                                string cyrpto_CAPTCHA_fwd_firstName = string.Empty;
                                string cyrpto_CAPTCHA_fwd_csrfToken = string.Empty;
                                string cyrpto_CAPTCHA_fwd_defaultText = string.Empty;
                                string cyrpto_CAPTCHA_fwd_iweLimitReached = string.Empty;

                                // string origSourceAlias = string.Empty;
                                //string origActionAlias = string.Empty;
                                string csrfToken_forCaptch = string.Empty;
                                string sourceAlias_forCaptcha = string.Empty;
                                string goback_forCaptcha = string.Empty;

                                if (postResponse1.Contains("Security Verification"))
                                {
                                    string dataforcapctha = HttpHelper.getHtmlfromUrl1(new Uri("https://www.google.com/recaptcha/api/noscript?k=6LcnacMSAAAAADoIuYvLUHSNLXdgUcq-jjqjBo5n"));
                                    if (!string.IsNullOrEmpty(dataforcapctha))
                                    {
                                        int startindex = dataforcapctha.IndexOf("id=\"recaptcha_challenge_field\"");
                                        if (startindex > 0)
                                        {
                                            string start = dataforcapctha.Substring(startindex).Replace("id=\"recaptcha_challenge_field\"", "");
                                            int endindex = start.IndexOf("\">");
                                            string end = start.Substring(0, endindex).Replace("value=", string.Empty).Replace("\"", string.Empty).Trim();
                                            ImageUrl = "https://www.google.com/recaptcha/api/image?c=" + end;
                                            System.Net.WebClient webclient = new System.Net.WebClient();
                                            byte[] args = webclient.DownloadData(ImageUrl);
                                            string[] arr1 = new string[] { Globals.CapchaLoginID, Globals.CapchaLoginPassword, "" };
                                            captchaText = DecodeDBC(arr1, args);
                                        }

                                        if (postResponse1.Contains("name=\"security-challenge-id\""))
                                        {
                                            int startindexnew = postResponse1.IndexOf("name=\"security-challenge-id\"");
                                            if (startindexnew > 0)
                                            {
                                                string start = postResponse1.Substring(startindexnew).Replace("name=\"security-challenge-id\"", "").Replace("value=\"", "");
                                                int endindex = start.IndexOf("\"");
                                                string end = start.Substring(0, endindex);
                                                captchachallengeid = end.Replace("\"", string.Empty).Trim();
                                            }
                                        }

                                        if (postResponse1.Contains("name=\"dts\""))
                                        {
                                            int startindexnew = postResponse1.IndexOf("name=\"dts\"");
                                            if (startindexnew > 0)
                                            {
                                                string start = postResponse1.Substring(startindexnew).Replace("name=\"dts\"", "").Replace("value=\"", "");
                                                int endindex = start.IndexOf("\"");
                                                string end = start.Substring(0, endindex);
                                                dts = end.Replace("\"", string.Empty).Trim();
                                            }
                                        }

                                        if (postResponse1.Contains("name=\"origActionAlias\""))
                                        {
                                            int startindexnew = postResponse1.IndexOf("name=\"origActionAlias\"");
                                            if (startindexnew > 0)
                                            {
                                                string start = postResponse1.Substring(startindexnew).Replace("name=\"origActionAlias\"", "").Replace("value=\"", "");
                                                int endindex = start.IndexOf("\"");
                                                string end = start.Substring(0, endindex);
                                                origActionAlias = end.Replace("\"", string.Empty).Trim();
                                            }
                                        }

                                        if (postResponse1.Contains("name=\"submissionId\""))
                                        {
                                            int startindexnew = postResponse1.IndexOf("name=\"submissionId\"");
                                            if (startindexnew > 0)
                                            {
                                                string start = postResponse1.Substring(startindexnew).Replace("name=\"submissionId\"", string.Empty).Replace("value=\"", string.Empty);
                                                int endindex = start.IndexOf("\"");
                                                string end = start.Substring(0, endindex);
                                                submissionID = end.Replace("\"", string.Empty).Trim();
                                            }
                                        }
                                        if (postResponse1.Contains("name=\"CAPTCHA-fwd-csrfToken\""))
                                        {
                                            int startindexnew = postResponse1.IndexOf("name=\"CAPTCHA-fwd-csrfToken\"");
                                            if (startindexnew > 0)
                                            {
                                                string start = postResponse1.Substring(startindexnew).Replace("name=\"CAPTCHA-fwd-csrfToken\"", string.Empty).Replace("value=\"", string.Empty);
                                                int endindex = start.IndexOf("\"");
                                                string end = start.Substring(0, endindex);
                                                CAPTCHAfwdcsrftoken = end.Replace("\"", string.Empty).Trim();
                                            }
                                        }
                                        if (postResponse1.Contains("name=\"CAPTCHA-fwd-signin\""))
                                        {
                                            int startindexnew = postResponse1.IndexOf("name=\"CAPTCHA-fwd-signin\"");
                                            if (startindexnew > 0)
                                            {
                                                string start = postResponse1.Substring(startindexnew).Replace("name=\"CAPTCHA-fwd-signin\"", string.Empty).Replace("value=\"", string.Empty);
                                                int endindex = start.IndexOf("\"");
                                                string end = start.Substring(0, endindex);
                                                CAPTCHAfwdsignin = end.Replace("\"", string.Empty).Trim();
                                            }
                                        }
                                        if (postResponse1.Contains("name=\"CAPTCHA-fwd-session_password\""))
                                        {
                                            int startindexnew = postResponse1.IndexOf("name=\"CAPTCHA-fwd-session_password\"");
                                            if (startindexnew > 0)
                                            {
                                                string start = postResponse1.Substring(startindexnew).Replace("name=\"CAPTCHA-fwd-session_password\"", string.Empty).Replace("value=\"", string.Empty);
                                                int endindex = start.IndexOf("\"");
                                                string end = start.Substring(0, endindex);
                                                CAPTCHAfwdsession_password = end.Replace("\"", string.Empty).Trim();
                                            }
                                        }
                                        if (postResponse1.Contains("name=\"CAPTCHA-fwd-session_key\""))
                                        {
                                            int startindexnew = postResponse1.IndexOf("name=\"CAPTCHA-fwd-session_key\"");
                                            if (startindexnew > 0)
                                            {
                                                string start = postResponse1.Substring(startindexnew).Replace("name=\"CAPTCHA-fwd-session_key\"", string.Empty).Replace("value=\"", string.Empty);
                                                int endindex = start.IndexOf("\"");
                                                string end = start.Substring(0, endindex);
                                                CAPTCHAfwdsession_key = end.Replace("\"", string.Empty).Trim();
                                            }
                                        }
                                        if (postResponse1.Contains("name=\"CAPTCHA-fwd-isJsEnabled\""))
                                        {
                                            int startindexnew = postResponse1.IndexOf("name=\"CAPTCHA-fwd-isJsEnabled\"");
                                            if (startindexnew > 0)
                                            {
                                                string start = postResponse1.Substring(startindexnew).Replace("name=\"CAPTCHA-fwd-isJsEnabled\"", string.Empty).Replace("value=\"", string.Empty);
                                                int endindex = start.IndexOf("\"");
                                                string end = start.Substring(0, endindex);
                                                CAPTCHAfwdisJsEnabled = end.Replace("\"", string.Empty).Trim();
                                            }
                                        }
                                        if (postResponse1.Contains("name=\"CAPTCHA-fwd-loginCsrfParam\""))
                                        {
                                            int startindexnew = postResponse1.IndexOf("name=\"CAPTCHA-fwd-loginCsrfParam\"");
                                            if (startindexnew > 0) ;
                                            {
                                                string start = postResponse1.Substring(startindexnew).Replace("name=\"CAPTCHA-fwd-loginCsrfParam\"", string.Empty).Replace("value=\"", string.Empty);
                                                int endindex = start.IndexOf("\"");
                                                string end = start.Substring(0, endindex);
                                                CAPTCHAfwdloginCsrfParam = end.Replace("\"", string.Empty).Trim();
                                            }
                                        }


                                        if (postResponse1.Contains("name=\"origSourceAlias\""))
                                        {
                                            int startindexnew = postResponse1.IndexOf("name=\"origSourceAlias\"");
                                            if (startindexnew > 0)
                                            {
                                                string start = postResponse1.Substring(startindexnew).Replace("name=\"origSourceAlias\"", "").Replace("value=\"", "");
                                                int endindex = start.IndexOf("\"");
                                                string end = start.Substring(0, endindex);
                                                origSourceAlias = end.Replace("\"", string.Empty).Trim();
                                            }
                                        }

                                        if (postResponse1.Contains("name=\"irhf\""))
                                        {
                                            int startindexnew = postResponse1.IndexOf("name=\"irhf\"");
                                            if (startindexnew > 0)
                                            {
                                                string start = postResponse1.Substring(startindexnew).Replace("name=\"irhf\"", "").Replace("value=\"", "");
                                                int endindex = start.IndexOf("\"");
                                                string end = start.Substring(0, endindex);
                                                irhf = end.Replace("\"", string.Empty).Trim();
                                            }
                                        }

                                        #region captcha value scraper region written by sharan

                                        if (string.IsNullOrEmpty(irhf))
                                        {
                                            string[] arr = Regex.Split(postResponse1, "irhf");
                                            irhf = Utils.getBetween(arr[1], "value=\"", "\"");
                                        }

                                        if (string.IsNullOrEmpty(dts))
                                        {
                                            dts = Utils.getBetween(postResponse1, "dts", "id=");
                                            dts = Utils.getBetween(dts, "value=\"", "\"");
                                        }
                                        if (string.IsNullOrEmpty(security_challenge_id))
                                        {
                                            security_challenge_id = Utils.getBetween(postResponse1, "security-challenge-id", "id=");
                                            security_challenge_id = Utils.getBetween(security_challenge_id, "value=\"", "\"");
                                        }

                                        if (string.IsNullOrEmpty(cyrpto_CAPTCHA_fwd_reason))
                                        {
                                            cyrpto_CAPTCHA_fwd_reason = Utils.getBetween(postResponse1, "cyrpto-CAPTCHA-fwd-reason", "id=");
                                            cyrpto_CAPTCHA_fwd_reason = Utils.getBetween(cyrpto_CAPTCHA_fwd_reason, "value=\"", "\"");
                                        }

                                        if (string.IsNullOrEmpty(cyrpto_CAPTCHA_fwd_lastName))
                                        {
                                            cyrpto_CAPTCHA_fwd_lastName = Utils.getBetween(postResponse1, "cyrpto-CAPTCHA-fwd-lastName\" value=\"", "\"");
                                        }
                                        if (string.IsNullOrEmpty(cyrpto_CAPTCHA_fwd_goback))
                                        {
                                            cyrpto_CAPTCHA_fwd_goback = Utils.getBetween(postResponse1, "cyrpto-CAPTCHA-fwd-goback\" value=\"", "\"");
                                        }

                                        if (string.IsNullOrEmpty(cyrpto_CAPTCHA_fwd_subject))
                                        {
                                            cyrpto_CAPTCHA_fwd_subject = Utils.getBetween(postResponse1, "cyrpto-CAPTCHA-fwd-subject\" value=\"", "\"");

                                        }

                                        if (string.IsNullOrEmpty(cyrpto_CAPTCHA_fwd_greeting))
                                        {
                                            cyrpto_CAPTCHA_fwd_greeting = Utils.getBetween(postResponse1, "cyrpto-CAPTCHA-fwd-greeting\" value=\"", "\"");
                                        }

                                        if (string.IsNullOrEmpty(cyrpto_CAPTCHA_fwd_authToken))
                                        {
                                            cyrpto_CAPTCHA_fwd_authToken = Utils.getBetween(postResponse1, "cyrpto-CAPTCHA-fwd-authToken\" value=\"", "\"");
                                        }
                                        if (string.IsNullOrEmpty(cyrpto_CAPTCHA_fwd_connectionParam))
                                        {
                                            cyrpto_CAPTCHA_fwd_connectionParam = Utils.getBetween(postResponse1, "cyrpto-CAPTCHA-fwd-connectionParam\" value=\"", "\"");

                                        }
                                        if (string.IsNullOrEmpty(cyrpto_CAPTCHA_fwd_iweReconnectSubmit))
                                        {
                                            cyrpto_CAPTCHA_fwd_iweReconnectSubmit = Utils.getBetween(postResponse1, "cyrpto-CAPTCHA-fwd-iweReconnectSubmit\" value=\"", "\"");
                                        }
                                        if (string.IsNullOrEmpty(cyrpto_CAPTCHA_fwd_javascriptEnabled))
                                        {
                                            cyrpto_CAPTCHA_fwd_javascriptEnabled = Utils.getBetween(postResponse1, "cyrpto-CAPTCHA-fwd-javascriptEnabled\" value=\"", "\"");
                                        }
                                        if (string.IsNullOrEmpty(cyrpto_CAPTCHA_fwd_authType))
                                        {
                                            cyrpto_CAPTCHA_fwd_authType = Utils.getBetween(postResponse1, "cyrpto-CAPTCHA-fwd-authType\" value=\"", "\"");
                                        }
                                        if (string.IsNullOrEmpty(cyrpto_CAPTCHA_fwd_key))
                                        {
                                            cyrpto_CAPTCHA_fwd_key = Utils.getBetween(postResponse1, "cyrpto-CAPTCHA-fwd-key\" value=\"", "\"");
                                        }
                                        if (string.IsNullOrEmpty(cyrpto_CAPTCHA_fwd_trk))
                                        {
                                            cyrpto_CAPTCHA_fwd_trk = Utils.getBetween(postResponse1, "cyrpto-CAPTCHA-fwd-trk\" value=\"", "\"");
                                        }
                                        if (string.IsNullOrEmpty(cyrpto_CAPTCHA_fwd_firstName))
                                        {
                                            cyrpto_CAPTCHA_fwd_firstName = Utils.getBetween(postResponse1, "cyrpto-CAPTCHA-fwd-firstName\" value=\"", "\"");

                                        }
                                        if (string.IsNullOrEmpty(cyrpto_CAPTCHA_fwd_csrfToken))
                                        {
                                            cyrpto_CAPTCHA_fwd_csrfToken = Utils.getBetween(postResponse1, "cyrpto-CAPTCHA-fwd-csrfToken\" value=\"", "\"");

                                        }
                                        if (string.IsNullOrEmpty(cyrpto_CAPTCHA_fwd_defaultText))
                                        {
                                            cyrpto_CAPTCHA_fwd_defaultText = Utils.getBetween(postResponse1, "cyrpto-CAPTCHA-fwd-defaultText\" value=\"", "\"");
                                        }
                                        if (string.IsNullOrEmpty(cyrpto_CAPTCHA_fwd_iweLimitReached))
                                        {
                                            cyrpto_CAPTCHA_fwd_iweLimitReached = Utils.getBetween(postResponse1, "cyrpto-CAPTCHA-fwd-iweLimitReached\" value=\"", "\"");

                                        }
                                        if (string.IsNullOrEmpty(origSourceAlias))
                                        {
                                            origSourceAlias = Utils.getBetween(postResponse1, "origSourceAlias\" value=\"", "\"");

                                        }
                                        if (string.IsNullOrEmpty(origActionAlias))
                                        {
                                            origActionAlias = Utils.getBetween(postResponse1, "origActionAlias\" value=\"", "\"");
                                        }
                                        if (string.IsNullOrEmpty(csrfToken_forCaptch))
                                        {
                                            csrfToken_forCaptch = Utils.getBetween(postResponse1, "csrfToken=", "&");
                                            //csrfToken_forCaptch = Uri.EscapeDataString(csrfToken_forCaptch);
                                            // here it should be in ajax:8743438493 format
                                        }
                                        if (string.IsNullOrEmpty(sourceAlias_forCaptcha))
                                        {
                                            sourceAlias_forCaptcha = Utils.getBetween(postResponse1, "sourceAlias\" value=\"", "\"");

                                        }
                                        if (string.IsNullOrEmpty(goback_forCaptcha))
                                        {
                                            goback_forCaptcha = Utils.getBetween(postResponse1, "name=\"goback\" value=\"", "\"");
                                        }

                                        #endregion




                                        if (!string.IsNullOrEmpty(ImageUrl) && !string.IsNullOrEmpty(captchaText))
                                        {
                                            string accountUser = string.Empty;
                                            string accountPass = string.Empty;

                                            // string   postdata = "recaptcha_challenge_field=" + ImageUrl.Replace("https://www.google.com/recaptcha/api/image?c=", string.Empty) + "&recaptcha_response_field=" + captchaText.Replace(" ", "+") + "&irhf=" + irhf + "&dts=" + dts + "&security-challenge-id=" + captchachallengeid + "&submissionId=" + submissionID + "&CAPTCHA-fwd-csrfToken=" + CAPTCHAfwdcsrftoken + "&CAPTCHA-fwd-isJsEnabled=" + CAPTCHAfwdisJsEnabled + "&CAPTCHA-fwd-signin=" + CAPTCHAfwdsignin + "&CAPTCHA-fwd-loginCsrfParam=" + CAPTCHAfwdloginCsrfParam + "&CAPTCHA-fwd-session_password="******"&CAPTCHAfwd-session_key=" + CAPTCHAfwdsession_key + "&session_password="******"&session_key=" + Uri.EscapeDataString(accountUser) + "&origSourceAlias=" + origSourceAlias + "&origActionAlias=" + origActionAlias + "&csrfToken=" + csrfToken + "&sourceAlias=" + sourceAlias;

                                            string postData_new = "recaptcha_challenge_field=" + ImageUrl.Replace("https://www.google.com/recaptcha/api/image?c=", string.Empty) + "&recaptcha_response_field=" + captchaText.Replace(" ", "+") + "&irhf=" + irhf + "&dts=" + dts + "&submissionId=&security-challenge-id=" + security_challenge_id + "&cyrpto-CAPTCHA-fwd-reason=" + cyrpto_CAPTCHA_fwd_reason + "&cyrpto-CAPTCHA-fwd-lastName=" + cyrpto_CAPTCHA_fwd_lastName + "&cyrpto-CAPTCHA-fwd-goback=" + cyrpto_CAPTCHA_fwd_goback + "&cyrpto-CAPTCHA-fwd-subject=" + cyrpto_CAPTCHA_fwd_subject + "&cyrpto-CAPTCHA-fwd-greeting=" + cyrpto_CAPTCHA_fwd_greeting + "&cyrpto-CAPTCHA-fwd-authToken=" + cyrpto_CAPTCHA_fwd_authToken + "&cyrpto-CAPTCHA-fwd-connectionParam=" + cyrpto_CAPTCHA_fwd_connectionParam + "&cyrpto-CAPTCHA-fwd-iweReconnectSubmit=" + cyrpto_CAPTCHA_fwd_iweReconnectSubmit + "&cyrpto-CAPTCHA-fwd-javascriptEnabled=" + cyrpto_CAPTCHA_fwd_javascriptEnabled + "&cyrpto-CAPTCHA-fwd-authType=" + cyrpto_CAPTCHA_fwd_authType + "&cyrpto-CAPTCHA-fwd-key=" + cyrpto_CAPTCHA_fwd_key + "&cyrpto-CAPTCHA-fwd-trk=" + cyrpto_CAPTCHA_fwd_trk + "&cyrpto-CAPTCHA-fwd-firstName=" + cyrpto_CAPTCHA_fwd_firstName + "&cyrpto-CAPTCHA-fwd-csrfToken=" + cyrpto_CAPTCHA_fwd_csrfToken + "&cyrpto-CAPTCHA-fwd-defaultText=" + cyrpto_CAPTCHA_fwd_defaultText + "&cyrpto-CAPTCHA-fwd-iweLimitReached=" + cyrpto_CAPTCHA_fwd_iweLimitReached + "&origSourceAlias=" + origSourceAlias + "&origActionAlias=" + origActionAlias + "&csrfToken=" + csrfToken_forCaptch + "&sourceAlias=" + sourceAlias_forCaptcha + "&goback=" + goback_forCaptcha;

                                            postData_new = postData_new.Replace(" ", string.Empty);
                                            postResponse1 = HttpHelper.postFormDataRef(new Uri("https://www.linkedin.com/people/captcha-submit"), postData_new, "https://www.linkedin.com/uas/login-submit", string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);


                                        }
                                    }
                                }

                                #endregion


                                string FinalValue = string.Empty;
                                try
                                {
                                    FinalValue = postResponse1.Substring(postResponse1.IndexOf("Esuccess"), (postResponse1.IndexOf(">", postResponse1.IndexOf("Esuccess")) - postResponse1.IndexOf("Esuccess"))).Replace("Esuccess", string.Empty).Trim();
                                    FinalValue = Uri.UnescapeDataString(FinalValue);
                                    string[] valuess = Regex.Split(FinalValue, "&");
                                    FinalValue = valuess[0].Replace("=", string.Empty);
                                    // FinalValue = postResponse1.Substring(postResponse1.IndexOf("Esuccess"), (postResponse.IndexOf(">", postResponse1.IndexOf("Esuccess")) - postResponse1.IndexOf("Esuccess"))).Replace("Esuccess", string.Empty);
                                    // Val_AuthType = FRNURLresponce.Substring(FRNURLresponce.IndexOf("authType="), (FRNURLresponce.IndexOf(">", FRNURLresponce.IndexOf("authType=")) - FRNURLresponce.IndexOf("authType="))).Replace("authType=", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Trim();
                                }
                                catch { }
                                try
                                {
                                    string lastGetResponse = HttpHelper.getHtmlfromUrl1(new Uri("http://www.linkedin.com/people/pymk?goback=" + Val_goback + "&trk=" + val_trk + "&report%2Esuccess=" + FinalValue));
                                }
                                catch { }
                                if (postResponse1.Contains("You must confirm your primary email address before sending an invitation."))
                                {
                                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ " + _UserName + "You must confirm your primary email address before sending an invitation.]");
                                    valid = false;
                                    PageNumber = 0;
                                    Isaccountvalid = false;
                                    break;
                                }
                                if (!pageResponce2.Contains("emailAddress-invitee-invitation"))
                                {
                                    //else if (postResponse1.Contains("<strong>Invitation to"))
                                    if (postResponse1.Contains("<strong>Invitations") || postResponse1.Contains("Send Invitation") || postResponse1.Contains("Send invitation") || postResponse1.Contains("<strong>Invitation"))
                                    {

                                        if (string.IsNullOrEmpty(firstName) && string.IsNullOrEmpty(lastName))
                                        {
                                            //firstName = "linkedin";
                                            //lastName = "Member";
                                            firstName = Val_firstName;
                                            lastName = Val_lastName;
                                        }
                                        if (!(postResponse1.Contains("Your invitation was not sent")))
                                        {
                                            GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Invitation to " + firstName + " " + lastName + " sent For Keyword : " + _ConnectSearchKeyword + " From Account : " + _UserName + " ]");
                                            string CSVHeader = "UserName" + "," + "SearchKeyword" + "," + "Invitation Sent To" + "," + "InvitationUrl";
                                            try
                                            {
                                                string[] url = Regex.Split(FrnAcceptUrL, "&authType");
                                                string CSV_Content = _UserName + "," + _ConnectSearchKeyword + "," + firstName + " " + lastName + "," + url[0];
                                                CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_AddConnectionSuccessWith2ndDegree);

                                                try
                                                {
                                                    string Querystring = "Insert into tb_ManageAddConnection (Keyword,LinkedinUrl,Username,DateTime) Values('" + _ConnectSearchKeyword + "','" + url[0] + "','" + _UserName + "','" + DateTime.Now.ToString("dd-MM-yyyy") + "')";
                                                    DataBaseHandler.InsertQuery(Querystring, "tb_ManageAddConnection");
                                                }
                                                catch { }
                                                valid = true;

                                                insertAccountData(_UserName, url[0], SendInvitationCount);




                                            }
                                            catch { }
                                        }
                                    }
                                    else if (postResponse1.Contains("You and this LinkedIn user don’t know anyone in common"))
                                    {
                                        string CSVHeader = "UserName" + "," + "SearchKeyword" + "," + "Invitation Sent To" + "," + "InvitationUrl";
                                        string[] url = Regex.Split(FrnAcceptUrL, "&authType");
                                        string CSV_Content = _UserName + "," + _ConnectSearchKeyword + ", ," + url[0];
                                        CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_ConnectionThroughUnkonwPeopleLink);
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Failed To Send Invitation From " + _UserName + " ]");
                                        valid = false;
                                        Isaccountvalid = false;
                                        continue;
                                    }
                                    else
                                    {
                                        string CSVHeader = "UserName" + "," + "SearchKeyword" + "," + "Invitation Sent To" + "," + "InvitationUrl";
                                        string[] url = Regex.Split(FrnAcceptUrL, "&authType");
                                        string CSV_Content = _UserName + "," + _ConnectSearchKeyword + "," + firstName + " " + lastName + "," + url[0];
                                        CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\LinkedInDominator\\ConnnectionNotAddedbyKeyword.csv");
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Failed To Send Invitation To" + firstName + " " + lastName + " ]");
                                        valid = false;
                                        // Isaccountvalid = false;
                                        SendInvitationCount--;
                                    }
                                }
                                if (pageResponce2.Contains("emailAddress-invitee-invitation"))
                                {
                                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Invitation to " + firstName + " " + lastName + " has already been sent from " + _UserName + " ]");
                                    SendInvitationCount--;
                                }

                                if (postResponse1.Contains("Your invitation was not sent"))
                                {
                                    string CSVHeader1 = "UserName" + "," + "SearchKeyword" + "," + "Invitation Sent To" + "," + "InvitationUrl";
                                    string[] url = Regex.Split(FrnAcceptUrL, "&authType");
                                    string CSV_Content = _UserName + "," + _ConnectSearchKeyword + "," + firstName + " " + lastName + "," + url[0];
                                    CSVUtilities.ExportDataCSVFile(CSVHeader1, CSV_Content, FilePath.path_ConnectionthroughKeywordSearchnotadded);
                                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Failed To Send Invitation From " + _UserName + " ]");
                                    valid = false;
                                    //   Isaccountvalid = false;
                                    SendInvitationCount--;

                                }

                                int Delay = RandomNumberGenerator.GenerateRandom(SearchMinDelay, SearchMaxDelay);
                                GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Invitation Delayed For : " + Delay + " Seconds ]");
                                Thread.Sleep(Delay * 1000);

                                SendInvitationCount++;
                                if (SendInvitationCount >= GlobalsAddConn.requestPerKeyword)  //Here we check  that number of request send if counter is equal to the number of request put by user then it return to mathod and made pagenumber = 0; 
                                {
                                    //SendInvitationCount--;
                                    PageNumber = 0;
                                    return;
                                }
                            }
                            else
                            {
                                GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Only visit the site " + FrnAcceptUrL + " ]");
                                string CSVHeader = "UserName" + "," + "Url";
                                string[] url = Regex.Split(FrnAcceptUrL, "&authType");
                                string CSV_Content = _UserName + "," + url[0];
                                CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_OnlyVisitProfileUsingKeyword);

                                DataSet Ds = new DataSet();
                                try
                                {
                                    string Querystring = "INSERT INTO tb_OnlyVisitProfile (Email,Url,DateTime) Values ('" + _UserName + "','" + url[0] + "','" + DateTime.Now + "')";
                                    Ds = DataBaseHandler.SelectQuery(Querystring, "tb_ManageAddConnection");
                                }
                                catch { }

                                insertAccountData(_UserName, url[0], SendInvitationCount);





                                int Delay = RandomNumberGenerator.GenerateRandom(SearchMinDelay, SearchMaxDelay);
                                Thread.Sleep(Delay * 1000);
                                GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Delayed For : " + Delay + " Seconds ]");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message == "Stream was not readable")
                    {

                    }
                    string CSVHeader = "UserName" + "," + "SearchKeyword" + "," + "Invitation Sent To" + "," + "InvitationUrl";
                    string[] url = Regex.Split(FrnAcceptUrL, "&authType");
                    string CSV_Content = _UserName + "," + _ConnectSearchKeyword + ",," + url[0];
                    CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_ConnectionthroughKeywordSearchnotadded);
                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Failed To Send Invitation From " + _UserName + " ]");
                    valid = false;
                    Isaccountvalid = false;
                    SendInvitationCount--;
                }
            }
        }
 public void StartCompanyEmployeeScraper(ref LinkedinUser objLinkedinUser)
 {
     try
     {
         if(objLinkedinUser.isloggedin)
         {
             GetEmployeeDataFromCompanyURL(ref objLinkedinUser.globusHttpHelper, GlobalsScraper.lstUrlCompanyEmpScraper);
         }
     }
     catch (Exception ex)
     {
     }
 }
        public void StartJobScraper(ref LinkedinUser objLinkedinUser, string JobUrl, int MaxLimitCount)
        {
            try
            {
                if (!GlobalsScraper.isStopJobScraper)
                {
                    GlobalsScraper.lstThreadsJobScraper.Add(Thread.CurrentThread);
                    GlobalsScraper.lstThreadsJobScraper = GlobalsScraper.lstThreadsJobScraper.Distinct().ToList();
                    Thread.CurrentThread.IsBackground = true;
                }
            }
            catch
            {
            }

            try
            {
                GlobusHttpHelper httpHelper = objLinkedinUser.globusHttpHelper;
                int current_Page_Num = 1;
                int total_no_of_pages = 0;
                int i = 1;
                bool IsCheckCount = true; ;

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

                if (JobUrl.Contains("<:>"))
                {
                    string[] arrJobUrl = Regex.Split(JobUrl, "<:>");
                    lstJobUrl.AddRange(arrJobUrl);
                }
                else
                {
                    lstJobUrl.Add(JobUrl);
                }

                foreach (string item in lstJobUrl)
                {
                    string tempItem = string.Empty;
                    string pagination_url = string.Empty;
                    string tempCount = string.Empty;
                    string starting_page = string.Empty;
                    string final_url = string.Empty;
                    string PageSource_first_page = string.Empty;

                    try
                    {
                        PageSource_first_page = httpHelper.getHtmlfromUrl(new Uri(item));
                        if (string.IsNullOrEmpty(PageSource_first_page))
                        {
                            PageSource_first_page = httpHelper.getHtmlfromUrl(new Uri(item));
                        }
                        try
                        {
                            tempCount = Utils.getBetween(PageSource_first_page, "resultCount\":", ",");
                            total_no_of_pages = int.Parse(tempCount);
                            GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Total Results :  " + total_no_of_pages + " ]");
                            total_no_of_pages = (total_no_of_pages / 25) + 1;
                        }
                        catch
                        { }
                        if (total_no_of_pages == -1)
                        {
                            total_no_of_pages = 2;
                        }
                        if (total_no_of_pages == 1)
                        {
                            total_no_of_pages = 2;
                        }
                        if (total_no_of_pages > 40)
                        {
                            total_no_of_pages = 40;
                        }
                        if (!string.IsNullOrEmpty(PageSource_first_page))
                        {
                            if (PageSource_first_page.Contains("page_number_i18n"))
                            {
                                try
                                {
                                    string pg_url = Utils.getBetween(PageSource_first_page, "page_number_i18n", "pageNum");
                                    pg_url = Utils.getBetween(pg_url, "pageURL\":\"", "\",");
                                    pagination_url = pg_url;
                                }
                                catch
                                { }
                            }
                        }
                        if (item.Contains("page_num="))
                        {
                            try
                            {
                                starting_page = Utils.getBetween(item, "page_num=", "&");
                                current_Page_Num = Convert.ToInt32(starting_page);
                                string current_page_url = Utils.getBetween("###" + pagination_url, "###", "page_num=");
                                current_page_url = current_page_url + "page_num=";
                                current_Page_Num += 1;
                                final_url = "https://www.linkedin.com" + current_page_url + current_Page_Num;
                            }
                            catch
                            { }
                        }
                        else
                        {
                            try
                            {
                                string pg_num = Utils.getBetween(pagination_url + "####", "page_num=", "####");
                                current_Page_Num = Convert.ToInt32(pg_num);
                                string current_page_url = Utils.getBetween("###" + pagination_url, "###", "page_num=");
                                current_page_url = current_page_url + "page_num=";

                                final_url = "https://www.linkedin.com" + current_page_url + current_Page_Num;
                            }
                            catch
                            { }
                        }
                    }
                    catch
                    { }

                    if (PageSource_first_page.Contains("lix_show_incommon_counts_jobs"))
                    {
                        try
                        {
                            List<string> PageSerchUrl = GettingAllUrl(PageSource_first_page);
                            PageSerchUrl.Distinct();

                            if (PageSerchUrl.Count == 0)
                            {
                                GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ On the basis of your Account you can able to see " + RecordURL.Count + " Results ]");
                                break;
                            }
                            foreach (string tempitem in PageSerchUrl)
                            {
                                if (true)
                                {
                                    if (tempitem.Contains("jobs2/view/"))
                                    {
                                        try
                                        {
                                            string urlSerch = tempitem;
                                            if (urlSerch.Contains("jobs2/view/"))
                                            {
                                                RecordURL.Add(urlSerch);
                                                if (!queRecordUrl.Contains(urlSerch))
                                                {
                                                    queRecordUrl.Enqueue(urlSerch);
                                                }
                                                RecordURL = RecordURL.Distinct().ToList();
                                            }
                                            try
                                            {
                                                GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ " + urlSerch + " ]");
                                            }
                                            catch { }
                                        }
                                        catch { }
                                    }
                                }
                            }

                            if (i == total_no_of_pages)
                            {
                                IsCheckCount = true;
                                break;
                            }

                            // countPageNum++;
                            i++;
                            Thread.Sleep(4000);
                        }
                        catch { }
                    }
                    _HttpHelper = httpHelper;
                    string Account = objLinkedinUser.username;
                    new Thread(() =>
                    {
                        if (IsCheckCount)
                        {
                            finalUrlCollectionForRecruter(Account, MaxLimitCount);
                        }
                    }).Start();

                StartAgain:
                    if (!string.IsNullOrEmpty(final_url))
                    {
                        while (true)
                        {
                            final_url = Utils.getBetween("###" + final_url, "###", "page_num=");
                            final_url = final_url + "page_num=" + current_Page_Num;

                            string PageSource = httpHelper.getHtmlfromUrl(new Uri(final_url));

                            if (IsCheckCount)
                            {

                            }

                            if (total_no_of_pages >= 1)
                            {
                                _HttpHelper = httpHelper;

                            }
                            {
                                if (true)
                                {
                                    if (PageSource.Contains("lix_show_incommon_counts_jobs"))
                                    {
                                        try
                                        {
                                            List<string> PageSerchUrl = GettingAllUrl(PageSource);
                                            PageSerchUrl.Distinct();

                                            if (PageSerchUrl.Count == 0)
                                            {
                                                GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ On the basis of your Account you can able to see " + RecordURL.Count + " Results ]");
                                                break;
                                            }

                                            foreach (string tempitem in PageSerchUrl)
                                            {
                                                if (true)
                                                {
                                                    if (tempitem.Contains("jobs2/view/"))
                                                    {
                                                        try
                                                        {
                                                            string urlSerch = tempitem;
                                                            if (urlSerch.Contains("jobs2/view/"))
                                                            {
                                                                RecordURL.Add(urlSerch);
                                                                if (!queRecordUrl.Contains(urlSerch))
                                                                {
                                                                    queRecordUrl.Enqueue(urlSerch);
                                                                }
                                                                RecordURL = RecordURL.Distinct().ToList();
                                                            }

                                                            try
                                                            {
                                                                GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ " + urlSerch + " ]");
                                                            }
                                                            catch { }
                                                        }
                                                        catch { }
                                                    }
                                                }
                                            }

                                            if (current_Page_Num == total_no_of_pages)
                                            {
                                                IsCheckCount = true;
                                                break;
                                            }
                                            current_Page_Num++;
                                            i++;
                                            Thread.Sleep(4000);
                                            if (!GlobalsScraper.isStopJobScraper)
                                            {
                                                // goto StartAgain;
                                            }
                                        }
                                        catch { }
                                    }
                                    else
                                    {
                                        if ((current_Page_Num == total_no_of_pages) && (!PageSource.Contains("&jobId=")))
                                        {
                                            break;
                                        }
                                        Thread.Sleep(5000);
                                    }
                                }
                            }

                        }
                    }
                }
            }
            catch { }

            GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ PROCESS COMPLETED ]");
            GlobusLogHelper.log.Info("-----------------------------------------------------------------------------------------------------------------------------------");
        }
        public void StartSendUpdate(ref LinkedinUser objLinkedinUser)
        {
            try
            {
                int numberOfThreads = 0;

                if (GlobalsGroups.ListGrpDiscussion.Count > 0)
                {
                    foreach (string Message in GlobalsGroups.ListGrpDiscussion)
                    {
                        GlobalsGroups.Que_GrpPostTitle_Post.Enqueue(Message);
                    }
                }
                else
                {
                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Please Add Group Title Message Text ]");
                    return;
                }

                if (GlobalsGroups.GroupUrl.Count > 0)
                {
                    foreach (string grpKey in GlobalsGroups.GroupUrl)
                    {
                        GlobalsGroups.Que_GrpKey_Post.Enqueue(grpKey);
                    }
                }
                else
                {
                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Group User Key Invalid ]");
                    return;
                }

                if (GlobalsGroups.ListGrpMoreDetails.Count > 0)
                {
                    foreach (string grpmoredtl in GlobalsGroups.ListGrpMoreDetails)
                    {
                        GlobalsGroups.Que_GrpMoreDtl_Post.Enqueue(grpmoredtl);
                    }
                }
                else
                {
                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Please Add Group MoreDetails Message Text ]");
                    return;
                }

                //if (chkSameMessageForAllGroup.Checked)
                {
                    GlobalsGroups.Que_GrpPostTitle_Post.Clear();
                    GlobalsGroups.Que_GrpMoreDtl_Post.Clear();
                    if (GlobalsGroups.ListGrpDiscussion.Count > 0)
                    {
                        foreach (string Message in GlobalsGroups.ListGrpDiscussion)
                        {
                            GlobalsGroups.Que_GrpPostTitle_Post.Enqueue(Message);
                            break;
                        }
                    }
                    else
                    {
                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Please Add Group Title Message Text ]");
                        return;
                    }



                    if (GlobalsGroups.ListGrpMoreDetails.Count > 0)
                    {
                        foreach (string grpmoredtl in GlobalsGroups.ListGrpMoreDetails)
                        {
                            GlobalsGroups.Que_GrpMoreDtl_Post.Enqueue(grpmoredtl);
                            break;
                        }
                    }
                    else
                    {
                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Please Add Group MoreDetails Message Text ]");
                        return;
                    }
                }

                PostGroupMsgUpdate(ref objLinkedinUser);
            }
            catch (Exception ex)
            {
                GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Error --> Group Update --> LinkedInGroupMessage() >>>> " + ex.Message + "StackTrace --> >>>" + ex.StackTrace, FilePath.Path_LinkedinErrorLogs);
                GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Error --> Group Update --> LinkedInGroupMessage() >>>> " + ex.Message + "StackTrace --> >>>" + ex.StackTrace, FilePath.Path_LinkedinGetGroupMemberErrorLogs);
            }
        }
        public void ConnectionSearch(ref LinkedinUser objLinkedinUser, int SearchMinDelay, int SearchMaxDelay)
        {
            bool checkStatus = true;
            GlobusHttpHelper HttpHelper = objLinkedinUser.globusHttpHelper;

            try
            {
                if (true)
                {
                    string strPageNumber = string.Empty;
                    string Textmessage = string.Empty;

                    //Login with User name and password ***********************

                    if (GlobalsAddConn.selectedDailyLimit)
                    {
                        checkStatus = checkDailyLimitWithDB(objLinkedinUser.username);
                    }
                    if (!checkStatus)
                    {
                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ You have reached the daily limit with : " + objLinkedinUser.username + " ]");
                        return;
                    }
                    //if (linkedinLoginAndLogout.LoginHttpHelper(_UserName, _Password, _ProxyAddress, _ProxyPort, _ProxyUserName, _ProxyPassword, ref HttpHelper, ref Textmessage))
                    if(objLinkedinUser.isloggedin)
                    {
                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Logged in with " + objLinkedinUser.username + " ]");

                        int proxyport = 888;
                        string SummaryLink = string.Empty;

                        Regex PortCheck = new Regex("^[0-9]*$");

                        if (PortCheck.IsMatch(objLinkedinUser.proxyport) && !string.IsNullOrEmpty(objLinkedinUser.proxyport))
                        {
                            proxyport = int.Parse(objLinkedinUser.proxyport);
                        }

                        while (que_SearchKeywords.Count > 0)
                        {
                            lock (locker_InvitataionKeyword)
                            {
                                if (que_SearchKeywords.Count > 0)
                                {
                                    _ConnectSearchKeyword = que_SearchKeywords.Dequeue();
                                }
                                else
                                {
                                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ All Loaded Keyword are used ]");
                                }
                            }

                            string Url = "http://www.linkedin.com/search/fpsearch?keywords=" + _ConnectSearchKeyword + "&keepFacets=keepFacets&page_num=1&pplSearchOrigin=ADVS&viewCriteria=2&sortCriteria=R&redir=redir";

                            string PgSrcMain = HttpHelper.getHtmlfromUrlProxy(new Uri(Url), objLinkedinUser.proxyip, Convert.ToInt32(objLinkedinUser.proxyport), objLinkedinUser.proxyusername, objLinkedinUser.proxypassword);
                            string[] Arr = Regex.Split(PgSrcMain, "results_count_with_keywords_i18n");
                            foreach (string item in Arr)
                            {
                                try
                                {
                                    if (!item.Contains("<!DOCTYPE"))
                                    {
                                        if (item.Contains("results for"))
                                        {
                                            string data = RemoveAllHtmlTag.StripHTML(item);
                                            data = data.Replace("\n", "");
                                            if (data.Contains(">"))
                                            {
                                                string[] ArrTemp = Regex.Split(data, "results");
                                                data = ArrTemp[0];
                                                data = data.Replace("\":\"", "").Replace(",", string.Empty);
                                                data = data.Trim();
                                                strPageNumber = data.ToString().Replace("&quot;", string.Empty).Replace(",", string.Empty).Replace("&", string.Empty).Replace(":", string.Empty).Replace("strong", string.Empty).Replace("\\u003e", "").Replace("\\u003c", "").Replace("/", "").Trim();
                                                break;
                                            }
                                        }
                                    }
                                }
                                catch { }
                            }

                            if (string.IsNullOrEmpty(strPageNumber))
                            {
                                string urlGetdata = "http://www.linkedin.com/vsearch/f?keywords=" + _ConnectSearchKeyword + "&orig=GLHD&pageKey=voltron_federated_search_internal_jsp&search=Search";
                                urlGetdata = "http://www.linkedin.com/vsearch/f?keywords=Jobs&orig=GLHD&pageKey=voltron_federated_search_internal_jsp&search=Search";
                                PgSrcMain = HttpHelper.getHtmlfromUrlProxy(new Uri(Url), objLinkedinUser.proxyip, proxyport, objLinkedinUser.proxyusername, objLinkedinUser.proxypassword);
                                Arr = Regex.Split(PgSrcMain, "div");
                                foreach (string item in Arr)
                                {
                                    try
                                    {
                                        if (!item.Contains("<!DOCTYPE"))
                                        {
                                            if (item.Contains("results-summary"))
                                            {
                                                string data = RemoveAllHtmlTag.StripHTML(item);
                                                data = data.Replace("\n", "");
                                                if (data.Contains(">"))
                                                {
                                                    string[] ArrTemp = data.Split('>');
                                                    data = ArrTemp[1];
                                                    data = data.Replace("results", "");
                                                    data = data.Trim();
                                                    string[] ArrTemp1 = data.Split(' ');
                                                    data = ArrTemp1[0].Replace(',', ' ').Trim();

                                                    strPageNumber = data.Replace(" ", string.Empty).Replace(",", string.Empty).Trim();
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    catch { }
                                }
                            }

                            try
                            {
                                PageNumber = int.Parse(strPageNumber);//find the page number for each key word
                            }
                            catch (Exception)
                            {
                                PageNumber = 0;
                                //throw;
                            }
                            if ((PageNumber == 0))
                            {
                                GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Sorry No Search Results For  Keyword : " + _ConnectSearchKeyword + " From Account: " + objLinkedinUser.username + " ]");
                                break;
                                //TestConnectPageSearch("1");
                            }

                            PageNumber = (PageNumber / 10) - 1;//each page have 10 data so number of record divide by 10....

                            if (PageNumber == -1)
                            {
                                PageNumber = 2;
                            }

                            for (int i = 1; i <= PageNumber; i++)
                            {
                                //loop for send request
                                if (!Isaccountvalid)
                                {
                                    return;
                                }
                                if (GlobalsAddConn.CheckTheDayLimit)
                                {
                                    if (GlobalsAddConn.no_of_profiles_can_be_visited == GlobalsAddConn.no_of_profiles_visited)
                                    {
                                        return;
                                    }
                                    if (GlobalsAddConn.dailyLimit <= GlobalsAddConn.no_of_profiles_visited)
                                    {
                                        return;
                                    }
                                }
                                if (!GlobalsAddConn.selectedUniqueConnection)
                                {
                                    TestConnectPageSearch(i.ToString(), SearchMinDelay, SearchMaxDelay, ref objLinkedinUser);
                                }
                                else
                                {
                                    TestConnectPageSearchForUniqueUrl(i.ToString(), SearchMinDelay, SearchMaxDelay, ref objLinkedinUser);
                                }
                            }

                            //insert
                            if (valid)
                            {
                                string CSVHeader = "UserName" + "," + "SearchKeyword";
                                string CSV_Content = objLinkedinUser.username + "," + _ConnectSearchKeyword;
                                if (SendInvitationCount > 0)
                                {
                                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ " + SendInvitationCount + "  Send Request Completed With " + objLinkedinUser.username + " and For Keyword " + _ConnectSearchKeyword + " ]");                                   
                                }
                                else
                                {
                                    CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_AddConnectionFail);
                                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Not Able To send Any Connection Request For Keyword " + _ConnectSearchKeyword + " ]");
                                }
                                SendInvitationCount = 0;                                
                            }
                        }
                    }
                    else
                    {
                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ " + objLinkedinUser.username + " Your LinkedIn account has been temporarily restricted ]");
                        return;
                    }
                }
                else
                {

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public void PostGroupMsgUpdate(ref LinkedinUser objLnkedinUser)
        {
            try
            {
                if (objLnkedinUser.isloggedin)
                {
                    GlobusHttpHelper HttpHelper = objLnkedinUser.globusHttpHelper;
                    string postdata = string.Empty;
                    string postUrl = string.Empty;
                    string ResLogin = string.Empty;
                    string csrfToken = string.Empty;
                    string sourceAlias = string.Empty;
                    string referal = string.Empty;

                    string ReturnString = string.Empty;
                    string PostGrpDiscussion = string.Empty;
                    string PostGrpMoreDetails = string.Empty;
                    string PostGrpAttachLink = string.Empty;
                    string PostGrpKey = string.Empty;

                    try
                    {
                        string MessageText = string.Empty;
                        string PostedMessage = string.Empty;
                        string pageSource = string.Empty;
                        
                        pageSource = HttpHelper.getHtmlfromUrl1(new Uri("http://www.linkedin.com/home?trk=hb_tab_home_top"));

                        if (pageSource.Contains("csrfToken"))
                        {
                            string pattern = @"\";
                            csrfToken = pageSource.Substring(pageSource.IndexOf("csrfToken"), 50);
                            string[] Arr = csrfToken.Split('&');
                            csrfToken = Arr[0];
                            csrfToken = csrfToken.Replace("csrfToken", "").Replace("\"", string.Empty).Replace("value", string.Empty).Replace("cs", string.Empty).Replace("id", string.Empty).Replace("=", string.Empty);
                            csrfToken = csrfToken.Replace(pattern, string.Empty.Trim());
                        }

                        if (pageSource.Contains("sourceAlias"))
                        {
                            string pattern1 = @"\";
                            sourceAlias = pageSource.Substring(pageSource.IndexOf("sourceAlias"), 100);
                            string[] Arr = sourceAlias.Split('"');
                            sourceAlias = Arr[2];
                            sourceAlias = sourceAlias.Replace(pattern1, string.Empty.Trim());
                        }

                        try
                        {

                            foreach (var Itegid in GlobalsGroups.SelectedGroups)
                            {
                                string[] grpNameWithDetails = Itegid.Split('^');

                                try
                                {
                                    lock (Locked_GrpKey_Post)
                                    {
                                        if (GlobalsGroups.Que_GrpKey_Post.Count > 0)
                                        {
                                            try
                                            {
                                                PostGrpKey = GlobalsGroups.Que_GrpKey_Post.Dequeue();
                                            }
                                            catch { }
                                        }
                                    }

                                    lock (Locked_GrpPostTitle_Post)
                                    {
                                        if (GlobalsGroups.Que_GrpPostTitle_Post.Count > 0)
                                        {
                                            try
                                            {
                                                PostGrpDiscussion = GlobalsGroups.Que_GrpPostTitle_Post.Dequeue();
                                            }
                                            catch { }
                                        }
                                    }

                                    lock (Locked_GrpMoreDtl_Post)
                                    {
                                        if (GlobalsGroups.Que_GrpMoreDtl_Post.Count > 0)
                                        {
                                            try
                                            {
                                                PostGrpMoreDetails = GlobalsGroups.Que_GrpMoreDtl_Post.Dequeue();
                                                //Que_GrpMoreDtl_Post.Clear();
                                            }
                                            catch { }
                                        }


                                    }

                                    lock (Locked_Que_GrpAttachLink_Post)
                                    {
                                        if (GlobalsGroups.Que_GrpAttachLink_Post.Count > 0)
                                        {
                                            try
                                            {
                                                PostGrpAttachLink = GlobalsGroups.Que_GrpAttachLink_Post.Dequeue();
                                            }
                                            catch { }
                                        }

                                    }

                                    string[] grpDisplay = Itegid.Split('^');
                                    string GrpName = grpDisplay[0].ToString().Replace("[", string.Empty).Trim();
                                    string[] PostGid = grpDisplay[1].Replace("]", string.Empty).Split(',');
                                    string Gid = string.Empty;

                                    //        HJKHKJH

                                    try
                                    {
                                        if (NumberHelper.ValidateNumber(PostGid[1].Trim()))
                                        {
                                            Gid = PostGid[1].Trim();
                                        }
                                        else if (NumberHelper.ValidateNumber(PostGid[2].Trim()))
                                        {
                                            Gid = PostGid[2].Trim();
                                        }
                                        else if (NumberHelper.ValidateNumber(PostGid[3].Trim()))
                                        {
                                            Gid = PostGid[3].Trim();
                                        }
                                        else if (NumberHelper.ValidateNumber(PostGid[4].Trim()))
                                        {
                                            Gid = PostGid[4].Trim();
                                        }
                                        else if (NumberHelper.ValidateNumber(PostGid[5].Trim()))
                                        {
                                            Gid = PostGid[5].Trim();
                                        }
                                        else if (NumberHelper.ValidateNumber(PostGid[6].Trim()))
                                        {
                                            Gid = PostGid[6].Trim();
                                        }
                                        else if (NumberHelper.ValidateNumber(PostGid[7].Trim()))
                                        {
                                            Gid = PostGid[7].Trim();
                                        }
                                        else if (NumberHelper.ValidateNumber(PostGid[8].Trim()))
                                        {
                                            Gid = PostGid[8].Trim();
                                        }
                                        else if (NumberHelper.ValidateNumber(PostGid[9].Trim()))
                                        {
                                            Gid = PostGid[9].Trim();
                                        }
                                        else if (NumberHelper.ValidateNumber(PostGid[10].Trim()))
                                        {
                                            Gid = PostGid[10].Trim();
                                        }
                                        else if (NumberHelper.ValidateNumber(PostGid[11].Trim()))
                                        {
                                            Gid = PostGid[11].Trim();
                                        }
                                        else if (NumberHelper.ValidateNumber(PostGid[12].Trim()))
                                        {
                                            Gid = PostGid[12].Trim();
                                        }
                                    }
                                    catch { }

                                    //string ReqUrl = PostGrpAttachLink;
                                    string ReqUrl = PostGrpMoreDetails;
                                    ReqUrl = ReqUrl.Replace(":", "%3A").Replace("//", "%2F%2F");
                                    referal = "http://www.linkedin.com/groups/" + grpDisplay[2].Replace(" ", "-") + "-" + Gid + "?goback=%2Egmr_" + Gid;
                                    string GetStatus = HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/share?getPreview=&url=" + ReqUrl), referal);

                                    string ImgCount = string.Empty;
                                    try
                                    {
                                        int StartinImgCnt = GetStatus.IndexOf("current");
                                        string startImgCnt = GetStatus.Substring(StartinImgCnt);
                                        int EndIndexImgCnt = startImgCnt.IndexOf("</span>");
                                        string EndImgCnt = startImgCnt.Substring(0, EndIndexImgCnt).Replace("value\":", "").Replace("\"", "");
                                        ImgCount = EndImgCnt.Replace("current", string.Empty).Replace(">", string.Empty);
                                    }
                                    catch
                                    {
                                        ImgCount = "0";
                                    }

                                    string LogoUrl = string.Empty;
                                    try
                                    {
                                        int StartinImgUrl = GetStatus.IndexOf("url");
                                        string startImgUrl = GetStatus.Substring(StartinImgUrl);
                                        int EndIndexImgUrl = startImgUrl.IndexOf("border=");
                                        string EndImgUrl = startImgUrl.Substring(0, EndIndexImgUrl).Replace("value\":", "").Replace("\"", "");
                                        LogoUrl = EndImgUrl.Replace("url=", string.Empty).Trim();
                                    }
                                    catch
                                    {
                                        LogoUrl = "false";
                                    }

                                    string EntityId = string.Empty;
                                    try
                                    {
                                        int StartinEntityId = GetStatus.IndexOf("data-entity-id");
                                        string startEntityId = GetStatus.Substring(StartinEntityId);
                                        int EndIndexEntityId = startEntityId.IndexOf("data-entity-url");
                                        string EndEntityId = startEntityId.Substring(0, EndIndexEntityId).Replace("value\":", "").Replace("\"", "");
                                        EntityId = EndEntityId.Replace("\"", string.Empty).Replace("data-entity-id", string.Empty).Replace("=", string.Empty).Trim();
                                    }
                                    catch { }

                                    string contentTitle = string.Empty;
                                    try
                                    {
                                        int StartinContent = GetStatus.IndexOf("share-view-title");
                                        string startContent = GetStatus.Substring(StartinContent);
                                        int EndIndexContent = startContent.IndexOf("</h4>");
                                        string EndContent = startContent.Substring(0, EndIndexContent).Replace("value\":", "").Replace("\"", "");
                                        contentTitle = EndContent.Replace("\"", string.Empty).Replace("\n", string.Empty).Replace("share-view-title", string.Empty).Replace("id=", string.Empty).Replace(">", string.Empty).Replace("&", "and").Replace("amp;", string.Empty).Trim();

                                        if (contentTitle.Contains("#"))
                                        {
                                            contentTitle = contentTitle.Replace("and", "&");
                                            contentTitle = Uri.EscapeDataString(contentTitle);
                                        }

                                    }
                                    catch { }

                                    string contentSummary = string.Empty;
                                    try
                                    {
                                        int StartinConSumm = GetStatus.IndexOf("share-view-summary\">");
                                        string startConSumm = GetStatus.Substring(StartinConSumm);
                                        int EndIndexConSumm = startConSumm.IndexOf("</span>");
                                        string EndConSumm = startConSumm.Substring(0, EndIndexConSumm).Replace("value\":", "").Replace("\"", "");
                                        contentSummary = EndConSumm.Replace("\"", string.Empty).Replace("\n", string.Empty).Replace("share-view-summary", string.Empty).Replace("id=", string.Empty).Replace(">", string.Empty).Replace("</span<a href=#", string.Empty).Trim();
                                        contentSummary = contentSummary.Replace(",", "%2C").Replace(" ", "%20");

                                        if (contentSummary.Contains("#"))
                                        {
                                            contentSummary = contentSummary.Replace("and", "&");
                                            contentSummary = Uri.EscapeDataString(contentSummary);
                                        }
                                    }
                                    catch { }

                                    string PostGroupstatus = string.Empty;
                                    string ResponseStatusMsg = string.Empty;
                                    csrfToken = csrfToken.Replace("<meta http-", "").Replace(">", "").Trim();
                                    try
                                    {
                                        //PostGroupstatus = "csrfToken=" + csrfToken + "&postTitle=" + PostGrpDiscussion + "&postText=" + PostGrpMoreDetails + "&pollChoice1-ANetPostForm=&pollChoice2-ANetPostForm=&pollChoice3-ANetPostForm=&pollChoice4-ANetPostForm=&pollChoice5-ANetPostForm=&pollEndDate-ANetPostForm=0&contentImageCount=0&contentImageIndex=-1&contentImage=&contentEntityID=&contentUrl=&contentTitle=&contentSummary=&contentImageIncluded=true&%23=&gid=" + Gid.Trim() + "&postItem=&ajax=true&tetherAccountID=&facebookTetherID=";
                                        PostGroupstatus = "csrfToken=" + csrfToken + "&postTitle=" + PostGrpDiscussion + "&postText=" + PostGrpMoreDetails + "&pollChoice1-ANetPostForm=&pollChoice2-ANetPostForm=&pollChoice3-ANetPostForm=&pollChoice4-ANetPostForm=&pollChoice5-ANetPostForm=&pollEndDate-ANetPostForm=0&contentImageCount=" + ImgCount + "&contentImageIndex=-1&contentImage=" + LogoUrl + "&contentEntityID=" + EntityId + "&contentUrl=" + ReqUrl + "&contentTitle=" + contentTitle + "&contentSummary=" + contentSummary + "&contentImageIncluded=true&%23=&gid=" + Gid + "&postItem=&ajax=true&tetherAccountID=&facebookTetherID=";
                                        ResponseStatusMsg = HttpHelper.postFormData(new Uri("http://www.linkedin.com/groups"), PostGroupstatus);
                                    }
                                    catch { }
                                    #region written by sharan
                                    try
                                    {
                                        string PagesourceProfile = HttpHelper.getHtmlfromUrl(new Uri("https://www.linkedin.com/profile/view?id=394473043&trk=nav_responsive_tab_profile"));
                                        string GoBackValue = string.Empty;
                                        string Url = string.Empty;
                                        if (PagesourceProfile.Contains("&goback="))
                                        {
                                            GoBackValue = Utils.getBetween(PagesourceProfile, "&goback=", "&").Trim();
                                            Url = "https://www.linkedin.com/grp/home?gid=" + Gid + "&goback=" + GoBackValue;
                                        }

                                        PostGroupstatus = "csrfToken=" + csrfToken + "&title=" + PostGrpDiscussion + "&details=" + PostGrpMoreDetails + "&groupId=" + Gid + "&displayCategory=DISCUSSION";
                                        ResponseStatusMsg = HttpHelper.postFormDataRef(new Uri("https://www.linkedin.com/grp/postForm/submit"), PostGroupstatus, Url, "", "");
                                    }
                                    catch (Exception ex)
                                    {
                                    }

                                    #endregion

                                    string CSVHeader = "UserName" + "," + "HeaderPost" + "," + "Details Post" + "," + "ToGroup";

                                    if (ResponseStatusMsg.Contains("SUCCESS") || ResponseStatusMsg.Contains("Accept  the description According to you"))
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Message Header Posted : " + PostGrpDiscussion + " Successfully on Group : " + grpDisplay[2] + " ]");
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Message More Details Posted : " + PostGrpMoreDetails + " Successfully on Group : " + grpDisplay[2] + " ]");

                                        string CSV_Content = objLnkedinUser.username + "," + PostGrpDiscussion.Replace(",", ";") + "," + PostGrpMoreDetails.Replace(",", ";") + "," + grpDisplay[2].Replace(",", string.Empty);
                                        CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_GroupUpdates);

                                    }
                                    else if (ResponseStatusMsg.Contains("Your request to join is still pending"))
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Your membership is pending approval on a Group:" + grpDisplay[2] + " ]");
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Message Header: " + PostGrpDiscussion + " Not Posted on Group:" + grpDisplay[2] + " Because Your membership is pending for approval. ]");
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Message More Details: " + PostGrpMoreDetails + " Not Posted on Group:" + grpDisplay[2] + " Because Your membership is pending for approval. ]");

                                        GlobusFileHelper.AppendStringToTextfileNewLine("Your membership is pending approval on a Group:" + grpDisplay[2], FilePath.path_GroupUpdate);
                                        GlobusFileHelper.AppendStringToTextfileNewLine("Message Header: " + PostGrpDiscussion + " Not Posted on Group:" + grpDisplay[2] + " Because Your membership is pending for approval. ", FilePath.path_GroupUpdate);
                                        GlobusFileHelper.AppendStringToTextfileNewLine("Message More Details: " + PostGrpMoreDetails + " Not Posted on Group:" + grpDisplay[2] + " Because Your membership is pending for approval. ", FilePath.path_GroupUpdate);
                                    }
                                    else if (ResponseStatusMsg.Contains("Your post has been submitted for review"))
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Message Header Posted : " + PostGrpDiscussion + " Successfully on Group : " + grpDisplay[2] + " ]");
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Message More Details Posted : " + PostGrpMoreDetails + " Successfully on Group : " + grpDisplay[2] + " ]");
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Your post has been submitted for review ]");
                                        string CSV_Content = objLnkedinUser.username + "," + PostGrpDiscussion.Replace(",", ";") + "," + PostGrpMoreDetails.Replace(",", ";") + "," + grpDisplay[2];

                                    }
                                    else if (ResponseStatusMsg.Contains("Error"))
                                    {
                                        //Log("[ " + DateTime.Now + " ] => [ Error in Post ]");
                                        GlobusFileHelper.AppendStringToTextfileNewLine("Error in Post", FilePath.path_GroupUpdate);

                                    }
                                    else
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Message Not Posted ]");
                                        GlobusFileHelper.AppendStringToTextfileNewLine("Message Not Posted", FilePath.path_GroupUpdate);
                                    }

                                    int delay = RandomNumberGenerator.GenerateRandom(GlobalsGroups.minDelay, GlobalsGroups.maxDelay);
                                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Delay for : " + delay + " Seconds ]");
                                    Thread.Sleep(delay * 1000);

                                }
                                catch (Exception ex)
                                {
                                    GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Error --> Group Update --> cmbGroupUser_SelectedIndexChanged() ---1--->>>> " + ex.Message + "StackTrace --> >>>" + ex.StackTrace + "    Stack Trace >>> " + ex.StackTrace, FilePath.Path_LinkedinGetGroupMemberErrorLogs);
                                    //Log("[ " + DateTime.Now + " ] => [ Error:" + ex.Message + "StackTrace --> >>>" + ex.StackTrace + " ]");
                                }
                            }

                        }
                        catch (Exception ex)
                        {
                            GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Error --> Group Update --> cmbGroupUser_SelectedIndexChanged() ---1--->>>> " + ex.Message + "StackTrace --> >>>" + ex.StackTrace, FilePath.Path_LinkedinErrorLogs);
                            GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Error --> Group Update --> cmbGroupUser_SelectedIndexChanged() ---1--->>>> " + ex.Message + "StackTrace --> >>>" + ex.StackTrace, FilePath.Path_LinkedinGetGroupMemberErrorLogs);
                            // Log("[ " + DateTime.Now + " ] => [ Error:" + ex.Message + "StackTrace --> >>>" + ex.StackTrace + " ]");
                        }

                    }
                    catch (Exception ex)
                    {
                        GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Error --> Group Update --> cmbGroupUser_SelectedIndexChanged() ---2--->>>> " + ex.Message + "StackTrace --> >>>" + ex.StackTrace, FilePath.Path_LinkedinErrorLogs);
                        GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Error --> Group Update --> cmbGroupUser_SelectedIndexChanged() ---2--->>>> " + ex.Message + "StackTrace --> >>>" + ex.StackTrace, FilePath.Path_LinkedinGetGroupMemberErrorLogs);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        public void TestConnectPageSearch(string pageNumber, int SearchMinDelay, int SearchMaxDelay, ref LinkedinUser objLinkedinUser)
        {
            int proxyport = 888;
            string SummaryLink = string.Empty;
            GlobusHttpHelper HttpHelper=objLinkedinUser.globusHttpHelper;
            string _ProxyAddress = objLinkedinUser.proxyip;
            string _ProxyUserName = objLinkedinUser.proxyusername;
            string _ProxyPassword = objLinkedinUser.proxypassword;

            Regex PortCheck = new Regex("^[0-9]*$");

            if (PortCheck.IsMatch(objLinkedinUser.proxyport) && !string.IsNullOrEmpty(objLinkedinUser.proxyport))
            {
                proxyport = int.Parse(objLinkedinUser.proxyport);
            }

            //recive the page number and then hit page wise and find the url in which we need to send the request.....

            string UrlConnectpage = "http://www.linkedin.com/search/fpsearch?keywords=" + _ConnectSearchKeyword + "&keepFacets=keepFacets&page_num=" + pageNumber + "&pplSearchOrigin=ADVS&viewCriteria=2&sortCriteria=R&redir=redir";
            string PgSrcMain1 = HttpHelper.getHtmlfromUrlProxy(new Uri(UrlConnectpage), _ProxyAddress, proxyport, _ProxyUserName, _ProxyPassword);

            string PostData = string.Empty;
            string page_num = string.Empty;
            string postUrl = string.Empty;
            string facetsOrder = string.Empty;

            if (PgSrcMain1.Contains("facetsOrder"))
            {
                facetsOrder = PgSrcMain1.Substring(PgSrcMain1.IndexOf("facetsOrder"), 200);
                string[] Arr = facetsOrder.Split('"');
                facetsOrder = Arr[2];
                string DecodedCharTest = Uri.UnescapeDataString(facetsOrder);
                string DecodedEmail = Uri.EscapeDataString(facetsOrder);
                facetsOrder = DecodedEmail;
            }

            page_num = pageNumber;

            PostData = "searchLocationType=Y&inNetworkSearch=inNetworkSearch&search=&viewCriteria=2&sortCriteria=C&facetsOrder=" + facetsOrder + "&page_num=" + page_num + "&openFacets=N%2CCC%2CG";
            postUrl = "http://www.linkedin.com/vsearch/p?page_num=" + page_num + "&orig=ADVS&keywords=" + _ConnectSearchKeyword + "";

            //Diclaration For Post Add Connection For Keyword
            string Val_goback = string.Empty;
            string Val_sourceAlias = string.Empty;
            string Val_key = string.Empty;
            string Val_defaultText = string.Empty;
            string Val_firstName = string.Empty;
            string Val_CsrToken = string.Empty;
            string Val_Subject = string.Empty;
            string Val_greeting = string.Empty;
            string Val_AuthToken = string.Empty;
            string Val_AuthType = string.Empty;
            string val_trk = string.Empty;
            string Val_lastName = string.Empty;

            string postResponse = HttpHelper.postFormDataProxy(new Uri(postUrl), PostData, _ProxyAddress, proxyport, _ProxyUserName, _ProxyPassword);

            #region commented by sharan
            //  List<string> PageSerchUrl = ChilkatBasedRegex.GettingAllUrls1(postResponse, "profile/view?id"); // commented because it scraping the urls in string format
            #endregion

            //  List<string> PageSerchUrl = ChilkatBasedRegex.GettingAllUrls1_writtenBysharan(postResponse, "profile/view?id");

            List<string> PageSerchUrl = ChilkatBasedRegex.GettingAllUrls1_writtenBysharan_fullUrl(postResponse);
            //fkglkfgl


            if (PageSerchUrl.Count == 0)
            {

            }
            string FrnAcceptUrL = string.Empty;
            foreach (string item in PageSerchUrl)
            {
                string FRNURLresponce = string.Empty;

                if (GlobalsAddConn.CheckTheDayLimit)
                {
                    if (GlobalsAddConn.no_of_profiles_can_be_visited == GlobalsAddConn.no_of_profiles_visited)
                    {
                        break;
                    }

                    if (GlobalsAddConn.dailyLimit == GlobalsAddConn.no_of_profiles_visited)
                    {
                        return;
                    }
                }


                try
                {
                    FrnAcceptUrL = item;
                    string[] urll = Regex.Split(FrnAcceptUrL, "&authType");



                    /// Check Url[0] exit in Database or not 

                    bool check = CheckAccountDetailDB(objLinkedinUser.username, urll[0], ref objLinkedinUser);
                    if (!check)
                    {
                        if (GlobalsAddConn.selectedOnlyVisit)
                        {
                            GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] this Profile :" + urll[0] + "  has already been visited today with username : "******"Select * From tb_ManageAddConnection Where Keyword='" + _ConnectSearchKeyword + "' and LinkedinUrl='" + urll[0] + "'";
                        ds = DataBaseHandler.SelectQuery(Querystring, "tb_ManageAddConnection");
                    }
                    catch { }

                    if (GlobalsAddConn.selectedOnlyVisit)
                    {
                        string[] url2 = Regex.Split(FrnAcceptUrL, "&authType");
                        DataSet ds1 = new DataSet();
                        try
                        {
                            string Querystring = "Select * From tb_OnlyVisitProfile Where Email='" + objLinkedinUser.username + "' and Url='" + url2[0] + "'";
                            ds1 = DataBaseHandler.SelectQuery(Querystring, "tb_OnlyVisitProfile");
                        }
                        catch { }

                        if (ds.Tables[0].Rows.Count < 1)
                        {
                            FRNURLresponce = HttpHelper.getHtmlfromUrl1(new Uri(FrnAcceptUrL));
                        }
                    }

                    if (!GlobalsAddConn.selectedOnlyVisit)
                    {
                        FRNURLresponce = HttpHelper.getHtmlfromUrl1(new Uri(FrnAcceptUrL));

                        if (FRNURLresponce.Contains("1<sup>st</sup>"))
                        {
                            string connectionType = Utils.getBetween(FRNURLresponce, "<div class=\"profile-overview\">", "profile-aux");
                            //string check1stCon = Utils.getBetween(FRNURLresponce, "class=\"profile-pic\"", "<a href=\"");
                            // if (check1stCon.Contains("1<sup>st</sup>"))
                            if (connectionType.Contains("1<sup>st</sup>"))
                            {
                                try
                                {
                                    string fullname = Utils.getBetween(connectionType, "span class=\"full-name\" dir=\"auto\">", "</span>");
                                    if (!string.IsNullOrEmpty(fullname))
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] =>" + fullname + " is your first connection");
                                    }
                                }
                                catch
                                { }
                                continue;
                            }
                        }
                        if (FRNURLresponce.Contains("Upgrade for full name"))
                        {
                            continue;
                        }

                        if (FRNURLresponce.Contains("memberId"))
                        {
                            Val_key = Utils.getBetween(FRNURLresponce, "memberId:\"", "\"}");
                        }
                        if (FRNURLresponce.Contains("csrfToken"))
                        {
                            try
                            {
                                Val_CsrToken = FRNURLresponce.Substring(FRNURLresponce.IndexOf("csrfToken"), 100);
                                string[] Arr = Val_CsrToken.Split('>'); //Val_CsrToken.Split('&');
                                Val_CsrToken = Arr[0].Replace("csrfToken=", "").Replace("\"", "").Trim();
                            }
                            catch { }

                        }

                        if (FRNURLresponce.Contains("authToken"))
                        {
                            try
                            {
                                int startindex = FRNURLresponce.IndexOf("authToken");
                                string start = FRNURLresponce.Substring(startindex);
                                int endindex = start.IndexOf(",");
                                string end = start.Substring(0, endindex);
                                Val_AuthToken = end.Replace(",", string.Empty).Replace("authToken=", string.Empty).Replace("\"", string.Empty).Trim();
                                if (Val_AuthToken.Contains("&"))
                                {
                                    string[] Arr = Val_AuthToken.Split('&');
                                    Val_AuthToken = Arr[0].Replace("authToken=", string.Empty);
                                }
                                if (Val_AuthToken.Contains("</noscript>"))
                                {
                                    try
                                    {
                                        string[] Val_Auth = Regex.Split(Val_AuthToken, ">");
                                        Val_AuthToken = Val_Auth[0].Replace("\"", string.Empty);
                                    }
                                    catch { }
                                }
                            }
                            catch { }
                        }
                        if (FRNURLresponce.Contains("authType"))
                        {
                            try
                            {
                                Val_AuthType = FRNURLresponce.Substring(FRNURLresponce.IndexOf("authType"), 50);
                                string[] Arr = Val_AuthType.Split('&');
                                Val_AuthType = Arr[0].Replace("authType=", "");
                                if (Val_AuthType.Contains("</noscript>"))
                                {
                                    Val_AuthType = Val_AuthType.Replace("</noscript>", string.Empty).Replace("\n", string.Empty).Replace(">", string.Empty).Replace("\\", string.Empty).Replace("\"", string.Empty).Trim();
                                }
                                try
                                {
                                    if (string.IsNullOrEmpty(Val_AuthType))
                                    {
                                        Val_AuthType = "OUT_OF_NETWORK";
                                    }
                                }
                                catch { }

                            }
                            catch { }
                        }


                        if (FRNURLresponce.Contains("goback"))
                        {
                            try
                            {
                                Val_goback = FRNURLresponce.Substring(FRNURLresponce.IndexOf("goback"), 300);
                                string[] Arr = Val_goback.Split('"');
                                Val_goback = Arr[0].Replace("goback=", "");
                            }
                            catch { }
                        }
                        if (FRNURLresponce.Contains("trk"))
                        {
                            try
                            {
                                val_trk = FRNURLresponce.Substring(FRNURLresponce.IndexOf("trk"), 100);
                                string[] Arr = val_trk.Split(',');
                                val_trk = Arr[0].Replace("trk=", "").Replace("\"", string.Empty);
                            }
                            catch { }
                        }

                        if (FRNURLresponce.Contains("\"full-name\""))
                        {
                            try
                            {
                                string[] name = Regex.Split(Utils.getBetween(FRNURLresponce, "\"full-name\" dir=\"auto\">", "</span>"), " ");
                                Val_firstName = name[0];
                                Val_lastName = name[1];
                            }
                            catch
                            { }
                        }

                        else
                        {
                            if (FRNURLresponce.Contains("lastName"))
                            {
                                try
                                {
                                    Val_lastName = FRNURLresponce.Substring(FRNURLresponce.IndexOf("lastName="), 300);
                                    try
                                    {
                                        string[] Arr = Val_lastName.Split('&');
                                        Val_lastName = Arr[0].Replace("lastName=", string.Empty).Replace(",", "").Replace("\"", "").Replace("&#225;", string.Empty).Trim();
                                    }
                                    catch { }
                                }
                                catch { }
                            }

                            if (FRNURLresponce.Contains("firstName") || FRNURLresponce.Contains("ShortTitle"))
                            {
                                try
                                {
                                    if (FRNURLresponce.Contains("firstName"))
                                    {
                                        try
                                        {
                                            Val_firstName = FRNURLresponce.Substring(FRNURLresponce.IndexOf("firstName="), 300);
                                            string[] Arr = Val_firstName.Split('&');
                                            Val_firstName = Arr[0].Replace("firstName=", "").Replace("i18n_HEADLINE", string.Empty).Replace("\"", "").Replace(",", string.Empty).Replace("}", string.Empty).Replace("link__endpoint", "").Trim();
                                        }
                                        catch { }
                                    }
                                    else if (FRNURLresponce.Contains("ShortTitle"))
                                    {
                                        Val_firstName = FRNURLresponce.Substring(FRNURLresponce.IndexOf("ShortTitle"), 30);
                                        string[] Arr = Val_firstName.Split('"');
                                        Val_firstName = Arr[2].Replace("ShortTitle=", "");
                                    }
                                }
                                catch { }
                            }
                        }

                        try
                        {
                            string[] Valuesss = Regex.Split(FRNURLresponce, "markAsReadOnClick");
                            try
                            {
                                Val_goback = Valuesss[1].Substring(Valuesss[1].IndexOf("goback="), (Valuesss[1].IndexOf(",", Valuesss[1].IndexOf("goback=")) - Valuesss[1].IndexOf("goback="))).Replace("goback=", string.Empty).Trim();
                            }
                            catch { }
                        }
                        catch { }

                        string thiredResponce = "http://www.linkedin.com/people/invite?from=profile&key=" + Val_key + "&firstName=" + Val_firstName + "&lastName=" + Val_lastName + "&authToken=" + Val_AuthToken + "&authType=" + Val_AuthType + "&csrfToken=" + Val_CsrToken + "&goback=" + Val_goback;
                        string pageResponce2 = HttpHelper.getHtmlfromUrl1(new Uri(thiredResponce));

                        if (pageResponce2.Contains("You and this LinkedIn user don’t know anyone in common"))
                        {
                            string CSVHeader = "UserName" + "," + "SearchKeyword" + "," + "Invitation Sent To" + "," + "InvitationUrl";
                            string[] url = Regex.Split(FrnAcceptUrL, "&authType");
                            string CSV_Content = objLinkedinUser.username + "," + _ConnectSearchKeyword + ", ," + url[0];
                            CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_ConnectionThroughUnkonwPeopleLink);
                            GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Failed To Send Invitation From " + objLinkedinUser.username + " ]");
                            valid = false;
                            GlobalsAddConn.no_of_profiles_visited++;
                            Isaccountvalid = false;
                            continue;
                        }


                        if (pageResponce2.Contains("sourceAlias"))
                        {
                            try
                            {
                                Val_sourceAlias = pageResponce2.Substring(pageResponce2.IndexOf("sourceAlias"), 100);
                                string[] Arr = Val_sourceAlias.Split('"');
                                Val_sourceAlias = Arr[2];
                            }
                            catch (Exception ex)
                            {


                            }
                        }
                        string[] strNameValue = Regex.Split(pageResponce2, "name=");

                        #region DecareVariable By vicky
                        string iweReconnectSubmit = string.Empty;
                        string iweLimitReached = string.Empty;
                        string companyID0 = string.Empty;
                        string companyName0 = string.Empty;
                        string companyID1 = string.Empty;
                        string schoolID = string.Empty;
                        string schoolcountryCode = string.Empty;
                        string schoolprovinceCode = string.Empty;
                        string subject = string.Empty;
                        string defaultText = string.Empty;
                        string csrfToken = string.Empty;
                        string sourceAlias = string.Empty;
                        string goback = string.Empty;
                        string titleIC0 = string.Empty;
                        string greeting = string.Empty;
                        string startYearIC0 = string.Empty;
                        string endYearIC0 = string.Empty;
                        string schoolText = string.Empty;
                        string titleIB0 = string.Empty;
                        string startYearIB0 = string.Empty;
                        string trk = string.Empty;
                        string authType = string.Empty;
                        string otheremail = string.Empty;
                        string firstName = string.Empty;
                        string lastName = string.Empty;

                        string existingEducation = string.Empty;
                        string activity_210152675 = string.Empty;
                        string activity_210152497 = string.Empty;
                        string existingPositionIB = string.Empty;
                        string reason = string.Empty;

                        #endregion

                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"existingEducation");
                            int tempstartindex = ArrForValue[1].IndexOf("id=\"");
                            string strValue = ArrForValue[1].Substring(tempstartindex).Replace("id=\"", string.Empty);
                            strValue = strValue.Substring(0, strValue.IndexOf("\""));
                            existingEducation = strValue;
                        }
                        catch { }
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"activity_210152675");
                            int tempstartindex = ArrForValue[1].IndexOf("id=\"");
                            string strValue = ArrForValue[1].Substring(tempstartindex).Replace("id=\"", string.Empty);
                            strValue = strValue.Substring(0, strValue.IndexOf("\""));
                            activity_210152675 = strValue;
                        }
                        catch { }
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"activity_210152497");
                            int tempstartindex = ArrForValue[1].IndexOf("id=\"");
                            string strValue = ArrForValue[1].Substring(tempstartindex).Replace("id=\"", string.Empty);
                            strValue = strValue.Substring(0, strValue.IndexOf("\""));
                            activity_210152497 = strValue;
                        }
                        catch { }
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"existingPositionIB");
                            int tempstartindex = ArrForValue[1].IndexOf("id=\"");
                            string strValue = ArrForValue[1].Substring(tempstartindex).Replace("id=\"", string.Empty);
                            strValue = strValue.Substring(0, strValue.IndexOf("\""));
                            existingPositionIB = strValue;
                        }
                        catch { }
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"reason");
                            int tempstartindex = ArrForValue[1].IndexOf("value=\"");
                            string strValue = ArrForValue[1].Substring(tempstartindex).Replace("value=\"", string.Empty);
                            strValue = strValue.Substring(0, strValue.IndexOf("\""));
                            reason = strValue;
                        }
                        catch { }
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"startYearIC.0");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            startYearIC0 = (strValue);

                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"authType");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            authType = (strValue);

                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"authType");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            authType = (strValue);

                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"trk");
                            int tempstartIndex = ArrForValue[1].IndexOf("id=\"");
                            string strValue = ArrForValue[1].Substring(tempstartIndex).Replace("id=\"", "");
                            strValue = strValue.Substring(0, strValue.IndexOf("\""));
                            // string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("type="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("type=")) - ArrForValue[1].IndexOf("type=")).Replace("type=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            trk = (strValue).Trim();

                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"endYearIC.0");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            endYearIC0 = (strValue);

                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"schoolText");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            schoolText = (strValue);

                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"startYearIB.0");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            startYearIB0 = (strValue);

                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"titleIB.0");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            titleIB0 = (strValue);

                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"companyID.0");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            companyID0 = (strValue);

                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"companyID.1");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            companyID1 = (strValue);

                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"schoolID");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            schoolID = (strValue);

                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"schoolcountryCode");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            schoolcountryCode = (strValue);

                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"schoolprovinceCode");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf(" ", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            schoolprovinceCode = (strValue);
                            if (!string.IsNullOrEmpty(schoolprovinceCode))
                            {

                                schoolprovinceCode = "";
                            }
                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"subject");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            subject = (strValue);
                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"defaultText");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            defaultText = (strValue);
                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"csrfToken");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            csrfToken = (strValue);
                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"sourceAlias");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            sourceAlias = (strValue);
                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"goback");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            goback = (strValue).Replace("&quot;", "%22").Replace(":", "%3A").Replace(",", "%2C").Replace("/", "%2F").Replace("{", "%7B").Replace(" ", "+");
                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"titleIC.0");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            titleIC0 = (strValue);
                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"otherEmail");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            otheremail = (strValue);
                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"iweLimitReached");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            iweLimitReached = (strValue);
                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            try
                            {
                                string[] ArrForValue = Regex.Split(pageResponce2, "name=\"iweReconnectSubmit");
                                string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("class=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                iweReconnectSubmit = (strValue);
                            }
                            catch { }
                            try
                            {
                                if (iweReconnectSubmit.Contains(">") || iweReconnectSubmit.Contains(">"))
                                {
                                    iweReconnectSubmit = "Send Invitation";
                                }
                            }
                            catch { }
                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            try
                            {
                                string[] ArrForValue = Regex.Split(pageResponce2, "name=\"greeting");
                                string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("class=\"message\">"), ArrForValue[1].IndexOf("<", ArrForValue[1].IndexOf("class=\"message\">")) - ArrForValue[1].IndexOf("class=\"message\">")).Replace("class=\"message\">", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                                greeting = (strValue);
                                greeting = greeting.Replace("&#39;", "'");
                                greeting = greeting.Replace(" ", "+");
                                greeting = Uri.EscapeUriString(greeting);
                                greeting = greeting.Remove(greeting.IndexOf("@"));  //added new
                            }
                            catch { }
                            try
                            {
                                if (iweReconnectSubmit.Contains(">") || iweReconnectSubmit.Contains(">"))
                                {
                                    //iweReconnectSubmit = "Send Invitation";
                                }
                            }
                            catch { }
                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"companyName.0");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            companyName0 = (strValue);
                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"firstName");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace("\"", string.Empty).Trim());
                            firstName = (strValue).Replace("&#225;", string.Empty);
                        }
                        catch { }
                        #endregion
                        #region
                        try
                        {
                            string[] ArrForValue = Regex.Split(pageResponce2, "name=\"lastName");
                            string strValue = (ArrForValue[1].Substring(ArrForValue[1].IndexOf("value="), ArrForValue[1].IndexOf("id=", ArrForValue[1].IndexOf("value=")) - ArrForValue[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\\\"", string.Empty).Replace(",", ";").Replace("\"", string.Empty).Trim());
                            lastName = (strValue);
                        }
                        catch { }
                        #endregion

                        string lastPostUrl = "http://www.linkedin.com/people/iweReconnectAction";
                        //
                        //*********post request for last process of send request 

                        //existingPositionIC=&companyName.0=&titleIC.0=&startYearIC.0=&endYearIC.0=&schoolText=&schoolID=&existingPositionIB=&companyName.1=&titleIB.0=&startYearIB.0=&endYearIB.0=&reason=IF&otherEmail=&greeting=I%27d+like+to+add+you+to+my+professional+network+on+LinkedIn.%0D%0A%0D%0A-+gaurav+agrawal&iweReconnectSubmit=Send+Invitation&key=141450&firstName=Ron&lastName=Bates&authToken=d7Ir&authType=OPENLINK&trk=prof-0-sb-connect-button&iweLimitReached=false&companyID.0=&companyID.1=&schoolID=&schoolcountryCode=&schoolprovinceCode=&javascriptEnabled=false&subject=gaurav+agrawal+wants+to+connect+on+LinkedIn+&defaultText=a908b3ba18701677a5879c1955035d05&csrfToken=ajax%3A8096156173388039261&                                                            sourceAlias=0_0ZD1VB-f52hFxNsCjPZdLV&goback=.fps_PBCK_*1_*1_*1_*1_*1_*1_*1_*2_*1_Y_*1_*1_*1_false_1_C_*1_*51_*1_*51_true_CC%2CN%2CG%2CI%2CPC%2CED%2CL%2CFG%2CTE%2CFA%2CSE%2CP%2CCS%2CF%2CDR_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2.npv_141450_*1_*1_OPENLINK_d7Ir_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1;
                        string NameOfSender = objLinkedinUser.username.Remove(objLinkedinUser.username.IndexOf("@"));
                        // tab-name username">
                        string SenderName = string.Empty;
                        try
                        {
                            SenderName = FRNURLresponce.Substring(FRNURLresponce.IndexOf("tab-name username\">"), (FRNURLresponce.IndexOf("<", FRNURLresponce.IndexOf("tab-name username\">")) - FRNURLresponce.IndexOf("tab-name username\">"))).Replace("tab-name username\">", string.Empty).Trim().Replace("tab-name username\">", string.Empty);
                            NameOfSender = Uri.EscapeUriString(SenderName);
                        }
                        catch { }

                        string LastPostData = "companyName.0=" + companyName0 + "titleIC.0=" + titleIC0 + "&startYearIC.0=" + startYearIC0 + "&endYearIC.0=" + endYearIC0 + "&schoolText=" + schoolText + "&schoolID=" + schoolID + "&companyName.1=" + companyName0 + "&titleIB.0=" + titleIB0 + "&startYearIB.0=" + startYearIB0 + "&endYearIB.0=" + endYearIC0 + "&reason=IF&otherEmail=" + otheremail + "&greeting=" + greeting + "&iweReconnectSubmit=" + iweReconnectSubmit.Replace(" ", "+") + "&key=" + Val_key + "&firstName=" + firstName + "&lastName=" + lastName + "&authToken=" + Val_AuthToken + "&authType=" + Val_AuthType + "&trk=" + trk + "&iweLimitReached=false&companyID.0=" + companyID0 + "&companyID.1=" + companyID1 + "&schoolID=" + schoolID + "&schoolcountryCode=" + schoolcountryCode + "&schoolprovinceCode=" + schoolprovinceCode + "&javascriptEnabled=false&subject=" + subject.Replace(" ", "+") + "&defaultText=" + defaultText + "&csrfToken=" + Val_CsrToken + "&sourceAlias=" + sourceAlias + "&goback=" + Val_goback;
                        string postResponse1 = HttpHelper.postFormDataProxy(new Uri(lastPostUrl), LastPostData, _ProxyAddress, proxyport, _ProxyUserName, _ProxyPassword);

                        //Esuccess
                        string FinalValue = string.Empty;
                        try
                        {
                            FinalValue = postResponse1.Substring(postResponse1.IndexOf("Esuccess"), (postResponse1.IndexOf(">", postResponse1.IndexOf("Esuccess")) - postResponse1.IndexOf("Esuccess"))).Replace("Esuccess", string.Empty).Trim();
                            FinalValue = Uri.UnescapeDataString(FinalValue);
                            string[] valuess = Regex.Split(FinalValue, ",");
                            FinalValue = valuess[0].Replace("=", string.Empty).Replace("\"", string.Empty);
                        }
                        catch { }
                        try
                        {
                            string lastGetResponse = HttpHelper.getHtmlfromUrl1(new Uri("http://www.linkedin.com/people/pymk?goback=" + Val_goback + "&trk=" + val_trk + "&report%2Esuccess=" + FinalValue));
                        }
                        catch { }
                        if (postResponse1.Contains("You must confirm your primary email address before sending an invitation."))
                        {
                            GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ " + objLinkedinUser.username + "You must confirm your primary email address before sending an invitation. ]");
                            valid = false;
                            PageNumber = 0;
                            Isaccountvalid = false;
                            break;
                        }

                        if (postResponse1.Contains("<strong>Invitations") || postResponse1.Contains("Send Invitation") || postResponse1.Contains("Invitation to"))
                        {
                            string alert = Utils.getBetween(postResponse1, "<div role=\"alert\"", "</div>");
                            if (alert.Contains("Invitation to <a href") && alert.Contains("</a> sent.</strong>"))
                            {


                                if (string.IsNullOrEmpty(firstName) && string.IsNullOrEmpty(lastName))
                                {
                                    firstName = "linkedin";
                                    lastName = "Member";
                                }
                                GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Invitation to " + firstName + " " + lastName + " sent From Account :" + objLinkedinUser.username + " ]");
                                string CSVHeader = "UserName" + "," + "SearchKeyword" + "," + "Invitation Sent To" + "," + "InvitationUrl";
                                try
                                {
                                    string[] url = Regex.Split(FrnAcceptUrL, "&authType");
                                    string CSV_Content = objLinkedinUser.username + "," + _ConnectSearchKeyword + "," + firstName + " " + lastName + "," + url[0];
                                    CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_AddConnectionSuccessWith2ndDegree);
                                    valid = true;
                                    insertAccountData(objLinkedinUser.username, url[0], SendInvitationCount);
                                }
                                catch { }
                            }
                        }
                        else if (pageResponce2.Contains("You sent an invitation to") || pageResponce2.Contains("Invitation to") )
                        {
                            GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Invitation to " + Val_firstName + " " + Val_lastName + " sent From Account :" + objLinkedinUser.username + " ]");
                            string CSVHeader = "UserName" + "," + "SearchKeyword" + "," + "Invitation Sent To" + "," + "InvitationUrl";
                            try
                            {
                                string[] url = Regex.Split(FrnAcceptUrL, "&authType");
                                string CSV_Content = objLinkedinUser.username + "," + _ConnectSearchKeyword + "," + firstName + " " + lastName + "," + url[0];
                                CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_AddConnectionSuccessWith2ndDegree);
                                valid = true;
                                insertAccountData(objLinkedinUser.username, url[0], SendInvitationCount);
                            }
                            catch { }
                        }
                        else if (postResponse1.Contains("You and this LinkedIn user don’t know anyone in common"))
                        {
                            string CSVHeader = "UserName" + "," + "SearchKeyword" + "," + "Invitation Sent To" + "," + "InvitationUrl";
                            string[] url = Regex.Split(FrnAcceptUrL, "&authType");
                            string CSV_Content = objLinkedinUser.username + "," + _ConnectSearchKeyword + ", ," + url[0];
                            CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_ConnectionThroughUnkonwPeopleLink);
                            GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Failed To Send Invitation From " + objLinkedinUser.username + " ]");
                            valid = false;
                            Isaccountvalid = false;
                        }
                        else
                        {
                            string CSVHeader = "UserName" + "," + "SearchKeyword" + "," + "Invitation Sent To" + "," + "InvitationUrl";
                            string[] url = Regex.Split(FrnAcceptUrL, "&authType");
                            string CSV_Content = objLinkedinUser.username + "," + _ConnectSearchKeyword + "," + firstName + " " + lastName + "," + url[0];
                            CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_ConnectionthroughKeywordSearchnotadded);
                            GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Failed To Send Invitation From " + objLinkedinUser.username + " ]");
                            valid = false;
                            SendInvitationCount--;

                        }


                        int Delay = RandomNumberGenerator.GenerateRandom(SearchMinDelay, SearchMaxDelay);
                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Invitation Delayed For : " + Delay + " Seconds ]");
                        Thread.Sleep(Delay * 1000);
                       

                        SendInvitationCount++;
                        if (SendInvitationCount >= GlobalsAddConn.requestPerKeyword)  //Here we check  that number of request send if counter is equal to the number of request put by user then it return to mathod and made pagenumber = 0; 
                        {
                            PageNumber = 0;
                            return;
                        }
                    }

                    else
                    {
                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Only visit the site " + FrnAcceptUrL + " ]");
                        string CSVHeader = "UserName" + "," + "Url";


                        string[] url = Regex.Split(FrnAcceptUrL, "&authType");
                        string CSV_Content = objLinkedinUser.username + "," + url[0];

                        insertAccountData(objLinkedinUser.username, url[0], SendInvitationCount);

                        CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_OnlyVisitProfileUsingKeyword);

                        DataSet ds2 = new DataSet();
                        try
                        {
                            string Querystring = "INSERT INTO tb_OnlyVisitProfile (Email,Url,DateTime) Values ('" + objLinkedinUser.username + "','" + url[0] + "','" + DateTime.Now + "')";
                            ds2 = DataBaseHandler.SelectQuery(Querystring, "tb_OnlyVisitProfile");
                        }
                        catch { }


                        int Delay = RandomNumberGenerator.GenerateRandom(SearchMinDelay, SearchMaxDelay);
                        Thread.Sleep(Delay * 1000);
                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Delayed For : " + Delay + " Seconds ]");

                        GlobalsAddConn.no_of_profiles_visited++;
                    }
                }
                catch (Exception ex)
                {
                    string CSVHeader = "UserName" + "," + "SearchKeyword" + "," + "Invitation Sent To" + "," + "InvitationUrl";
                    string[] url = Regex.Split(FrnAcceptUrL, "&authType");
                    string CSV_Content = objLinkedinUser.username + "," + _ConnectSearchKeyword + ",," + url[0];
                    CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_ConnectionthroughKeywordSearchnotadded);
                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Failed To Send Invitation From " + objLinkedinUser.username + " ]");
                    valid = false;
                    Isaccountvalid = false;
                }
            }
        }
        public string FormURL(ref LinkedinUser objLinkedinUser)
        {
            GlobusHttpHelper objHttpHelper = objLinkedinUser.globusHttpHelper;
            string url = "https://www.linkedin.com/sales/search/?";
            try
            {
                if (!string.IsNullOrEmpty(currentCompany))
                {
                    url = url + "&company=" + currentCompany;
                    // url = url + "&companyScope=" + GlobalsScraper.selectedCurrentPast_Input_SalesNav;
                }


                if (!string.IsNullOrEmpty(relationship))
                {
                    int i = 0;
                    string[] rawRelationship = Regex.Split(relationship, ",");
                    string addRelationshipValue = "facet=N";
                    for (i = 0; i < rawRelationship.Count(); i++)
                    {
                        addRelationshipValue = addRelationshipValue + "&facet.N=" + rawRelationship[i];
                    }
                    url = url + addRelationshipValue;
                }
                if (!string.IsNullOrEmpty(location))
                {
                    string locationResponse = objHttpHelper.getHtmlfromUrl(new Uri("https://www.linkedin.com/ta/region?query=" + Uri.EscapeDataString(location)));
                    string rawLocationValue = Utils.getBetween(locationResponse, "\"id\":\"", "\",\"");
                    url = url + "&facet=G&facet.G=" + rawLocationValue;
                }
                if (!string.IsNullOrEmpty(title))
                {
                    url = url + "&jobTitle=" + title;
                    
                }
                if (!string.IsNullOrEmpty(titleScope))
                {
                    url = url + "&titleScope=" + titleScope;
                }
                    
                if (!string.IsNullOrEmpty(industry))
                {
                    int i = 0;
                    string[] rawIndustry = Regex.Split(industry, ",");
                    string addIndustryValue = "&facet=I";
                    for (i = 0; i < rawIndustry.Count(); i++)
                    {
                        addIndustryValue = addIndustryValue + "&facet.I=" + rawIndustry[i];
                    }
                    url = url + addIndustryValue;
                }
                if (!string.IsNullOrEmpty(country))
                {
                    //  url = url + "&countryCode=" + SalesNavigatorGlobals.country;
                }
                if (!string.IsNullOrEmpty(within))
                {
                    url = url + "&radiusMiles=" + within;
                }
                if (!string.IsNullOrEmpty(postalCode))
                {
                    url = url + "&postalCode=" + postalCode;
                }
                if (!string.IsNullOrEmpty(firstName))
                {
                    url = url + "&firstName=" + firstName;
                }
                if (!string.IsNullOrEmpty(lastName))
                {
                    url = url + "&lastName=" + lastName;
                }
                if (!string.IsNullOrEmpty(seniorityLevel))
                {
                    int i = 0;
                    string[] rawSeniorityLevel = Regex.Split(seniorityLevel, ",");
                    string addSeniorityValue = "&facet=SE";
                    for (i = 0; i < rawSeniorityLevel.Count(); i++)
                    {
                        addSeniorityValue = addSeniorityValue + "&facet.SE=" + rawSeniorityLevel[i];
                    }
                    url = url + addSeniorityValue;
                }
                if (!string.IsNullOrEmpty(function))
                {
                    int i = 0;
                    string[] rawFunction = Regex.Split(function, ",");
                    string addFunctionValue = "&facet=FA";
                    for (i = 0; i < rawFunction.Count(); i++)
                    {
                        addFunctionValue = addFunctionValue + "&facet.FA=" + rawFunction[i];
                    }
                    url = url + addFunctionValue;
                }
                if (!string.IsNullOrEmpty(companySize))
                {
                    int i = 0;
                    string[] rawCompanySize = Regex.Split(companySize, ",");
                    string addCompanySizeValue = "&facet=CS";
                    for (i = 0; i < rawCompanySize.Count(); i++)
                    {
                        addCompanySizeValue = addCompanySizeValue + "&facet.CS=" + rawCompanySize[i];
                    }
                    url = url + addCompanySizeValue;
                }
                if (!string.IsNullOrEmpty(yearOfExperience))
                {
                    int i = 0;
                    string[] rawYearsOfExperience = Regex.Split(yearOfExperience, ",");
                    string addYearsOfExperienceValue = "&facet=TE";
                    for (i = 0; i < rawYearsOfExperience.Count(); i++)
                    {
                        addYearsOfExperienceValue = addYearsOfExperienceValue + "&facet.TE=" + rawYearsOfExperience[i];
                    }
                    url = url + addYearsOfExperienceValue;
                }
                if (!string.IsNullOrEmpty(language))
                {
                    int i = 0;
                    string[] rawlanguage = Regex.Split(language, ",");
                    string addLanguageValue = "&facet=L";
                    for (i = 0; i < rawlanguage.Count(); i++)
                    {
                        addLanguageValue = addLanguageValue + "&facet.L=" + rawlanguage[i];
                    }
                    url = url + addLanguageValue;
                }
                if (!string.IsNullOrEmpty(whenJoined))
                {
                    int i = 0;
                    string[] rawWhenJoined = Regex.Split(whenJoined, ",");
                    string addWhenJoinedValue = "&facet=DR";
                    for (i = 0; i < rawWhenJoined.Count(); i++)
                    {
                        addWhenJoinedValue = addWhenJoinedValue + "&facet.DR=" + rawWhenJoined[i];
                    }
                    url = url + addWhenJoinedValue;
                }
                //url = url + "&defaultSelection=false&start=replaceVariableCounter&count=100";
                url = url + "&defaultSelection=false&start=0&count=10&searchHistoryId=1540160093";


                if (!string.IsNullOrEmpty(keyword))
                {
                    url = url + "&keywords=" + Uri.EscapeDataString(keyword) + "&trk=lss-search-tab";
                }
                else
                {
                    url = url + "&trk=lss-search-tab";
                }
            }
            catch (Exception ex)
            {
            }
            return url;
        }
        private void LoadAccounts()
        {
            //Globals.IsFreeVersion = true;

          

            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();

                if (result == true)
                {


                    DateTime sTime = DateTime.Now;

                    #region MyRegion
                    //if (lblAccounts_ManageAccounts_LoadsAccountsPath.InvokeRequired)
                    //{
                    //    lblAccounts_ManageAccounts_LoadsAccountsPath.Invoke(new MethodInvoker(delegate
                    //    {
                    //        lblAccounts_ManageAccounts_LoadsAccountsPath.Text = ofd.FileName;
                    //    }));
                    //}
                    //else
                    //{
                    //    lblAccounts_ManageAccounts_LoadsAccountsPath.Text = ofd.FileName;
                    //} 
                    #endregion

                    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);

                    #region MyRegion
                    //if (grvAccounts_ManageAccounts_ManageAccountsDetails.InvokeRequired)
                    //{
                    //    grvAccounts_ManageAccounts_ManageAccountsDetails.Invoke(new MethodInvoker(delegate
                    //    {
                    //        grvAccounts_ManageAccounts_ManageAccountsDetails.DataSource = null;
                    //    }));
                    //}
                    //else
                    //{
                    //    grvAccounts_ManageAccounts_ManageAccountsDetails.DataSource = null;
                    //} 
                    #endregion

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

                    //if (templist.Count > 0)
                    //{
                    //    LDGlobals.loadedAccountsDictionary.Clear();
                    //    LDGlobals.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;
                               

                                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(':')[5];
                                    proxyPort = account.Split(':')[6];
                                    proxyUserName = account.Split(':')[7];
                                    proxyPassword = account.Split(':')[8];
                                  


                                }

                                //dt.Rows.Add(accountUser, accountPass, ScreenName, FollowerCount, FollwingCount, proxyAddress, proxyPort, proxyUserName, proxyPassword, GroupName, AccountStatus);
                                dt.Rows.Add(accountUser, accountPass, proxyAddress, proxyPort, proxyUserName, proxyPassword);


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



                                try
                                {
                                    // loadedAccountsDictionary.Clear();
                                    LinkedinUser objLinkedinUser = new LinkedinUser();
                                    objLinkedinUser.username = accountUser;
                                    objLinkedinUser.password = accountPass;
                                    objLinkedinUser.proxyip = proxyAddress;
                                    objLinkedinUser.proxyport = proxyPort;
                                    objLinkedinUser.proxyusername = proxyUserName;
                                    objLinkedinUser.proxypassword = proxyPassword;

                                    LDGlobals.loadedAccountsDictionary.Add(objLinkedinUser.username, objLinkedinUser);

                             

                                    LDGlobals.listAccounts.Add(objLinkedinUser.username + ":" + objLinkedinUser.password + ":" + objLinkedinUser.proxyip + ":" + objLinkedinUser.proxyport + ":" + objLinkedinUser.proxyusername + ":" + objLinkedinUser.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);
                        }

                    }
                    DataSet objDataSet= Qm.SelectAccounts();
                    dt = objDataSet.Tables["tb_LinkedInAccount"];

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

                    this.Dispatcher.Invoke(new Action(delegate
                    {
                        grvAccounts_AccountCreator_AccountDetails.ItemsSource = dv;

                    }));
                    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;
            }));

        }