Ejemplo n.º 1
0
        private void SetLogFileUrl(int id, DateTime day)
        {
            // 只给显示当天的链接
            if (day.Date != DateTime.Today)
            {
                return;
            }

            if (_totalResult.UnitTestResults == null || _totalResult.UnitTestResults.Count == 0)
            {
                return;
            }

            string today   = day.Date.ToString("yyyy-MM-dd");
            string logPath = ClientLogController.GetClientLogPath();

            // 只判断第一个节点就知道前面有没有处理过
            if (_totalResult.UnitTestResults[0].LogFileUrl == null)
            {
                lock ( s_lock ) {
                    if (_totalResult.UnitTestResults[0].LogFileUrl == null)
                    {
                        foreach (var t in _totalResult.UnitTestResults)
                        {
                            string name     = $"{today}-{id}-UnitTest-Result-{t.ProjectName}.xml";
                            string filepath = Path.Combine(logPath, name);
                            if (File.Exists(filepath))
                            {
                                t.LogFileUrl = ClientLogController.GetLogFileUrl(name);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void DeleteZipFiles()
        {
            // ZIP文件只保留一天一个文件
            string logpath = ClientLogController.GetClientLogPath();
            Dictionary <string, string> dict = new Dictionary <string, string>();

            string[] files = Directory.GetFiles(logpath, "*.zip", SearchOption.TopDirectoryOnly);

            foreach (var file in files)
            {
                try {
                    string filename = Path.GetFileNameWithoutExtension(file);
                    string key      = filename.Substring(0, 12);                // 分支号 + 日期
                    string value    = null;

                    // 一天只保留一个文件
                    if (dict.TryGetValue(key, out value))
                    {
                        File.Delete(value);
                        dict[key] = file;
                    }
                    else
                    {
                        dict[key] = file;
                    }
                }
                catch {
                    // 如果访问文件失败,就只能忽略异常了
                }
            }
        }
Ejemplo n.º 3
0
        public string UploadClientLog(HttpFile logFile, int flag)
        {
            string savepath = ClientLogController.GetClientLogPath();

            string filename = string.Format("{0}_{1}.zip", flag, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));
            string zipPath  = Path.Combine(savepath, filename);

            if (File.Exists(zipPath))
            {
                File.Delete(zipPath);
            }

            // 将上传文件先保存到临时目录
            File.WriteAllBytes(zipPath, logFile.FileBody);

            // 释放压缩包中的日志文件,如果存在就覆盖
            SpecChecker.CoreLibrary.Common.ZipHelper.ExtractFiles(zipPath, savepath);

            //System.Threading.Thread.Sleep(2000);
            return("200");
        }
Ejemplo n.º 4
0
        private void DeleteTxtFiles(string pattern)
        {
            // 只保留一周的日志文件
            DateTime minday = DateTime.Today.AddDays(-5d);

            string logpath = ClientLogController.GetClientLogPath();

            string[] files = Directory.GetFiles(logpath, pattern, SearchOption.TopDirectoryOnly);
            foreach (var file in files)
            {
                try {
                    string   filename   = Path.GetFileNameWithoutExtension(file);
                    string   dateString = filename.Substring(0, 10);
                    DateTime day        = DateTime.Parse(dateString);
                    if (day <= minday)
                    {
                        File.Delete(file);
                    }
                }
                catch {
                    // 如果访问文件失败,就只能忽略异常了
                }
            }
        }