Пример #1
0
    // Start is called before the first frame update
    void Start()
    {
        //createZipSrcFilePath = Application.dataPath + "/" + "Video";
        //Debug.Log("createZipSrcFilePath:"+ createZipSrcFilePath);
        //createSrcFileSaveZipPath = Application.dataPath + "/Fuyou.zip";

        ////ZipHelper.CreateZipFile(createZipSrcFilePath, createSrcFileSaveZipPath);

        //bool isZipSuccess = ZipHelper.UnZip(createSrcFileSaveZipPath,createZipSrcFilePath);
        //if (isZipSuccess == true) {
        //    Debug.Log("解压成功...");
        //}
        //else {
        //    Debug.Log("解压失败...");
        //}

        //createZipSrcFilePath = Application.dataPath + "/" + "Test";
        //createSrcFileSaveZipPath = Application.dataPath + "/TestSlamSlope0809_003.zip";
        //isZipSuccess = ZipHelper.UnZip(createSrcFileSaveZipPath, createZipSrcFilePath, "0123");
        //if (isZipSuccess == true)
        //{
        //    Debug.Log("解压成功...");
        //}
        //else
        //{
        //    Debug.Log("解压失败...");
        //}

        createZipSrcFilePath = Application.dataPath + "/" + "Video";
        Debug.Log("createZipSrcFilePath:" + createZipSrcFilePath);
        createSrcFileSaveZipPath = Application.dataPath + "/Fuyou.zip";

        ZipHelper.CreateZipFile(createZipSrcFilePath, createSrcFileSaveZipPath, "1111");
    }
Пример #2
0
        public void Execute(TaskContext context, TaskAction action)
        {
            string[] files = Directory.GetFiles(context.TempPath, "*.*", SearchOption.TopDirectoryOnly);
            if (files.Length == 0)
            {
                return;
            }


            // 获取所有日志文件,仅包含:xml, txt
            string[] logFiles = (from f in files
                                 where f.EndsWith(".xml", StringComparison.OrdinalIgnoreCase) ||
                                 f.EndsWith(".txt", StringComparison.OrdinalIgnoreCase)
                                 select f).ToArray();

            string zipFile = context.Branch.Id.ToString() + "__log.zip";
            string zipPath = Path.Combine(context.TempPath, zipFile);

            // 创建压缩包文件
            ZipHelper.CreateZipFile(zipPath, logFiles);

            // 上传日志
            string     website = ConfigurationManager.AppSettings["ServiceWebsite"];
            HttpOption option  = new HttpOption {
                Method = "POST",
                Url    = website.TrimEnd('/') + "/ajax/scan/Upload/UploadClientLog.ppx",
                Data   = new { logFile = new FileInfo(zipPath), flag = context.Branch.Id }
            };

            option.GetResult();

            context.ConsoleWrite("UploadClientLogTask OK");
        }
        public string Post([FromBody] PostModel data)
        {
            string result = string.Empty;

            //返回zip文件
            if (data.code == "zip")
            {
                JObject  jsonObj = JObject.Parse(data.list);
                JToken   record  = jsonObj;
                DocModel model   = null;
                foreach (JProperty jp1 in record)
                {
                    JArray jar = JArray.Parse(jp1.Value.ToString());
                    for (int i = 0; i < jar.Count; i++)
                    {
                        model          = new DocModel();
                        model.template = data.template;
                        JToken record2 = jar[i];
                        foreach (JProperty jp2 in record2)
                        {
                            switch (jp2.Name)
                            {
                            case "name":
                                model.name = jp2.Value.ToString();
                                break;

                            case "doc":
                                model.doc = jp2.Value.ToString();
                                break;

                            default:
                                break;
                            }
                        }
                        CreateDoc(model);
                    }
                }
                string rootUrl = System.Configuration.ConfigurationManager.AppSettings["WEBURL"];
                string path    = System.Configuration.ConfigurationManager.AppSettings["TemplatePath"];
                ZipHelper.CreateZipFile(path + "build/", path + "build.zip");
                Directory.Delete(path + "build", true);
                //File.Delete(path + "build");
                //File.Delete(path + "build.zip");
                result = rootUrl + "\build\build.zip";
            }
            //返回doc文档
            if (data.code == "doc")
            {
                DocModel model = new DocModel();
                model.doc      = data.list;
                model.template = data.template;
                model.name     = data.name;
                result         = CreateDoc(model);
            }
            return(result);
        }
