/// <summary> /// Creates a RuleFilteringInfo object that describes any rule specific filtering that should be applied to a rule. /// </summary> /// <param name="rule">Rule configuration object.</param> /// <returns>RuleFilteringInfo.</returns> protected RuleFilteringInfo CreateRuleFiltering(ResourceStaticAnalysisRulesConfig.Rule rule) { var filteringExpressionMethod = this.CreateFilteringExpression(rule.Cultures, rule.Projects, rule.FilteringExpressions); RuleFilteringInfo ruleFilter = null; if (filteringExpressionMethod != null) { ruleFilter = new RuleFilteringInfo(); ruleFilter.ReplaceExisting = rule.OverrideContainerFiltering; ruleFilter.RuleName = rule.Type; ruleFilter.FilteringExpressionMethod = filteringExpressionMethod; } return(ruleFilter); }
/// <summary> /// Process the ResourceStaticAnalysisRulesConfig to create the required filtering for the RuleContainer. /// </summary> /// <param name="rulesConfig">ResourceStaticAnalysisRulesConfig object to process.</param> /// <param name="ruleContainer">RuleContainer object to update with the filtering.</param> protected void ProcessRuleConfig(ResourceStaticAnalysisRulesConfig rulesConfig, RuleContainer ruleContainer) { if (rulesConfig == null || ruleContainer == null) { return; } ruleContainer.FilteringExpressionMethod = this.CreateFilteringExpression(rulesConfig.Cultures, rulesConfig.Projects, rulesConfig.FilteringExpressions); List <RuleFilteringInfo> ruleFilters = new List <RuleFilteringInfo>(); foreach (ResourceStaticAnalysisRulesConfig.Rule rule in rulesConfig.Rules) { if (rule.Enabled) { RuleFilteringInfo ruleFilteringInfo = this.CreateRuleFiltering(rule); if (ruleFilteringInfo != null) { ruleFilters.Add(ruleFilteringInfo); } } else { ruleContainer.DisabledRules.Add(rule.Type); } } if (ruleFilters.Any()) { ruleContainer.PerRuleFilteringExpressionMethods = ruleFilters; } if (!String.IsNullOrWhiteSpace(rulesConfig.WorkingFolder)) { String workingFolder = Environment.ExpandEnvironmentVariables(rulesConfig.WorkingFolder); if (!Path.IsPathRooted(workingFolder) && !String.IsNullOrWhiteSpace(rulesConfig.PathToConfigFile)) { workingFolder = Path.Combine(Path.GetDirectoryName(rulesConfig.PathToConfigFile), workingFolder); } ruleContainer.WorkingFolder = Path.GetFullPath(workingFolder); } }