async private void DoGenerateZip(object obj) { try { WorkInProgress = true; if (DeliveryBatch != null) { DeliveryInProgress = Visibility.Visible; var result = await RestHub.GenerateZIP(DeliveryBatch.Id, MaxZipSize * 1000 * 1000); if (result.HttpCode == System.Net.HttpStatusCode.OK) { ZipResultDTO zipResult = (ZipResultDTO)result.UserObject; ZipResult.ShowResult(zipResult); } else { AppErrorBox.ShowErrorMessage("Error While Generating ZIP . .", result.HttpResponse); } DeliveryInProgress = Visibility.Hidden; } else { MessageBox.Show("From Batch, From Category, Delivery Batch Number Is Required . . ."); } WorkInProgress = false; } catch (Exception ex) { Log.This(ex); } }
public void ZipFiles_NoFiles_NoZip() { FileZipper zipper = new FileZipper(); ZipResult zipResult = zipper.ZipFiles(Enumerable.Empty <string>()); Assert.IsNull(zipResult); }
public void ZipFiles_OneFile_ZipResult() { FileZipper zipper = new FileZipper(); var readme = Path.Combine(GetTestLogDirectoryPath(), "readme.txt"); ZipResult zipResult = zipper.ZipFiles(new[] { readme }); Assert.IsNotNull(zipResult); }
public void ZipFiles_OneFile_ZipResultContainsFileLog() { FileZipper zipper = new FileZipper(); var readmeTxt = "readme.txt"; var fullPath = Path.Combine(GetTestLogDirectoryPath(), readmeTxt); ZipResult zipResult = zipper.ZipFiles(new[] { fullPath }); Assert.AreEqual(readmeTxt, zipResult.Entries[0]); }
public void ZipFiles_OneFile_ZipResultContainsFile() { FileZipper zipper = new FileZipper(); var readmeTxt = "readme.txt"; var fullPath = Path.Combine(GetTestLogDirectoryPath(), readmeTxt); ZipResult zipResult = zipper.ZipFiles(new[] { fullPath }); var entry = this.GetEntry(zipResult.ZipStream, readmeTxt); Assert.IsNotNull(entry); }
/// <summary> /// Download an Album converting a list of Images in a zip file /// </summary> /// <param name="id">The identity of the Album</param> /// <returns>The zip file with all the images in Album</returns> public ActionResult DownloadAlbum(int id) { ZipResult result = new ZipResult(MediaServices.GetImagePathsForDownload(id, HttpContext.Server)); Album album = AlbumServices.FindAllEntities(a => a.AlbumId == id, null, null).FirstOrDefault(); if (album != null) { result.FileName = album.Name.Replace(" ", "_") + ".zip"; } return(result); }
public void OnClickZip() { #if !UNITY_EDITOR return; #endif ZipCB = new ZipResult(); sTime = Time.realtimeSinceStartup; string[] paths = { Path.Combine(Application.dataPath, "UI/") }; ZipHelper.Zip(paths, Path.Combine(Application.dataPath, "StreamingAssets/UI.zip"), null, ZipCB); }
public void ZipFiles_OneFile_ZipResultContainsFileWithCorrectContent() { FileZipper zipper = new FileZipper(); var readmeTxt = "readme.txt"; var fullPath = Path.Combine(GetTestLogDirectoryPath(), readmeTxt); ZipResult zipResult = zipper.ZipFiles(new[] { fullPath }); var entry = this.GetEntry(zipResult.ZipStream, readmeTxt); StreamReader reader = new StreamReader(entry.GetStream()); string text = reader.ReadToEnd(); Assert.AreEqual("TEST_SUCCESS", text); }
public void SendMail_MailMessageNullResult_BodySaysNoFiles() { MailServiceStub mailService = new MailServiceStub(); Mailer mailer = new Mailer(mailService); ZipResult result = null; string subject = "this is the subject"; mailer.SendZip(result, emailAddress, emailAddress, subject, this.attachmentName); var mailMessage = mailService.MailMessage; Assert.IsTrue(mailMessage.Body.Contains("No files found for range specified")); }
public void ZipFiles_ManyFiles_ZipResultContainsMultipleFileEntries() { var files = Directory.GetFiles(GetTestLogDirectoryPath(), "*.txt"); Assert.Greater(files.Length, 5, "Missing Files for testing"); FileZipper zipper = new FileZipper(); using (ZipResult zipResult = zipper.ZipFiles(files)) { Assert.AreEqual(files.Length, zipResult.Entries.Count()); } }
public void SendMail_MailMessageCorrectEmailTo() { MailServiceStub mailService = new MailServiceStub(); Mailer mailer = new Mailer(mailService); ZipResult result = new ZipResult() { Entries = new string[0], ZipStream = new MemoryStream() }; string emailAddressto = "*****@*****.**"; string subject = "this is the subject"; mailer.SendZip(result, emailAddressto, emailAddress, subject, this.attachmentName); Assert.AreEqual(emailAddressto, mailService.MailMessage.To.First().Address); }
public void SendMail_MailMessageSent() { Mock <IMailService> mailMock = new Mock <IMailService>(); Mailer mailer = new Mailer(mailMock.Object); ZipResult result = new ZipResult() { Entries = new string[0], ZipStream = new MemoryStream() }; string emailAddress = "*****@*****.**"; string subject = "This is the subject"; mailer.SendZip(result, emailAddress, emailAddress, subject, this.attachmentName); mailMock.Verify(service => service.SendMessage(It.IsAny <MailMessage>())); }
/// <summary> /// Key: nombre /// Value: xmlString /// </summary> /// <param name="listaXmls"></param> /// <returns></returns> public static ZipResult ZipResult(List<KeyValuePair<string, string>> listaXmls, string fileName) { var xml = new XmlDocument(); xml.LoadXml(listaXmls.ElementAt(0).Value); var result = new ZipResult(String.Format("{0}.xml", listaXmls.ElementAt(0).Key), GetBytesFromXmlDocument(xml)); for (int i = 1; i < listaXmls.Count; i++) { var elto = listaXmls.ElementAt(i); var nuevo = new XmlDocument(); nuevo.LoadXml(elto.Value); result.AddFile(String.Format("{0}.xml", elto.Key), GetBytesFromXmlDocument(nuevo)); } result.FileDownloadName = fileName; return result; }
public void SendMail_MailMessageFileAttached() { MailServiceStub mailService = new MailServiceStub(); Mailer mailer = new Mailer(mailService); ZipResult result = new ZipResult() { Entries = new string[0], ZipStream = new MemoryStream() }; string subject = "this is the subject"; mailer.SendZip(result, emailAddress, emailAddress, subject, this.attachmentName); var attachmentCollection = mailService.MailMessage.Attachments; Assert.AreEqual(1, attachmentCollection.Count); }
public void SendMail_MailMessageNoStream_NoAttachment() { MailServiceStub mailService = new MailServiceStub(); Mailer mailer = new Mailer(mailService); ZipResult result = new ZipResult() { Entries = new string[0], ZipStream = null }; string subject = "this is the subject"; mailer.SendZip(result, emailAddress, emailAddress, subject, this.attachmentName); var mailMessage = mailService.MailMessage; Assert.IsEmpty(mailMessage.Attachments, "Shouldn't be any attachments"); }
/// <summary> /// Key: nombre /// Value: xmlString /// </summary> /// <param name="listaXmls"></param> /// <returns></returns> public static ZipResult ZipResult(List <KeyValuePair <string, string> > listaXmls, string fileName) { var xml = new XmlDocument(); xml.LoadXml(listaXmls.ElementAt(0).Value); var result = new ZipResult(String.Format("{0}.xml", listaXmls.ElementAt(0).Key), GetBytesFromXmlDocument(xml)); for (int i = 1; i < listaXmls.Count; i++) { var elto = listaXmls.ElementAt(i); var nuevo = new XmlDocument(); nuevo.LoadXml(elto.Value); result.AddFile(String.Format("{0}.xml", elto.Key), GetBytesFromXmlDocument(nuevo)); } result.FileDownloadName = fileName; return(result); }
public void SendMail_MailMessageCorrectSubject() { MailServiceStub mailService = new MailServiceStub(); Mailer mailer = new Mailer(mailService); var memoryStream = new MemoryStream(); ZipResult result = new ZipResult() { Entries = new string[0], ZipStream = memoryStream }; string subject = "this is the subject"; mailer.SendZip(result, emailAddress, emailAddress, subject, this.attachmentName); var mailMessage = mailService.MailMessage; Assert.AreEqual(subject, mailMessage.Subject); }
public void SendMail_MailMessageMessageBodySet() { MailServiceStub mailService = new MailServiceStub(); Mailer mailer = new Mailer(mailService); var thisisoneTxt = "thisisone.txt"; ZipResult result = new ZipResult() { Entries = new[] { thisisoneTxt }, ZipStream = new MemoryStream() }; string subject = "this is the subject"; mailer.SendZip(result, emailAddress, emailAddress, subject, this.attachmentName); var body = mailService.MailMessage.Body; Assert.IsTrue(body.Contains(thisisoneTxt), "Message body does not contain the entry " + thisisoneTxt); }
public void SendMail_MailMessageCorrectFileAttached() { MailServiceStub mailService = new MailServiceStub(); Mailer mailer = new Mailer(mailService); var memoryStream = new MemoryStream(); ZipResult result = new ZipResult() { Entries = new string[0], ZipStream = memoryStream }; string subject = "this is the subject"; mailer.SendZip(result, emailAddress, emailAddress, subject, this.attachmentName); var attachmentCollection = mailService.MailMessage.Attachments; Assert.AreSame(memoryStream, attachmentCollection.First().ContentStream); }
private IEnumerator unZip(List <DownLoadFile> list) { if (!verInfo.IsReleaseVer) { LuaInterface.Debugger.Log(string.Format("--unZip--listcount: {0}", list.Count)); } if (!checkFiles(list)) { //文件校验失败,重新下载 showMsg("取消", delegate { closeMessageBox(); Application.Quit(); }, "文件校验失败,是否重新下载", "确定", delegate { closeMessageBox(); if (versionReqCor != null) { StopCoroutine(versionReqCor); versionReqCor = StartCoroutine(versionReq()); } }); yield break; } yield return(null); if (slider != null) { slider.gameObject.SetActive(true); } for (int i = 0; i < list.Count; i++) { if (!downSizeLab.gameObject.activeSelf) { downSizeLab.gameObject.SetActive(true); downSizeLab.text = string.Format("正在解压:{0}/{1}", i, list.Count); yield return(new WaitForSeconds(0.5f)); } string gzipFileUrl = list[i].localFile; if (File.Exists(gzipFileUrl)) { string[] arraytemp = gzipFileUrl.Split('/'); string gzipFileName = arraytemp[arraytemp.Length - 1]; string gzipFilePath = gzipFileUrl.Replace(gzipFileName, ""); ZipResult zipResult = new ZipResult(); ZipHelper.Decompress(string.Format("{0}{1}", gzipFilePath, gzipFileName), gzipFilePath, ref zipResult); if (zipResult.Errors) { if (!verInfo.IsReleaseVer) { LuaInterface.Debugger.LogError("解压结果:失败" + i); } //重新下包。。。 showMsg("取消", delegate { closeMessageBox(); Application.Quit(); }, "解压失败,是否重新解压文件", "确定", delegate { closeMessageBox(); if (unZipCor != null) { StopCoroutine(unZipCor); } unZipCor = StartCoroutine(unZip(list)); }); yield break; } if (downSizeLab != null) { downSizeLab.text = string.Format("正在解压:{0}/{1}", (i + 1), list.Count); yield return(null); if (!verInfo.IsReleaseVer) { LuaInterface.Debugger.Log(string.Format("--->:{0}, {1}", downSizeLab.gameObject.activeSelf, downSizeLab.text)); } } //删除patch压缩包 if (File.Exists(gzipFileUrl)) { File.Delete(gzipFileUrl); } } } verInfo = FileUtils.GetCurrentVerNo(); VersionInfoData.CurrentVersionInfo = verInfo; if (currentVerNoLab != null) { currentVerNoLab.text = string.Format("当前资源版本 {0}", verInfo.VersionNum); } if (downSizeLab != null) { downSizeLab.gameObject.SetActive(false); } if (slider != null) { slider.gameObject.SetActive(false); } if (startGameCor != null) { StopCoroutine(startGameCor); } startGameCor = StartCoroutine(startGame()); }
/// <summary> /// 解压缩文件 /// </summary> /// <param name="GzipFile">压缩包文件名</param> /// <param name="targetPath">解压缩目标路径</param> public static void Decompress(string GzipFile, string targetPath, ref ZipResult zipResult) { zipResult.Errors = false; try { UnityEngine.Debug.Log("开始解压"); string directoryName = targetPath; if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); //生成解压目录 } string CurrentDirectory = directoryName; byte[] data = new byte[2048]; int size = 2048; ZipEntry theEntry = null; ////long zipFileIndex = 0; using (ZipInputStream s = new ZipInputStream(File.OpenRead(GzipFile))) { while ((theEntry = s.GetNextEntry()) != null) { ////if (zipResult.FileCount < theEntry.ZipFileIndex) ////{ //// zipResult.FileCount = theEntry.ZipFileIndex; ////} string dir = (CurrentDirectory + theEntry.Name).Replace("\\", "/"); string[] temp = dir.Split('/'); dir = dir.Replace(temp[temp.Length - 1], ""); DirectoryInfo di = new DirectoryInfo(dir); if (!di.Exists) { di.Create(); } if (theEntry.Name != String.Empty) { // 检查多级目录是否存在 if (theEntry.Name.Contains("//")) { string parentDirPath = theEntry.Name.Remove(theEntry.Name.LastIndexOf("//") + 1); if (!Directory.Exists(parentDirPath)) { Directory.CreateDirectory(CurrentDirectory + parentDirPath); } } //解压文件到指定的目录 using (FileStream streamWriter = File.Create(CurrentDirectory + theEntry.Name)) { while (true) { size = s.Read(data, 0, data.Length); if (size <= 0) { break; } streamWriter.Write(data, 0, size); } streamWriter.Close(); } ////zipFileIndex++; ////zipResult.UnZipPercent = 1f * zipFileIndex / zipResult.FileCount; //UnityEngine.Debug.Log("--UnZipPercent-->" + zipResult.UnZipPercent); } } s.Close(); UnityEngine.Debug.Log("解压成功"); } } catch (Exception ex) { zipResult.Errors = true; UnityEngine.Debug.LogError("解压失败:" + ex.ToString()); } }
//public FileResult Download(string fullpath) //{ //int dot = fullpath.LastIndexOf(".") + 1; //string pattern = fullpath.Substring(dot,fullpath.Length-dot); //string contentType = "application/" + pattern; //int divide=fullpath.LastIndexOf("\\")+1; //string _fullpath=Server.MapPath(fullpath); //string filename = fullpath.Substring(divide, fullpath.Length - divide); //return File(_fullpath, contentType, filename); //} public ActionResult Download(string fullpath) { if (fullpath.IndexOf(",") != -1) { string[] patharray = fullpath.Split(','); string[] folderarray = new string[patharray.Length]; string[] filearrary = new string[patharray.Length]; int i = 0; foreach (string file in patharray) { int folderindex = 0; if (file.IndexOf("[folder]") != -1) { int foldermark = file.IndexOf("[folder]") + 9; string _folderpath = file.Substring(foldermark, file.Length - foldermark); _folderpath = Server.MapPath(_folderpath); folderarray[folderindex++] = _folderpath; } else { int divide = file.LastIndexOf("\\") + 1; string _fullpath = Server.MapPath(file); string filename = file.Substring(divide, file.Length - divide); filearrary[i++] = _fullpath; } } var zipResult = new ZipResult(folderarray, filearrary); zipResult.FileName = "download.zip"; return(zipResult); } else { int folderindex = 0; string[] folderarray = new string[1]; if (fullpath.IndexOf("[folder]") != -1) { int foldermark = fullpath.IndexOf("[folder]") + 9; string _folderpath = fullpath.Substring(foldermark, fullpath.Length - foldermark); _folderpath = Server.MapPath(_folderpath); folderarray[folderindex++] = _folderpath; var zipResult = new ZipResult(folderarray); zipResult.FileName = "download.zip"; return(zipResult); } else { int dot = fullpath.LastIndexOf(".") + 1; string pattern = fullpath.Substring(dot, fullpath.Length - dot); string contentType = "application/" + pattern; int divide = fullpath.LastIndexOf("\\") + 1; string _fullpath = Server.MapPath(fullpath); string filename = fullpath.Substring(divide, fullpath.Length - divide); return(File(_fullpath, contentType, filename)); } } }
/// <summary> /// Download an Album converting a list of Images in a zip file /// </summary> /// <param name="id">The identity of the Album</param> /// <returns>The zip file with all the images in Album</returns> public ActionResult DownloadAlbum(int id) { ZipResult result = new ZipResult(MediaServices.GetImagePathsForDownload(id, HttpContext.Server)); Album album = AlbumServices.FindAllEntities(a => a.AlbumId == id,null,null).FirstOrDefault(); if (album != null) { result.FileName = album.Name.Replace(" ","_") + ".zip"; } return result; }
public ActionResult Export(int year) { var donations = _donationRepository .GetDonations(year) .ToArray(); var ipcIdNo = ConfigurationManager.AppSettings["IPC_ID_NO"]; var ipcAbbrName = ConfigurationManager.AppSettings["IPC_ABBR_NAME"]; var fileNo = 0; var i = 0; var result = new ZipResult { FileName = "DONS-" + year + "-" + ipcAbbrName + ".zip" }; while (i < donations.Length) { fileNo++; using (var exporter = new CsvExporter()) { exporter.Create(); string[] headers = new string[6]; headers[0] = "0"; headers[1] = "7"; headers[2] = year.ToString(); headers[3] = "7"; headers[4] = "0"; headers[5] = ipcIdNo; exporter.WriteLine(headers); string[] fields = new string[14]; int count = 0; decimal total = 0; for (; i < donations.Length && count < 40000; i++) { var donation = donations[i]; count++; total += donation.DonationAmount; fields[0] = "1"; // Details fields[1] = ((int)donation.IdType).ToString(); fields[2] = donation.IdNumber; fields[3] = donation.FirstName; fields[4] = donation.LastName; fields[5] = donation.AddressLine1; fields[6] = donation.AddressLine2; fields[7] = donation.AddressLine3; fields[8] = donation.PostalCode; fields[9] = donation.DonationAmount.ToString(); fields[10] = donation.DonationDate.ToString("yyyyMMdd"); fields[11] = donation.ReceiptNumber; fields[12] = "O"; // Outright Cash fields[13] = "Z"; // Default is Z exporter.WriteLine(fields); } var footers = new string[3]; footers[0] = "2"; footers[1] = count.ToString(); footers[2] = total.ToString(CultureInfo.InvariantCulture); exporter.WriteLine(footers); var memoryStream = new MemoryStream(); exporter.Save(memoryStream); result.AddEntry("DONS-" + year + "-" + ipcAbbrName + "-" + fileNo.ToString("99") + ".csv", memoryStream.ToArray()); } } return(result); }