Example #1
0
        /// <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);
            }
        }
        /// <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);
            }
        }