public void PostFinalMsgGroupMember_1By1(ref GlobusHttpHelper HttpHelper, Dictionary<string, string> SlectedContacts, List<string> GrpMemSubjectlist, List<string> GrpMemMessagelist, string msg, string body, string UserName, string FromemailId, string FromEmailNam, string SelectedGrpName, string grpId, bool mesg_with_tag, bool msg_spintaxt, int mindelay, int maxdelay, bool preventMsgSameGroup, bool preventMsgWithoutGroup, bool preventMsgGlobal)
        {
            try
            {
               // MsgGroupMemDbManager objMsgGroupMemDbMgr = new MsgGroupMemDbManager();

                string postdata = string.Empty;
                string postUrl = string.Empty;
                string ResLogin = string.Empty;
                string csrfToken = string.Empty;
                string sourceAlias = string.Empty;
                string ReturnString = string.Empty;
                string PostMsgSubject = string.Empty;
                string PostMsgBody = string.Empty;
                string FString = string.Empty;

                try
                {


                    string MessageText = string.Empty;
                    string PostedMessage = string.Empty;
                    string senderEmail = string.Empty;
                    string getComposeData = HttpHelper.getHtmlfromUrl(new Uri("https://www.linkedin.com/inbox/compose"));


                    if (!getComposeData.Contains("There was an error with the file upload. Please try again later."))
                    {
                        #region MyRegion
                        try
                        {
                            int startindex = getComposeData.IndexOf("\"senderEmail\" value=\"");
                            if (startindex < 0)
                            {
                                startindex = getComposeData.IndexOf("\"senderEmail\",\"value\":\"");
                            }
                            string start = getComposeData.Substring(startindex).Replace("\"senderEmail\" value=\"", string.Empty).Replace("\"senderEmail\",\"value\":\"", string.Empty);
                            int endindex = start.IndexOf("\"/>");
                            if (endindex < 0)
                            {
                                endindex = start.IndexOf("\",\"");
                            }
                            string end = start.Substring(0, endindex).Replace("\"/>", string.Empty).Replace("\",\"", string.Empty);
                            senderEmail = end.Trim();
                        }
                        catch (Exception ex)
                        {
                            senderEmail = Utils.getBetween(getComposeData, "<", ">");
                        }
                        string pageSource = HttpHelper.getHtmlfromUrl(new Uri("https://www.linkedin.com/home?trk=hb_tab_home_top"));
                        if (pageSource.Contains("csrfToken"))
                        {
                            try
                            {
                                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).Replace("\n", string.Empty).Replace(">", string.Empty).Replace("<script typ", string.Empty);
                                csrfToken = csrfToken.Trim();
                            }
                            catch (Exception ex)
                            {

                            }

                        }

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

                            }
                        }

                        if (pageSource.Contains("goback="))
                        {
                            try
                            {
                            }
                            catch (Exception ex)
                            {

                            }
                        }

                        foreach (KeyValuePair<string, string> itemChecked in SlectedContacts)
                        {
                            try
                            {
                                DataSet ds = new DataSet();
                                DataSet ds_bList = new DataSet();
                                string ContactName = string.Empty;
                                string Nstring = string.Empty;
                                string connId = string.Empty;
                                string FName = string.Empty;
                                string Lname = string.Empty;
                                string tempBody = string.Empty;
                                string tempsubject = string.Empty;
                                string n_ame1 = string.Empty;

                                //grpId = itemChecked.Key.ToString();

                                try
                                {
                                    // FName = itemChecked.Value.Split(' ')[0];
                                    // Lname = itemChecked.Value.Split(' ')[1];
                                    try
                                    {
                                        n_ame1 = itemChecked.Value.Split(']')[1].Trim(); ;
                                    }
                                    catch
                                    { }
                                    if (string.IsNullOrEmpty(n_ame1))
                                    {
                                        try
                                        {
                                            n_ame1 = itemChecked.Value;
                                        }
                                        catch
                                        { }
                                    }
                                    string[] n_ame = Regex.Split(n_ame1, " ");
                                    FName = " " + n_ame[0];
                                    Lname = n_ame[1];

                                    if (!string.IsNullOrEmpty(n_ame[2]))
                                    {
                                        Lname = Lname + n_ame[2];
                                    }
                                    if (!string.IsNullOrEmpty(n_ame[3]))
                                    {
                                        Lname = Lname + n_ame[3];
                                    }
                                    if (!string.IsNullOrEmpty(n_ame[4]))
                                    {
                                        Lname = Lname + n_ame[4];
                                    }
                                    if (!string.IsNullOrEmpty(n_ame[5]))
                                    {
                                        Lname = Lname + n_ame[5];
                                    }
                                }
                                catch (Exception ex)
                                {
                                }

                                try
                                {
                                    ContactName = FName + " " + Lname;
                                    ContactName = ContactName.Replace("%20", " ");
                                }
                                catch { }

                                
                                GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Adding Contact : " + ContactName + " ]");

                                string ToCd = itemChecked.Key;
                                List<string> AddAllString = new List<string>();

                                if (FString == string.Empty)
                                {
                                    string CompString = "{" + "\"" + "_" + ToCd.Trim() + "\"" + ":" + "{" + "\"" + "memberId" + "\"" + ":" + "\"" + ToCd.Trim() + "\"" + "," + "\"" + "firstName" + "\"" + ":" + "\"" + FName + "\"" + "," + "\"" + "lastName" + "\"" + ":" + "\"" + Lname + "\"" + "}";
                                    FString = CompString;
                                }
                                else
                                {
                                    string CompString = "\"" + "_" + ToCd.Trim() + "\"" + ":" + "{" + "\"" + "memberId" + "\"" + ":" + "\"" + ToCd.Trim() + "\"" + "," + "\"" + "firstName" + "\"" + ":" + "\"" + FName + "\"" + "," + "\"" + "lastName" + "\"" + ":" + "\"" + Lname + "\"" + "}";
                                    FString = CompString;
                                }

                                if (Nstring == string.Empty)
                                {
                                    Nstring = FString;
                                    connId = ToCd;
                                }
                                else
                                {
                                    Nstring += "," + FString;
                                    connId += " " + ToCd;
                                }

                                Nstring += "}";
                                tempsubject = msg;
                                try
                                {
                                    string PostMessage = string.Empty;
                                    string ResponseStatusMsg = string.Empty;

                                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Message Sending Process Running.. ]");
                                    if (mesg_with_tag == true)
                                    {
                                        tempsubject = msg;
                                    }
                                    if (msg_spintaxt == true)
                                    {
                                        try
                                        {
                                            msg = GrpMemSubjectlist[RandomNumberGenerator.GenerateRandom(0, GrpMemSubjectlist.Count - 1)];
                                            body = GrpMemMessagelist[RandomNumberGenerator.GenerateRandom(0, GrpMemMessagelist.Count - 1)];
                                        }
                                        catch
                                        {
                                        }
                                    }

                                    if (mesg_with_tag == true)
                                    {
                                        if (string.IsNullOrEmpty(FName))
                                        {
                                            tempBody = body.Replace("<Insert Name>", ContactName);
                                        }
                                        else
                                        {
                                          //  tempBody = GlobusSpinHelper.spinLargeText(new Random(), body);

                                           // if (lstSubjectReuse.Count == GrpMemSubjectlist.Count)
                                           // {
                                          //      lstSubjectReuse.Clear();
                                           // }
                                            //foreach (var itemSubject in GrpMemSubjectlist)
                                            //{
                                            //    if (string.IsNullOrEmpty(TemporarySubject))
                                            //    {
                                            //        TemporarySubject = itemSubject;
                                            //        tempsubject = itemSubject;
                                            //        lstSubjectReuse.Add(itemSubject);
                                            //        break;
                                            //    }
                                            //    else if (!lstSubjectReuse.Contains(itemSubject))
                                            //    {
                                            //        TemporarySubject = itemSubject;
                                            //        tempsubject = itemSubject;
                                            //        lstSubjectReuse.Add(itemSubject);
                                            //        break;
                                            //    }
                                            //    else
                                            //    {
                                            //        continue;
                                            //    }
                                            //}

                                            tempBody = tempBody.Replace("<Insert Name>", FName);

                                            tempsubject = tempsubject.Replace("<Insert Name>", FName);
                                        }
                                    }
                                    else
                                    {
                                        if (string.IsNullOrEmpty(FName))
                                        {
                                            tempBody = body.Replace("<Insert Name>", ContactName);
                                        }
                                        else
                                        {
                                            tempBody = body.Replace("<Insert Name>", FName);
                                        }
                                    }

                                    if (SelectedGrpName.Contains(":"))
                                    {
                                        try
                                        {
                                            string[] arrSelectedGrpName = Regex.Split(SelectedGrpName, ":");
                                            if (arrSelectedGrpName.Length > 1)
                                            {
                                                SelectedGrpName = arrSelectedGrpName[1];
                                            }
                                        }
                                        catch (Exception ex)
                                        {

                                        }
                                    }




                                    if (mesg_with_tag == true)
                                    {
                                        tempBody = tempBody.Replace("<Insert Group>", SelectedGrpName);
                                        tempBody = tempBody.Replace("<Insert From Email>", FromEmailNam);
                                        tempBody = tempBody.Replace("<Insert Name>", string.Empty).Replace("<Insert Group>", string.Empty).Replace("<Insert From Email>", string.Empty);
                                    }
                                    else
                                    {
                                        tempBody = tempBody.Replace("<Insert Group>", SelectedGrpName);
                                        tempBody = tempBody.Replace("<Insert From Email>", FromEmailNam);
                                        tempBody = tempBody.Replace("<Insert Name>", string.Empty).Replace("<Insert Group>", string.Empty).Replace("<Insert From Email>", string.Empty);
                                    }

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


                                    if (preventMsgSameGroup)
                                    {
                                        try
                                        {
                                            string Querystring = "Select MsgFrom,MsgToId,MsgTo,MsgGroupId,MsgGroupName,MsgSubject,MsgBody From tb_ManageMsgGroupMem Where MsgFrom ='" + UserName + "' and MsgGroupId = " + grpId + " and MsgToId = " + connId + "";
                                            ds = DataBaseHandler.SelectQuery(Querystring, "tb_ManageMsgGroupMem");
                                        }
                                        catch { }
                                    }

                                    if (preventMsgWithoutGroup)
                                    {
                                        try
                                        {
                                            string Querystring = "Select MsgFrom,MsgToId,MsgTo,MsgGroupId,MsgGroupName,MsgSubject,MsgBody From tb_ManageMsgGroupMem Where MsgFrom ='" + UserName + "' and MsgToId = " + connId + "";
                                            ds = DataBaseHandler.SelectQuery(Querystring, "tb_ManageMsgGroupMem");
                                        }
                                        catch { }
                                    }
                                    if (preventMsgGlobal)
                                    {
                                        try
                                        {
                                            string Querystring = "Select MsgFrom,MsgToId,MsgTo,MsgGroupId,MsgGroupName,MsgSubject,MsgBody From tb_ManageMsgGroupMem Where MsgToId = " + connId + "";
                                            ds = DataBaseHandler.SelectQuery(Querystring, "tb_ManageMsgGroupMem");
                                        }
                                        catch { }
                                    }

                                    try
                                    {

                                        if (ds.Tables.Count > 0)
                                        {
                                            if (ds.Tables[0].Rows.Count > 0)
                                            {

                                                PostMessage = "";
                                                ResponseStatusMsg = "Already Sent";

                                            }
                                            else
                                            {
                                                if (ds_bList.Tables.Count > 0 && ds_bList.Tables[0].Rows.Count > 0)
                                                {
                                                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ User: "******" is Added BlackListed List For Send Messages Pls Check ]");
                                                    ResponseStatusMsg = "BlackListed";
                                                }
                                                else
                                                {

                                                    try
                                                    {
                                                        string Url_compose = "https://www.linkedin.com/inbox/#compose?connId=" + ToCd + "&groupId=" + grpId;
                                                        string Responce = HttpHelper.getHtmlfromUrl(new Uri(Url_compose));
                                                        {

                                                            string PostUrlsssss = "https://www.linkedin.com/inbox/mailbox/message/send";


                                                            string PostDataFinal1 = "senderEmail=645883950&ccInput=&subject=" + Uri.EscapeDataString(tempsubject.ToString()) + "&body=" + Uri.EscapeDataString(tempBody.ToString()) + "&persist=true&showRecipients=showRecipients&isReply=&isForward=&itemId=&recipients=" + ToCd + "&recipientNames=%5B%7B%22memberId%22%3A" + ToCd + "%2C%22fullName%22%3A%22" + ContactName + "%22%7D%5D&groupId=" + grpId + "&csrfToken=" + csrfToken + "&sourceAlias=0_3mbGc9okCQbybxvc2A5Vz5&submit=Envoyer";
                                                            ResponseStatusMsg = HttpHelper.postFormData(new Uri(PostUrlsssss), PostDataFinal1);
                                                        }


                                                    }
                                                    catch (Exception ex)
                                                    {
                                                    }
                                                    if (ResponseStatusMsg.Contains("upload_error") && ResponseStatusMsg.Contains("There was an error with the file upload. Please try again later"))
                                                    {
                                                        PostMessage = "csrfToken=" + csrfToken + "&subject=" + Uri.EscapeDataString(msg.ToString()) + "&body=" + Uri.EscapeDataString(tempBody.ToString()) + "&submit=Send+Message&fromName=" + Uri.EscapeDataString(FromEmailNam) + "&showRecipeints=showRecipeints&fromEmail=" + FromemailId + "&connectionIds=" + connId + "&connectionNames=&allowEditRcpts=true&addMoreRcpts=false&openSocialAppBodySuffix=&st=&viewerDestinationUrl=&contentType=MEBC&groupID=" + grpId + "";
                                                        ResponseStatusMsg = HttpHelper.postFormData(new Uri("https://www.linkedin.com/groupMsg"), PostMessage);
                                                    }


                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (ds_bList.Tables.Count > 0)
                                            {
                                                if (ds_bList.Tables[0].Rows.Count > 0)
                                                {

                                                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ User: "******" is Added BlackListed List For Send Messages Pls Check ]");
                                                    ResponseStatusMsg = "BlackListed";
                                                }
                                                else
                                                {
                                                    try
                                                    {
                                                        string Url_compose = "https://www.linkedin.com/inbox/#compose?connId=" + ToCd + "&groupId=" + grpId;
                                                        string Responce = HttpHelper.getHtmlfromUrl(new Uri(Url_compose));
                                                        {

                                                            string PostUrlsssss = "https://www.linkedin.com/inbox/mailbox/message/send";


                                                            string PostDataFinal1 = "senderEmail=645883950&ccInput=&subject=" + Uri.EscapeDataString(tempsubject.ToString()) + "&body=" + Uri.EscapeDataString(tempBody.ToString()) + "&persist=true&showRecipients=showRecipients&isReply=&isForward=&itemId=&recipients=" + ToCd + "&recipientNames=%5B%7B%22memberId%22%3A" + ToCd + "%2C%22fullName%22%3A%22" + ContactName + "%22%7D%5D&groupId=" + grpId + "&csrfToken=" + csrfToken + "&sourceAlias=0_3mbGc9okCQbybxvc2A5Vz5&submit=Envoyer";
                                                            ResponseStatusMsg = HttpHelper.postFormData(new Uri(PostUrlsssss), PostDataFinal1);
                                                        }


                                                    }
                                                    catch (Exception ex)
                                                    {
                                                    }
                                                    if (ResponseStatusMsg.Contains("upload_error") && ResponseStatusMsg.Contains("There was an error with the file upload. Please try again later"))
                                                    {
                                                        PostMessage = "csrfToken=" + csrfToken + "&subject=" + Uri.EscapeDataString(msg.ToString()) + "&body=" + Uri.EscapeDataString(tempBody.ToString()) + "&submit=Send+Message&fromName=" + Uri.EscapeDataString(FromEmailNam) + "&showRecipeints=showRecipeints&fromEmail=" + FromemailId + "&connectionIds=" + connId + "&connectionNames=&allowEditRcpts=true&addMoreRcpts=false&openSocialAppBodySuffix=&st=&viewerDestinationUrl=&contentType=MEBC&groupID=" + grpId + "";
                                                        ResponseStatusMsg = HttpHelper.postFormData(new Uri("https://www.linkedin.com/groupMsg"), PostMessage);
                                                    }


                                                    //  PostMessage = "csrfToken=" + csrfToken + "&subject=" + Uri.EscapeDataString(tempsubject.ToString()) + "&body=" + Uri.EscapeDataString(tempBody.ToString()) + "&submit=Send+Message&fromName=" + Uri.EscapeDataString(FromEmailNam) + "&showRecipeints=showRecipeints&fromEmail=" + FromemailId + "&connectionIds=" + connId + "&connectionNames=&allowEditRcpts=true&addMoreRcpts=false&openSocialAppBodySuffix=&st=&viewerDestinationUrl=&contentType=MEBC&groupID=" + grpId + "";
                                                    // ResponseStatusMsg = HttpHelper.postFormData(new Uri("https://www.linkedin.com/groupMsg"), PostMessage);
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        // if (ResponseStatusMsg.Contains("upload_error") && ResponseStatusMsg.Contains("There was an error with the file upload. Please try again later"))
                                        {
                                            PostMessage = "csrfToken=" + csrfToken + "&subject=" + Uri.EscapeDataString(msg.ToString()) + "&body=" + Uri.EscapeDataString(tempBody.ToString()) + "&submit=Send+Message&fromName=" + Uri.EscapeDataString(FromEmailNam) + "&showRecipeints=showRecipeints&fromEmail=" + FromemailId + "&connectionIds=" + connId + "&connectionNames=&allowEditRcpts=true&addMoreRcpts=false&openSocialAppBodySuffix=&st=&viewerDestinationUrl=&contentType=MEBC&groupID=" + grpId + "";
                                            ResponseStatusMsg = HttpHelper.postFormData(new Uri("https://www.linkedin.com/groupMsg"), PostMessage);
                                        }

                                        //PostMessage = "csrfToken=" + csrfToken + "&subject=" + Uri.EscapeDataString(msg.ToString()) + "&body=" + Uri.EscapeDataString(tempBody.ToString()) + "&submit=Send+Message&showRecipeints=showRecipeintsfromName=" + Uri.EscapeDataString(FromEmailNam) + "&fromEmail=" + FromemailId + "&connectionIds=" + connId + "&connectionNames=&allowEditRcpts=true&addMoreRcpts=false&openSocialAppBodySuffix=&st=&viewerDestinationUrl=&contentType=MEBC&groupID=" + grpId + "";
                                        //ResponseStatusMsg = HttpHelper.postFormData(new Uri("http://www.linkedin.com/groupMsg"), PostMessage);
                                    }

                                    if ((!ResponseStatusMsg.Contains("Your message was successfully sent.") && !ResponseStatusMsg.Contains("Already Sent")) && (!ResponseStatusMsg.Contains("Se ha enviado tu mensaje satisfactoriamente") && !ResponseStatusMsg.Contains("Ya ha sido enviada") && !ResponseStatusMsg.Contains("Uw bericht is verzonden")))
                                    {

                                        if (ResponseStatusMsg.Contains("Already Sent") || (ResponseStatusMsg.Contains("Ya ha sido enviada") || (ResponseStatusMsg.Contains("BlackListed"))))
                                        {
                                            continue;
                                        }

                                        try
                                        {
                                            pageSource = HttpHelper.getHtmlfromUrl(new Uri("https://www.linkedin.com/groups?viewMembers=&gid=" + grpId));

                                            if (pageSource.Contains("contentType="))
                                            {
                                                try
                                                {
                                                    string Url_compose = "https://www.linkedin.com/inbox/#compose?connId=" + ToCd + "&groupId=" + grpId;
                                                    string Responce = HttpHelper.getHtmlfromUrl(new Uri(Url_compose));
                                                    {

                                                        string PostUrlsssss = "https://www.linkedin.com/inbox/mailbox/message/send";


                                                        string PostDataFinal1 = "senderEmail=645883950&ccInput=&subject=" + Uri.EscapeDataString(tempsubject.ToString()) + "&body=" + Uri.EscapeDataString(tempBody.ToString()) + "&persist=true&showRecipients=showRecipients&isReply=&isForward=&itemId=&recipients=" + ToCd + "&recipientNames=%5B%7B%22memberId%22%3A" + ToCd + "%2C%22fullName%22%3A%22" + ContactName + "%22%7D%5D&groupId=" + grpId + "&csrfToken=" + csrfToken + "&sourceAlias=0_3mbGc9okCQbybxvc2A5Vz5&submit=Envoyer";
                                                        ResponseStatusMsg = HttpHelper.postFormData(new Uri(PostUrlsssss), PostDataFinal1);
                                                    }
                                                    if (ResponseStatusMsg.Contains("upload_error") && ResponseStatusMsg.Contains("There was an error with the file upload. Please try again later"))
                                                    {
                                                        PostMessage = "csrfToken=" + csrfToken + "&subject=" + Uri.EscapeDataString(msg.ToString()) + "&body=" + Uri.EscapeDataString(tempBody.ToString()) + "&submit=Send+Message&fromName=" + Uri.EscapeDataString(FromEmailNam) + "&showRecipeints=showRecipeints&fromEmail=" + FromemailId + "&connectionIds=" + connId + "&connectionNames=&allowEditRcpts=true&addMoreRcpts=false&openSocialAppBodySuffix=&st=&viewerDestinationUrl=&contentType=MEBC&groupID=" + grpId + "";
                                                        ResponseStatusMsg = HttpHelper.postFormData(new Uri("https://www.linkedin.com/groupMsg"), PostMessage);
                                                    }


                                                }
                                                catch (Exception ex)
                                                {
                                                }

                                                //try
                                                //{
                                                //    string contentType = pageSource.Substring(pageSource.IndexOf("contentType="), pageSource.IndexOf("&", pageSource.IndexOf("contentType=")) - pageSource.IndexOf("contentType=")).Replace("contentType=", string.Empty).Replace("contentType=", string.Empty).Trim();

                                                //    string pageSource2 = HttpHelper.getHtmlfromUrl1(new Uri("https://www.linkedin.com/groupMsg?displayCreate=&contentType=" + contentType + "&connId=" + connId + "&groupID=" + grpId + ""));

                                                //    //  PostMessage = "csrfToken=" + csrfToken + "&subject=" + Uri.EscapeDataString(msg.ToString()) + "&body=" + Uri.EscapeDataString(tempBody.ToString()) + "&submit=Send+Message&showRecipeints=showRecipeints&fromName=" + FromEmailNam + "&fromEmail=" + FromemailId + "&connectionIds=" + connId + "&connectionNames=" + Uri.EscapeUriString(Nstring) + "&allowEditRcpts=true&addMoreRcpts=false&openSocialAppBodySuffix=&st=&viewerDestinationUrl=&contentType=" + contentType + "&groupID=" + grpId + "";

                                                //    string postData_Message_posting = "senderEmail=914640570&ccInput=&subject=hi&body=hello&persist=true&showRecipients=showRecipients&isReply=&isForward=&itemId=&recipients=313092875&recipientNames=%5B%7B%22memberId%22%3A313092875%2C%22fullName%22%3A%22SibghatUllah+K.+Khan%22%7D%5D&groupId=" + grpId + "&csrfToken=" + csrfToken + "&sourceAlias=0_3mbGc9okCQbybxvc2A5Vz5&submit=Send+Message";
                                                //    string postUrlll = "https://www.linkedin.com/inbox/mailbox/message/send";
                                                //    ResponseStatusMsg = HttpHelper.postFormData(new Uri(postUrlll), postData_Message_posting);
                                                //}
                                                //catch (Exception ex)
                                                //{
                                                //}
                                            }


                                            // ResponseStatusMsg = HttpHelper.postFormData(new Uri("https://www.linkedin.com/groupMsg"), PostMessage);
                                        }
                                        catch (Exception ex)
                                        {

                                        }
                                    }

                                    if ((ResponseStatusMsg.Contains("Your message was successfully sent.")) || (ResponseStatusMsg.Contains("Se ha enviado tu mensaje satisfactoriamente") || (ResponseStatusMsg.Contains("Uw bericht is verzonden"))))
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Subject Posted : " + tempsubject + " ]");
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Body Text Posted : " + tempBody.ToString() + " ]");
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Message Posted To Account: " + ContactName + " ]");
                                        ReturnString = "Your message was successfully sent.";

                                        #region CSV
                                        string bdy = string.Empty;
                                        try
                                        {
                                            bdy = body.ToString().Replace("\r", string.Empty).Replace("\n", " ").Replace(",", " ");
                                        }
                                        catch { }
                                        if (string.IsNullOrEmpty(bdy))
                                        {
                                            bdy = tempBody.ToString().Replace(",", ":");
                                        }
                                        string CSVHeader = "UserName" + "," + "Subject" + "," + "Body Text" + "," + "ContactName";
                                        string CSV_Content = UserName + "," + tempsubject + "," + bdy.ToString() + "," + ContactName;
                                        CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_MessageSentGroupMember);

                                        try
                                        {
                                            InsertMsgGroupMemData(UserName, Convert.ToInt32(connId), ContactName, Convert.ToInt32(grpId), SelectedGrpName, msg, tempBody);
                                        }
                                        catch { }

                                        #endregion

                                    }
                                    else if (ResponseStatusMsg.Contains("There was an unexpected problem that prevented us from completing your request"))
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ There was an unexpected problem that prevented us from completing your request ! ]");
                                        GlobusFileHelper.AppendStringToTextfileNewLine("Error In Message Posting", FilePath.path_MessageGroupMember);
                                    }
                                    else if (ResponseStatusMsg.Contains("You are no longer authorized to message this"))
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ You are no longer authorized to message this ! ]");
                                        GlobusFileHelper.AppendStringToTextfileNewLine("Error In Message Posting", FilePath.path_MessageGroupMember);
                                    }
                                    else if ((ResponseStatusMsg.Contains("Already Sent")) || (ResponseStatusMsg.Contains("Ya ha sido enviada")))
                                    {
                                        string bdy = string.Empty;
                                        try
                                        {
                                            bdy = body.ToString().Replace("\r", string.Empty).Replace("\n", " ").Replace(",", " ");
                                        }
                                        catch { }
                                        if (string.IsNullOrEmpty(bdy))
                                        {
                                            bdy = tempBody.ToString().Replace(",", ":");
                                        }
                                        string CSVHeader = "UserName" + "," + "Subject" + "," + "Body Text" + "," + "ContactName";
                                        string CSV_Content = UserName + "," + msg + "," + bdy.ToString() + "," + ContactName;
                                        CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_MessageAlreadySentGroupMember);

                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Message Not Posted To Account: " + ContactName + " because it has sent the same message]");
                                    }
                                    else if ((ResponseStatusMsg.Contains("Votre message a bien")) || ResponseStatusMsg.Contains("class=\"alert success") || (ResponseStatusMsg.Contains("Ya ha sido enviada")))
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Subject Posted : " + tempsubject + " ]");
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Body Text Posted : " + tempBody.ToString() + " ]");
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Message Posted To Account: " + ContactName + " ]");
                                        ReturnString = "Your message was successfully sent.";


                                        string bdy = string.Empty;
                                        try
                                        {
                                            bdy = body.ToString().Replace("\r", string.Empty).Replace("\n", " ").Replace(",", " ");
                                        }
                                        catch { }
                                        if (string.IsNullOrEmpty(bdy))
                                        {
                                            bdy = tempBody.ToString().Replace(",", ":");
                                        }
                                        string CSVHeader = "UserName" + "," + "Subject" + "," + "Body Text" + "," + "ContactName";
                                        string CSV_Content = UserName + "," + tempsubject + "," + bdy.ToString() + "," + ContactName;
                                        CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_MessageSentGroupMember);

                                        try
                                        {
                                            InsertMsgGroupMemData(UserName, Convert.ToInt32(connId), ContactName, Convert.ToInt32(grpId), SelectedGrpName, msg, tempBody);
                                        }
                                        catch { }
                                    }
                                    else
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Error In Message Posting ]");
                                        GlobusFileHelper.AppendStringToTextfileNewLine("Error In Message Posting", FilePath.path_MessageGroupMember);
                                    }

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

                                }
                                catch (Exception ex)
                                {
                                    //Log("[ " + DateTime.Now + " ] => [ Error:" + ex.Message + "StackTrace --> >>>" + ex.StackTrace + " ]");
                                    GlobusFileHelper.AppendStringToTextfileNewLine(" Error:" + ex.Message + "StackTrace --> >>>" + ex.StackTrace, FilePath.path_MessageGroupMember);
                                }
                            }
                            catch (Exception ex)
                            {
                                //Log("[ " + DateTime.Now + " ] => [ Error:" + ex.Message + "StackTrace --> >>>" + ex.StackTrace);
                                GlobusFileHelper.AppendStringToTextfileNewLine(" Error:" + ex.Message + "StackTrace --> >>>" + ex.StackTrace, FilePath.path_MessageGroupMember);
                            }
                        }
                        #endregion
                    }
                    else
                    {

                        try
                        {
                            int startindex = getComposeData.IndexOf("\"senderEmail\" value=\"");
                            if (startindex < 0)
                            {
                                startindex = getComposeData.IndexOf("\"senderEmail\",\"value\":\"");
                            }
                            string start = getComposeData.Substring(startindex).Replace("\"senderEmail\" value=\"", string.Empty).Replace("\"senderEmail\",\"value\":\"", string.Empty);
                            int endindex = start.IndexOf("\"/>");
                            if (endindex < 0)
                            {
                                endindex = start.IndexOf("\",\"");
                            }
                            string end = start.Substring(0, endindex).Replace("\"/>", string.Empty).Replace("\",\"", string.Empty);
                            senderEmail = end.Trim();
                        }
                        catch (Exception ex)
                        {
                            senderEmail = Utils.getBetween(getComposeData, "<", ">");
                        }





                        string pageSource = HttpHelper.getHtmlfromUrl(new Uri("https://www.linkedin.com/home?trk=hb_tab_home_top"));
                        if (pageSource.Contains("csrfToken"))
                        {
                            try
                            {
                                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).Replace("\n", string.Empty).Replace(">", string.Empty).Replace("<script typ", string.Empty);
                                csrfToken = csrfToken.Trim();
                            }
                            catch (Exception ex)
                            {

                            }

                        }

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

                            }
                        }

                        if (pageSource.Contains("goback="))
                        {
                            try
                            {
                            }
                            catch (Exception ex)
                            {

                            }
                        }

                        foreach (KeyValuePair<string, string> itemChecked in SlectedContacts)
                        {
                            try
                            {
                                DataSet ds = new DataSet();
                                DataSet ds_bList = new DataSet();
                                string ContactName = string.Empty;
                                string Nstring = string.Empty;
                                string connId = string.Empty;
                                string FName = string.Empty;
                                string Lname = string.Empty;
                                string tempBody = string.Empty;
                                string tempsubject = string.Empty;
                                string n_ame1 = string.Empty;

                                //grpId = itemChecked.Key.ToString();



                                try
                                {
                                    // FName = itemChecked.Value.Split(' ')[0];
                                    // Lname = itemChecked.Value.Split(' ')[1];
                                    try
                                    {
                                        n_ame1 = itemChecked.Value.Split(']')[1].Trim(); ;
                                    }
                                    catch
                                    { }
                                    if (string.IsNullOrEmpty(n_ame1))
                                    {
                                        try
                                        {
                                            n_ame1 = itemChecked.Value;
                                        }
                                        catch
                                        { }
                                    }
                                    string[] n_ame = Regex.Split(n_ame1, " ");
                                    FName = " " + n_ame[0];
                                    Lname = n_ame[1];

                                    if (!string.IsNullOrEmpty(n_ame[2]))
                                    {
                                        Lname = Lname + n_ame[2];
                                    }
                                    if (!string.IsNullOrEmpty(n_ame[3]))
                                    {
                                        Lname = Lname + n_ame[3];
                                    }
                                    if (!string.IsNullOrEmpty(n_ame[4]))
                                    {
                                        Lname = Lname + n_ame[4];
                                    }
                                    if (!string.IsNullOrEmpty(n_ame[5]))
                                    {
                                        Lname = Lname + n_ame[5];
                                    }
                                }
                                catch (Exception ex)
                                {
                                }

                                try
                                {
                                    ContactName = FName + " " + Lname;
                                    ContactName = ContactName.Replace("%20", " ");
                                }
                                catch { }

                                GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Adding Contact : " + ContactName + " ]");

                                string ToCd = itemChecked.Key;
                                List<string> AddAllString = new List<string>();

                                if (FString == string.Empty)
                                {
                                    string CompString = "{" + "\"" + "_" + ToCd.Trim() + "\"" + ":" + "{" + "\"" + "memberId" + "\"" + ":" + "\"" + ToCd.Trim() + "\"" + "," + "\"" + "firstName" + "\"" + ":" + "\"" + FName + "\"" + "," + "\"" + "lastName" + "\"" + ":" + "\"" + Lname + "\"" + "}";
                                    FString = CompString;
                                }
                                else
                                {
                                    string CompString = "\"" + "_" + ToCd.Trim() + "\"" + ":" + "{" + "\"" + "memberId" + "\"" + ":" + "\"" + ToCd.Trim() + "\"" + "," + "\"" + "firstName" + "\"" + ":" + "\"" + FName + "\"" + "," + "\"" + "lastName" + "\"" + ":" + "\"" + Lname + "\"" + "}";
                                    FString = CompString;
                                }

                                if (Nstring == string.Empty)
                                {
                                    Nstring = FString;
                                    connId = ToCd;
                                }
                                else
                                {
                                    Nstring += "," + FString;
                                    connId += " " + ToCd;
                                }

                                Nstring += "}";
                                tempsubject = msg;
                                string full_name = string.Empty;
                                try
                                {
                                    string PostMessage = string.Empty;
                                    string ResponseStatusMsg = string.Empty;

                                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Message Sending Process Running.. ]");
                                    if (mesg_with_tag == true)
                                    {
                                        tempsubject = msg;
                                    }
                                    if (msg_spintaxt == true)
                                    {
                                        try
                                        {
                                            msg = GrpMemSubjectlist[RandomNumberGenerator.GenerateRandom(0, GrpMemSubjectlist.Count - 1)];
                                            body = GrpMemMessagelist[RandomNumberGenerator.GenerateRandom(0, GrpMemMessagelist.Count - 1)];
                                        }
                                        catch
                                        {
                                        }
                                    }

                                    if (mesg_with_tag == true)
                                    {
                                        if (string.IsNullOrEmpty(FName))
                                        {
                                            tempBody = body.Replace("<Insert Name>", ContactName);
                                        }
                                        else
                                        {
                                            //tempBody = GlobusSpinHelper.spinLargeText(new Random(), body);

                                            //if (lstSubjectReuse.Count == GrpMemSubjectlist.Count)
                                            //{
                                            //    lstSubjectReuse.Clear();
                                            //}
                                            //foreach (var itemSubject in GrpMemSubjectlist)
                                            //{
                                            //    if (string.IsNullOrEmpty(TemporarySubject))
                                            //    {
                                            //        TemporarySubject = itemSubject;
                                            //        tempsubject = itemSubject;
                                            //        lstSubjectReuse.Add(itemSubject);
                                            //        break;
                                            //    }
                                            //    else if (!lstSubjectReuse.Contains(itemSubject))
                                            //    {
                                            //        TemporarySubject = itemSubject;
                                            //        tempsubject = itemSubject;
                                            //        lstSubjectReuse.Add(itemSubject);
                                            //        break;
                                            //    }
                                            //    else
                                            //    {
                                            //        continue;
                                            //    }
                                            //}

                                            tempBody = tempBody.Replace("<Insert Name>", FName);

                                            tempsubject = tempsubject.Replace("<Insert Name>", FName);
                                        }
                                    }
                                    else
                                    {
                                        if (string.IsNullOrEmpty(FName))
                                        {
                                            tempBody = body.Replace("<Insert Name>", ContactName);
                                        }
                                        else
                                        {
                                            tempBody = body.Replace("<Insert Name>", FName);
                                        }
                                    }

                                    if (SelectedGrpName.Contains(":"))
                                    {
                                        try
                                        {
                                            string[] arrSelectedGrpName = Regex.Split(SelectedGrpName, ":");
                                            if (arrSelectedGrpName.Length > 1)
                                            {
                                                SelectedGrpName = arrSelectedGrpName[1];
                                            }
                                        }
                                        catch (Exception ex)
                                        {

                                        }
                                    }
                                    try
                                    {
                                        full_name = Utils.getBetween("####" + ContactName, "####", "(");
                                    }
                                    catch
                                    { }
                                    #region To insert Full Name

                                    if (mesg_with_tag == true)
                                    {
                                        try
                                        {
                                            if (tempsubject.Contains("<Insert Full Name>"))
                                            {
                                                tempsubject = tempsubject.Replace("<Insert Full Name>", full_name);
                                            }
                                            if (tempBody.Contains("<Insert Full Name>"))
                                            {
                                                tempBody = tempBody.Replace("<Insert Full Name>", full_name);
                                            }

                                        }
                                        catch { }

                                    }


                                    #endregion

                                    if (mesg_with_tag == true)
                                    {
                                        tempBody = tempBody.Replace("<Insert Group>", SelectedGrpName);
                                        tempBody = tempBody.Replace("<Insert From Email>", senderEmail);
                                        tempBody = tempBody.Replace("<Insert Name>", string.Empty).Replace("<Insert Group>", string.Empty).Replace("<Insert From Email>", string.Empty);

                                        tempsubject = tempsubject.Replace("<Insert Group>", SelectedGrpName);
                                        tempsubject = tempsubject.Replace("<Insert From Email>", senderEmail);
                                        tempsubject = tempsubject.Replace("<Insert Name>", string.Empty).Replace("<Insert Group>", string.Empty).Replace("<Insert From Email>", string.Empty);
                                    }
                                    else
                                    {
                                        tempBody = tempBody.Replace("<Insert Group>", SelectedGrpName);
                                        tempBody = tempBody.Replace("<Insert From Email>", FromEmailNam);
                                        tempBody = tempBody.Replace("<Insert Name>", string.Empty).Replace("<Insert Group>", string.Empty).Replace("<Insert From Email>", string.Empty);
                                    }

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


                                    if (preventMsgSameGroup)
                                    {
                                        try
                                        {
                                            string Querystring = "Select MsgFrom,MsgToId,MsgTo,MsgGroupId,MsgGroupName,MsgSubject,MsgBody From tb_ManageMsgGroupMem Where MsgFrom ='" + UserName + "' and MsgGroupId = " + grpId + " and MsgToId = " + connId + "";
                                            ds = DataBaseHandler.SelectQuery(Querystring, "tb_ManageMsgGroupMem");
                                        }
                                        catch { }
                                    }

                                    if (preventMsgWithoutGroup)
                                    {
                                        try
                                        {
                                            string Querystring = "Select MsgFrom,MsgToId,MsgTo,MsgGroupId,MsgGroupName,MsgSubject,MsgBody From tb_ManageMsgGroupMem Where MsgFrom ='" + UserName + "' and MsgToId = " + connId + "";
                                            ds = DataBaseHandler.SelectQuery(Querystring, "tb_ManageMsgGroupMem");
                                        }
                                        catch { }
                                    }
                                    if (preventMsgGlobal)
                                    {
                                        try
                                        {
                                            string Querystring = "Select MsgFrom,MsgToId,MsgTo,MsgGroupId,MsgGroupName,MsgSubject,MsgBody From tb_ManageMsgGroupMem Where MsgToId = " + connId + "";
                                            ds = DataBaseHandler.SelectQuery(Querystring, "tb_ManageMsgGroupMem");
                                        }
                                        catch { }
                                    }

                                    try
                                    {

                                        if (ds.Tables.Count > 0)
                                        {
                                            if (ds.Tables[0].Rows.Count > 0)
                                            {

                                                PostMessage = "";
                                                ResponseStatusMsg = "Already Sent";

                                            }
                                            else
                                            {
                                                if (ds_bList.Tables.Count > 0 && ds_bList.Tables[0].Rows.Count > 0)
                                                {
                                                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ User: "******" is Added BlackListed List For Send Messages Pls Check ]");
                                                    ResponseStatusMsg = "BlackListed";
                                                }
                                                else
                                                {
                                                    #region send InMail
                                                    if (IssendInMail)
                                                    {
                                                        try
                                                        {
                                                            string csrfToken_inmail = string.Empty;
                                                            string Referer_InMail = string.Empty;
                                                            string authToken = string.Empty;

                                                            string url = "https://www.linkedin.com/premium/inmail/compose?destID=" + ToCd;
                                                            string responce_Inmail = HttpHelper.getHtmlfromUrl(new Uri(url));
                                                            if (!string.IsNullOrEmpty(responce_Inmail))
                                                            {
                                                                try
                                                                {
                                                                    csrfToken_inmail = Utils.getBetween(responce_Inmail, "csrfToken=", "\">");
                                                                }
                                                                catch { }
                                                            }

                                                            string subject_InMail = tempsubject.Replace(" ", "+");
                                                            string body_InMail = tempBody.Replace(" ", "+");
                                                            Referer_InMail = "https://www.linkedin.com/premium/inmail/compose?destID=" + ToCd;
                                                            string Action_url_InMail = "https://www.linkedin.com/premium/inmail/send?csrfToken=" + csrfToken_inmail;
                                                            // Referer_InMail = "https://www.linkedin.com/premium/inmail/compose?destID=" + ToCd + "&creationType=DC&authToken=" + authToken + "&authType=name&utm_source=Profile_inmail&utm_medium=onsite&utm_campaign=Subs";
                                                            string postData_InMail = "title=" + subject_InMail + "&document=" + body_InMail + "&destID=" + ToCd + "&creationType=DC&proposalType=" + category_to_send_inmail + "&authType=&authToken=";
                                                            ResponseStatusMsg = HttpHelper.postDataFormessagePosting(new Uri(Action_url_InMail), postData_InMail, Referer_InMail);


                                                        }
                                                        catch
                                                        { }



                                                    }
                                                    #endregion

                                                    #region direct message
                                                    else
                                                    {
                                                        try
                                                        {
                                                            string Url_compose = "https://www.linkedin.com/inbox/#compose?connId=" + ToCd + "&groupId=" + grpId;
                                                            string Responce = HttpHelper.getHtmlfromUrl(new Uri(Url_compose));

                                                            string url = "https://www.linkedin.com/inbox/compose?connId=" + ToCd + "&groupId=" + grpId;
                                                            string emailSender = string.Empty;
                                                            string resp = HttpHelper.getHtmlfromUrl(new Uri(url));
                                                            try
                                                            {
                                                                emailSender = Utils.getBetween(resp, "senderEmail-composeForm", "recipientNames");
                                                                emailSender = Utils.getBetween(emailSender, "value\":\"", "\"}");
                                                                if (string.IsNullOrEmpty(emailSender))
                                                                {
                                                                    try
                                                                    {
                                                                        emailSender = Utils.getBetween(resp, "senderEmail", "selected\":true");
                                                                        emailSender = Utils.getBetween(emailSender, "\"value\":\"", "\",");
                                                                    }
                                                                    catch
                                                                    { }
                                                                }

                                                            }
                                                            catch
                                                            { }

                                                            try
                                                            {
                                                                ContactName = ContactName.Trim();
                                                                ContactName = Utils.getBetween("###" + ContactName, "###", "(");
                                                                ContactName = ContactName.Replace(" ", "+");
                                                            }
                                                            catch
                                                            { }

                                                            string postUrlFinal = "https://www.linkedin.com/inbox/mailbox/message/send";
                                                            string PostDataFinal = "senderEmail=" + emailSender + "&ccInput=&subject=" + tempsubject.Replace(" ", "+") + "&body=" + tempBody.Replace(" ", "+") + "&persist=true&showRecipients=showRecipients&isReply=&isForward=&itemId=&recipients=" + ToCd + "&recipientNames=%5B%7B%22memberId%22%3A" + ToCd + "%2C%22fullName%22%3A%22" + ContactName + "%22%7D%5D&groupId=" + grpId + "&csrfToken=" + csrfToken + "&sourceAlias=0_3mbGc9okCQbybxvc2A5Vz5&submit=Send+Message";


                                                            ResponseStatusMsg = HttpHelper.postFormData(new Uri(postUrlFinal), PostDataFinal);
                                                        }
                                                        catch
                                                        {
                                                        }
                                                    }
                                                    #endregion
                                                    if (!ResponseStatusMsg.Contains("Your message was successfully sent"))
                                                    {
                                                        //string Url_compose1 = "https://www.linkedin.com/inbox/#compose?connId=" + ToCd + "&groupId=" + grpId;
                                                        //string Responce1 = HttpHelper.getHtmlfromUrl(new Uri(Url_compose1));

                                                        //string postUrlFinal1 = "https://www.linkedin.com/inbox/mailbox/message/send";
                                                        //string PostDataFinal1 = "senderEmail=914640570&ccInput=&subject=" + Uri.EscapeDataString(tempsubject.ToString()) + "&body=" + Uri.EscapeDataString(tempBody.ToString()) + "&persist=true&showRecipients=showRecipients&isReply=&isForward=&itemId=&recipients=" + ToCd + "&recipientNames=%5B%7B%22memberId%22%3A" + ToCd + "%2C%22fullName%22%3A%22" + ContactName + "%22%7D%5D&groupId=" + grpId + "&csrfToken=" + csrfToken + "&sourceAlias=0_3mbGc9okCQbybxvc2A5Vz5&submit=Send+Message";


                                                        //ResponseStatusMsg = HttpHelper.postFormData(new Uri(postUrlFinal1), PostDataFinal1);

                                                        //if (ResponseStatusMsg.Contains("upload_error") && ResponseStatusMsg.Contains("There was an error with the file upload. Please try again later"))
                                                        //{
                                                        //    PostMessage = "csrfToken=" + csrfToken + "&subject=" + Uri.EscapeDataString(msg.ToString()) + "&body=" + Uri.EscapeDataString(tempBody.ToString()) + "&submit=Send+Message&fromName=" + Uri.EscapeDataString(FromEmailNam) + "&showRecipeints=showRecipeints&fromEmail=" + FromemailId + "&connectionIds=" + connId + "&connectionNames=&allowEditRcpts=true&addMoreRcpts=false&openSocialAppBodySuffix=&st=&viewerDestinationUrl=&contentType=MEBC&groupID=" + grpId + "";
                                                        //    ResponseStatusMsg = HttpHelper.postFormData(new Uri("https://www.linkedin.com/groupMsg"), PostMessage);
                                                        //}
                                                    }
                                                    //Comment By ajay 
                                                    //PostMessage = "csrfToken=" + csrfToken + "&subject=" + Uri.EscapeDataString(msg.ToString()) + "&body=" + Uri.EscapeDataString(tempBody.ToString()) + "&submit=Send+Message&fromName=" + Uri.EscapeDataString(FromEmailNam) + "&showRecipeints=showRecipeints&fromEmail=" + FromemailId + "&connectionIds=" + connId + "&connectionNames=&allowEditRcpts=true&addMoreRcpts=false&openSocialAppBodySuffix=&st=&viewerDestinationUrl=&contentType=MEBC&groupID=" + grpId + "";
                                                    //ResponseStatusMsg = HttpHelper.postFormData(new Uri("https://www.linkedin.com/groupMsg"), PostMessage);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (ds_bList.Tables.Count > 0)
                                            {
                                                if (ds_bList.Tables[0].Rows.Count > 0)
                                                {

                                                    GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ User: "******" is Added BlackListed List For Send Messages Pls Check ]");
                                                    ResponseStatusMsg = "BlackListed";
                                                }
                                                else
                                                {

                                                    #region  wriiten by sharan

                                                    #region Send InMail
                                                    if (IssendInMail)
                                                    {
                                                        try
                                                        {
                                                            string csrfToken_inmail = string.Empty;
                                                            string Referer_InMail = string.Empty;
                                                            string authToken = string.Empty;

                                                            string url = "https://www.linkedin.com/premium/inmail/compose?destID=" + ToCd;
                                                            string responce_Inmail = HttpHelper.getHtmlfromUrl(new Uri(url));
                                                            if (!string.IsNullOrEmpty(responce_Inmail))
                                                            {
                                                                csrfToken_inmail = Utils.getBetween(responce_Inmail, "csrfToken=", "\">");
                                                                // Referer_InMail = Utils.getBetween(responce_Inmail, "X-FS-Origin-Request\":\"", "\"");



                                                            }

                                                            string subject_InMail = tempsubject.Replace(" ", "+");
                                                            string body_InMail = tempBody.Replace(" ", "+");
                                                            Referer_InMail = "https://www.linkedin.com/premium/inmail/compose?destID=" + ToCd;
                                                            string Action_url_InMail = "https://www.linkedin.com/premium/inmail/send?csrfToken=" + csrfToken_inmail;
                                                            // Referer_InMail = "https://www.linkedin.com/premium/inmail/compose?destID=" + ToCd + "&creationType=DC&authToken=" + authToken + "&authType=name&utm_source=Profile_inmail&utm_medium=onsite&utm_campaign=Subs";
                                                            string postData_InMail = "title=" + subject_InMail + "&document=" + body_InMail + "&destID=" + ToCd + "&creationType=DC&proposalType=" + category_to_send_inmail + "&authType=&authToken=";
                                                            ResponseStatusMsg = HttpHelper.postDataFormessagePosting(new Uri(Action_url_InMail), postData_InMail, Referer_InMail);


                                                        }
                                                        catch
                                                        { }


                                                    }
                                                    #endregion

                                                    #region directMessage
                                                    else
                                                    {
                                                        try
                                                        {
                                                            string Url_compose = "https://www.linkedin.com/inbox/#compose?connId=" + ToCd + "&groupId=" + grpId;
                                                            string Responce = HttpHelper.getHtmlfromUrl(new Uri(Url_compose));

                                                            string url = "https://www.linkedin.com/inbox/compose?connId=" + ToCd + "&groupId=" + grpId;
                                                            string emailSender = string.Empty;
                                                            string resp = HttpHelper.getHtmlfromUrl(new Uri(url));
                                                            try
                                                            {
                                                                emailSender = Utils.getBetween(resp, "senderEmail-composeForm", "recipientNames");
                                                                emailSender = Utils.getBetween(emailSender, "value\":\"", "\"}");
                                                                if (string.IsNullOrEmpty(emailSender))
                                                                {
                                                                    try
                                                                    {
                                                                        emailSender = Utils.getBetween(resp, "senderEmail", "selected\":true");
                                                                        emailSender = Utils.getBetween(emailSender, "\"value\":\"", "\",");
                                                                    }
                                                                    catch
                                                                    { }
                                                                }
                                                            }
                                                            catch
                                                            { }

                                                            try
                                                            {
                                                                ContactName = ContactName.Trim();
                                                                ContactName = Utils.getBetween("###" + ContactName, "###", "(");
                                                                ContactName = ContactName.Replace(" ", "+");
                                                            }
                                                            catch
                                                            { }

                                                            string postUrlFinal = "https://www.linkedin.com/inbox/mailbox/message/send";
                                                            string PostDataFinal = "senderEmail=" + emailSender + "&ccInput=&subject=" + tempsubject.Replace(" ", "+") + "&body=" + tempBody.Replace(" ", "+") + "&persist=true&showRecipients=showRecipients&isReply=&isForward=&itemId=&recipients=" + ToCd + "&recipientNames=%5B%7B%22memberId%22%3A" + ToCd + "%2C%22fullName%22%3A%22" + ContactName + "%22%7D%5D&groupId=" + grpId + "&csrfToken=" + csrfToken + "&sourceAlias=0_3mbGc9okCQbybxvc2A5Vz5&submit=Send+Message";


                                                            ResponseStatusMsg = HttpHelper.postFormData(new Uri(postUrlFinal), PostDataFinal);
                                                        }
                                                        catch
                                                        {
                                                        }
                                                    }

                                                    #endregion

                                                    if (ResponseStatusMsg.Contains("Sorry, you have reached a limit for directly messaging group members"))
                                                    {
                                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Sorry, you have reached a limit for directly messaging group members]");
                                                        return;
                                                    }

                                                    if (!ResponseStatusMsg.Contains("Your message was successfully sent"))
                                                    {
                                                        try
                                                        {
                                                            //string action_url = "https://www.linkedin.com/premium/inmail/send?csrfToken=" + csrfToken;
                                                            //string referer = "https://www.linkedin.com/premium/inmail/compose?destID=" + ToCd + "&creationType=OPEN_LINK&authToken=mdaI&authType=name&utm_source=Profile_inmail&utm_medium=onsite&utm_campaign=Subs";
                                                            //string pd = "title=" + tempsubject.Replace(" ", "+") + "&document=" + tempBody.Replace(" ", "+") + "&destID=" + ToCd + "&creationType=OPEN_LINK&proposalType=JOB_OFFER&senderEmail=&authType=name&authToken=llYo";
                                                            //ResponseStatusMsg = HttpHelper.postDataFormessagePosting(new Uri(action_url), pd, referer);
                                                        }
                                                        catch
                                                        { }
                                                    }
                                                    #endregion


                                                    //string Url_compose = "https://www.linkedin.com/inbox/#compose?connId=" + ToCd + "&groupId=" + grpId;
                                                    //string Responce = HttpHelper.getHtmlfromUrl(new Uri(Url_compose));

                                                    //string postUrlFinal = "https://www.linkedin.com/inbox/mailbox/message/send";
                                                    //string PostDataFinal = "senderEmail=913067065&ccInput=&subject=" + Uri.EscapeDataString(tempsubject) + "+&body=" + Uri.EscapeDataString(tempBody) + "&persist=true&showRecipients=showRecipients&isReply=&isForward=&itemId=&recipients=" + ToCd + "&recipientNames=%5B%7B%22memberId%22%3A" + ToCd + "%2C%22fullName%22%3A%22" + ContactName.Replace(" ", "+") + "%22%7D%5D&groupId=" + grpId + "&csrfToken=" + csrfToken + "&sourceAlias=0_3mbGc9okCQbybxvc2A5Vz5&submit=Send+Message";

                                                    //ResponseStatusMsg = HttpHelper.postFormData(new Uri(postUrlFinal), PostDataFinal);

                                                    //if (ResponseStatusMsg.Contains("upload_error") && ResponseStatusMsg.Contains("There was an error with the file upload. Please try again later"))
                                                    //{
                                                    //    PostMessage = "csrfToken=" + csrfToken + "&subject=" + Uri.EscapeDataString(tempsubject.ToString()) + "&body=" + Uri.EscapeDataString(tempBody.ToString()) + "&submit=Send+Message&fromName=" + Uri.EscapeDataString(FromEmailNam) + "&showRecipeints=showRecipeints&fromEmail=" + FromemailId + "&connectionIds=" + connId + "&connectionNames=&allowEditRcpts=true&addMoreRcpts=false&openSocialAppBodySuffix=&st=&viewerDestinationUrl=&contentType=MEBC&groupID=" + grpId + "";
                                                    //    ResponseStatusMsg = HttpHelper.postFormData(new Uri("https://www.linkedin.com/groupMsg"), PostMessage);
                                                    //}






                                                }
                                            }
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        //PostMessage = "csrfToken=" + csrfToken + "&subject=" + Uri.EscapeDataString(msg.ToString()) + "&body=" + Uri.EscapeDataString(tempBody.ToString()) + "&submit=Send+Message&showRecipeints=showRecipeintsfromName=" + Uri.EscapeDataString(FromEmailNam) + "&fromEmail=" + FromemailId + "&connectionIds=" + connId + "&connectionNames=&allowEditRcpts=true&addMoreRcpts=false&openSocialAppBodySuffix=&st=&viewerDestinationUrl=&contentType=MEBC&groupID=" + grpId + "";
                                        //ResponseStatusMsg = HttpHelper.postFormData(new Uri("http://www.linkedin.com/groupMsg"), PostMessage);
                                    }
                                    #region commented for null response
                                    //if (string.IsNullOrEmpty(ResponseStatusMsg))
                                    //{
                                    //    try
                                    //    {
                                    //        string action_url = "https://www.linkedin.com/messaging/compose?connId="+ToCd+"&groupId="+grpId;
                                    //        string referer = "https://www.linkedin.com/grp/members?gid="+grpId;
                                    //        string get_response = HttpHelper.getHtmlfromUrl(new Uri(action_url));

                                    //        if (get_response.Contains("memberProfile"))
                                    //        {
                                    //            string all_details = Utils.getBetween(get_response, "<code id", "<script>");
                                    //            string[] arr = Regex.Split(all_details, "recipients");
                                    //            string recipient_details = string.Empty;
                                    //            string authToken = string.Empty;

                                    //            foreach (string item in arr)
                                    //            {
                                    //                if (item.Contains(ToCd))
                                    //                {
                                    //                    recipient_details = item;
                                    //                    break;
                                    //                }
                                    //            }

                                    //            authToken = Utils.getBetween(recipient_details, "authToken", "\"}");



                                    //            string s1 = Utils.getBetween("###" + authToken, "###", "profileId");
                                    //            string first_last_name = Utils.getBetween("###" + s1, "", "profileId");
                                    //            first_last_name = first_last_name + "profileId\":\"";


                                    //        }

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

                                    #region commented by sharan after LI update

                                    //if ((!ResponseStatusMsg.Contains("Your message was successfully sent.") && !ResponseStatusMsg.Contains("Already Sent")) && (!ResponseStatusMsg.Contains("Se ha enviado tu mensaje satisfactoriamente") && !ResponseStatusMsg.Contains("Ya ha sido enviada") && !ResponseStatusMsg.Contains("Uw bericht is verzonden")))
                                    //{

                                    //    if (ResponseStatusMsg.Contains("Already Sent") || (ResponseStatusMsg.Contains("Ya ha sido enviada") || (ResponseStatusMsg.Contains("BlackListed"))))
                                    //    {
                                    //        continue;
                                    //    }

                                    //    try
                                    //    {
                                    //        pageSource = HttpHelper.getHtmlfromUrl1(new Uri("https://www.linkedin.com/groups?viewMembers=&gid=" + grpId));

                                    //        if (pageSource.Contains("contentType="))
                                    //        {
                                    //            try
                                    //            {
                                    //                string Url_compose = "https://www.linkedin.com/inbox/#compose?connId=" + ToCd + "&groupId=" + grpId;
                                    //                string Responce = HttpHelper.getHtmlfromUrl(new Uri(Url_compose));

                                    //                string postUrlFinal = "https://www.linkedin.com/inbox/mailbox/message/send";
                                    //                string PostDataFinal = "senderEmail=914640570&ccInput=&subject=" + Uri.EscapeDataString(tempsubject.ToString()) + "&body=" + Uri.EscapeDataString(tempBody.ToString()) + "&persist=true&showRecipients=showRecipients&isReply=&isForward=&itemId=&recipients=" + ToCd + "&recipientNames=%5B%7B%22memberId%22%3A" + ToCd + "%2C%22fullName%22%3A%22" + ContactName + "%22%7D%5D&groupId=" + grpId + "&csrfToken=" + csrfToken + "&sourceAlias=0_3mbGc9okCQbybxvc2A5Vz5&submit=Send+Message";


                                    //                ResponseStatusMsg = HttpHelper.postFormData(new Uri(postUrlFinal), PostDataFinal);

                                    //                if (ResponseStatusMsg.Contains("upload_error") && ResponseStatusMsg.Contains("There was an error with the file upload. Please try again later"))
                                    //                {
                                    //                    PostMessage = "csrfToken=" + csrfToken + "&subject=" + Uri.EscapeDataString(tempsubject.ToString()) + "&body=" + Uri.EscapeDataString(tempBody.ToString()) + "&submit=Send+Message&fromName=" + Uri.EscapeDataString(FromEmailNam) + "&showRecipeints=showRecipeints&fromEmail=" + FromemailId + "&connectionIds=" + connId + "&connectionNames=&allowEditRcpts=true&addMoreRcpts=false&openSocialAppBodySuffix=&st=&viewerDestinationUrl=&contentType=MEBC&groupID=" + grpId + "";
                                    //                    ResponseStatusMsg = HttpHelper.postFormData(new Uri("https://www.linkedin.com/groupMsg"), PostMessage);
                                    //                }

                                    //                #region MyRegion

                                    //                #endregion
                                    //            }
                                    //            catch (Exception ex)
                                    //            {
                                    //            }
                                    //        }


                                    //        ResponseStatusMsg = HttpHelper.postFormData(new Uri("https://www.linkedin.com/groupMsg"), PostMessage);
                                    //    }
                                    //    catch (Exception ex)
                                    //    {

                                    //    }
                                    //}

                                    #endregion

                                    if ((ResponseStatusMsg.Contains("Your message was successfully sent.")) || (ResponseStatusMsg.Contains("Se ha enviado tu mensaje satisfactoriamente") || (ResponseStatusMsg.Contains("Uw bericht is verzonden")) || ResponseStatusMsg.Contains("success")) || ResponseStatusMsg.Contains("inmCategory"))
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Subject Posted : " + tempsubject + " ]");
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Body Text Posted : " + tempBody.ToString() + " ]");
                                        if (IssendInMail)
                                        {
                                            GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ InMail  Posted To Account: " + ContactName + " ]");
                                        }
                                        else
                                        {
                                            GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Message Posted To Account: " + ContactName + " ]");
                                        }

                                        ReturnString = "Your message was successfully sent.";

                                        #region CSV
                                        string bdy = string.Empty;
                                        try
                                        {
                                            bdy = body.ToString().Replace("\r", string.Empty).Replace("\n", " ").Replace(",", " ");
                                        }
                                        catch { }
                                        if (string.IsNullOrEmpty(bdy))
                                        {
                                            bdy = tempBody.ToString().Replace(",", ":");
                                        }
                                        string CSVHeader = "UserName" + "," + "Subject" + "," + "Body Text" + "," + "ContactName";
                                        string CSV_Content = UserName + "," + tempsubject + "," + bdy.ToString() + "," + ContactName;
                                        CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_MessageSentGroupMember);

                                        try
                                        {
                                            InsertMsgGroupMemData(UserName, Convert.ToInt32(connId), ContactName, Convert.ToInt32(grpId), SelectedGrpName, msg, tempBody);
                                        }
                                        catch { }

                                        #endregion

                                    }
                                    else if (ResponseStatusMsg.Contains("There was an unexpected problem that prevented us from completing your request"))
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ There was an unexpected problem that prevented us from completing your request ! ]");
                                        GlobusFileHelper.AppendStringToTextfileNewLine("Error In Message Posting", FilePath.path_MessageGroupMember);
                                    }
                                    else if (ResponseStatusMsg.Contains("You are no longer authorized to message this"))
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ You are no longer authorized to message this ! ]");
                                        GlobusFileHelper.AppendStringToTextfileNewLine("Error In Message Posting", FilePath.path_MessageGroupMember);
                                    }
                                    else if ((ResponseStatusMsg.Contains("Already Sent")) || (ResponseStatusMsg.Contains("Ya ha sido enviada")))
                                    {
                                        string bdy = string.Empty;
                                        try
                                        {
                                            bdy = body.ToString().Replace("\r", string.Empty).Replace("\n", " ").Replace(",", " ");
                                        }
                                        catch { }
                                        if (string.IsNullOrEmpty(bdy))
                                        {
                                            bdy = tempBody.ToString().Replace(",", ":");
                                        }
                                        string CSVHeader = "UserName" + "," + "Subject" + "," + "Body Text" + "," + "ContactName";
                                        string CSV_Content = UserName + "," + msg + "," + bdy.ToString() + "," + ContactName;
                                        CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, FilePath.path_MessageAlreadySentGroupMember);

                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Message Not Posted To Account: " + ContactName + " because it has sent the same message]");
                                    }
                                    else
                                    {
                                        GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Error In Message Posting ]");
                                        GlobusFileHelper.AppendStringToTextfileNewLine("Error In Message Posting", FilePath.path_MessageGroupMember);
                                    }

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

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

                    }

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



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

        }