public async Task <IMarkpadDocument> SaveDocumentAs(IMarkpadDocument document) { var path = dialogService.GetFileSavePath("Save As", "*.md", Constants.ExtensionFilter + "|All Files (*.*)|*.*"); if (string.IsNullOrEmpty(path)) { throw new TaskCanceledException("Save As Cancelled"); } await fileSystem.File.WriteAllTextAsync(path, document.MarkdownContent); var siteContext = siteContextGenerator.GetContext(path); var newDocumentAssociatedFiles = new List <FileReference>(); var newFileDirectory = Path.GetDirectoryName(path); foreach (var associatedFile in document.AssociatedFiles) { var newAbsolutePath = Path.Combine(newFileDirectory, associatedFile.RelativePath); var newRelativePath = associatedFile.RelativePath; newAbsolutePath = newAbsolutePath.Replace(document.Title + "_images", Path.GetFileNameWithoutExtension(path) + "_images"); newRelativePath = newRelativePath.Replace(document.Title + "_images", Path.GetFileNameWithoutExtension(path) + "_images"); if (associatedFile.FullPath != newAbsolutePath) { fileSystem.File.Copy(associatedFile.FullPath, newAbsolutePath); } newDocumentAssociatedFiles.Add(new FileReference(newAbsolutePath, newRelativePath, true)); } var newMarkdownFile = new FileMarkdownDocument(path, document.MarkdownContent, siteContext, newDocumentAssociatedFiles, this, eventAggregator, dialogService, fileSystem); return(newMarkdownFile); }
public void Open(IMarkpadDocument document, bool isNew = false) { MarkpadDocument = document; Document.Text = document.MarkdownContent ?? string.Empty; Original = isNew ? null : document.MarkdownContent; Update(); }
public void Open(IMarkpadDocument document) { MarkpadDocument = document; Document.Text = document.MarkdownContent; Original = document.MarkdownContent; Update(); }
public Task <IMarkpadDocument> SaveDocumentAs(IMarkpadDocument document) { var path = dialogService.GetFileSavePath("Save As", "*.md", Constants.ExtensionFilter + "|All Files (*.*)|*.*"); if (string.IsNullOrEmpty(path)) { return(TaskEx.FromResult(document)); } return(NewMarkdownFile(path, document.MarkdownContent)); }
public void SavePage(IMarkpadDocument documentViewModel) { if (documentViewModel == null) return; var dialogService = new DialogService(); var fileName = dialogService.GetFileSavePath(SAVE_TITLE, SAVE_DEFAULT_EXT, SAVE_FILTER); if (string.IsNullOrEmpty(fileName)) return; var markdown = documentViewModel.MarkdownContent; var html = _documentParser.ParseClean(markdown); File.WriteAllText(fileName, html); }
/// <summary> /// Publishes any document /// </summary> /// <param name="postId"></param> /// <param name="document"></param> /// <returns></returns> public Task <IMarkpadDocument> PublishDocument(string postId, 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 categories = new List <string>(); var webDocument = document as WebDocument; if (webDocument != null) { categories = webDocument.Categories; } var pd = new Details { Title = document.Title, Categories = categories.ToArray() }; var detailsResult = windowManager.ShowDialog(new PublishDetailsViewModel(pd, blogs)); if (detailsResult != true) { return(TaskEx.FromResult <IMarkpadDocument>(null)); } var newDocument = new WebDocument(pd.Blog, null, pd.Title, document.MarkdownContent, new FileReference[0], this, webDocumentService.Value, siteContextGenerator.GetWebContext(pd.Blog), fileSystem); foreach (var associatedFile in document.AssociatedFiles) { newDocument.AddFile(new FileReference(associatedFile.FullPath, associatedFile.RelativePath, false)); } return(newDocument.Save()); }
public void SavePage(IMarkpadDocument documentViewModel) { if (documentViewModel == null) { return; } var dialogService = new DialogService(); var fileName = dialogService.GetFileSavePath(SAVE_TITLE, SAVE_DEFAULT_EXT, SAVE_FILTER); if (string.IsNullOrEmpty(fileName)) { return; } var markdown = documentViewModel.MarkdownContent; var html = _documentParser.ParseClean(markdown); File.WriteAllText(fileName, html); }
/// <summary> /// Publishes any document /// </summary> /// <param name="postId"></param> /// <param name="document"></param> /// <returns></returns> public Task <IMarkpadDocument> PublishDocument(string postId, 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 categories = new List <string>(); var webDocument = document as WebDocument; if (webDocument != null) { categories = webDocument.Categories; } var pd = new Details { Title = document.Title, Categories = categories.ToArray() }; var detailsResult = windowManager.ShowDialog(new PublishDetailsViewModel(pd, blogs)); if (detailsResult != true) { return(TaskEx.FromResult <IMarkpadDocument>(null)); } var newDocument = new WebDocument(pd.Blog, null, pd.Title, document.MarkdownContent, this, webDocumentService.Value, siteContextGenerator.GetWebContext(pd.Blog)); return(newDocument.Save()); }
public async Task<IMarkpadDocument> SaveDocumentAs(IMarkpadDocument document) { var path = dialogService.GetFileSavePath("Save As", "*.md", Constants.ExtensionFilter + "|All Files (*.*)|*.*"); if (string.IsNullOrEmpty(path)) throw new TaskCanceledException("Save As Cancelled"); await fileSystem.File.WriteAllTextAsync(path, document.MarkdownContent); var siteContext = siteContextGenerator.GetContext(path); var newDocumentAssociatedFiles = new List<FileReference>(); var newFileDirectory = Path.GetDirectoryName(path); foreach (var associatedFile in document.AssociatedFiles) { var newAbsolutePath = Path.Combine(newFileDirectory, associatedFile.RelativePath); var newRelativePath = associatedFile.RelativePath; newAbsolutePath = newAbsolutePath.Replace(document.Title + "_images", Path.GetFileNameWithoutExtension(path) + "_images"); newRelativePath = newRelativePath.Replace(document.Title + "_images", Path.GetFileNameWithoutExtension(path) + "_images"); if (associatedFile.FullPath != newAbsolutePath) { fileSystem.File.Copy(associatedFile.FullPath, newAbsolutePath); } newDocumentAssociatedFiles.Add(new FileReference(newAbsolutePath, newRelativePath, true)); } var newMarkdownFile = new FileMarkdownDocument(path, document.MarkdownContent, siteContext, newDocumentAssociatedFiles, this, eventAggregator, dialogService, fileSystem); return newMarkdownFile; }
/// <summary> /// Publishes any document /// </summary> /// <param name="postId"></param> /// <param name="document"></param> /// <returns></returns> public Task<IMarkpadDocument> PublishDocument(string postId, 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 categories = new List<string>(); var webDocument = document as WebDocument; if (webDocument != null) categories = webDocument.Categories; var pd = new Details { Title = document.Title, Categories = categories.ToArray()}; var detailsResult = windowManager.ShowDialog(new PublishDetailsViewModel(pd, blogs)); if (detailsResult != true) return TaskEx.FromResult<IMarkpadDocument>(null); var newDocument = new WebDocument(pd.Blog, null, pd.Title, document.MarkdownContent, new FileReference[0], this, webDocumentService.Value, siteContextGenerator.GetWebContext(pd.Blog), fileSystem); foreach (var associatedFile in document.AssociatedFiles) { newDocument.AddFile(new FileReference(associatedFile.FullPath, associatedFile.RelativePath, false)); } return newDocument.Save(); }
public Task<IMarkpadDocument> SaveDocumentAs(IMarkpadDocument document) { var path = dialogService.GetFileSavePath("Save As", "*.md", Constants.ExtensionFilter + "|All Files (*.*)|*.*"); if (string.IsNullOrEmpty(path)) return TaskEx.FromResult(document); return NewMarkdownFile(path, document.MarkdownContent); }
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)); }