Esempio n. 1
0
 public WebMarkdownFile(
     BlogSetting blog, Post post, 
     Func<string, IMetaWeblogService> getMetaWeblog, 
     IDialogService dialogService, 
     IDocumentFactory documentFactory)
     : base(post.title, post.description, blog.BlogName, documentFactory)
 {
     this.blog = blog;
     this.post = post;
     this.getMetaWeblog = getMetaWeblog;
     this.dialogService = dialogService;
 }
        public async Task DeleteDocument(BlogSetting blog, Post post)
        {
            if (blog.WebSourceType == WebSourceType.MetaWebLog)
            {
                await getMetaWeblog(blog.WebAPI).DeletePostAsync((string)post.postid, blog);
                return;
            }
            if (blog.WebSourceType == WebSourceType.GitHub)
            {
                return;
            }

            throw new ArgumentException(string.Format("Unsupported WebSourceType ({0})", blog.WebSourceType));
        }
Esempio n. 3
0
 public string NewPost(BlogSetting settings, Post newpost, bool b)
 {
     return proxy.NewPost(settings.BlogInfo.blogid, settings.Username, settings.Password, newpost, b);
 }
Esempio n. 4
0
 public void EditPost(string postid, BlogSetting settings, Post newpost, bool b)
 {
     proxy.EditPost(postid, settings.Username, settings.Password, newpost, b);
 }
        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
                   };
        }
 public Task<bool> EditPostAsync(string postid, string username, string password, Post post, bool publish)
 {
     return Task<bool>.Factory.FromAsync(BeginEditPost(postid, username, password, post, publish, null, null), EndEditPost);
 }
 public bool EditPost(string postid, string username, string password, Post post, bool publish)
 {
     return (bool)Invoke("EditPost", new object[] { postid, username, password, post, publish });
 }
 public IAsyncResult BeginNewPost(string blogid, string username, string password, Post post, bool publish, AsyncCallback callback, object asyncState)
 {
     return BeginInvoke("NewPost", new object[] { blogid, username, password, post, publish }, this, callback, asyncState);
 }
 public Task<string> NewPostAsync(string blogid, string username, string password, Post post, bool publish)
 {
     return Task<string>.Factory.FromAsync(BeginNewPost(blogid, username, password, post, publish, null, null), EndNewPost);
 }
 public string NewPost(string blogid, string username, string password, Post post, bool publish)
 {
     return (string)Invoke("NewPost", new object[] { blogid, username, password, post, publish });
 }
Esempio n. 11
0
        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 newpost.postid.ToString();
        }
 public Task EditPostAsync(string postid, BlogSetting blog, Post post, bool publish)
 {
     return proxy.EditPostAsync(postid, blog.Username, blog.Password, post, publish);
 }
Esempio n. 13
0
        IMarkpadDocument CreateNewWebMarkdownFile(string postid, string postTitle, string[] categories, string content, BlogSetting blog)
        {
            var proxy = getMetaWeblog(blog.WebAPI);

            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 new WebMarkdownFile(blog, newpost, getMetaWeblog, dialogService, this);
        }
Esempio n. 14
0
        public Task<IMarkpadDocument> PublishDocument(IMarkpadDocument document)
        {
            var blogs = blogService.GetBlogs();
            if (blogs == null || blogs.Count == 0)
            {
                if (!blogService.ConfigureNewBlog("Publish document"))
                    return TaskEx.FromResult<IMarkpadDocument>(null);
                blogs = blogService.GetBlogs();
                if (blogs == null || blogs.Count == 0)
                    return TaskEx.FromResult<IMarkpadDocument>(null);
            }

            var post = new Post();
            var pd = new Details { Title = document.Title, Categories = post.categories };
            var detailsResult = windowManager.ShowDialog(new PublishDetailsViewModel(pd, blogs));
            if (detailsResult != true)
                return TaskEx.FromResult<IMarkpadDocument>(null);

            return TaskEx.Run(() => CreateNewWebMarkdownFile(null, pd.Title, pd.Categories, document.MarkdownContent, pd.Blog));
        }