/// <summary> /// Evaluates the policy and set the violations in the task list (error window of Visual Studio). /// </summary> /// <returns>The policy failures, if any, that occurred.</returns> public override PolicyFailure[] Evaluate() { PolicyFailure[] failures = null; using (EvaluationProcess process = new EvaluationProcess()) { // Analyse if there are any violations process.Initialize(new EvaluationContext(this, this.Settings, this.PendingCheckin)); failures = process.Analyze(); if (taskProvider != null) { // Set the settings into the taskprovider and clear it. taskProvider.Settings = this.Settings; taskProvider.Clear(); // If there are violations, add them to the tasks list (error window) if (failures != null && failures.Length > 0) { foreach (PolicyFailure failure in failures) { SourceAnalysisPolicyFailure policyFailure = (SourceAnalysisPolicyFailure)failure; foreach (Violation violation in policyFailure.Violations) { taskProvider.AddTask(violation); } } } } } return(failures); }
/// <summary> /// Evaluates the policy. /// </summary> /// <returns>The policy failures, if any, that occurred.</returns> public override PolicyFailure[] Evaluate() { PolicyFailure[] failures = null; var allViolation = new List <Violation>(); using (EvaluationProcess process = new EvaluationProcess()) { process.Initialize(new EvaluationContext(this, this.Settings, this.PendingCheckin)); failures = process.Analyze(); if (taskProvider != null) { taskProvider.Settings = this.Settings; taskProvider.Clear(); if (failures != null && failures.Length > 0) { foreach (PolicyFailure failure in failures) { SourceAnalysisPolicyFailure policyFailure = (SourceAnalysisPolicyFailure)failure; foreach (Violation violation in policyFailure.Violations) { taskProvider.AddTask(violation); allViolation.Add(violation); } } } } } if (allViolation.Count > 0) { return(allViolation.Select(v => new ExtendPolicyFailure(v, this)).Cast <PolicyFailure>().ToArray()); } return(failures ?? new PolicyFailure[0]); }