public static Task PublishSingle(CmdletObject cmdlet, ModuleObject module, Blogger blogger, Boolean quiet) { return(Task.Factory.StartNew(() => { var post = new Post { Title = cmdlet.Name, PostId = cmdlet.ArticleIDString, HTML = HtmlProcessor.GenerateHtmlView(cmdlet, module).Result }; if (blogger == null) { blogger = Utils.InitializeBlogger(module.Provider); } if (blogger == null) { Utils.MsgBox("Warning", Strings.WarnBloggerNeedsMoreData, MessageBoxImage.Exclamation); return; } if (String.IsNullOrEmpty(cmdlet.ArticleIDString)) { // assuming that article does not exist cmdlet.ArticleIDString = blogger.AddPost(post); if (!String.IsNullOrEmpty(cmdlet.ArticleIDString) && !quiet) { Utils.MsgBox("Success", new Win32Exception(0).Message, MessageBoxImage.Information); } // get post URL once published if (!String.IsNullOrEmpty(cmdlet.ArticleIDString)) { try { cmdlet.URL = module.Provider.ProviderName.ToLower() == "codeplex" ? module.Provider.Blog.URL + "wikipage?title=" + cmdlet.Name : blogger.GetPost(cmdlet.ArticleIDString).Permalink; if (!Uri.IsWellFormedUriString(cmdlet.URL, UriKind.Absolute)) { var baseUrl = new Uri(module.Provider.ProviderURL); cmdlet.URL = $"{baseUrl.Scheme}://{baseUrl.DnsSafeHost}{cmdlet.URL}"; } } catch { } } } else { try { // assuming that article exist, so we just change it blogger.UpdatePost(post); var baseUrl = new Uri(module.Provider.ProviderURL); String permalink = blogger.GetPost(cmdlet.ArticleIDString).Permalink; cmdlet.URL = $"{baseUrl.Scheme}://{baseUrl.DnsSafeHost}{permalink}"; } catch (Exception e) { // 0x80131600 connect succeeds, but the post is deleted. Remove postid if (e.HResult == -2146232832 || e.HResult == -2147023728) { cmdlet.ArticleIDString = null; } throw; } } })); }