private async Task DoNewAsync() { await SafeExecutionContext.ExecuteAsync( this, async() => { var newNoteForm = new TextInputBox(Resources.NewNotePrompt, new Tuple <Func <string, bool>, string>[] { new Tuple <Func <string, bool>, string>(string.IsNullOrEmpty, Resources.TitleRequired), new Tuple <Func <string, bool>, string>(this.ExistingNotesTitle.Contains, Resources.TitleExists) }); if (newNoteForm.ShowDialog() == DialogResult.OK) { var title = newNoteForm.InputText; var note = new Note { ID = Guid.Empty, Title = title, Content = string.Empty, DatePublished = DateTime.UtcNow }; await this.ImportNote(note); } }); }
/// <summary> /// Executes the current extension. /// </summary> /// <param name="shell">The <see cref="IShell" /> object on which the current extension will be executed.</param> protected override async void DoExecute(IShell shell) { try { var setting = this.SettingProvider.GetExtensionSetting <ImportFromWebSetting>(); var dialog = new ImportFromWebDialog(setting); if (dialog.ShowDialog() == DialogResult.OK) { var title = HtmlUtilities.ExtractTitle(dialog.HtmlContent); if (string.IsNullOrEmpty(title) || shell.ExistingNotesTitle.Contains(title)) { var titleInputDialog = new TextInputBox(Resources.ImportFromWebInputTitleText, Resources.ImportFromWebInputTitlePrompt, title, new[] { new Tuple <Func <string, bool>, string>(string.IsNullOrEmpty, Resources.ImportFromWebEmptyTitleErrorMsg), new Tuple <Func <string, bool>, string>(shell.ExistingNotesTitle.Contains, Resources.ImportFromWebDuplicatedTitleErrorMsg) }); if (titleInputDialog.ShowDialog() == DialogResult.OK) { title = titleInputDialog.InputText; } else { return; } } await shell.ImportNote(new Note { Title = title, Content = dialog.HtmlContent }); } } catch (Exception ex) { FrmExceptionDialog.ShowException(ex); } }