コード例 #1
0
 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;
             }
         }
     }));
 }
コード例 #2
0
        private void GenerateBlogPost(string outputId, string imageCodeBlog, string linksPage, IEnumerable <string> shortenedLinks, LinksBackup linksBackup, VideoInfo videoInfo)
        {
            string blogTitle;

            if (videoInfo.Title.Contains("Tokyo Hot"))
            {
                blogTitle = string.Format("{0}", videoInfo.Title.Replace("Tokyo Hot", "Tokyo-Hot"));
            }
            else
            {
                if (videoInfo.RemoveIdDash)
                {
                    outputId = outputId.Replace("-", "");
                }

                blogTitle = videoInfo.HideId ? videoInfo.Title :
                            string.Format("[{0}] {1}", outputId, videoInfo.Title);
            }

            string linksContent = null;

            foreach (var shortenedLink in shortenedLinks)
            {
                if (string.IsNullOrEmpty(linksContent))
                {
                    linksContent = "<a href=\"" + shortenedLink + "\">" + shortenedLink + "</a>";
                }
                else
                {
                    linksContent += "<br />or<br /><a href=\"" + shortenedLink + "\">" + shortenedLink + "</a>";
                }
            }
            if (string.IsNullOrEmpty(linksContent))
            {
                linksContent = linksPage;
            }

            Blogger.AddPost(new Blogger.BlogPost(blogTitle, imageCodeBlog, linksContent, linksBackup));

            var content = blogTitle + Environment.NewLine + Environment.NewLine +
                          "<div style='text-align: center;'>" +
                          imageCodeBlog +
                          "</div>" +
                          string.Format("Download(Mega.nz, {0}) : < br />< !--more-- > ", SecondHostName) +
                          linksContent
                          + Environment.NewLine + Environment.NewLine +
                          "==" + Environment.NewLine + Environment.NewLine;

            File.AppendAllText(outputPath_blog, content);
        }