Example #1
0
        public void SendInvitation(ref GlobusHttpHelper HttpHelper, string grpURL, string grpId)
        {
            try
            {
                string FString = string.Empty;
                string Nstring = string.Empty;
                string connId = string.Empty;
                string FullName = string.Empty;
                string ToMsg = string.Empty;
                string ContactName = string.Empty;

                string URL = "http://www.linkedin.com/manageGroup?dispAddMbrs=&gid=" + grpId + "&invtActn=im-invite&cntactSrc=cs-connections";

                string grpPageSource = HttpHelper.getHtmlfromUrl1(new Uri(URL));

                //string csrfToken = GetCsrfToken(grpPageSource);
                try
                {
                    int startindex = grpPageSource.IndexOf("csrfToken=");
                    string start = grpPageSource.Substring(startindex).Replace("csrfToken=",string.Empty);
                    int endindex = start.IndexOf("\"");
                    string end = start.Substring(0, endindex).Replace("\"", string.Empty);
                    csrfToken = end.Trim();
                }
                catch
                { }
                ClsLinkedinMain clsLinkedinMain = new ClsLinkedinMain();
                Dictionary<string, string> dTotalFriends = clsLinkedinMain.PostAddMembers(ref HttpHelper, accountUser);

                // To manage the code for friends in which invitation already sent

                // SucessfullySendInvitationToFriend();

                //int counter = 1;

                foreach (KeyValuePair<string, string> itemChecked in dTotalFriends)
                {
                    try
                    {
                        //if (!IsAllAccounts)
                        //{
                        //    if (counter > 50)
                        //    {
                        //        break;
                        //    }
                        //}

                        //counter++;

                        string FName = string.Empty;
                        string Lname = string.Empty;

                        FName = itemChecked.Value.Split(' ')[0];
                        Lname = itemChecked.Value.Split(' ')[1];

                        FullName = FName + " " + Lname;
                        try
                        {
                            ContactName = ContactName + "  :  " + FullName;
                        }
                        catch { }
                        if (ToMsg == string.Empty)
                        {
                            ToMsg += FullName;
                        }
                        else
                        {
                            ToMsg += ";" + FullName;
                        }

                        Log("[ " + DateTime.Now + " ] => [ Adding Contact : " + FullName + " ]");

                        string ToCd = itemChecked.Key;

                        if (ToCd.Contains(":"))
                        {
                            try
                            {
                                ToCd = ToCd.Substring(ToCd.IndexOf(":"), ToCd.Length - ToCd.IndexOf(":")).Replace(":", string.Empty).Trim();
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Error >>> " + ex.StackTrace);
                            }

                        }

                        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;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("ex.Message >>> " + ex.Message + "StackTrace --> >>>" + ex.StackTrace + "  ex.Stack Trace >>> " + ex.StackTrace);
                    }

                    //}
                    Nstring += "}";

                    string postData = "csrfToken=" + csrfToken + "&emailRecipients=&subAddMbrs=Send+Invitations&gid=" + grpId + "&invtActn=im-invite&cntactSrc=cs-connections&remIntives=999&connectionIds=" + connId + "&connectionNames=" + Uri.EscapeUriString(Nstring) + "&contactIDs=&newGroup=false";

                    string response = HttpHelper.postFormData(new Uri("http://www.linkedin.com/manageGroup"), postData);

                    //if (response.Contains("You have successfully sent invitations to this group") || response.Contains("Upgrade Your Account"))
                        if (response.Contains("You have successfully sent invitations to this group"))
                    {
                        Log("[ " + DateTime.Now + " ] => [ You have successfully sent invitations to Group : " + grpURL + " With Username : "******"Invite user : "******" ]");
                        string CSVHeader = "GroupUrl" + "," + "UserName" + "," + "Invite User" ;
                        string CSVContent = grpURL + "," + accountUser + "," + FullName;
                        CSVUtilities.ExportDataCSVFile(CSVHeader, CSVContent, Globals.path_SentInvitationGroup);
                       // GlobusFileHelper.AppendStringToTextfileNewLine(content, Globals.path_SentInvitationGroup);

                    }
                    else
                    {
                        Log("[ " + DateTime.Now + " ] => [ Couldn't Send Invitation With Username : "******" ]");
                        string CSVHeader = "GroupUrl" + "," + "UserName";
                        string CSVContent = grpURL + "," + accountUser;
                        CSVUtilities.ExportDataCSVFile(CSVHeader, CSVContent, Globals.path_NotSentInvitationGroup);
                        //GlobusFileHelper.AppendStringToTextfileNewLine(content, Globals.path_NotSentInvitationGroup);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error >>> " + ex.StackTrace);
            }
        }
Example #2
0
        public void PostFinalMsg(ref GlobusHttpHelper HttpHelper, Dictionary<string, string> SlectedContacts,string userText, List<string> GrpMemSubjectlist, string msg, string body, string UserEmail, string FromemailId, string FromEmailNam, bool msg_spintaxt, int mindelay, int maxdelay, bool preventMsgSameUser, bool preventMsgGlobalUser)
        {
            ComposeMsgDbManager objComposeMsgDbMgr = new ComposeMsgDbManager();

             try
             {
                 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;
                 string Nstring = string.Empty;
                 string connId = string.Empty;
                 string FullName = string.Empty;
                 string ToMsg = string.Empty;
                 string ToCd = string.Empty;

                 try
                 {
                     DataSet ds_bList = new DataSet();
                     DataSet ds = new DataSet();
                     string MessageText = string.Empty;
                     string PostedMessage = string.Empty;

                     string pageSource = HttpHelper.getHtmlfromUrl1(new Uri("http://www.linkedin.com/home?trk=hb_tab_home_top"));
                     if (pageSource.Contains("csrfToken"))
                     {
                         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();
                     }

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

                     if (IsAllAccounts)
                     {
                         try
                         {
                             ClsLinkedinMain obj_ClsLinkedinMain = new ClsLinkedinMain();

                             Dictionary<string, string> dTotalFriends = obj_ClsLinkedinMain.PostAddMembers(ref HttpHelper, UserEmail);

                             Log("[ " + DateTime.Now + " ] => [ No. Of Friends = " + dTotalFriends.Count + " With Username >>> " + UserEmail + " ]");

                             if (dTotalFriends.Count > 0)
                             {

                                 PostMessageToAllAccounts(ref HttpHelper,SlectedContacts, dTotalFriends, msg, body, UserEmail, FromemailId, FromEmailNam, mindelay, mindelay);

                                 int count = SlectedContacts2.Count();

                                 if (count > 0)
                                 {
                                     do
                                     {

                                         PostMessageToAllAccounts(ref HttpHelper, SlectedContacts2, dTotalFriends, msg, body, UserEmail, FromemailId, FromEmailNam, mindelay, mindelay);
                                         count = SlectedContacts2.Count();

                                     } while (count > 0);
                                 }
                             }
                             Log("[ " + DateTime.Now + " ] => [ PROCESS COMPLETED With Username >>> " + UserEmail + " ]");
                             Log("-----------------------------------------------------------------------------------------------------------------------------------");

                             return;
                         }
                         catch (Exception ex)
                         {
                         }
                     }

                             string ContactName = string.Empty;
                             int counter = 1;
                             Dictionary<string, string> SlectedSentContacts = new Dictionary<string, string>();
                             Nstring = string.Empty;
                             ContactName = string.Empty;
                             string ProfileUrl = string.Empty;
                             string ProfileID = string.Empty;
                             foreach (KeyValuePair<string, string> itemChecked in SlectedContacts)
                             {
                                 if (Globals.groupStatusString == "API")
                                 {
                                     ProfileUrl = "https://www.linkedin.com/contacts/view?id=" + itemChecked.Key + "";
                                     string profilePageSource = HttpHelper.getHtmlfromUrl1(new Uri(ProfileUrl));
                                     ProfileID = Utils.getBetween(profilePageSource, "id=", ",").Replace("\"", "");
                                 }
                                 else
                                 {
                                     ProfileUrl = "https://www.linkedin.com/profile/view?id=" + itemChecked.Key + "";

                                     ProfileID = itemChecked.Key;
                                 }

                                 if (counter < 50)
                                 {
                                     SlectedSentContacts.Add(itemChecked.Key, itemChecked.Value);

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

                                     if (ds_bList.Tables.Count > 0 && ds_bList.Tables[0].Rows.Count > 0)
                                     {
                                         Log("[ " + DateTime.Now + " ] => [ User: "******":", string.Empty).Trim() + " is Added BlackListed List For Send Messages Pls Check ]");

                                     }
                                     else
                                     {

                                         try
                                         {

                                             string FName = string.Empty;
                                             string Lname = string.Empty;

                                             try
                                             {
                                                 FName = itemChecked.Value.Split(' ')[0];
                                                 Lname = itemChecked.Value.Split(' ')[1];
                                             }
                                             catch { }

                                             FullName = FName + " " + Lname;
                                             try
                                             {
                                                 //ContactName = ContactName + "  :  " + FullName;
                                                 ContactName = "  :  " + FullName;
                                             }
                                             catch { }

                                             if (ToMsg == string.Empty)
                                             {
                                                 //ToMsg += FullName;
                                                 ToMsg = FullName;
                                             }
                                             else
                                             {
                                                 //ToMsg += ";" + FullName;
                                                 ToMsg = ";" + FullName;
                                             }

                                             Log("[ " + DateTime.Now + " ] => [ Adding Contact " + FullName + " ]");

                                             //ToCd = itemChecked.Key;  //for client sudi
                                             ToCd = ProfileID;
                                             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;
                                                 Nstring = FString;
                                                 connId = ToCd;
                                                 //connId += " " + ToCd;
                                             }

                                         }
                                         catch { }
                                         //Nstring += "}";
                                     }

                                 }
                                 else
                                 {
                                     try
                                     {
                                         SlectedContacts1.Add(itemChecked.Key, itemChecked.Value);
                                     }
                                     catch
                                     {

                                     }
                                 }
                                 counter++;

                                 //}

                                 if (SlectedContacts1.Count != 0)
                                 {
                                     foreach (KeyValuePair<string, string> itemremove in SlectedSentContacts)
                                     {
                                         SlectedContacts1.Remove(itemremove.Key);
                                     }
                                 }

                                 if (msg_spintaxt == true)
                                 {
                                     try
                                     {
                                         body = GlobusSpinHelper.spinLargeText(new Random(), userText);
                                         msg = GrpMemSubjectlist[RandomNumberGenerator.GenerateRandom(0, GrpMemSubjectlist.Count - 1)];
                                     }
                                     catch
                                     {
                                     }

                                     body = body.Replace("<Insert Name>", FullName);
                                     body = body.Replace("<Insert From Email>", FromEmailNam);

                                 }

                                 if (preventMsgSameUser)
                                 {
                                     try
                                     {
                                         string Querystring = "Select MsgFrom,MsgToId,MsgTo,MsgSubject,MsgBody From tb_ManageComposeMsg Where MsgFrom ='" + UserEmail + "' and MsgBody = '" + body + "' and MsgToId = " + connId + "";
                                         ds = DataBaseHandler.SelectQuery(Querystring, "tb_ManageComposeMsg");
                                     }
                                     catch { }
                                 }

                                 if (preventMsgGlobalUser)
                                 {
                                     try
                                     {
                                         string Querystring = "Select MsgFrom,MsgToId,MsgTo,MsgSubject,MsgBody From tb_ManageComposeMsg Where MsgToId = " + connId + "";
                                         ds = DataBaseHandler.SelectQuery(Querystring, "tb_ManageComposeMsg");
                                     }
                                     catch { }
                                 }

                                 try
                                 {
                                     string PostMessage = string.Empty;
                                     string ResponseStatusMsg = string.Empty;

                                     Log("[ " + DateTime.Now + " ] => [ Message Sending Process Running.. ]");

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

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

                                         }
                                         else
                                         {

                                             PostMessage = "senderEmail=" + FromemailId.Trim() + "&ccInput=&subject=" + Uri.EscapeDataString(msg.ToString()) + "&body=" + Uri.EscapeDataString(body.ToString()) + "&isReply=&isForward=&itemId=&recipients=" + Uri.EscapeUriString(connId) + "&recipientNames=" + Uri.EscapeUriString(Nstring) + "&groupId=&csrfToken=" + csrfToken + "&sourceAlias=" + sourceAlias + "&submit=Send+Message";
                                             //ResponseStatusMsg = HttpHelper.postFormData(new Uri("http://www.linkedin.com/inbox/mailbox/message/send"), PostMessage);

                                             ResponseStatusMsg = HttpHelper.postFormDataRef(new Uri("http://www.linkedin.com/inbox/mailbox/message/send"), PostMessage, "https://www.linkedin.com/inbox/", "", "", "XMLHttpRequest", "https://www.linkedin.com","1");   //ahmed sudi client changes
                                         }
                                     }
                                     else
                                     {

                                         PostMessage = "senderEmail=" + FromemailId.Trim() + "&ccInput=&subject=" + Uri.EscapeDataString(msg.ToString()) + "&body=" + Uri.EscapeDataString(body.ToString()) + "&isReply=&isForward=&itemId=&recipients=" + Uri.EscapeUriString(connId) + "&recipientNames=" + Uri.EscapeUriString(Nstring) + "&groupId=&csrfToken=" + csrfToken + "&sourceAlias=" + sourceAlias + "&submit=Send+Message";
                                         //ResponseStatusMsg = HttpHelper.postFormData(new Uri("http://www.linkedin.com/inbox/mailbox/message/send"), PostMessage);
                                         ResponseStatusMsg = HttpHelper.postFormDataRef(new Uri("http://www.linkedin.com/inbox/mailbox/message/send"), PostMessage, "https://www.linkedin.com/inbox/", "", "", "XMLHttpRequest", "https://www.linkedin.com", "1");   //ahmed sudi client changes
                                     }

                                     if (ResponseStatusMsg.Contains("Your message was successfully sent.") || ResponseStatusMsg.Contains("Tu mensaje ha sido enviado con éxito."))
                                     {
                                         foreach (var item in SlectedSentContacts)
                                         {
                                             try
                                             {
                                                 string Querystring = "Select ProfileID From tb_BlackListAccount Where ProfileID ='" + item.Key + "'";
                                                 ds_bList = DataBaseHandler.SelectQuery(Querystring, "tb_BlackListAccount");
                                             }
                                             catch { }

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

                                                 Log("[ " + DateTime.Now + " ] => [ User: "******":", string.Empty).Trim() + " is Added BlackListed List For Send Messages Pls Check ]");
                                             }
                                             else
                                             {
                                                 Log("[ " + DateTime.Now + " ] => [ Subject Posted : " + msg + " ]");
                                                 Log("[ " + DateTime.Now + " ] => [ Body Text Posted : " + body.ToString() + " ]");
                                                 Log("[ " + DateTime.Now + " ] => [ Message Posted To Account: " + item.Value + " With Username >>> " + UserEmail + " ]");

                                                 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 = body.ToString().Replace(",", ":");
                                                 }

                                                 string CSVHeader = "UserName" + "," + "Subject" + "," + "Body Text" + "," + "ContactName" + "," + "ProfileUrl";
                                                 string CSV_Content = UserEmail + "," + msg + "," + bdy + "," + ContactName.Replace(":", string.Empty).Trim() + "," + ProfileUrl;
                                                 CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, Globals.path_ComposeMessageSent);

                                                 try
                                                 {
                                                     objComposeMsgDbMgr.InsertComposeMsgData(UserEmail, Convert.ToInt32(connId), ContactName, msg, bdy);
                                                 }
                                                 catch { }
                                             }
                                         }

                                     }

                                     else if (ResponseStatusMsg.Contains("There was an unexpected problem that prevented us from completing your request."))
                                     {
                                         Log("[ " + DateTime.Now + " ] => [ Error In Message Posting ]");
                                         GlobusFileHelper.AppendStringToTextfileNewLine("Error In Message Posting", Globals.path_ComposeMessage);
                                     }
                                     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 = bdy.ToString().Replace(",", ":");
                                         }
                                         string CSVHeader = "UserName" + "," + "Subject" + "," + "Body Text" + "," + "ContactName";
                                         string CSV_Content = UserEmail + "," + msg + "," + bdy.ToString() + "," + ContactName;
                                         CSVUtilities.ExportDataCSVFile(CSVHeader, CSV_Content, Globals.path_MessageAlreadySentComposeMgs);

                                         Log("[ " + DateTime.Now + " ] => [ Message Not Posted To Account: " + ContactName.Replace(":", string.Empty) + " because it has sent the same message already]");
                                     }
                                     else
                                     {
                                         Log("[ " + DateTime.Now + " ] => [ Failed In Message Posting ]");
                                         GlobusFileHelper.AppendStringToTextfileNewLine("Failed In Message Posting", Globals.path_ComposeMessage);
                                     }

                                     //if (SlectedContacts1.Count != 0) //client ahmed sudi
                                     {
                                         int delay = RandomNumberGenerator.GenerateRandom(mindelay, maxdelay);
                                         Log("[ " + DateTime.Now + " ] => [ " + "Delay for : " + delay + " Seconds ]");
                                         Thread.Sleep(delay * 1000);
                                     }

                                 }
                                 catch (Exception ex)
                                 {
                                     GlobusFileHelper.AppendStringToTextfileNewLine(" Error:" + ex.Message + "StackTrace --> >>>" + ex.StackTrace, Globals.path_ComposeMessage);
                                 }
                             }

                 }
                 catch (Exception ex)
                 {
                     GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Error -->  PostFinalMsg() --> 1 --> " + ex.Message + "StackTrace --> >>>" + ex.StackTrace, Globals.Path_LinkedinErrorLogs);
                     GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Error --> PostFinalMsg() --> 1 --> " + ex.Message + "StackTrace --> >>>" + ex.StackTrace, Globals.Path_LinkedinComposeMessageErrorLogs);
                 }

             }
             catch (Exception ex)
             {
                 GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Error -->  PostFinalMsg() --> 2 --> " + ex.Message + "StackTrace --> >>>" + ex.StackTrace, Globals.Path_LinkedinErrorLogs);
                 GlobusFileHelper.AppendStringToTextfileNewLine("DateTime :- " + DateTime.Now + " :: Error --> PostFinalMsg() --> 2 --> " + ex.Message + "StackTrace --> >>>" + ex.StackTrace, Globals.Path_LinkedinComposeMessageErrorLogs);
             }
        }