Beispiel #1
0
        private async void LoadAccountHTTPSession_posting()
        {
            InitalizeProxy(PostingAccount, ref PROXY_Posting);
            AccountMangerRow = Login.DT_AccountManager.Select("UserName_Email='" + PostingAccount + "'").FirstOrDefault();

            string stateFile   = PostingAccount.GetHashCode().ToString();
            var    userSession = new UserSessionData
            {
                UserName = PostingAccount,
                Password = AccountMangerRow["Password"].ToString()
            };
            var httpClientHandler = new HttpClientHandler {
                Proxy = PROXY_Posting
            };


            var delay = RequestDelay.FromSeconds(2, 2);

            PinApi_posing = PinApiBuilder.CreateBuilder().SetUser(userSession)
                            .UseLogger(new DebugLogger(LogLevel.All)) // use logger for requests and debug messages
                            .UseHttpClientHandler(httpClientHandler)
                            .SetRequestDelay(delay)
                            .Build();
            try
            {
                if (File.Exists(stateFile))
                {
                    using (var fs = File.OpenRead(stateFile))
                    {
                        PinApi_posing.LoadStateDataFromStream(fs);
                    }
                }
                else
                {
                    var logvar = await PinApi_posing.LoginAsync();

                    var state = PinApi_posing.GetStateDataAsStream();
                    using (var fileStream = File.Create(stateFile))
                    {
                        state.Seek(0, SeekOrigin.Begin);
                        state.CopyTo(fileStream);
                    }
                }
            }
            catch (Exception ex)
            {
                Login.MainInstance.LogReport(true, PostingAccount, "Http Sesstion " + ex.Message);
                Login.MainInstance.GridControl_Tasks.BeginInvoke(new Action(() =>
                {
                    TaskMangerRow["Errors"] = (int.Parse(TaskMangerRow["Errors"].ToString()) + 1);
                }));
            }
        }
Beispiel #2
0
        async Task loadUserifAsync()
        {
            string stateFile   = textBox1.Text.GetHashCode().ToString();
            var    userSession = new UserSessionData
            {
                UserName = textBox1.Text,
                Password = textBox2.Text
            };
            var delay = RequestDelay.FromSeconds(2, 2);

            PinApi = PinApiBuilder.CreateBuilder().SetUser(userSession)
                     .UseLogger(new DebugLogger(LogLevel.All)) // use logger for requests and debug messages
                     .SetRequestDelay(delay)
                     .Build();


            try
            {
                if (File.Exists(stateFile))
                {
                    Console.WriteLine("Loading state from file");
                    using (var fs = File.OpenRead(stateFile))
                    {
                        PinApi.LoadStateDataFromStream(fs);
                    }
                }


                else
                {
                    var logvar = await PinApi.LoginAsync();


                    var state = PinApi.GetStateDataAsStream();
                    using (var fileStream = File.Create(stateFile))
                    {
                        state.Seek(0, SeekOrigin.Begin);
                        state.CopyTo(fileStream);
                    }
                }
            }
            catch (Exception exa)
            {
                Console.WriteLine(exa);
            }
        }
Beispiel #3
0
        private async void Btn_Add_ClickAsync(object sender, EventArgs e)
        {
            ProgWait.Visible = true;
            try
            {
                //   var client = new PinSharpClient(txt_accesstoken.Text);


                //  var user = await client.Me.GetUserAsync();

                string stateFile   = txt_Username.Text.GetHashCode().ToString();
                var    userSession = new UserSessionData
                {
                    UserName = txt_Username.Text,
                    Password = txt_password.Text
                };

                InitalizeProxy(txt_proxy.Text, txt_Username.Text);
                var httpClientHandler = new HttpClientHandler {
                    Proxy = loginproxy
                };


                var delay = RequestDelay.FromSeconds(2, 2);
                PinApi = PinApiBuilder.CreateBuilder().SetUser(userSession)
                         .UseLogger(new DebugLogger(LogLevel.All)) // use logger for requests and debug messages
                         .UseHttpClientHandler(httpClientHandler)
                         .SetRequestDelay(delay)
                         .Build();
                try
                {
                    if (File.Exists(stateFile))
                    {
                        using (var fs = File.OpenRead(stateFile))
                        {
                            PinApi.LoadStateDataFromStream(fs);
                        }
                    }
                    else
                    {
                        var logvar = await PinApi.LoginAsync();

                        var state = PinApi.GetStateDataAsStream();
                        using (var fileStream = File.Create(stateFile))
                        {
                            state.Seek(0, SeekOrigin.Begin);
                            state.CopyTo(fileStream);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogReport(true, txt_Username.Text, "Http Sesstion " + ex.Message);
                }
                var user = await PinApi.UserProcessor.GetCurrentUserAsync();

                DataRow dr = DT_AccountManager.NewRow();

                DT_AccountManager.Rows.Add(user.Value.username, txt_password.Text, "ok", txt_accesstoken.Text, "Following", "Followers", "Pins", user.Value.first_name + " " + user.Value.last_name);

                appHelper.SetUserDataTable_Control = DT_AccountManager;
            }
            catch (Exception ex)
            {
                LogReport(true, txt_Username.Text, ex.Message);
            }



            ProgWait.Visible = false;
        }