public override FileReference SaveImage(Bitmap image)
        {
            var imageFileName = GetFileNameBasedOnTitle(Title, SiteContext.WorkingDirectory);

            fileSystem.SaveImagePng(image, imageFileName);

            var relativePath = ToRelativePath(SiteContext.WorkingDirectory, SiteContext.WorkingDirectory, imageFileName);
            var fileReference = new FileReference(imageFileName, relativePath, false);
            imagesToSave.Add(fileReference);

            return fileReference;
        }
        public override FileReference SaveImage(Bitmap image)
        {
            var imageFileName = GetFileNameBasedOnTitle(Title, siteContext.SiteBasePath);

            using (var stream = new FileStream(imageFileName, FileMode.Create))
            {
                image.Save(stream, ImageFormat.Png);
            }

            var relativePath = "/" + ToRelativePath(siteContext.SiteBasePath, FileName, imageFileName).TrimStart('\\', '/');
            var fileReference = new FileReference(imageFileName, relativePath, true);
            AddFile(fileReference);

            return fileReference;
        }
        public async Task SaveDocumentAs_CopiesAssociatedFiles()
        {
            // arrange
            dialogService.GetFileSavePath(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>()).Returns(@"c:\AnotherPath\Test.md");
            const string content = @"Some text

![Alt](AssociatedImage.png)";
            var fileReference = new FileReference(@"c:\Path\AssociatedImage.png", "AssociatedImage.png", true);
            var doc = new TestMarkpadDocumentBase("Title", content, null, new[]{fileReference}, documentFactory,
                                                  Substitute.For<ISiteContext>(), fileSystem);

            // act
            var document = await documentFactory.SaveDocumentAs(doc);

            // assert
            Assert.Equal(1, document.AssociatedFiles.Count());
            Assert.Equal(@"c:\AnotherPath\AssociatedImage.png", document.AssociatedFiles.Single().FullPath);
            Assert.Equal("AssociatedImage.png", document.AssociatedFiles.Single().RelativePath);
            fileSystem.File.Received().Copy(@"c:\Path\AssociatedImage.png", @"c:\AnotherPath\AssociatedImage.png");
        }
Ejemplo n.º 4
0
        public override FileReference SaveImage(Bitmap image)
        {
            var workingDirectory = SiteContext.WorkingDirectory;
            var imageFileName = GetFileNameBasedOnTitle(Title, workingDirectory);

            image.Save(Path.Combine(workingDirectory, imageFileName), ImageFormat.Png);

            var relativePath = ToRelativePath(workingDirectory, workingDirectory, imageFileName);
            var fileReference = new FileReference(imageFileName, relativePath, false);
            AddFile(fileReference);

            return fileReference;
        }
 public void AddFile(FileReference fileReference)
 {
     associatedFiles.Add(fileReference);
 }