Example #1
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            YA ps = YA.Default;

            ps.isSave = (bool)cb1.IsChecked;
            if (yadisk.OAuthp == "")
            {
                ps.isSave = false;
            }
            ps.Save();
            Close();
        }
Example #2
0
        public void tokenfromsetting()
        {
            YA ps = YA.Default;

            OAuthp = ps.OAuth;
        }
Example #3
0
        private void cb1_Loaded(object sender, RoutedEventArgs e)
        {
            YA ps = YA.Default;

            cb1.IsChecked = ps.isSave;
        }
Example #4
0
        private void browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            Grid.SetColumnSpan(browser, 2);
            string code = HttpUtility.ParseQueryString(browser.Source.Query).Get("code");

            if (browser.Source.ToString() == "https://www.yandex.ru/")
            {
                browser.Source = new System.Uri("https://oauth.yandex.ru/authorize?response_type=code&client_id=bfec704e15514115b366a5d3512cd66f");
            }
            if (code != "")
            {
                var url       = "https://oauth.yandex.ru/token";
                var webClient = new WebClient();
                // Создаём коллекцию параметров
                var pars = new NameValueCollection();

                webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                webClient.Headers.Add("Authorization", "Basic YmZlYzcwNGUxNTUxNDExNWIzNjZhNWQzNTEyY2Q2NmY6M2Y2MzZlMjE3NWExNDQwZWFmZDdkODYzMGJhNTJiMjA=");


                // Добавляем необходимые параметры в виде пар ключ, значение
                pars.Add("grant_type", "authorization_code");
                pars.Add("code", code);

                // Посылаем параметры на сервер
                // Может быть ответ в виде массива байт
                var    response  = webClient.UploadValues(url, pars);
                string save_html = System.Text.Encoding.UTF8.GetString(response);
                OAuth  account   = JsonConvert.DeserializeObject <OAuth>(save_html);
                // MessageBox.Show(account.access_token.ToString());


                //webClient = new WebClient();
                //url = "https://webdav.yandex.ru/?userinfo";
                //Thread.Sleep(1000);
                //webClient.Headers.Add("Authorization", "OAuth " + account.access_token);
                //string response1 = webClient.DownloadString(url);
                //string save_html = System.Text.Encoding.UTF8.GetString(response);
                //MessageBox.Show(response1);
                //Login login = JsonConvert.DeserializeObject<Login>(response);

                //   MessageBox.Show(login);

                //сохраняем в настройках
                YA ps = YA.Default;
                ps.OAuth = account.access_token;
                ps.Save();


                yadisk yadisk1 = new yadisk();
                yadisk1.tokenfromsetting();
                yadisk1.combat_zapros("CREATEDIR", @"GN_arhiv");



                Grid.SetColumnSpan(browser, 1);
                // browser.SetValue(Grid.ColumnSpan, 1); .Grid.ColumnSpan
                //   Close();
            }
            else
            {
            }
        }