/// <summary> /// Checks a specific rule against a provided project /// </summary> /// <param name="project">The project to apply the rule to</param> /// <param name="rule">The rule to apply</param> /// <param name="errorMessage">The error message describing why the rule failed (null if it passed)</param> /// <returns>True if the rule passed, otherwise false</returns> private static bool CheckRule(ProjectInfo project, RefRule rule, out string errorMessage) { errorMessage = null; if (rule.Type == RuleType.Include) { var includeRule = rule as SingleRefRule; // Check if ref is included in either the local or global references var isRefIncluded = project.Refs.Contains(includeRule.Ref) || project.ProjectRefs.Contains(includeRule.Ref); if (!isRefIncluded) { errorMessage = includeRule.Ref + " is required to be referenced in project " + project.Name; } return(isRefIncluded); } if (rule.Type == RuleType.Exclude) { var excludeRule = rule as SingleRefRule; // Check if the ref is not in either the global or local references var isRefExcluded = !project.Refs.Contains(excludeRule.Ref) && !project.ProjectRefs.Contains(excludeRule.Ref); if (!isRefExcluded) { errorMessage = excludeRule.Ref + " should not be a reference in project " + project.Name; } return(isRefExcluded); } if (rule.Type == RuleType.OnlyLocalReferences) { var localRule = rule as MultiRefRule; // First check if there are any local project references that are not on the rules included list var invalidProjRefs = project.ProjectRefs.Where(x => !localRule.Refs.Contains(x)); if (invalidProjRefs.Any()) { errorMessage = project.Name + " contains invalid local project references, "; errorMessage += String.Join(", ", invalidProjRefs); return(false); } // Secondly, check if there are any references on the rules included list that is not in the project var missingProfRefs = localRule.Refs.Where(x => !project.ProjectRefs.Contains(x)).ToList(); if (missingProfRefs.Any()) { errorMessage = project.Name + " should contain the local references, "; errorMessage += String.Join(", ", missingProfRefs); return(false); } return(true); } errorMessage = "Rule was not recognised"; return(false); }
public ReportEntry(ReportLevel level, string message, RefRule rule = null) { Level = level; Message = message; Rule = rule; }