Exemple #1
0
        SaveResult CreateOrUpdateMetaWebLogPost(WebDocument document, string[] categories, BlogSetting blog)
        {
            var newContent = document.MarkdownContent;
            var proxy      = getMetaWeblog(blog.WebAPI);

            if (document.AssociatedFiles.Count(f => !f.Saved) > 0)
            {
                foreach (var imageToUpload in document.AssociatedFiles.Where(f => !f.Saved))
                {
                    var response = proxy.NewMediaObject(blog, new MediaObject
                    {
                        name = imageToUpload.FullPath,
                        type = "image/png",
                        bits = File.ReadAllBytes(imageToUpload.FullPath)
                    });

                    newContent          = newContent.Replace(imageToUpload.RelativePath, response.url);
                    imageToUpload.Saved = true;
                }
            }

            var newpost = new Post();

            try
            {
                if (string.IsNullOrWhiteSpace(document.Id))
                {
                    var permalink = document.Title;

                    newpost = new Post
                    {
                        permalink   = permalink,
                        title       = document.Title,
                        dateCreated = DateTime.Now,
                        description = blog.Language == "HTML" ? DocumentParser.GetBodyContents(newContent) : newContent,
                        categories  = categories,
                        format      = blog.Language
                    };
                    newpost.postid = proxy.NewPost(blog, newpost, true);
                }
                else
                {
                    newpost             = proxy.GetPost(document.Id, blog);
                    newpost.title       = document.Title;
                    newpost.description = blog.Language == "HTML" ? DocumentParser.GetBodyContents(newContent) : newContent;
                    newpost.categories  = categories;
                    newpost.format      = blog.Language;

                    proxy.EditPost(document.Id, blog, newpost, true);
                }
            }
            catch (WebException ex)
            {
                dialogService.ShowError("Error Publishing", ex.Message, "");
            }
            catch (XmlRpcException ex)
            {
                dialogService.ShowError("Error Publishing", ex.Message, "");
            }
            catch (XmlRpcFaultException ex)
            {
                dialogService.ShowError("Error Publishing", ex.Message, "");
            }

            return(new SaveResult
            {
                Id = newpost.postid.ToString(),
                NewDocumentContent = newContent
            });
        }
        string CreateOrUpdateMetaWebLogPost(
            string postid, string postTitle,
            string[] categories, string content,
            ICollection <string> imagesToUpload,
            BlogSetting blog)
        {
            var proxy = getMetaWeblog(blog.WebAPI);

            if (imagesToUpload.Count > 0)
            {
                foreach (var imageToUpload in imagesToUpload)
                {
                    var response = proxy.NewMediaObject(blog, new MediaObject
                    {
                        name = imageToUpload,
                        type = "image/png",
                        bits = File.ReadAllBytes(imageToUpload)
                    });

                    content = content.Replace(imageToUpload, response.url);
                }
            }

            var newpost = new Post();

            try
            {
                if (string.IsNullOrWhiteSpace(postid))
                {
                    var permalink = postTitle;

                    newpost = new Post
                    {
                        permalink   = permalink,
                        title       = postTitle,
                        dateCreated = DateTime.Now,
                        description = blog.Language == "HTML" ? DocumentParser.GetBodyContents(content) : content,
                        categories  = categories,
                        format      = blog.Language
                    };
                    newpost.postid = proxy.NewPost(blog, newpost, true);
                }
                else
                {
                    newpost             = proxy.GetPost(postid, blog);
                    newpost.title       = postTitle;
                    newpost.description = blog.Language == "HTML" ? DocumentParser.GetBodyContents(content) : content;
                    newpost.categories  = categories;
                    newpost.format      = blog.Language;

                    proxy.EditPost(postid, blog, newpost, true);
                }
            }
            catch (WebException ex)
            {
                dialogService.ShowError("Error Publishing", ex.Message, "");
            }
            catch (XmlRpcException ex)
            {
                dialogService.ShowError("Error Publishing", ex.Message, "");
            }
            catch (XmlRpcFaultException ex)
            {
                dialogService.ShowError("Error Publishing", ex.Message, "");
            }

            return((string)newpost.postid);
        }