Esempio n. 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;
            }

            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);
            }
        }
        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);
            }
        }
Esempio n. 3
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;
            }

            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);
            }
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
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);
            }
        }
Esempio n. 6
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;
            }


            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);
            }
        }