Exemple #1
0
        public void Execute(TaskContext context, TaskAction action)
        {
            if (action.Items == null || action.Items.Length == 0)
            {
                action.Items = context.JobOption.SlnFiles;
            }

            if (action.Items == null || action.Items.Length == 0)
            {
                return;
            }


            foreach (string path in action.Items)
            {
                string        commandArgs = $"  \"{path}\"  /t:Rebuild /p:Configuration=\"Debug\" /consoleloggerparameters:ErrorsOnly /nologo /m";
                ExecuteResult result      = CommandLineHelper.Execute(s_msbuildPath, commandArgs);
                context.ConsoleWrite(result.ToString());

                // 注意:
                // 有些分支下面可能包含多个解决方案文件 sln,会导致编译多次
                // 这里的判断逻辑是:只要有一个项目没有编译通过,就认为是编译失败

                if (context.TotalResult.BuildIsOK.HasValue == false ||  // 还没有赋值过(第一次进入)
                    context.TotalResult.BuildIsOK.Value                 // 前面编译成功
                    )
                {
                    string text = result.Output.Trim(' ', '\r', '\n', '\t');
                    context.TotalResult.BuildIsOK = string.IsNullOrEmpty(text);
                }
            }
        }
Exemple #2
0
        public void Execute(TaskContext context, TaskAction action)
        {
            string[] files = Directory.GetFiles(context.TempPath, "*.*", SearchOption.TopDirectoryOnly);
            if (files.Length == 0)
            {
                return;
            }


            // 获取所有日志文件,仅包含:xml, txt
            string[] logFiles = (from f in files
                                 where f.EndsWith(".xml", StringComparison.OrdinalIgnoreCase) ||
                                 f.EndsWith(".txt", StringComparison.OrdinalIgnoreCase)
                                 select f).ToArray();

            string zipFile = context.Branch.Id.ToString() + "__log.zip";
            string zipPath = Path.Combine(context.TempPath, zipFile);

            // 创建压缩包文件
            ZipHelper.CreateZipFile(zipPath, logFiles);

            // 上传日志
            string     website = ConfigurationManager.AppSettings["ServiceWebsite"];
            HttpOption option  = new HttpOption {
                Method = "POST",
                Url    = website.TrimEnd('/') + "/ajax/scan/Upload/UploadClientLog.ppx",
                Data   = new { logFile = new FileInfo(zipPath), flag = context.Branch.Id }
            };

            option.GetResult();

            context.ConsoleWrite("UploadClientLogTask OK");
        }
        public void Execute(TaskContext context, TaskAction action)
        {
            if (action.Items == null || action.Items.Length == 0)
            {
                action.Items = context.JobOption.SlnFiles;
            }

            if (action.Items == null || action.Items.Length == 0)
            {
                return;
            }

            TotalResult totalResult             = context.TotalResult;
            List <VsRuleCheckResult> resultList = new List <VsRuleCheckResult>();

            try {
                foreach (string path in action.Items)
                {
                    VsRuleScaner             scaner = new VsRuleScaner();
                    List <VsRuleCheckResult> list   = scaner.Execute(context.Branch, path);
                    resultList.AddRange(list);
                }
                totalResult.VsRuleCheckResults.AddRange(resultList);
                context.ConsoleWrite("VsRuleScanTask OK");
            }
            catch (Exception ex) {
                totalResult.VsRuleCheckException = ex.ToString();
                context.ProcessException(ex);
            }
        }
