private void listKeysToolStripMenuItem_Click(object sender, EventArgs e) { KeyWindow kw = new KeyWindow(); kw.ShowDialog(); kw.Dispose(); // Once closed we can dispose }
protected override void OnBeginBlockingUserInput() { if (!KeyWindow.Subviews.Any(v => v is InteractionBlockerView)) { KeyWindow.Add(new InteractionBlockerView()); } }
//открывает диалоговое окно с безопасным вводом ключа private void MenuKeyEnter_Click(object sender, RoutedEventArgs e) { this.Visibility = Visibility.Hidden; KeyWindow window = new KeyWindow(); window.ShowDialog(); KeyBox.Text = window.correctKey; this.Visibility = Visibility.Visible; }
//проверяет корректность введённого в окно KeyWindow ключа и не позволяет пользователю вводить недопустимые символы public static void CheckKey(object sender, ICollection <TextChange> changes) { KeyWindow window = sender as KeyWindow; GradientStop correct = new GradientStop(Colors.Green, 0.5); GradientStop error = new GradientStop(Colors.Red, 0.5); if (window.FullKeyBox.Text.Length == 0) { window.KeyErrors.Text = "Пустой ключ недопустим"; window.BackgroudGrad.GradientStops.RemoveAt(4); window.BackgroudGrad.GradientStops.Insert(4, error); } foreach (var item in changes) { if (item.AddedLength == 0) { if ((window.FullKeyBox.Text != "") && (item.RemovedLength > 0)) { window.KeyErrors.Text = ""; window.BackgroudGrad.GradientStops.RemoveAt(4); window.BackgroudGrad.GradientStops.Insert(4, correct); } return; } else { for (int i = item.Offset; i < (item.Offset + item.AddedLength); i++) { char insertedSymb = window.FullKeyBox.Text[i]; if (!TextEncoder.RusAlphabet.Contains(insertedSymb) && !TextEncoder.RusUpperAlphabet.Contains(insertedSymb)) { window.FullKeyBox.Text = window.FullKeyBox.Text.Remove(item.Offset, item.AddedLength); window.FullKeyBox.CaretIndex = window.FullKeyBox.Text.Length; window.KeyErrors.Text = "Попытка ввести неверный символ пресечена"; window.BackgroudGrad.GradientStops.RemoveAt(4); window.BackgroudGrad.GradientStops.Insert(4, error); return; } window.KeyErrors.Text = ""; window.BackgroudGrad.GradientStops.RemoveAt(4); window.BackgroudGrad.GradientStops.Insert(4, correct); } } } }
/// <summary> /// Twitter 連携に関するイベント設定を行います。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async Task _UsingPostTwitterAsync() { if (this.checkBoxPostTwitter.Checked) { var settings = Properties.Settings.Default; var consumerKey = (string)settings["ConsumerKey"] ?? null; var consumerSecret = (string)settings["ConsumerSecret"] ?? null; var accessToken = (string)settings["AccessToken"] ?? null; var accessTokenSecret = (string)settings["AccessTokenSecret"] ?? null; if (string.IsNullOrEmpty(consumerKey) || string.IsNullOrEmpty(consumerSecret) || string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(accessTokenSecret)) { // Consumer Key / Secret をここで入力 var key = new KeyWindow(consumerKey, consumerSecret); if (key.ShowDialog() == DialogResult.OK) { (this._ConsumerKey, this._ConsumerSecret) = key.CkPair; } // 入力された Consumer Key / Secret を元に インスタンス生成 this._Twitter = new Twitter(this._ConsumerKey, this._ConsumerSecret, this._HttpClient); if (this._ConsumerKey != null && this._ConsumerSecret != null) { // 認証を実施します await this._Twitter.AuthorizeAsync(); // Form が Close したと同時に ShowDialog も完了する。 var oauth = new OAuthWindow(); if (oauth.ShowDialog() == DialogResult.OK) { await this._Twitter.GetAccessTokenAsync(oauth.PinCode); } // 認証完了メッセージの投稿 await this.PostTwitterAsync($"Authentication completion for Kisaragi.\r\n{DateTimeOffset.Now}"); // 各種認証キーを設定ファイルに保存する settings["ConsumerKey"] = this._Twitter.ConsumerKey; settings["ConsumerSecret"] = this._Twitter.ConsumerSecret; settings["AccessToken"] = this._Twitter.AccessToken; settings["AccessTokenSecret"] = this._Twitter.AccessTokenSecret; settings["UserId"] = this._Twitter.UserId; settings["ScreenName"] = this._Twitter.ScreenName; settings.Save(); } else { this.checkBoxPostTwitter.Checked = false; MessageBox.Show("Twitter 連携をキャンセルします。\r\n" + "再度認証するには、チェックボックスをクリックしてください。", "認証未実施", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { new KisaragiMessageBox("Twitter 連携用認証キーは既に存在しています。" + "\r\nTwitter 連携を行うにはチェックを入れたままにしてください。", "通知", 2000); } } }