private void Application_Startup(object sender, StartupEventArgs e) { if (!Directory.Exists(Messanger.PATH)) { Directory.CreateDirectory(Messanger.PATH); } Messanger.Read(); }
public void CloseButton_Clicked() { var data = this.DataContext as SettingViewModel; if (!Equals(data.UserName, buffer.UserName) || !Equals(data.GitHubName, buffer.GitHubName)) { Messanger.Write(); if (!Equals(data.GitHubName, buffer.GitHubName)) { Grass.GetGrass(data.GitHubName); } } this.Hide(); }
public SettingWindow(SettingViewModel viewModel) { InitializeComponent(); MouseLeftButtonUp += (a, e) => Keyboard.ClearFocus(); ThemeButton.Click += (a, e) => Messanger.ThemeWrite(); TwitterAuthButton.Click += (a, e) => AuthWindow.ShowDialog(); PostData.Click += async(a, e) => { if (File.Exists(Messanger.FILEPATH)) { var json = File.ReadAllBytes(Messanger.FILEPATH); var data = MessagePackSerializer.Deserialize <MainWindowViewModel>(json); var mp = MessagePackSerializer.Serialize(data); await Messanger.PostDataAsync(mp); } }; this.Closing += (a, e) => AuthWindow.Close(); this.DataContext = viewModel; buffer = new SettingViewModel() { GitHubName = viewModel.GitHubName, UserName = viewModel.UserName }; }
private async Task SetAuthAsync() { this.Label.Content = "認証中..."; CodeTextBox.IsEnabled = false; bool isSuc = false; try { var tokens = await Session?.GetTokensAsync(CodeTextBox.Text); var authToken = await ConnectAzureAsync(tokens); Messanger.HttpClient.DefaultRequestHeaders.Clear(); Messanger.HttpClient.DefaultRequestHeaders.Add("X-ZUMO-AUTH", authToken); var(model, IsSuccess) = await Messanger.GetDataAsync(); isSuc = IsSuccess; if (IsSuccess && model != null) { MainWindow.MainViewModel.UpdateViewModel(model); Messanger.Wrote += async bytes => await Messanger.PostDataAsync(bytes); using (var fs = new FileStream(Messanger.KEY_FILEPATH, FileMode.Create, FileAccess.Write)) { await MessagePackSerializer.SerializeAsync(fs, authToken); } } else if (IsSuccess) { var m = MessagePackSerializer.Serialize(MainWindow.MainViewModel); await Messanger.PostDataAsync(m); using (var fs = new FileStream(Messanger.KEY_FILEPATH, FileMode.Create, FileAccess.Write)) { await MessagePackSerializer.SerializeAsync(fs, authToken); } } else { Messanger.HttpClient.DefaultRequestHeaders.Clear(); } } catch { this.Label.Content = "認証失敗"; CodeTextBox.IsEnabled = true; return; } CodeTextBox.IsEnabled = true; if (isSuc) { this.Label.Content = "認証成功"; MainWindow.SettingWindow.TwitterAuthButton.IsEnabled = false; MainWindow.SettingWindow.TwitterAuthButton.Content = "認証済み"; } else { this.Label.Content = "認証失敗"; } await Task.Delay(1500); this.Label.Content = "Webブラウザでログイン後、表示されるコードを入力して下さい。"; this.Hide(); }
public void CloseButton_Clicked() { Messanger.Write(); this.Hide(); }