Esempio n. 1
0
 public void TraverseFolder2(DirectoryInfo dir, Action <FileInfo, List <Tlog>, string> act, List <Tlog> tlogs, string zipName) //搜索文件夹中的文件
 {
     foreach (var file in dir.GetFiles())
     {
         try
         {
             act(file, tlogs, zipName);
             if (tlogs.Count() > 4500)
             {
                 TlogRepository.BulkInsertAll(tlogs);
                 tlogs.Clear();
             }
         }
         catch (Exception e)
         {
             // 移动文件到Error,记录Log
             string strToPath = TestErrorPath + "\\" + zipName;
             if (!Directory.Exists(strToPath))
             {
                 Directory.CreateDirectory(strToPath);
             }
             File.Move(file.FullName, strToPath + "\\" + file.Name);
             WriteSysLog(e.Message);
         }
     }
     DirectoryInfo[] allDir = dir.GetDirectories();
     foreach (DirectoryInfo d in allDir)
     {
         TraverseFolder2(d, act, tlogs, zipName);
     }
 }
Esempio n. 2
0
        public void TestLogExcute(string logFromPath,
                                  string logToPath,
                                  Action <FileInfo, List <Tlog>, string> transfaseDataTable)
        {
            double move = 0, read = 0, zip = 0, del = 0;
            var    fileCount = 0;

            var total = CodeTimer.TimeLong("总共时间",
                                           1,
                                           () =>
            {
                string zipFileName  = DateTime.Now.ToString("yyyyMMddHHmm");
                string logToAbsPath = logToPath + "\\" + zipFileName;

                try
                {
                    // ReSharper disable once AccessToModifiedClosure
                    move = CodeTimer.TimeLong("移动数据", 1, () => FileUtil.MoveFolder(logFromPath, logToAbsPath, ref fileCount));

                    DirectoryInfo myFolder = new DirectoryInfo(logToAbsPath);
                    List <Tlog> tlogs      = new List <Tlog>();
                    read = CodeTimer.TimeLong("解析数据", 1, () =>
                    {
                        TraverseFolder2(myFolder, transfaseDataTable, tlogs, zipFileName);
                        TlogRepository.BulkInsertAll(tlogs);
                    }
                                              );

                    zip = CodeTimer.TimeLong("压缩数据",
                                             1,
                                             () =>
                    {
                        if (FileUtil.Zip(logToAbsPath, logToAbsPath + ".zip", ""))
                        {
                            del = CodeTimer.TimeLong("删除数据", 1, () => FileUtil.DeleteDir(logToAbsPath));
                        }
                    });
                    zip = zip - del;
                }
                catch (Exception e)
                {
                    string log = "解析数据出错,原因:[" + e + "、消息:" + e.Message + "]";
                    Console.WriteLine(@"	Err:	"+ e.Message);
                    WriteSysLog(log);
                }
            });

            OperationLogRepository.Insert(new OperationLog()
            {
                Num           = fileCount,
                MoveTimes     = move,
                ReadTimes     = read,
                ZipTimes      = zip,
                DeleteTimes   = del,
                TotalTimes    = total,
                OperationType = "TestLog"
            });
        }
Esempio n. 3
0
 /// <summary>
 /// 删除部门信息
 /// </summary>
 /// <param name="ids">要删除的部门信息编号</param>
 /// <returns>业务操作结果</returns>
 public OperationResult DeleteTlogs(params int[] ids)
 {
     return(TlogRepository.Delete(ids));
 }
Esempio n. 4
0
 /// <summary>
 /// 更新部门信息
 /// </summary>
 /// <param name="dtos">包含更新信息的部门DTO信息</param>
 /// <returns>业务操作结果</returns>
 public OperationResult EditTlogs(params TlogDto[] dtos)
 {
     return(TlogRepository.Update(dtos));
 }
Esempio n. 5
0
 /// <summary>
 /// 添加部门信息
 /// </summary>
 /// <param name="dtos">要添加的部门信息DTO信息</param>
 /// <returns>业务操作结果</returns>
 public OperationResult AddTlogs(params TlogDto[] dtos)
 {
     return(TlogRepository.Insert(dtos));
 }
Esempio n. 6
0
 /// <summary>
 /// 检查部门信息是否存在
 /// </summary>
 /// <param name="predicate">检查谓语表达式</param>
 /// <param name="id">更新的部门信息编号</param>
 /// <returns>部门信息是否存在</returns>
 public bool CheckTlogExists(Expression <Func <Tlog, bool> > predicate, int id = 0)
 {
     return(TlogRepository.CheckExists(predicate, id));
 }