/Twitpic/SettingWindow.xaml.cs
C# | 94 lines | 83 code | 8 blank | 3 comment | 6 complexity | 9f6e34a3bdad25732ed4183b8d844c38 MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Reactive.Linq;
- using Codeplex.OAuth;
- using System.Diagnostics;
- using ImageUploader.Extensions.Twitpic.Properties;
-
- namespace ImageUploader.Extensions.Twitpic
- {
- /// <summary>
- /// SettingWindow.xaml の相互作用ロジック
- /// </summary>
- public partial class SettingWindow : Window
- {
- RequestToken _requestToken;
-
- public SettingWindow()
- {
- InitializeComponent();
- }
-
- private void RequestUrlButton_Click(object sender, RoutedEventArgs e)
- {
- Observable.Defer(() =>
- {
- var authorizer = new OAuthAuthorizer(TwitpicUploader.CONSUMER_KEY, TwitpicUploader.CONSUMER_SECRET);
- return authorizer.GetRequestToken("http://twitter.com/oauth/request_token");
- })
- .Retry(3)
- .Select(res => res.Token)
- .Subscribe(token =>
- {
- _requestToken = token;
- var url = new OAuthAuthorizer(TwitpicUploader.CONSUMER_KEY, TwitpicUploader.CONSUMER_SECRET)
- .BuildAuthorizeUrl("http://twitter.com/oauth/authorize", token);
- Process.Start(url);
- });
-
- }
-
- private void PinCodeTextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- if ((_requestToken != null) && (!string.IsNullOrEmpty(PinCodeTextBox.Text)))
- {
- OkButton.IsEnabled = true;
- }
- else
- {
- OkButton.IsEnabled = false;
- }
- }
-
- private void OkButton_Click(object sender, RoutedEventArgs e)
- {
- if ((_requestToken != null) && (!string.IsNullOrEmpty(PinCodeTextBox.Text)))
- {
- Observable.Defer(() =>
- {
- var authorizer = new OAuthAuthorizer(TwitpicUploader.CONSUMER_KEY, TwitpicUploader.CONSUMER_SECRET);
- return authorizer.GetAccessToken("http://twitter.com/oauth/access_token", _requestToken, PinCodeTextBox.Text);
- })
- .Retry(3)
- .Subscribe(res =>
- {
- Dispatcher.BeginInvoke((Action)(() =>
- {
- Settings.Default.AccessTokenKey = res.Token.Key;
- Settings.Default.AccessTokenSecret = res.Token.Secret;
- Settings.Default.Save();
- MessageBox.Show("認証に成功しました","情報",MessageBoxButton.OK,MessageBoxImage.Information);
- this.Close();
- }));
- });
-
- }
- }
-
- private void CancelButton_Click(object sender, RoutedEventArgs e)
- {
- this.Close();
- }
- }
- }