예제 #1
0
        internal void SaveTotalResultToFile()
        {
            string resultFile = Path.Combine(_tempPath, "TotalResult.json");
            string json       = _totalResult.ToJson();

            File.WriteAllText(resultFile, json, Encoding.UTF8);
        }
예제 #2
0
        public void Execute(TaskContext context, TaskAction action)
        {
            string website = ConfigurationManager.AppSettings["ServiceWebsite"];

            if (string.IsNullOrEmpty(website))
            {
                throw new ConfigurationErrorsException("ServiceWebsite没有配置。");
            }

            TotalResult totalResult = context.TotalResult;

            // 按业务单元和扫描类别分组小计
            //CalculateSubTotal(totalResult);
            context.ConsoleWrite("ExecSubTotalResult OK");
            context.ConsoleWrite("\r\n任务结束时间:" + DateTime.Now.ToTimeString());

            // 获取控件台的所有输出内容
            totalResult.ConsoleText = context.OutputText;


            // 为了防止提交的数据过大,所以采用压缩的方式提交数据(大约可压缩10倍),
            string json = totalResult.ToJson();
            string data = CompressHelper.GzipCompress(json);


            HttpOption option = new HttpOption {
                Method = "POST",
                Url    = website.TrimEnd('/') + "/ajax/scan/Upload/UploadResult.ppx",
                Data   = new { base64 = data, branchId = context.Branch.Id }
            };

            option.Headers.Add("authentication-key", ConfigurationManager.AppSettings["authentication-key"]);
            option.Headers.Add("app-version", SpecChecker.CoreLibrary.Config.JobManager.AppVersion);
            string responseText = option.GetResult();

            if (responseText == "200")
            {
                context.ConsoleWrite("UploadResultTask OK");
            }
            else
            {
                context.ConsoleWrite("\r\n上传结果出现异常:##################");
                context.ConsoleWrite(responseText);
            }
        }
예제 #3
0
        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");
        }