protected WebSiteContext(BlogSetting blog, IWebDocumentService webDocumentService, IEventAggregator eventAggregator)
 {
     this.blog = blog;
     this.webDocumentService = webDocumentService;
     this.eventAggregator = eventAggregator;
     workingDirectory = Path.Combine(Path.GetTempPath(), blog.BlogName);
 }
 public GithubSiteContext(BlogSetting blog, 
     IWebDocumentService webDocumentService,
     IGithubApi github,
     IEventAggregator eventAggregator) :
     base(blog, webDocumentService, eventAggregator)
 {
     this.github = github;
 }
 public MetaWeblogSiteContext(
     BlogSetting blog,
     Func<string, IMetaWeblogService> getMetaWeblog,
     IWebDocumentService webDocumentService,
     IEventAggregator eventAggregator) : base(blog, webDocumentService, eventAggregator)
 {
     this.getMetaWeblog = getMetaWeblog;
 }
        public WebSiteContext GetWebContext(BlogSetting blog)
        {
            if (blog.WebSourceType == WebSourceType.MetaWebLog)
                return new MetaWeblogSiteContext(blog, getMetaWeblog, webDocumentService, eventAggregator);
            if (blog.WebSourceType == WebSourceType.GitHub)
                return new GithubSiteContext(blog, webDocumentService, github, eventAggregator);

            return null;
        }
Esempio n. 5
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 WebDocumentItem(
     IWebDocumentService webDocumentService,
     IEventAggregator eventAggregator, 
     string id, 
     string title, 
     BlogSetting blog) :
     base(eventAggregator)
 {
     this.webDocumentService = webDocumentService;
     this.id = id;
     this.blog = blog;
     Name = title;
 }
        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));
        }
        public async Task<string> GetDocumentContent(BlogSetting blog, string id)
        {
            if (blog.WebSourceType == WebSourceType.MetaWebLog)
            {
                var post = await getMetaWeblog(blog.WebAPI).GetPostAsync(id, blog);
                return post.description;
            }
            if (blog.WebSourceType == WebSourceType.GitHub)
            {
                return await githubApi.FetchFileContents(blog.Token, blog.Username, blog.WebAPI, id);
            }

            throw BadWebSourceTypeException(blog);            
        }
Esempio n. 9
0
 public WebDocument(
     BlogSetting blog,
     string id,
     string title,
     string content,
     IDocumentFactory documentFactory,
     IWebDocumentService webDocumentService,
     WebSiteContext siteContext) :
     base(title, content, blog.BlogName, documentFactory)
 {
     Id = id;
     this.blog = blog;
     this.webDocumentService = webDocumentService;
     this.siteContext = siteContext;
 }
 public WebDocument(
     BlogSetting blog,
     string id,
     string title,
     string content,
     IEnumerable<FileReference> associatedFiles,
     IDocumentFactory documentFactory,
     IWebDocumentService webDocumentService,
     WebSiteContext siteContext,
     IFileSystem fileSystem) :
     base(title, content, blog.BlogName, associatedFiles, documentFactory, siteContext, fileSystem)
 {
     Id = id;
     this.blog = blog;
     this.webDocumentService = webDocumentService;
 }
        public Task<SaveResult> SaveDocument(BlogSetting blog, WebDocument document)
        {
            if (blog.WebSourceType == WebSourceType.MetaWebLog)
            {
                return TaskEx.Run(() =>
                {
                    var categories = document.Categories.ToArray();
                    return CreateOrUpdateMetaWebLogPost(document, categories, blog);
                });
            }
            if (blog.WebSourceType == WebSourceType.GitHub)
            {
                return CreateOrUpdateGithubPost(document.Title, document.MarkdownContent, document.AssociatedFiles, blog);   
            }

            return TaskEx.Run(new Func<SaveResult>(() =>
            {
                throw BadWebSourceTypeException(blog);
            }));
        }
Esempio n. 12
0
        public Task<string> SaveDocument(BlogSetting blog, WebDocument document)
        {
            if (blog.WebSourceType == WebSourceType.MetaWebLog)
            {
                return TaskEx.Run(() =>
                {
                    var categories = document.Categories.ToArray();
                    return CreateOrUpdateMetaWebLogPost(document.Id, document.Title, categories, document.MarkdownContent,
                                                 document.ImagesToSaveOnPublish, blog);
                });
            }
            if (blog.WebSourceType == WebSourceType.GitHub)
            {
                return CreateOrUpdateGithubPost(document.Title, document.MarkdownContent, document.ImagesToSaveOnPublish, blog);   
            }

            return TaskEx.Run(new Func<string>(() =>
            {
                throw BadWebSourceTypeException(blog);
            }));
        }
Esempio n. 13
0
 public Post GetPost(string postid, BlogSetting settings)
 {
     return proxy.GetPost(postid, settings.Username, settings.Password);
 }
Esempio n. 14
0
 public void EditPost(string postid, BlogSetting settings, Post newpost, bool b)
 {
     proxy.EditPost(postid, settings.Username, settings.Password, newpost, b);
 }
