Exemple #1
0
 protected Rule Rule <TParent>(Func <AnalysisMember <TParent> > forEachResult, Func <Result <TParent>, Tuple <bool, Severity> > condition, Evaluate evaluate, params Feature[] features)
 {
     return(this.BuildRule(forEachResult, delegate(Result x)
     {
         RuleResult ruleResult;
         try
         {
             Tuple <bool, Severity> tuple = condition((Result <TParent>)x);
             ruleResult = new RuleResult(tuple.Item1)
             {
                 Severity = new Severity?(tuple.Item2)
             };
         }
         catch (Exception exception)
         {
             ruleResult = new RuleResult(exception);
         }
         return new Result[]
         {
             ruleResult
         };
     }, evaluate, Severity.Info, features));
 }
Exemple #2
0
 protected Rule Rule(Func <Tuple <bool, Severity> > condition, Evaluate evaluate, params Feature[] features)
 {
     return(this.BuildRule(() => this.Analysis.RootAnalysisMember, delegate(Result x)
     {
         RuleResult ruleResult;
         try
         {
             Tuple <bool, Severity> tuple = condition();
             ruleResult = new RuleResult(tuple.Item1)
             {
                 Severity = new Severity?(tuple.Item2)
             };
         }
         catch (Exception exception)
         {
             ruleResult = new RuleResult(exception);
         }
         return new Result[]
         {
             ruleResult
         };
     }, evaluate, Severity.Info, features));
 }
Exemple #3
0
 internal RuleResult(RuleResult toCopy, AnalysisMember source, Result parent, ExDateTime startTime, ExDateTime stopTime) : base(toCopy, source, parent, startTime, stopTime)
 {
     this.Severity = toCopy.Severity;
 }
Exemple #4
0
 protected abstract TRuleConclusion BuildRuleConclusion(RuleResult ruleResult);
Exemple #5
0
        private IEnumerator <Result <T> > CreateProducerEnumerator()
        {
            AnalysisMember parent = base.Features.GetFeature <ForEachResultFeature>().ForEachResultFunc();

            if (parent == null)
            {
                this.OnStart();
                Result <T> rootResult = base.Analysis.RootAnalysisMember.UntypedResults.Single <Result>() as Result <T>;
                this.results = this.results.Add(rootResult);
                this.OnEvaluate(rootResult);
                yield return(rootResult);

                this.OnComplete();
            }
            else
            {
                Func <Result, IEnumerable <Result> > resultFunc = base.Features.GetFeature <ResultsFeature>().ResultFunc;
                Func <FeatureSet, Result, bool>      func;
                if (!base.Features.HasFeature <FilterFeature>())
                {
                    func = ((FeatureSet fs, Result r) => true);
                }
                else
                {
                    func = base.Features.GetFeature <FilterFeature>().FilterFunc;
                }
                Func <FeatureSet, Result, bool> filterFunc = func;
                this.OnStart();
                foreach (Result parentResult in parent.UntypedResults)
                {
                    if (!parentResult.HasException)
                    {
                        ExDateTime startTime = ExDateTime.Now;
                        Stopwatch  stopWatch = Stopwatch.StartNew();
                        foreach (Result result in resultFunc(parentResult))
                        {
                            Result <T> producerResult = (Result <T>)result;
                            if (base.IsAnalysisCanceled)
                            {
                                yield break;
                            }
                            stopWatch.Stop();
                            ExDateTime stopTime = startTime + stopWatch.Elapsed;
                            if (producerResult.HasException)
                            {
                                if (producerResult.Exception is AnalysisException)
                                {
                                    AnalysisException ex = (AnalysisException)producerResult.Exception;
                                    ex.AnalysisMemberSource = this;
                                }
                                if (producerResult.Exception is CriticalException)
                                {
                                    base.CancelAnalysis((CriticalException)producerResult.Exception);
                                }
                            }
                            Result <T> filterResult = producerResult;
                            try
                            {
                                if (!filterFunc(base.Features, producerResult))
                                {
                                    filterResult = new Result <T>(new FilteredException(this, producerResult));
                                }
                            }
                            catch (Exception inner)
                            {
                                base.CancelAnalysis(new CriticalException(this, inner));
                            }
                            Result <T> consumerResult;
                            if (filterResult is RuleResult)
                            {
                                RuleResult toCopy     = filterResult as RuleResult;
                                RuleResult ruleResult = new RuleResult(toCopy, this, parentResult, startTime, stopTime);
                                consumerResult = (ruleResult as Result <T>);
                            }
                            else
                            {
                                consumerResult = new Result <T>(filterResult, this, parentResult, startTime, stopTime);
                            }
                            this.results = this.results.Add(consumerResult);
                            this.OnEvaluate(consumerResult);
                            yield return(consumerResult);

                            startTime = stopTime;
                            stopWatch.Restart();
                        }
                    }
                }
                this.results = this.results.AsCompleted();
                this.OnComplete();
            }
            yield break;
        }