Example #1
0
        // writer
        async public static Task XmlGenerateHelp(StringBuilder SB, IEnumerable <CmdletObject> cmdlets, ProgressBar pb, Boolean isOffline)
        {
            List <CmdletObject> cmdletsToProcess = isOffline
                                ? new List <CmdletObject>(cmdlets)
                                : new List <CmdletObject>(cmdlets.Where(x => x.GeneralHelp.Status != ItemStatus.Missing));

            if (cmdletsToProcess.Count == 0)
            {
                return;
            }
            BBCodeParser bbrules  = HtmlProcessor.GetParser(ParserType.Clear);
            Double       duration = 0;

            if (pb != null)
            {
                duration = 100.0 / cmdletsToProcess.Count;
            }
            SB.Append("<helpItems schema=\"maml\">" + n);
            foreach (CmdletObject cmdlet in cmdletsToProcess)
            {
                await XmlGenerateBody(bbrules, SB, cmdlet);

                if (pb != null)
                {
                    pb.Value += duration;
                }
            }
            SB.Append("</helpItems>");
        }
 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;
             }
         }
     }));
 }