Exemple #4
0
        public void Execute(TaskContext context, TaskAction action)
        {
            if (action.Items == null || action.Items.Length == 0)
            {
                return;
            }


            foreach (string line in action.Items)
            {
                string        workingDirectory = Path.GetDirectoryName(line);
                ExecuteResult result           = CommandLineHelper.Execute(line, null, workingDirectory);
                context.ConsoleWrite(result.ToString());
            }

            context.ConsoleWrite("ExecuteFileTask OK");
        }
        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);
            }
        }
        public void Execute(TaskContext context, TaskAction action)
        {
            if (action.Items == null || action.Items.Length == 0)
            {
                return;
            }


            StringBuilder sb = new StringBuilder();

            foreach (string line in action.Items)
            {
                sb.AppendLine(line);
            }

            ExecuteResult result = ExecuteBat(sb.ToString());

            context.ConsoleWrite(result.ToString());

            context.ConsoleWrite("ExecuteCommnadTask OK");
        }
        public void Execute(TaskContext context, TaskAction action)
        {
            if (action.Items == null)
            {
                return;
            }

            TotalResult totalResult = context.TotalResult;
            List <AssemblyScanResult> resultList = new List <AssemblyScanResult>();

            try {
                foreach (string line in action.Items)
                {
                    AssemblyScaner scaner = new AssemblyScaner();

                    TextLineSerializer serializer = new TextLineSerializer();
                    AssemblyScanOption option     = serializer.Deserialize <AssemblyScanOption>(line);
                    if (string.IsNullOrEmpty(option.Bin))
                    {
                        throw new ArgumentException("AssemblyScan任务的参数不正确,没有指定 bin 参数");
                    }

                    if (string.IsNullOrEmpty(option.Sln))
                    {
                        if (context.JobOption.SlnFiles != null && context.JobOption.SlnFiles.Length == 1)
                        {
                            option.Sln = context.JobOption.SlnFiles[0];
                        }
                        else
                        {
                            throw new ArgumentException("AssemblyScan任务的参数不正确,没有指定 sln 参数");
                        }
                    }

                    List <AssemblyScanResult> list = scaner.Execute(context.Branch, option);
                    resultList.AddRange(list);
                }


                totalResult.RuntimeScanResults.AddRange(resultList);

                context.ConsoleWrite("AssemblyScanTask OK");
            }
            catch (Exception ex) {
                totalResult.RuntimeScanException = ex.ToString();
                context.ProcessException(ex);
            }
        }
Exemple #8
0
        private void LogRuntimeEnvironment(TaskContext context)
        {
            context.ConsoleWrite("\r\n任务开始时间:" + DateTime.Now.ToTimeString());
            try {
                context.ConsoleWrite("当前计算机名:" + System.Environment.MachineName);
                context.ConsoleWrite("当前登录用户:" + System.Environment.UserName);
            }
            catch { // 这二个信息取不到就算了
            }

            context.ConsoleWrite("扫描工具版本:" + JobManager.AppVersion);
            context.ConsoleWrite("任务配置文件:");
            context.ConsoleWrite(ConfigHelper.GetFile(context.JobOption.TaskFileName));
            context.ConsoleWrite("\r\n");
        }
        public void Execute(TaskContext context, TaskAction action)
        {
            if (action.Items == null || action.Items.Length == 0)
            {
                action.Items = context.JobOption.CodePath;
            }

            if (action.Items == null || action.Items.Length == 0)
            {
                return;
            }

            TotalResult            totalResult = context.TotalResult;
            List <CodeCheckResult> resultList  = new List <CodeCheckResult>();

            try {
                foreach (string path in action.Items)
                {
                    CodeScaner scaner = new CodeScaner();
                    scaner.ExcludePaths = LoadExcludePaths(path);
                    List <CodeCheckResult> list = scaner.Execute(context.Branch, path);
                    resultList.AddRange(list);
                }


                // 过滤前端代码的检查结果
                totalResult.JsCodeCheckResults.AddRange(
                    (from x in resultList
                     where x.FileName.EndsWith(".js", StringComparison.OrdinalIgnoreCase)
                     select x).ToList());

                // 过滤服务端代码的检查结果
                totalResult.CsCodeCheckResults.AddRange(
                    (from x in resultList
                     where x.FileName.EndsWith(".js", StringComparison.OrdinalIgnoreCase) == false
                     select x).ToList());

                context.ConsoleWrite("CodeScanTask OK");
            }
            catch (Exception ex) {
                totalResult.CodeCheckException = ex.ToString();
                context.ProcessException(ex);
            }
        }
Exemple #10
0
        public void Execute(TaskContext context, TaskAction action)
        {
            if (action.Items == null || action.Items.Length == 0)
            {
                action.Items = context.JobOption.CodePath;
            }

            if (action.Items == null || action.Items.Length == 0)
            {
                return;
            }


            foreach (string path in action.Items)
            {
                string        commandArgs = $" get  /recursive  /noprompt  itemspec \"{path}\"";
                ExecuteResult result      = CommandLineHelper.Execute(s_tfsClientPath, commandArgs);
                context.ConsoleWrite(result.ToString());
            }
        }