Пример #4
0
        public void TestMethod1()
        {
            ZipHelper.CreateZipFile(@"D:\Common", @"D:\common001.zip");
            var filelist =
                Directory.EnumerateFiles(@"D:\Common", "*", SearchOption.AllDirectories);

            ZipHelper.CreateZipFile(@"D:\Common", filelist.ToList(), @"D:\common002.zip");

            ZipHelper.CreateZipFile(@"D:\Common", @"D:\中国.zip");
            ZipHelper.CreateZipFile(@"D:\Common", filelist.ToList(), @"D:\中国2.zip");
        }
Пример #5
0
 public void CreateZipFile_3()
 {
     ZipHelper.CreateZipFile(".", @"..\", "CreateZipFile_3.zip");
     Assert.Inconclusive("See the file.");
 }
Пример #6
0
 public void CreateZipFile_2()
 {
     ZipHelper.CreateZipFile(@"..\..\Release", ".", "CreateZipFile_2.zip");
     Assert.Inconclusive("See the file.");
 }
Пример #7
0
        //下载全部的附件get all attachs by noteId
        public async Task <IActionResult> DownloadAll(string noteId)
        {
            var note = noteService.GetNoteById(noteId.ToLongByHex());

            if (note == null)
            {
                return(Content("No found note,Please check the  noteId"));
            }

            if (GetUserIdBySession() != note.UserId)
            {
                return(Content("No permission to access attachments"));
            }
            // 得到文件列表
            var attachs = await attachService.ListAttachsAsync(noteId.ToLongByHex(), GetUserIdBySession());

            if (attachs.IsNullOrNothing())
            {
                return(Content(""));
            }
            var sb        = new StringBuilder();
            var fileStore = FileStoreServiceFactory.Instance(config);

            //下载拼接
            foreach (var attach in attachs)
            {
                sb.Append(attach.AttachId);
            }
            //计算AttachId合并字符串的哈希
            string md5         = SHAEncryptHelper.MD5Encrypt(sb.ToString());
            var    dir         = config.FileStoreConfig.TempFolder + Path.DirectorySeparatorChar + note.NoteId.ToHex();
            var    zipFileName = config.FileStoreConfig.TempFolder + Path.DirectorySeparatorChar + md5 + ".zip";

            if (!System.IO.File.Exists(zipFileName))
            {
                //清理文件夹
                if (Directory.Exists(dir))
                {
                    Directory.Delete(dir, true);
                }

                Directory.CreateDirectory(dir);

                //下载附件到本地
                foreach (var attach in attachs)
                {
                    string fileName = TextFilterUtil.DelUnSafeChar(attach.Title);
                    await fileStore.GetObjectAsync(config.MinIOConfig.NoteFileBucketName, attach.Path, dir + Path.DirectorySeparatorChar + fileName);
                }
                //执行压缩
                ZipHelper compressedFilesHelper = new ZipHelper();
                compressedFilesHelper.CreateZipFile(zipFileName, null, dir);
            }
            var memi = GetMemi(".zip");

            var stream = System.IO.File.Open(zipFileName, FileMode.Open, FileAccess.Read);

            {
                return(File(stream, memi, Path.GetFileName(zipFileName)));
            }
        }
        /*/// <summary>
         * /// 开始工作
         * /// </summary>
         * private void DoWork()
         * {
         *  for (int i = 0; i < 100; i++)
         *  {
         *      // 记录进度
         *      // 实际应用中需要进一步控制(利用用户信息、cookies等),防止并发造成混乱
         *      this.context.Application["progress"] = i + 1;
         *      Random r = new Random();
         *      Thread.Sleep(r.Next(10, 100));
         *  }
         *  // 完成后释放资源
         *  this.context.Application["progress"] = null;
         * }
         *
         * /// <summary>
         * /// 查询进度
         * /// </summary>
         * /// <returns>进度</returns>
         * private int GetProgress()
         * {
         *  if (this.context.Application["progress"] != null)
         *  {
         *      return (int)this.context.Application["progress"];
         *  }
         *  else
         *  {
         *      return -1;
         *  }
         * }*/

        /// <summary>
        /// 压缩
        /// </summary>
        /// <param name="type">任务类型</param>
        /// <param name="projectID">任务ID</param>
        /// <param name="finishedPerson">完成人ID</param>
        /// <returns></returns>
        public string Compress(string type, string projectID, string finishedPerson)
        {
            string result = "{\"result\":\"0\"}";

            try
            {
                string employeeRootPath = ConfigurationManager.AppSettings["employeePath"];
                //===================================== type为0,普通任务 =====================================
                if (type == "0")
                {
                    DataTable dt = new ProjectBLL().GetFinalScript(projectID, finishedPerson);

                    //string finishedPerson = context.Request["FinishedPerson"];

                    LogHelper.WriteLine("finishedPerson: " + finishedPerson);

                    //DataRow[] dr = dt.Select(string.Format("FINISHEDPERSON = '{0}'", finishedPerson));

                    if (dt != null && dt.Rows.Count > 0)
                    {
                        string employeeNo = dt.Rows[0]["EMPLOYEENO"].ToString(); //员工编号
                        string taskNo     = dt.Rows[0]["taskno"].ToString();     //任务目录

                        LogHelper.WriteLine("employeeNo: " + employeeNo);
                        LogHelper.WriteLine("taskNo: " + taskNo);

                        string currentEmpPath = string.Format("{0}{1}", employeeRootPath, employeeNo);//员工目录
                        LogHelper.WriteLine("currentEmpPath: " + currentEmpPath);
                        //遍历员工目录,即找出各个任务的目录
                        foreach (DirectoryInfo taskFolder in new DirectoryInfo(currentEmpPath).GetDirectories())
                        {
                            LogHelper.WriteLine("如果目录名是以任务名打头的,   上面    taskNo :   " + taskNo);
                            //如果目录名是以任务名打头的,说明就是它了,因为员工会在原文件夹名后面加上乱七八糟的东西。如果前面他也敢动,那我也没办法了。
                            if (taskFolder.Name.StartsWith(taskNo))
                            {
                                foreach (DirectoryInfo taskFolderChild in new DirectoryInfo(taskFolder.FullName).GetDirectories())
                                {
                                    if (taskFolderChild.Name == "完成稿")
                                    {
                                        string destinationFileName = taskFolderChild.FullName + ".zip";
                                        if (!File.Exists(destinationFileName))
                                        {
                                            //ZipHelper.CreateZip(taskFolder.FullName, taskFolder.FullName + ".zip");
                                            ZipHelper.CreateZipFile(taskFolder.FullName + "\\" + taskFolderChild.Name, destinationFileName);
                                            result = "{\"result\":\"1\"}";
                                            break;
                                        }
                                        else
                                        {
                                            result = "{\"result\":\"2\"}";
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //===================================== type为1,售后任务 =====================================
                else if (type == "1")
                {
                    DataTable dt             = new ProjectBLL().GetProjectModifyByModifyID(projectID);
                    string    employeeNo     = dt.Rows[0]["employeeNo"].ToString();                   //员工编号
                    string    taskNo         = dt.Rows[0]["taskNo"].ToString();                       //任务目录
                    string    currentEmpPath = string.Format("{0}{1}", employeeRootPath, employeeNo); //员工目录
                    //遍历员工目录,即找出各个任务的目录
                    foreach (DirectoryInfo taskFolder in new DirectoryInfo(currentEmpPath).GetDirectories())
                    {
                        //如果目录名是以任务名打头的,说明就是它了,因为员工会在原文件夹名后面加上乱七八糟的东西。如果前面他也敢动,那我也没办法了。
                        if (taskFolder.Name.StartsWith(taskNo))
                        {
                            //修改记录目录
                            string modifyRecordFolder = ConfigurationManager.AppSettings["modifyRecordFolderName"].ToString();
                            //遍历单个任务目录下的文件夹
                            foreach (DirectoryInfo taskFolderChild in taskFolder.GetDirectories())
                            {
                                //如果目录名是“修改记录”
                                if (taskFolderChild.Name == modifyRecordFolder)
                                {
                                    //进一步遍历每次修改记录目录
                                    foreach (DirectoryInfo modifyFolder in taskFolderChild.GetDirectories())
                                    {
                                        //每次修改记录产生的文件夹
                                        string modifyFolderName = modifyFolder.Name;
                                        //数据库中存储的修改记录文件夹
                                        string dtFolderName = dt.Rows[0]["folderName"].ToString();
                                        //如果目录名包含“完成”并且是当前售后任务打头的,那么就是它了
                                        //if (modifyFolderName.Contains("完成") && modifyFolderName.StartsWith(dtFolderName))
                                        LogHelper.WriteLine("modifyFolderName == dtFolderName   :" + modifyFolderName + "----" + dtFolderName);
                                        if (modifyFolderName == dtFolderName)
                                        {
                                            if (Directory.Exists(modifyFolder.FullName))
                                            {
                                                string destinationFileName = modifyFolder.FullName + ".zip";
                                                if (!File.Exists(destinationFileName))
                                                {
                                                    ZipHelper.CreateZipFile(modifyFolder.FullName, destinationFileName);
                                                    result = "{\"result\":\"1\"}";
                                                    break;
                                                }
                                                else
                                                {
                                                    result = "{\"result\":\"2\"}";
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                        //break;
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLine("压缩失败!\r\n" + ex.Message);
                return("{\"result\":\"0\"}");
            }
            return(result);
        }