Exemple #1
0
        public void IgnoreRule(BestPracticeRule rule, bool ignore = true, IAnnotationObject obj = null)
        {
            if (obj == null)
            {
                obj = _model;
            }

            var ignoreRules = new AnalyzerIgnoreRules(obj ?? _model);

            if (ignore)
            {
                if (!ignoreRules.RuleIDs.Contains(rule.ID))
                {
                    ignoreRules.RuleIDs.Add(rule.ID);
                }
            }
            else
            {
                if (ignoreRules.RuleIDs.Contains(rule.ID))
                {
                    ignoreRules.RuleIDs.Remove(rule.ID);
                }
            }

            ignoreRules.Save(obj);
        }
Exemple #2
0
 public List <AnalyzerResult> ResultsByRule(BestPracticeRule rule)
 {
     if (_results.TryGetValue(rule, out List <AnalyzerResult> results))
     {
         return(results);
     }
     return(new List <AnalyzerResult>());
 }
Exemple #3
0
 private IReadOnlyDictionary <string, string> GetNUnitRuleProps(BestPracticeRule rule)
 {
     return(new Dictionary <string, string> {
         { "Description", rule.Description },
         { "Severity", rule.Severity.ToString() },
         { "Category", rule.Category },
         { "RuleID", rule.ID }
     });
 }
Exemple #4
0
        public void AddRule(BestPracticeRule rule, bool global = false)
        {
            rule.ID = GetUniqueId(rule.ID);
            if (global)
            {
                GlobalRules.Add(rule);
            }
            else
            {
                LocalRules.Add(rule);
            }

            DoCollectionChanged(NotifyCollectionChangedAction.Add, rule);
        }
Exemple #5
0
 public void AssignFrom(BestPracticeRule other)
 {
     Category           = other.Category;
     CompatibilityLevel = other.CompatibilityLevel;
     Description        = other.Description;
     Enabled            = other.Enabled;
     ErrorMessage       = other.ErrorMessage;
     Expression         = other.Expression;
     FixExpression      = other.FixExpression;
     ID          = other.ID;
     IsValid     = other.IsValid;
     Name        = other.Name;
     ObjectCount = other.ObjectCount;
     Scope       = other.Scope;
     Severity    = other.Severity;
 }
Exemple #6
0
        public IEnumerable <AnalyzerResult> Analyze(BestPracticeRule rule)
        {
            if (rule.CompatibilityLevel > Model.Database.CompatibilityLevel)
            {
                yield return new AnalyzerResult {
                           Rule = rule, InvalidCompatibilityLevel = true
                }
            }
            ;

            // Loop through the types of objects in scope for this rule:
            foreach (var currentScope in rule.Scope.Enumerate())
            {
                // Gets a collection of all objects of this type:
                var collection = GetCollection(currentScope);

                LambdaExpression lambda = null;

                bool   isError    = false;
                string errMessage = string.Empty;

                // Parse the expression specified on the rule (this can fail if the expression is malformed):
                try
                {
                    lambda = System.Linq.Dynamic.DynamicExpression.ParseLambda(collection.ElementType, typeof(bool), rule.Expression);
                }
                catch (Exception ex)
                {
                    // Hack, since compiler does not allow to yield return directly from a catch block:
                    isError    = true;
                    errMessage = ex.Message;
                }
                if (isError)
                {
                    yield return(new AnalyzerResult {
                        Rule = rule, RuleError = errMessage, RuleErrorScope = currentScope
                    });
                }
                else
                {
                    var result = new List <ITabularNamedObject>();
                    try
                    {
                        result = collection.Provider.CreateQuery(
                            Expression.Call(
                                typeof(Queryable), "Where",
                                new Type[] { collection.ElementType },
                                collection.Expression, Expression.Quote(lambda))).OfType <ITabularNamedObject>().ToList();
                    }
                    catch (Exception ex)
                    {
                        isError    = true;
                        errMessage = ex.Message;
                    }
                    if (isError)
                    {
                        yield return(new AnalyzerResult {
                            Rule = rule, RuleError = errMessage, RuleErrorScope = currentScope
                        });
                    }
                    else
                    {
                        foreach (var res in result)
                        {
                            yield return new AnalyzerResult {
                                       Rule = rule, Object = res
                            }
                        }
                    };
                }
            }
        }
Exemple #7
0
 public int ObjectCountByRule(BestPracticeRule rule)
 {
     return(ResultsByRule(rule).Count(r => !r.Ignored));
 }
Exemple #8
0
 public IEnumerable <AnalyzerResult> Analyze(BestPracticeRule rule)
 {
     return(rule.Analyze(Model));
 }