コード例 #1
0
        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);
        }
コード例 #2
0
        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");
        }
コード例 #3
0
        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");
        }
コード例 #4
0
        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;
        }