Exemple #11
0
        public void Execute(TaskContext context, TaskAction action)
        {
            if (string.IsNullOrEmpty(context.Branch.MongoLocation))
            {
                return;
            }


            TotalResult totalResult = context.TotalResult;

            try {
                ExceptionLogScaner scaner = new ExceptionLogScaner();
                bool isMongoDb            = context.Branch.MongoLocation.StartsWith("mongodb", StringComparison.OrdinalIgnoreCase);

                DateTime start, end;
                if (DateTime.Now.Hour < 12)
                {
                    // 有些产品组只在凌晨运行扫描工具,会导致当天的数据几乎是零,
                    // 所以,这里的规则是:如果在 12点前运行工具,就取前一天的数据
                    start = DateTime.Today.AddDays(-1);
                    end   = DateTime.Today;
                }
                else
                {
                    start = DateTime.Today;
                    end   = DateTime.Today.AddDays(1d);
                }

                List <ExceptionInfo> list = isMongoDb
                                                        ? scaner.Execute(start, end, context.Branch.MongoLocation)
                                                        : scaner.Execute2(start, end, context.Branch.MongoLocation);


                totalResult.ExceptionInfos = list;
                context.ConsoleWrite("ExceptionLogTask OK");
            }
            catch (Exception ex) {
                totalResult.ExceptionLogException = ex.ToString();
                context.ProcessException(ex);
            }
        }
Exemple #12
0
        public void Execute(TaskContext context, TaskAction action)
        {
            if (action.Items == null || action.Items.Length == 0)
            {
                action.Items = context.JobOption.CodePath;
            }

            if (action.Items == null || action.Items.Length == 0)
            {
                return;
            }


            FileHelper file = new FileHelper();

            foreach (string path in action.Items)
            {
                file.ClearBinObjFiles(path);
            }

            context.ConsoleWrite("ClearBinObjTask OK");
        }
Exemple #13
0
        public void Execute(TaskContext context, TaskAction action)
        {
            if (string.IsNullOrEmpty(context.Branch.DbLocation))
            {
                return;
            }


            TotalResult totalResult = context.TotalResult;

            try {
                DatabaseScaner       scaner = new DatabaseScaner();
                List <DbCheckResult> list   = scaner.Execute(context.Branch);


                // 数据库的扫描结果不做累加
                totalResult.DbCheckResults = list;
                context.ConsoleWrite("DatabaseScanTask OK");
            }
            catch (Exception ex) {
                totalResult.DbCheckException = ex.ToString();
                context.ProcessException(ex);
            }
        }
        public void Execute(TaskContext context, TaskAction action)
        {
            if (action.Items == null || action.Items.Length == 0)
            {
                action.Items = context.JobOption.SlnFiles;
            }

            if (action.Items == null || action.Items.Length == 0)
            {
                return;
            }


            TotalResult totalResult = context.TotalResult;

            try {
                foreach (string path in action.Items)
                {
                    UnitTestRunner runner = new UnitTestRunner(context);

                    SlnUnitTestResult total = runner.Execute(context.Branch, path);
                    if (total != null)
                    {
                        totalResult.UnitTestResults.AddRange(total.UnitTestResults);
                        totalResult.CodeCoverResults.AddRange(total.CodeCoverResults);
                    }
                }

                // 计算总结果
                int caseCount  = 0;
                int casePassed = 0;

                int totalStatements   = 0;
                int coveredStatements = 0;

                foreach (var t in totalResult.UnitTestResults)
                {
                    caseCount  += t.Total;
                    casePassed += t.Passed;
                }

                foreach (var c in totalResult.CodeCoverResults)
                {
                    totalStatements   += c.Total;
                    coveredStatements += c.Passed;
                }

                // 更新结果
                totalResult.UnitTestTotal  = caseCount;
                totalResult.UnitTestPassed = casePassed;

                if (totalStatements == 0)
                {
                    totalResult.CodeCover = 0;
                }
                else
                {
                    totalResult.CodeCover = (int)((100 * coveredStatements) / totalStatements);
                }


                context.ConsoleWrite("CodeCoverTask OK");
            }
            catch (Exception ex) {
                totalResult.UnitTestPassed = -1;
                totalResult.UnitTestTotal  = -1;
                context.ProcessException(ex);
            }
        }