예제 #1
0
        public ActionResult RepFile(string path_js, string path_po, string path_out)
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();
            #region 文件数据读取

            List <FileInfo> JSFileList = FileAction.ReadDir(path_js, "js");

            if (JSFileList == null || JSFileList.Count <= 0)
            {
                return(Error("不存在此目录,或目录下无对应文件!", "Index", false));
            }

            #endregion

            // 赋予必要参数
            RepFilePara.dic     = GetLanPo(path_po);
            RepFilePara.path    = path_js;
            RepFilePara.outpath = path_out;
            RepFilePara.errInfo = new List <string>();
            Thread thread;

            // 循环所有文件
            foreach (var item in JSFileList)
            {
                RepFilePara para = new RepFilePara
                {
                    file = item
                };
                // 每一个文件,开辟一个线程
                thread = new Thread(new ThreadStart(para.RepFile));
                thread.Start();
            }

            // 输出日志信息,保存为文件
            StringBuilder builder = new StringBuilder();
            foreach (var item in RepFilePara.errInfo)
            {
                builder.Append(item + "\n");
            }
            FileAction.AppendStr(path_out + "\\log.txt", builder.ToString());

            watch.Stop();
            return(Success($"导出成功!开启线程{JSFileList.Count}个," +
                           $"用时:{watch.ElapsedMilliseconds * 1.0 / 1000 / 60}分钟", "Index", false));
        }