/// <summary> /// 重新计算某一天的小组日汇总数据 /// URL: /ajax/scan/Admin/RefreshDailySummary.ppx?day=2016-04-28 /// </summary> /// <param name="day"></param> /// <returns></returns> public string RefreshDailySummary(DateTime day) { List <GroupDailySummary2> list = new List <GroupDailySummary2>(); foreach (JobOption job in JobManager.Jobs) { // 计算当天的汇总数据 TotalResult data = ScanResultCache.LoadTotalResult(job.Id, day, true); GroupDailySummary2 summary = new GroupDailySummary2(); summary.GroupName = job.Name; summary.Data = ToSummary2(data); list.Add(summary); } string filename = GetDataFileName(day); string savepath = Path.GetDirectoryName(filename); if (Directory.Exists(savepath) == false) { Directory.CreateDirectory(savepath); } string json = list.ToJson(); File.WriteAllText(filename, json); return(json); }
//[OutputCache(Duration = 60 * 30, VaryByParam = "id;day;flag;sort", VaryByHeader = "User-Agent")] public PageResult ShowScanResult(int id, DateTime day, string flag, string sort, int?page) { _totalResult = ScanResultCache.GetTotalResult(id, day); _branchId = id; _dataFlag = flag; _sortField = sort; _pageIndex = page; switch (flag) { case "RuntimeScan": return(ShowAssemblyScanResult()); case "DatabaseScan": return(ShowDatabaseScanResult()); case "JsCodeScan": return(ShowJsCodeScanResult()); case "CsCodeScan": return(ShowCsCodeScanResult()); case "ExceptionLog": return(ShowExceptionLog()); case "PerformanceLog": return(ShowPerformanceLog()); case "ProjectScan": return(ShowProjectScanResult()); case "VsRuleScan": return(ShowVsRuleScanResult()); case "UnitTest": { SetLogFileUrl(id, day); return(ShowUnitTestResult()); } case "CodeCover": return(ShowCodeCoverResult()); case "CommentScan": return(ShowCommentScanResult()); default: throw new NotImplementedException(); } }
public IActionResult ShowPerformanceLog(int id, DateTime day, Guid g, int?xml) { TotalResult totalResult = ScanResultCache.GetTotalResult(id, day); PerformanceInfo info = totalResult.PerformanceInfos.FirstOrDefault(x => x.InfoGuid == g); if (info == null) { return(new TextResult("parameters is invaild.")); } if (xml.HasValue && xml.Value == 1) { return(new XmlResult(info)); } else { return(PageResult("/CodeScan/Partial/PerformanceDetail.cshtml", info)); } }
public IActionResult DailyReport(int id, DateTime day) { BranchSettings branch = JobManager.GetBranch(id); if (branch == null) { return(new TextResult("id is invaild.")); } if (day > DateTime.Today) { return(new TextResult("day is invaild.")); } DateTime today = day.Date; DailyReportViewModel model = new DailyReportViewModel(); model.Today = today.ToDateString(); model.DayMonth = today.Day.ToString() + "/" + today.Month.ToString(); //today.ToString("d/M"); model.Branch = branch; // 加载工具扫描的结果 TotalResult totalResult = null; try { totalResult = ScanResultCache.GetTotalResult(id, day); } catch (FileNotFoundException) { return(new TextResult("找不到匹配的数据文件。")); } model.ComplieMessage = totalResult.CompilerError; model.TotalResult = totalResult; // 注意:注释问题不是单独扫描出来的, // 是由于大家觉得这类问题的修复优先级可以降低点,所以就从【代码扫描结果】中提取 // 提取之后,还要从【代码扫描结果】去掉那部分数据 totalResult.EvalCommentScanResultCount(); return(PageResult("/CodeScan/DailyReport.cshtml", model)); }
/// <summary> /// 从某天开始算起,找出一个有数据的日期, /// 如果参数中的日期没有数据,就往前找,直到有数据为止。 /// </summary> /// <param name="today"></param> private DateTime?GetResultfulDay(DateTime today) { // 因为有时候数据不是连续的,所以如果当天数据不存在,就往前找,最后尝试30次 for (int i = 0; i < 30; i++) { foreach (var b in JobManager.Jobs) { string datafile = ScanResultCache.GetTotalResultFilePath(b.Id, today); if (File.Exists(datafile)) { // 只要找到数据就跳出,否则日期减一,继续往前找 return(today); } } // 如果所有分支都没有数据,就把日期减1,继续往前找 today = today.AddDays(-1); } return(null); }
/// <summary> /// 重新计算(按日期)所有的小组日汇总数据 /// URL: /ajax/scan/Admin/RefreshAllDailySummary.ppx /// </summary> /// <returns></returns> public string RefreshAllDailySummary() { StringBuilder sb = new StringBuilder(); DateTime day = new DateTime(2016, 3, 19); DateTime today = DateTime.Today; while (day <= today) { // 拿 1 号分支判断有没有数据文件 string filePath = ScanResultCache.GetTotalResultFilePath(1, day); if (File.Exists(filePath)) { // 刷新第一天的汇总数据 RefreshDailySummary(day); sb.AppendLine(filePath); } day = day.AddDays(1d); } return(sb.ToString()); }
public string UploadResult(string base64, int branchId) { string authkey = ConfigurationManager.AppSettings["authentication-key"]; if (this.GetHeader("authentication-key") != authkey) { return("authentication-key is invalid."); } string appVersion = this.GetHeader("app-version"); if (appVersion != SpecChecker.CoreLibrary.Config.JobManager.AppVersion) { return("客户端版本不匹配。"); } // 为了防止提交的数据过大,所以采用压缩的方式提交数据(大约可压缩10倍), // 为了方便调试,将压缩后的数据以BASE64方式传输 string json = CompressHelper.GzipDecompress(base64); TotalResult result = json.FromJson <TotalResult>(); // 设置问题分类 result.SetIssueCategory(); json = result.ToJson(); // 上面的调用会修改数据,所以重新生成JSON DateTime today = DateTime.Today; string filename = ScanResultCache.GetTotalResultFilePath(branchId, today); string uploadPath = Path.GetDirectoryName(filename); if (Directory.Exists(uploadPath) == false) { Directory.CreateDirectory(uploadPath); } // JSON文本的体积小,序列化/反序列化更快,而且特殊字符的支持更好,所以这里使用JSON,不再使用XML //XmlHelper.XmlSerializeToFile(result, filename, Encoding.UTF8); //File.WriteAllText(filename, json, Encoding.UTF8); SpecChecker.CoreLibrary.Common.ZipHelper.CreateZipFileFromText(filename, json); // 刷新小组汇总数据 // 这个任务只能放在服务端完成,因为客户端没有完整的数据 DailySummaryHelper helper = new DailySummaryHelper(); helper.RefreshDailySummary(today); // 清除缓存 ScanResultCache.RemoveCache(branchId, today); //// 发送通知邮件 //Uri requestUri = this.HttpContext.Request.Url; //SendEmailHelper.Send(today, branchId, requestUri); return("200"); }