private async void ButtonPostBlog_Click(object sender, System.Windows.RoutedEventArgs e) { StatusBar.ShowStatusProgress("Uploading Blog post..."); GetCustomFieldsFromObservableCollection(); if (string.IsNullOrEmpty(Model.ActivePostMetadata.WeblogName)) { MessageBox.Show("Please select or create a Weblog to post to before posting.", "No Weblog Selected", MessageBoxButton.OK, MessageBoxImage.Warning); if (Model.WeblogNames.Count == 0) { ActiveWebLogsPageForNew(); } else { ComboWebLogSite.Focus(); } StatusBar.ShowStatus(); return; } var editor = Model.AppModel.ActiveEditor; // Update the Markdown document first string markdown = Model.ActivePostMetadata.SetPostYamlFromMetaData(); editor.SetMarkdown(markdown); editor.SaveDocument(); WeblogAddinConfiguration.Current.LastWeblogAccessed = Model.ActivePostMetadata.WeblogName; var window = Model.AppModel.Window; try { bool result = await Model.Addin.SendPost(Model.ActiveWeblogInfo, Model.ActivePostMetadata.PostStatus == "draft"); if (result) { Close(); window.ShowStatusSuccess($"Blog post '{Model.ActivePost.Title}` uploaded."); } else { window.ShowStatusError("Upload of blog post failed."); } } finally { StatusBar.ShowStatus(); } }
private async void ButtonPostBlog_Click(object sender, System.Windows.RoutedEventArgs e) { StatusBar.ShowStatusProgress("Uploading Blog post..."); GetCustomFieldsFromObservableCollection(); if (string.IsNullOrEmpty(Model.ActivePostMetadata.WeblogName)) { MessageBox.Show("Please select or create a Weblog to post to before posting.", "No Weblog Selected", MessageBoxButton.OK, MessageBoxImage.Warning); if (Model.WeblogNames.Count == 0) { ActiveWebLogsPageForNew(); } else { ComboWebLogSite.Focus(); } StatusBar.ShowStatus(); return; } var editor = Model.AppModel.ActiveEditor; WeblogAddinConfiguration.Current.LastWeblogAccessed = Model.ActivePostMetadata.WeblogName; var window = Model.AppModel.Window; // save before sending just in case if (Model.Configuration.AutoSavePost) { editor.SaveDocument(); } try { bool result = await Model.Addin.SendPost(Model.ActiveWeblogInfo, Model.ActivePostMetadata.PostStatus == "draft"); if (result) { Close(); window.ShowStatusSuccess($"Blog post '{Model.ActivePost.Title}` uploaded."); } else { window.ShowStatusError("Upload of blog post failed."); } // Sendpost updated the editor - save to disk if (Model.Configuration.AutoSavePost) { editor.SaveDocument(); } } catch (Exception ex) { window.ShowStatusError($"An unhandled error occurred sending the post: {ex.Message}"); } }