Пример #1
0
        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);
            }
        }
Пример #2
0
        public void ZipFiles_NoFiles_NoZip()
        {
            FileZipper zipper    = new FileZipper();
            ZipResult  zipResult = zipper.ZipFiles(Enumerable.Empty <string>());

            Assert.IsNull(zipResult);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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]);
        }
Пример #5
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);
        }
Пример #6
0
        /// <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);
        }
Пример #7
0
    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);
    }
Пример #8
0
        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);
        }
Пример #9
0
        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"));
        }
Пример #10
0
        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());
            }
        }
Пример #11
0
        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);
        }
Пример #12
0
        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>()));
        }
Пример #13
0
        /// <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;
        }
Пример #14
0
        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);
        }
Пример #15
0
        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");
        }
Пример #16
0
        /// <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);
        }
Пример #17
0
        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);
        }
Пример #18
0
        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);
        }
Пример #19
0
        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);
        }
Пример #20
0
        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());
        }
Пример #21
0
    /// <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());
        }
    }
Пример #22
0
        //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));
                }
            }
        }
Пример #23
0
 /// <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;
 }
Пример #24
0
        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);
        }