Skip to content

Commit

Permalink
重构代码
Browse files Browse the repository at this point in the history
  • Loading branch information
oldrev committed Feb 6, 2017
1 parent 773f0e0 commit 9b6b13c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Sandwych.Reporting.Test/OpenDocument/OdtTemplateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ public void TestStatements()
[Test]
public void UseImageShouldBeOk()
{
var image1Path = TemplateTestHelper.GetTestResourceAbsolutleFilePath("resources/go-home.PNG");
var ctx = new Dictionary<string, object>() {
{ "image1", new Image("png", File.ReadAllBytes("resources/go-home.PNG")) },
{ "image1", new Image("png", File.ReadAllBytes(image1Path)) },
};

var result = OdfTemplateTestHelper.RenderTemplate(
Expand Down
18 changes: 8 additions & 10 deletions Sandwych.Reporting/OpenDocument/OdfTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,20 @@ public override void Save(Stream outStream)
throw new ArgumentNullException("outStream");
}

//ODF 格式约定 mimetype 必须为第一个文件
//ODF 格式约定 mimetype 必须为 ZIP 包里的第一个文件
if (!this.entries.ContainsKey(MimeTypeEntryPath))
{
throw new InvalidDataException("Entry 'mimetype' not found");
}

using (var ze = new ZipArchive(outStream, ZipArchiveMode.Create))
using (var zip = new ZipArchive(outStream, ZipArchiveMode.Create))
{
this.AppendZipEntry(ze, MimeTypeEntryPath);
this.AppendZipEntry(zip, MimeTypeEntryPath);
this.entries.Remove(MimeTypeEntryPath);

foreach (var item in this.entries)
{
if (item.Key == MimeTypeEntryPath)
{
continue;
}

this.AppendZipEntry(ze, item.Key);
this.AppendZipEntry(zip, item.Key);
}
}
}
Expand All @@ -102,11 +98,13 @@ private void AppendZipEntry(ZipArchive archive, string name)
case "JPEG":
case "JPG":
case "PNG":
case "MP3":
case "MP4":
cl = CompressionLevel.NoCompression;
break;

default:
cl = CompressionLevel.Optimal;
cl = CompressionLevel.Fastest;
break;
}
var zae = archive.CreateEntry(name, cl);
Expand Down

0 comments on commit 9b6b13c

Please sign in to comment.