private async void FrmMain_Load(object sender, EventArgs e) { await SafeExecutionContext.ExecuteAsync( this, async() => { this.lblTitle.Text = string.Empty; this.lblDatePublished.Text = string.Empty; this.htmlEditor.Html = EmptyContent; this.htmlEditor.Enabled = false; if (this.mnuSaveAs != null) { this.mnuSaveAs.Enabled = false; } var desktopClientService = new DesktopClientService(this.settings); this.checkUpdateResult = await desktopClientService.CheckUpdateAsync(); this.slblUpdateAvailable.Visible = this.checkUpdateResult.HasUpdate; await this.LoadNotesAsync(); }, () => { this.slblStatus.Text = Resources.Loading; this.sp.Visible = true; }, () => this.sp.Visible = false); }
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); } }); }
public async Task ImportNote(Note note, bool rethrow = false) { Type[] exceptionTypes = null; if (rethrow) { exceptionTypes = new[] { typeof(NoteAlreadyExistsException) }; } await SafeExecutionContext.ExecuteAsync(this, async() => { var existingNoteTitles = this.ExistingNotesTitle; if (existingNoteTitles.Contains(note.Title)) { throw new NoteAlreadyExistsException(Resources.TitleExists); } var canceled = await this.SaveWorkspaceAsync(); if (!canceled) { this.ClearWorkspace(); note.Content = string.IsNullOrEmpty(note.Content) ? string.Empty : crypto.Encrypt(note.Content); this.workspace = new Workspace(note); this.workspace.PropertyChanged += this.workspace_PropertyChanged; await this.SaveWorkspaceSlientlyAsync(); await this.LoadNotesAsync(); } }, () => { this.slblStatus.Text = Resources.Importing; this.sp.Visible = true; }, () => this.sp.Visible = false, exceptionTypes); }
private async Task DoRestoreAsync() { await SafeExecutionContext.ExecuteAsync( this, async() => { var treeNode = this.tvNotes.SelectedNode; if (treeNode != null) { var item = GetItem(treeNode); var note = item.Data; using (var dataAccessProxy = this.CreateDataAccessProxy()) { await dataAccessProxy.RestoreAsync(note.ID); } await this.CorrectNodeSelectionAsync(treeNode); treeNode.Remove(); this.tvNotes.AddItem(this.notesNode.Nodes, item); note.DeletedFlag = DeleteFlag.None; this.ResortNodes(this.notesNode); if (this.trashNode.Nodes.Count == 0) { this.mnuEmptyTrash.Enabled = false; this.cmnuEmptyTrash.Enabled = false; } } }, () => { this.slblStatus.Text = Resources.Restoring; this.sp.Visible = true; }, () => this.sp.Visible = false); }
private void Action_ChangePassword(object sender, EventArgs e) { SafeExecutionContext.Execute(this, () => { var changePasswordForm = new FrmChangePassword(this.credential); changePasswordForm.ShowDialog(); }); }
private void DoRename() { SafeExecutionContext.Execute( this, () => { var node = this.tvNotes.SelectedNode; node.BeginEdit(); }); }
private async Task DoOpenAsync() { await SafeExecutionContext.ExecuteAsync( this, async() => await this.OpenTreeNodeAsync(this.tvNotes.SelectedNode), () => { this.slblStatus.Text = Resources.Opening; this.sp.Visible = true; }, () => this.sp.Visible = false); }
private void Action_Settings(object sender, EventArgs e) { SafeExecutionContext.Execute( this, () => { var settingsForm = new FrmSettings(this.settings, this.extensionManager, this.styleManager); if (settingsForm.ShowDialog() == DialogResult.OK) { this.UpdateSettings(); } }); }
private async Task DoEmptyTrashAsync() { await SafeExecutionContext.ExecuteAsync( this, async() => { var confirmResult = MessageBox.Show( Resources.DeleteNoteConfirm, Resources.Confirmation, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (confirmResult == DialogResult.Yes) { this.slblStatus.Text = Resources.Deleting; this.sp.Visible = true; using (var dataAccessProxy = this.CreateDataAccessProxy()) { await dataAccessProxy.EmptyTrashAsync(); } this.trashNode.Nodes.Clear(); if (this.notesNode.Nodes.Count > 0) { var firstNode = this.notesNode.Nodes[0]; var firstNote = GetItem(firstNode).Data; await this.LoadNoteAsync(firstNote.ID); } else { this.tvNotes.SelectedNode = this.notesNode; this.lblTitle.Text = string.Empty; this.lblDatePublished.Text = string.Empty; this.htmlEditor.Enabled = false; this.htmlEditor.Html = EmptyContent; if (this.mnuSaveAs != null) { this.mnuSaveAs.Enabled = false; } } this.mnuEmptyTrash.Enabled = false; this.cmnuEmptyTrash.Enabled = false; } }, null, () => this.sp.Visible = false); }
private async void tvNotes_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) { if (!e.CancelEdit) { await SafeExecutionContext.ExecuteAsync( this, async() => { var title = e.Label; if (string.IsNullOrEmpty(title)) { return; } this.slblStatus.Text = Resources.Renaming; this.sp.Visible = true; if (this.notesNode.Nodes.Cast <TreeNode>().Any(n => n != e.Node && n.Text == title)) { MessageBox.Show( Resources.TitleExists, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Warning); e.CancelEdit = true; } else { var item = GetItem(e.Node); var nodeMetadata = item.Data; using (var dataAccessProxy = this.CreateDataAccessProxy()) { var selectedNote = await dataAccessProxy.GetNoteAsync(nodeMetadata.ID); var noteUpdate = new Note { ID = nodeMetadata.ID, Title = title, Content = selectedNote.Content }; await dataAccessProxy.UpdateNoteAsync(noteUpdate); this.lblTitle.Text = title; this.workspace.Title = title; item.Title = title; this.tvNotes.Refresh(); } } }, null, () => this.sp.Visible = false); } }
/// <summary> /// Executes the current extension. /// </summary> /// <param name="shell">The <see cref="IShell" /> object on which the current extension will be executed.</param> protected async override void DoExecute(IShell shell) { if (shell.HasActiveDocument) { await SafeExecutionContext.ExecuteAsync((Form)shell.Owner, async() => { var blogSetting = this.SettingProvider.GetExtensionSetting <BlogSetting>(); if (string.IsNullOrEmpty(blogSetting.MetaWeblogAddress) || string.IsNullOrEmpty(blogSetting.UserName) || string.IsNullOrEmpty(blogSetting.Password)) { MessageBox.Show(Resources.MissingBlogConfigurationMsg, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var gateway = new BlogGateway(blogSetting.MetaWeblogAddress, blogSetting.UserName, blogSetting.Password); if (await gateway.TestConnectionAsync()) { var blogPublishDialog = new FrmBlogPublish(gateway); if (blogPublishDialog.ShowDialog() == DialogResult.OK) { var selectedCategories = blogPublishDialog.SelectedCategories.Select(s => s.Title).ToList(); var postInfo = new PostInfo { Categories = selectedCategories, DateCreated = DateTime.Now, Description = HtmlUtilities.Tidy(HtmlUtilities.ReplaceFileSystemImages(shell.Note.Content)), Title = shell.Note.Title }; await gateway.PublishBlog(postInfo, selectedCategories); shell.StatusText = Resources.PublishSucceeded; } } else { MessageBox.Show(Resources.BlogExtensionCannotConnectToBlogService, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }); } else { MessageBox.Show(Resources.NoActiveNoteOpened, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private async Task DoSaveAsync() { if (!this.workspace.IsSaved) { await SafeExecutionContext.ExecuteAsync( this, async() => await this.SaveWorkspaceSlientlyAsync(), () => { this.slblStatus.Text = Resources.Saving; this.sp.Visible = true; }, () => this.sp.Visible = false); } }
private async void tvNotes_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Button == MouseButtons.Left && e.Node != null && !ReferenceEquals(e.Node, this.notesNode) && !ReferenceEquals(e.Node, this.trashNode)) { await SafeExecutionContext.ExecuteAsync( this, async() => await this.OpenTreeNodeAsync(e.Node), () => { this.slblStatus.Text = Resources.Opening; this.sp.Visible = true; }, () => this.sp.Visible = false); } }
protected override void DoExecute(IShell shell) { if (shell.HasActiveDocument) { SafeExecutionContext.Execute((Form)shell.Owner, () => { var setting = this.SettingProvider.GetExtensionSetting <InsertSourceCodeSetting>(); var insertCodeDialog = new FrmInsertSourceCode(setting); if (insertCodeDialog.ShowDialog() == DialogResult.OK) { shell.InsertHtml(insertCodeDialog.SourceCodeTag); } }); } else { MessageBox.Show(Resources.NoActiveNoteOpened, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private async Task DoReconnectAsync() { await SafeExecutionContext.ExecuteAsync( this, async() => { var canceled = false; var localCredential = LoginProvider.Login(delegate { canceled = true; }, this.settings, true); if (!canceled && localCredential != null) { this.credential.UserName = localCredential.UserName; this.credential.Password = localCredential.Password; this.credential.ServerUri = localCredential.ServerUri; this.Text = string.Format( "CloudNotes - {0}@{1}", this.credential.UserName, this.credential.ServerUri); await this.LoadNotesAsync(); } }); }
private async void btnTestConnection_Click(object sender, EventArgs e) { bool hasError = false; errorProvider.Clear(); if (string.IsNullOrEmpty(txtMetaWeblogAddress.Text)) { errorProvider.SetError(txtMetaWeblogAddress, "Please input the MetaWeblog address."); hasError = true; } if (string.IsNullOrEmpty(txtUserName.Text)) { errorProvider.SetError(txtUserName, "Please input the user name."); hasError = true; } if (string.IsNullOrEmpty(txtPassword.Text)) { errorProvider.SetError(txtPassword, "Please input the password."); hasError = true; } if (hasError) { return; } await SafeExecutionContext.ExecuteAsync(this.ParentForm, async() => { var gateway = new BlogGateway(txtMetaWeblogAddress.Text, txtUserName.Text, txtPassword.Text); if (await gateway.TestConnectionAsync()) { MessageBox.Show(Resources.TestConnectionSucceeded, Resources.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(Resources.TestConnectionFailed, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }); }
private async Task DoDeleteAsync() { await SafeExecutionContext.ExecuteAsync( this, async() => { var confirmResult = MessageBox.Show( Resources.DeleteNoteConfirm, Resources.Confirmation, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (confirmResult == DialogResult.Yes) { this.slblStatus.Text = Resources.Deleting; this.sp.Visible = true; var treeNode = this.tvNotes.SelectedNode; if (treeNode != null) { var note = GetItem(treeNode).Data; using (var dataAccessProxy = this.CreateDataAccessProxy()) { await dataAccessProxy.DeleteAsync(note.ID); } await this.LoadNotesAsync(); } if (this.trashNode.Nodes.Count == 0) { this.mnuEmptyTrash.Enabled = false; this.cmnuEmptyTrash.Enabled = false; } } }, null, () => this.sp.Visible = false); }
private async Task DoNewAsync() { await SafeExecutionContext.ExecuteAsync( this, async() => { //var newNoteForm = new TextInputBox(Resources.NewNoteTitleText, // Resources.NewNotePrompt, new[] // { // new Tuple<Func<string, bool>, string>(string.IsNullOrEmpty, Resources.TitleRequired), // new Tuple<Func<string, bool>, string>(this.ExistingNotesTitle.Contains, // Resources.TitleExists) // }); var newNoteForm = new FrmCreateNote(Resources.NewNotePrompt, this.styleManager, this.settings, new[] { 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.SelectedTitle; var note = new Note { ID = Guid.Empty, Title = title, Content = newNoteForm.SelectedEmptyHtml, DatePublished = DateTime.UtcNow }; await this.ImportNote(note); } }); }
private void Action_About(object sender, EventArgs e) { SafeExecutionContext.Execute(this, () => new FrmAbout(this.extensionManager).ShowDialog()); }
private void InitializeExtensions() { Func <ToolStripMenuItem> createExtensionsToolMenuItem = () => { var extensionsTool = (ToolStripMenuItem)mnuTools.DropDownItems.Add(Resources.ExtensionsMenuItemName); extensionsTool.Image = Resources.plugin; return(extensionsTool); }; // Initialize tool extensions var toolExtensions = this.extensionManager.ToolExtensions.ToList(); if (toolExtensions.Count > 0) { mnuTools.DropDownItems.Add(new ToolStripSeparator()); ToolStripMenuItem parentTool = null; if (this.settings.General.ShowUnderExtensionsMenu) { if (this.settings.General.OnlyShowForMaximumExtensionsLoaded) { if (this.settings.General.MaximumExtensionsLoadedValue < toolExtensions.Count) { parentTool = createExtensionsToolMenuItem(); } else { parentTool = mnuTools; } } else { parentTool = createExtensionsToolMenuItem(); } } else { parentTool = mnuTools; } foreach (var toolExtension in toolExtensions) { var extensionToolStrip = (ToolStripMenuItem)parentTool.DropDownItems.Add(toolExtension.ToolName); extensionToolStrip.Image = toolExtension.ToolIcon; extensionToolStrip.ToolTipText = toolExtension.ToolTip; extensionToolStrip.ShowShortcutKeys = true; extensionToolStrip.ShortcutKeys = (Keys)toolExtension.Shortcut; extensionToolStrip.Tag = toolExtension.ID; extensionToolStrip.Click += (s, e) => { SafeExecutionContext.Execute(this, () => toolExtension.Execute(this)); }; } } // Initialize export extensions var exportExtensions = this.extensionManager.ExportExtensions.ToList(); if (exportExtensions.Count > 0) { var idx = this.mnuFile.DropDownItems.IndexOf(mnuSave); this.mnuFile.DropDownItems.Insert(++idx, new ToolStripSeparator()); this.mnuSaveAs = new ToolStripMenuItem(Resources.SaveAsMenuText); this.mnuSaveAs.ShortcutKeys = Keys.Control | Keys.Alt | Keys.S; this.mnuSaveAs.Click += (s, e) => { SafeExecutionContext.Execute(this, () => { var exportExtensionArray = this.extensionManager.ExportExtensions.ToArray(); var filters = new StringBuilder(); for (var i = 0; i < exportExtensionArray.Length; i++) { filters.AppendFormat("{0}|{1}|", exportExtensionArray[i].FileExtensionDescription, exportExtensionArray[i].FileExtension); } var saveFileDialog = new SaveFileDialog() { Title = Resources.SaveAsDialogTitle, AddExtension = true, FileName = this.Note == null ? string.Empty : this.Note.Title, Filter = filters.ToString().Trim('|'), OverwritePrompt = true, InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) }; if (saveFileDialog.ShowDialog() == DialogResult.OK) { var exportExtension = exportExtensionArray[saveFileDialog.FilterIndex - 1]; exportExtension.SetFileName(saveFileDialog.FileName); try { exportExtension.Execute(this); MessageBox.Show(Resources.SaveAsSuccessful, Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (ExportCancelledException) { MessageBox.Show(Resources.SaveAsCancelled, Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }); }; this.mnuFile.DropDownItems.Insert(++idx, mnuSaveAs); } }
private void Action_Print(object sender, EventArgs e) { SafeExecutionContext.Execute(this, () => this.htmlEditor.ExecuteButtonFunction <PrintButton>()); }