Пример #1
0
 private void frmMain_Load(object sender, EventArgs e)
 {
     try
     {
         db = new DataEntities();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
         return;
     }
     messageGridView.DataSource = null;
     messageGridView.DataSource = db.Messages.Where(aa => aa.DateSended == null).OrderBy(zz => zz.nextTryDate);
 }
Пример #2
0
        public static bool SendDmMessage(int?SenderUserID, string ReciverScreenName, string Message, out RequestResult Result)
        {
            if (SenderUserID.HasValue)
            {
                var v = new TwitterAtomationWa.DataEntities().Accounts.FirstOrDefault(a => a.id == SenderUserID);

                if (v != null)
                {
                    return(SendDmMessage(v.ScreenName, ReciverScreenName, Message, out Result));
                }
            }

            Result = RequestResult.Unknown;
            return(false);
        }
Пример #3
0
        private static void DeleteUser(Account vUser)
        {
            var db       = new TwitterAtomationWa.DataEntities();
            var messages = db.Messages.Where(aa => aa.SenderscreenName == vUser.ScreenName);

            foreach (var message in messages)
            {
                db.Messages.DeleteObject(message);
                db.SaveChanges();
            }
            var vU = db.Accounts.FirstOrDefault(aa => aa.ScreenName == vUser.ScreenName);

            db.Accounts.DeleteObject(vU);
            db.SaveChanges();

            SaveDeleteUserInTempFile(vUser);
        }
Пример #4
0
        public static bool LoginUser(string username, string password, string proxyaddress = "")
        {
            try
            {
                #region Login Part

                WebProxy P = GetProxy(proxyaddress);

                OAuthTokenResponse requestToken = OAuthUtility.GetRequestToken(Classes.AppSetting.ConsumerKey, Classes.AppSetting.ConsumerSecret, "oob");
                // Direct or instruct the user to the following address:
                Uri authorizationUri = OAuthUtility.BuildAuthorizationUri(requestToken.Token);
                //authenticity_token=aa84db7931040b1ed321372ae2b001ccf4f6e20e&oauth_token=uT3RaA72ld4sIZMwtUxlx1021VRjCkS0VEPyeYj3Fys&session%5Busername_or_email%5D=omidam81&session%5Bpassword%5D=omidomid

                HttpWebRequest R = (HttpWebRequest)HttpWebRequest.Create(authorizationUri);
                R.Proxy = P;
                CookieContainer Cookies = new CookieContainer();
                R.CookieContainer = Cookies;
                using (HttpWebResponse W = (HttpWebResponse)R.GetResponse())
                {
                    System.IO.StreamReader sr = new System.IO.StreamReader(W.GetResponseStream());

                    var str1111 = sr.ReadToEnd();
                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    doc.LoadHtml(str1111);
                    var    authenticity_token = doc.DocumentNode.SelectSingleNode("//input[@name='authenticity_token']").Attributes["value"].Value;
                    string url = string.Format("authenticity_token={0}&oauth_token={1}&session%5Busername_or_email%5D={2}&session%5Bpassword%5D={3}",
                                               authenticity_token, requestToken.Token, username, password);
                    url = "https://twitter.com/oauth/authorize?" + System.Web.HttpUtility.HtmlDecode(url);

                    HttpWebRequest RP = (HttpWebRequest)HttpWebRequest.Create(url);
                    RP.Proxy = P;


                    RP.Method          = "POST";
                    RP.CookieContainer = new CookieContainer();
                    foreach (Cookie item in W.Cookies)
                    {
                        RP.CookieContainer.Add(item);
                    }
                    HttpWebResponse WP = (HttpWebResponse)RP.GetResponse();
                    sr      = new System.IO.StreamReader(WP.GetResponseStream());
                    str1111 = sr.ReadToEnd();
                    doc     = new HtmlAgilityPack.HtmlDocument();
                    doc.LoadHtml(str1111);
                    #endregion
                    var code = doc.DocumentNode.SelectSingleNode("//kbd[@aria-labelledby='code-desc']/code").InnerHtml;
                    OAuthTokenResponse resp = OAuthUtility.GetAccessToken(Classes.AppSetting.ConsumerKey, Classes.AppSetting.ConsumerSecret, requestToken.Token, code);
                    #region Save To Database
                    var db      = new TwitterAtomationWa.DataEntities();
                    var account = db.Accounts.FirstOrDefault(aa => aa.ScreenName == username);
                    if (account == null)
                    {
                        account = new Account()
                        {
                            DateCreated  = DateTime.Now,
                            TokenSecret  = resp.TokenSecret,
                            Token        = resp.Token,
                            ScreenName   = resp.ScreenName,
                            Name         = password,
                            ProxyAddress = proxyaddress
                        };
                        db.Accounts.AddObject(account);
                        db.SaveChanges();
                    }
                    else
                    {
                        account.Token        = resp.Token;
                        account.TokenSecret  = resp.TokenSecret;
                        account.ProxyAddress = proxyaddress;
                        db.SaveChanges();
                    }
                }



                return(true);

                #endregion
            }
            catch
            {
                return(false);
            }
        }