public void GetPostTest() { var weblogInfo = new WeblogInfo { ApiUrl = STR_JEKYLL_PROJECT_FOLDER, Name = "Jekyll Test Blog" }; var pub = new LocalJekyllPublisher(null, weblogInfo, null); var post = pub.GetPost(STR_JEKYLL_POST_ID); Assert.IsNotNull(post); Assert.IsNotNull(post.Body); }
/// <summary> /// Returns a Post by Id /// </summary> /// <param name="postId"></param> /// <param name="weblogInfo"></param> /// <returns></returns> public Post GetPost(string postId, WeblogInfo weblogInfo) { if (weblogInfo.Type == WeblogTypes.MetaWeblogApi || weblogInfo.Type == WeblogTypes.Wordpress) { MetaWebLogWordpressApiClient client; client = new MetaWebLogWordpressApiClient(weblogInfo); return(client.GetPost(postId)); } if (weblogInfo.Type == WeblogTypes.LocalJekyll) { var pub = new LocalJekyllPublisher(null, weblogInfo, null); return(pub.GetPost(postId)); } // Medium doesn't support post retrieval so return null return(null); }
private async Task CreateDownloadedPost() { var item = ListViewPosts.SelectedItem as Post; if (item == null) { return; } WeblogInfo weblogInfo = Model.ActiveWeblogInfo; StatusBar.ShowStatusProgress("Downloading Weblog post '" + item.Title + "'"); string postId = item.PostId?.ToString(); Post post = null; if (weblogInfo.Type == WeblogTypes.MetaWeblogApi) { var wrapper = new MetaWeblogWrapper(weblogInfo.ApiUrl, weblogInfo.Username, mmApp.DecryptString(weblogInfo.Password), weblogInfo.BlogId); try { post = await Task.Run(() => wrapper.GetPost(postId)); } catch (Exception ex) { StatusBar.ShowStatusError("Unable to download post.\r\n\r\n" + ex.Message); return; } Model.Addin.CreateDownloadedPostOnDisk(post, weblogInfo.Name); } else if (weblogInfo.Type == WeblogTypes.Wordpress) { var wrapper = new WordPressWrapper(weblogInfo.ApiUrl, weblogInfo.Username, mmApp.DecryptString(weblogInfo.Password)); try { post = wrapper.GetPost(postId); } catch (Exception ex) { StatusBar.ShowStatus(); StatusBar.ShowStatusError("Unable to download post.\r\n\r\n" + ex.Message); return; } Model.Addin.CreateDownloadedPostOnDisk(post, weblogInfo.Name); } else if (weblogInfo.Type == WeblogTypes.LocalJekyll) { var pub = new LocalJekyllPublisher(null, weblogInfo, null); post = pub.GetPost(postId); if (post == null) { StatusBar.ShowStatusError("Unable to import post from Jekyll."); return; } string outputFile = pub.CreateDownloadedPostOnDisk(post, weblogInfo.Name); mmApp.Model.Window.OpenTab(outputFile); mmApp.Model.Window.ShowFolderBrowser(folder: Path.GetDirectoryName(outputFile)); } Close(); StatusBar.ShowStatusSuccess("Post has been imported into Markdown Monster Web log Posts."); }