Esempio n. 15
0
        public async Task<IMarkpadDocument> OpenBlogPost(BlogSetting blog, string id, string name)
        {
            var metaWeblogSiteContext = siteContextGenerator.GetWebContext(blog);

            var content = await webDocumentService.Value.GetDocumentContent(blog, id);

            return new WebDocument(blog, id, name, content, new FileReference[0], this, webDocumentService.Value, metaWeblogSiteContext, fileSystem);
        }
        async Task<SaveResult> CreateOrUpdateGithubPost(string postTitle, string content, IEnumerable<FileReference> referencedFiles, BlogSetting blog)
        {
            var treeToUpload = new GitTree();
            var imagesToUpload = referencedFiles.Where(f=>!f.Saved).ToList();
            if (imagesToUpload.Count > 0)
            {
                foreach (var imageToUpload in imagesToUpload)
                {
                    var imageContent = Convert.ToBase64String(File.ReadAllBytes(imageToUpload.FullPath));
                    var item = new GitFile
                    {
                        type = "tree",
                        path = imageToUpload.FullPath,
                        mode = ((int)GitTreeMode.SubDirectory),
                        content = imageContent
                    };

                    treeToUpload.tree.Add(item);
                }
            }

            var gitFile = new GitFile
            {
                path = postTitle,
                content = content,
                mode = (int)GitTreeMode.File,
                type = "blob"
            };
            treeToUpload.tree.Add(gitFile);

            var newTree = await githubApi.NewTree(blog.Token, blog.Username, blog.WebAPI, blog.BlogInfo.blogid, treeToUpload);
            var uploadedFile = newTree.Item1.tree.Single(t => t.path == gitFile.path);
            foreach (var fileReference in imagesToUpload)
            {
                fileReference.Saved = true;
            }

            return new SaveResult
                   {
                       Id = uploadedFile.sha,
                       NewDocumentContent = content
                   };
        }
 public Task<bool> DeletePostAsync(string postid, BlogSetting blog)
 {
     return proxy.DeletePostAsync(string.Empty, postid, blog.Username, blog.Password, false);
 }
 static ArgumentException BadWebSourceTypeException(BlogSetting blog)
 {
     return new ArgumentException(string.Format("WebSource Type is invalid ({0})", blog.WebSourceType));
 }
 public Task<MediaObjectInfo> NewMediaObjectAsync(BlogSetting blog, MediaObject mediaObject)
 {
     return proxy.NewMediaObjectAsync(blog.BlogInfo.blogid, blog.Username, blog.Password, mediaObject);
 }
        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<Post> GetPostAsync(string postid, BlogSetting settings)
 {
     return proxy.GetPostAsync(postid, settings.Username, settings.Password);
 }
Esempio n. 22
0
 public Task<Post[]> GetRecentPostsAsync(BlogSetting settings, int i)
 {
     return proxy.GetRecentPostsAsync(settings.BlogInfo.blogid, settings.Username, settings.Password, i);
 }
Esempio n. 23
0
 public string NewPost(BlogSetting settings, Post newpost, bool b)
 {
     return proxy.NewPost(settings.BlogInfo.blogid, settings.Username, settings.Password, newpost, b);
 }
 public Task EditPostAsync(string postid, BlogSetting blog, Post post, bool publish)
 {
     return proxy.EditPostAsync(postid, blog.Username, blog.Password, post, publish);
 }
Esempio n. 25
0
        async Task<string> CreateOrUpdateGithubPost(string postTitle, string content, 
            ICollection<string> imagesToUpload, BlogSetting blog)
        {
            var treeToUpload = new GitTree();
            if (imagesToUpload.Count > 0)
            {
                foreach (var imageToUpload in imagesToUpload)
                {
                    var imageContent = Convert.ToBase64String(File.ReadAllBytes(imageToUpload));
                    var item = new GitFile
                    {
                        type = "tree",
                        path = imageToUpload,
                        mode = ((int)GitTreeMode.SubDirectory),
                        content = imageContent
                    };
                    treeToUpload.tree.Add(item);
                }
            }

            var gitFile = new GitFile
            {
                path = postTitle,
                content = content,
                mode = (int)GitTreeMode.File,
                type = "blob"
            };
            treeToUpload.tree.Add(gitFile);

            var newTree = await githubApi.NewTree(blog.Token, blog.Username, blog.WebAPI, blog.BlogInfo.blogid, treeToUpload);
            var uploadedFile = newTree.Item1.tree.Single(t => t.path == gitFile.path);
            return uploadedFile.sha;
        }
Esempio n. 26
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();
        }
Esempio n. 27
0
 public Task<BlogInfo[]> GetUsersBlogsAsync(BlogSetting settings)
 {
     return proxy.GetUsersBlogsAsync("MarkPad", settings.Username, settings.Password);
 }
 public MediaObjectInfo NewMediaObject(BlogSetting blog, MediaObject mediaObject)
 {
     return proxy.NewMediaObject(blog.BlogInfo.blogid, blog.Username, blog.Password, mediaObject);
 }
 public void InitializeBlog(BlogSetting blog)
 {
     CurrentBlog = blog;
 }
Esempio n. 30
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);
        }