Example #1
0
        public void RunProject(Project project, Action<Report, RunLogItem> onComplete)
        {
            var log = new RunLogItem();

            log.Start = DateTime.Now;
            log.Project = project.Name;

            if (project == null)
            {
                throw new ArgumentException();
            }

            if (project.RuleSet == null)
            {
                throw new Exception("RuleSet is not specified. ");
            }

            var context = new ExamContext(project);

            foreach (var i in project.RuleSet)
            {
                try
                {
                    i.Exam(context);
                }
                catch (Exception e)
                {
                    context.WriteOutput(i.Name, new Output
                    {
                        Summary = e.Message,
                        Details = new List<string>
                        {
                            e.ToString(),
                        },
                    });
                    context.AddResult(new ExamResult()
                    {
                        RuleName = i.Name,
                        Status = ActionStatus.Failed,
                    });
                    context.AddViolation(new Violation
                    {
                        RuleName = i.Name,
                        Description = e.Message,
                    });
                    continue;
                }
            }

            var report = context.GenerateReport();

            var path = SaveReportToFile(report);

            log.End = DateTime.Now;
            log.Status = report.Status;
            log.Report = path;
            log.Rules = project.RuleSet.Count;

            list.Insert(0, log);

            SaveRunlog(log);

            if (onComplete != null)
            {
                onComplete.Invoke(report, log);
            }
        }