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 FileMarkdownDocumentTests() { siteContext = Substitute.For <ISiteContext>(); documentFactory = Substitute.For <IDocumentFactory>(); eventAggregator = Substitute.For <IEventAggregator>(); dialogService = Substitute.For <IDialogService>(); fileSystem = TestObjectMother.GetFileSystem(); documentUnderTest = CreateFileMarkdownDocument(DocumentFilename, "Content"); }
public FileMarkdownDocumentTests() { siteContext = Substitute.For<ISiteContext>(); documentFactory = Substitute.For<IDocumentFactory>(); eventAggregator = Substitute.For<IEventAggregator>(); dialogService = Substitute.For<IDialogService>(); fileSystem = TestObjectMother.GetFileSystem(); documentUnderTest = CreateFileMarkdownDocument(DocumentFilename, "Content"); }
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; }