public static async Task AppendToEntry(bool writeWithSpans) { //append Stream testArchive = await StreamHelpers.CreateTempCopyStream(zfile("normal.zip")); using (ZipArchive archive = new ZipArchive(testArchive, ZipArchiveMode.Update, true)) { ZipArchiveEntry e = archive.GetEntry("first.txt"); using (Stream s = e.Open()) { s.Seek(0, SeekOrigin.End); byte[] data = Encoding.ASCII.GetBytes("\r\n\r\nThe answer my friend, is blowin' in the wind."); if (writeWithSpans) { s.Write(data, 0, data.Length); } else { s.Write(new ReadOnlySpan <byte>(data)); } } var file = FileData.GetFile(zmodified(Path.Combine("append", "first.txt"))); e.LastWriteTime = file.LastModifiedDate; } IsZipSameAsDir(testArchive, zmodified("append"), ZipArchiveMode.Read, requireExplicit: true, checkTimes: true); }
public void GenerateReport(int id) { EntityDTO dto = entityData.GetOneEntity(id); dto.ExtractProperties(); FileDTO file = filesData.GetFile(dto.DGXFileName); byte[] diagram = file.Data; //Save the raw .wmf file int poolCount = entityData.GetPoolCount(dto.ID); this.imageManager = new WmfImageManager(dto, diagram, dto.DGXFileName, dto.Type, poolCount, true); string resizedDiagram = imageManager.SaveAndResizeImage(diagram, dto.DGXFileName, dto.Type, poolCount, true); string[] images = new string[] { PathResolver.MapPath(resizedDiagram) }; if (poolCount > 1 && dto.Type == 142) { //slice the wmf SubProcessSlicer slicer = new SubProcessSlicer(resizedDiagram); images = slicer.Slice(); } List <PdfContentParameter> contents = ReportBuilder.BuildReport(dto); byte[] pdfBytes = PDFBuilder.CreatePDF(contents, images, dto.Type); this.view.RenderReport(pdfBytes); }
public static async Task OverwriteEntry() { //Overwrite file Stream testArchive = await StreamHelpers.CreateTempCopyStream(zfile("normal.zip")); using (ZipArchive archive = new ZipArchive(testArchive, ZipArchiveMode.Update, true)) { string fileName = zmodified(Path.Combine("overwrite", "first.txt")); ZipArchiveEntry e = archive.GetEntry("first.txt"); var file = FileData.GetFile(fileName); e.LastWriteTime = file.LastModifiedDate; using (var stream = await StreamHelpers.CreateTempCopyStream(fileName)) { using (Stream es = e.Open()) { es.SetLength(0); stream.CopyTo(es); } } } IsZipSameAsDir(testArchive, zmodified("overwrite"), ZipArchiveMode.Read, requireExplicit: true, checkTimes: true); }
protected override string BuildDiagramImage(EntityDTO dto) { StringBuilder html = new StringBuilder(); EntityData data = new EntityData(); FileData files = new FileData(); FileDTO file = files.GetFile(dto.DGXFileName); byte[] imageBytes = file.Data; string path = string.Format("{0}_{1}", file.Date.ToFileTime().ToString(), dto.DGXFileName); int poolCount = data.GetPoolCount(dto.ID); WmfImageManager imageManager = new WmfImageManager(dto, imageBytes, path, dto.Type, poolCount, false); path = imageManager.ProcessImage(); html.Append("<div id=\"diagram-line\" class=\"clearfix\">"); html.Append("<div id=\"diagram-line-left\" class=\"infoBox\">To navigate to the related process and sub-process of this diagram, use the menu on the right.<br/>To navigate related informations, select the tabs above.</div>"); if (dto.Type == 111) { html.Append(BuildQuickLinks(dto)); } html.Append("<div style=\"clear: both;\"></div>"); html.Append("</div>"); html.AppendFormat(GlobalStringResource.Presenter_BuildDiagramImage_Tag, path.Replace(@"\", @"/")); html.Append(GlobalStringResource.BreakTag); return(html.ToString()); }
public string BuildDiagramContent(EntityDTO dto) { EntityData data = new EntityData(); FileData files = new FileData(); FileDTO file = files.GetFile(dto.DGXFileName); byte[] imageBytes = file.Data; string path = string.Format("{0}_{1}", file.Date.ToFileTime().ToString(), dto.DGXFileName); int poolCount = data.GetPoolCount(dto.ID); WmfImageManager imageManager = new WmfImageManager(dto, imageBytes, path, dto.Type, poolCount, false); path = imageManager.ProcessImage(); return(path.Replace(@"\", @"/")); }
private static async Task UpdateArchive(ZipArchive archive, string installFile, string entryName) { string fileName = installFile; ZipArchiveEntry e = archive.CreateEntry(entryName); var file = FileData.GetFile(fileName); e.LastWriteTime = file.LastModifiedDate; using (var stream = await StreamHelpers.CreateTempCopyStream(fileName)) { using (Stream es = e.Open()) { es.SetLength(0); stream.CopyTo(es); } } }
public Object GetCopy(Int32 copyCode = 0) { Object result = null; String uri = TnModel.GetRegCopyUri(copyCode); Int32 index = uri.IndexOf('}'); if (index >= 0) { String alias = uri.Substring(1, index - 1); String path = uri.Substring(index + 1, uri.Length - index - 1); FileData fd = FileData.GetFile(alias, path); if (fd != null && fd.Contents != null) { result = File(fd.Contents, fd.ContentType, fd.Name); } } return(result); }
public static async Task UpdateZipArchive_OverwriteCorruptedEntry() { MemoryStream stream = await StreamHelpers.CreateTempCopyStream(zfile("normal.zip")); int updatedUncompressedLength = 1310976; string overwrite = "\r\n\r\nThe answer my friend, is blowin' in the wind."; byte[] data = Encoding.ASCII.GetBytes(overwrite); int nameOffset = PatchDataRelativeToFileName(Encoding.ASCII.GetBytes(s_tamperedFileName), stream, 8); // patch uncompressed size in file header PatchDataRelativeToFileName(Encoding.ASCII.GetBytes(s_tamperedFileName), stream, 22, nameOffset + s_tamperedFileName.Length); // patch in central directory too using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Update, true)) { ZipArchiveEntry e = archive.GetEntry(s_tamperedFileName); string fileName = zmodified(Path.Combine("overwrite", "first.txt")); var file = FileData.GetFile(fileName); using (var s = new MemoryStream(data)) using (Stream es = e.Open()) { Assert.Equal(updatedUncompressedLength, es.Length); es.SetLength(0); await s.CopyToAsync(es, s_bufferSize); Assert.Equal(data.Length, es.Length); } } using (ZipArchive modifiedArchive = new ZipArchive(stream, ZipArchiveMode.Read)) { ZipArchiveEntry e = modifiedArchive.GetEntry(s_tamperedFileName); using (Stream s = e.Open()) using (var ms = new MemoryStream()) { await s.CopyToAsync(ms, s_bufferSize); Assert.Equal(data.Length, ms.Length); Assert.Equal(overwrite, Encoding.ASCII.GetString(ms.GetBuffer(), 0, data.Length)); } } }
public Object Index(String alias) { Object result = null; if (Request.Form.Count > 0) { Dictionary <String, String> pars = new Dictionary <String, String>(Request.Form.Count); for (int i = 0; i < Request.Form.Count; i++) { pars.Add(Request.Form.Keys[i], Request.Form.GetValues(i)[0]); } if (pars.ContainsKey("cmd")) { String html; String path = Utility.UnEscape(pars["path"]); switch (pars["cmd"]) { case "GetFileInfo": html = "GetFileInfo: '" + path + "'"; //html = FileTree.GetFileInfo(alias, path); result = html; break; case "GetDirectoryInfo": Guid sessionId = new Guid(); html = FileTree.RenderDirectoryTree(sessionId, alias, path); result = html; break; case "DownloadFile": FileData fd = FileData.GetFile(alias, path); result = File(fd.Contents, fd.ContentType, fd.Name); break; default: break; } } } return(result); }
protected string BuildDiagramImageReturningPath(EntityDTO dto) { StringBuilder html = new StringBuilder(); EntityData data = new EntityData(); FileData files = new FileData(); FileDTO file = files.GetFile(dto.DGXFileName); byte[] imageBytes = file.Data; string path = string.Format("{0}_{1}", file.Date.ToFileTime().ToString(), dto.DGXFileName); int poolCount = data.GetPoolCount(dto.ID); WmfImageManager imageManager = new WmfImageManager(dto, imageBytes, path, dto.Type, poolCount, false); path = imageManager.ProcessImage(); return(path); }
public static async Task AppendToEntry() { //append Stream testArchive = await StreamHelpers.CreateTempCopyStream(zfile("normal.zip")); using (ZipArchive archive = new ZipArchive(testArchive, ZipArchiveMode.Update, true)) { ZipArchiveEntry e = archive.GetEntry("first.txt"); using (StreamWriter s = new StreamWriter(e.Open())) { s.BaseStream.Seek(0, SeekOrigin.End); s.Write("\r\n\r\nThe answer my friend, is blowin' in the wind."); } var file = FileData.GetFile(zmodified(Path.Combine("append", "first.txt"))); e.LastWriteTime = file.LastModifiedDate; } IsZipSameAsDir(testArchive, zmodified("append"), ZipArchiveMode.Read, requireExplicit: true, checkTimes: true); }
/// <summary> /// /// </summary> /// <param name="dto"></param> /// <returns></returns> protected virtual string BuildDiagramImage(EntityDTO dto) { StringBuilder html = new StringBuilder(); EntityData data = new EntityData(); FileData files = new FileData(); FileDTO file = files.GetFile(dto.DGXFileName); byte[] imageBytes = file.Data; string path = string.Format("{0}_{1}", file.Date.ToFileTime().ToString(), dto.DGXFileName); int poolCount = data.GetPoolCount(dto.ID); WmfImageManager imageManager = new WmfImageManager(dto, imageBytes, path, dto.Type, poolCount, false); path = imageManager.ProcessImage(); html.AppendFormat(GlobalStringResource.Presenter_BuildDiagramImage_Tag, path.Replace(@"\", @"/")); html.Append(GlobalStringResource.BreakTag); return(html.ToString()); }
public static async Task UpdateModifications() { //delete and move var testArchive = await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("normal.zip")); using (ZipArchive archive = new ZipArchive(testArchive, ZipArchiveMode.Update, true)) { ZipArchiveEntry toBeDeleted = archive.GetEntry("binary.wmv"); toBeDeleted.Delete(); toBeDeleted.Delete(); //delete twice should be okay ZipArchiveEntry moved = archive.CreateEntry("notempty/secondnewname.txt"); ZipArchiveEntry orig = archive.GetEntry("notempty/second.txt"); using (Stream origMoved = orig.Open(), movedStream = moved.Open()) { origMoved.CopyTo(movedStream); } moved.LastWriteTime = orig.LastWriteTime; orig.Delete(); } ZipTest.IsZipSameAsDir(testArchive, ZipTest.zmodified("deleteMove"), ZipArchiveMode.Read, false, false); //append testArchive = await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("normal.zip")); using (ZipArchive archive = new ZipArchive(testArchive, ZipArchiveMode.Update, true)) { ZipArchiveEntry e = archive.GetEntry("first.txt"); using (StreamWriter s = new StreamWriter(e.Open())) { s.BaseStream.Seek(0, SeekOrigin.End); s.Write("\r\n\r\nThe answer my friend, is blowin' in the wind."); } e.LastWriteTime = new DateTimeOffset(2010, 7, 7, 11, 57, 18, new TimeSpan(-7, 0, 0)); } ZipTest.IsZipSameAsDir(testArchive, ZipTest.zmodified("append"), ZipArchiveMode.Read, false, false); //Overwrite file testArchive = await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("normal.zip")); using (ZipArchive archive = new ZipArchive(testArchive, ZipArchiveMode.Update, true)) { String fileName = ZipTest.zmodified(Path.Combine("overwrite", "first.txt")); ZipArchiveEntry e = archive.GetEntry("first.txt"); var file = FileData.GetFile(fileName); e.LastWriteTime = file.LastModifiedDate; using (var stream = await StreamHelpers.CreateTempCopyStream(fileName)) { using (Stream es = e.Open()) { es.SetLength(0); stream.CopyTo(es); } } } ZipTest.IsZipSameAsDir(testArchive, ZipTest.zmodified("overwrite"), ZipArchiveMode.Read, false, false); }