Exemple #1
0
        /// <summary>
        ///     Executes the completeness.
        /// </summary>
        /// <typeparam name="TAssessment">The type of the assessment.</typeparam>
        /// <param name="completenessCategory">The completeness category.</param>
        /// <param name="assessment">The assessment.</param>
        /// <param name="ruleSet">The rule set.</param>
        /// <returns></returns>
        public CompletenessResults ExecuteCompleteness <TAssessment> (string completenessCategory, TAssessment assessment, string ruleSet)
        {
            var ruleCollection = _completenessRuleCollectionFactory.GetCompletenessRuleCollection <TAssessment> (completenessCategory);
            var ruleEngine     = _ruleEngineFactory.CreateRuleEngine(assessment, ruleCollection);

            return(ExecuteCompleteness(ruleEngine, completenessCategory, assessment, ruleSet));
        }
Exemple #2
0
        public void Run(AssessmentInstance assessmentInstance)
        {
            //TODO:If Required
            //Need to update pillar to allow for named rule collections _ruleCollectionFactory.CreateRuleCollection<AssessmentInstance>("NidaWorkflow");
            var ruleCollection    = IoC.CurrentContainer.Resolve <NidaWorkflowRuleCollection>();
            var ruleEngine        = _ruleEngineFactory.CreateRuleEngine(assessmentInstance, ruleCollection);
            var ruleEngineContext = new RuleEngineContext <AssessmentInstance>(assessmentInstance, new SelectAllRulesInRuleSetSelector(assessmentInstance.AssessmentName + "RuleSet"));

            ruleEngineContext.WorkingMemory.AddContextObject(_messageCollector, "MessageCollector");
            ruleEngine.ExecuteRules(ruleEngineContext);
        }
        public CompletenessResults CalculateCompleteness <TAssessment>(string completenessCategory, TAssessment assessment, IContainItemDefinitions itemDefinitionContainer) where TAssessment : AssessmentInstance
        {
            var completenessResults = CalculateCompleteness(assessment, itemDefinitionContainer, completenessCategory);
            //todo: to better use completenessCategory
            var ruleCollection         = _completenessRuleCollectionFactory.GetCompletenessRuleCollection <TAssessment>(assessment.AssessmentName);
            var ruleEngine             = _ruleEngineFactory.CreateRuleEngine(assessment, ruleCollection);
            var skippedQuestionResults = ruleEngine.ExecuteRuleSet(assessment, "CompletenessRuleSet");

            completenessResults.UpdateTotal(completenessResults.Total - skippedQuestionResults.RuleViolations.Count());

            return(completenessResults);
        }
Exemple #4
0
        /// <summary>
        /// Gets the interceptor options.
        /// </summary>
        /// <typeparam name="TOwner">The type of the owner.</typeparam>
        /// <param name="frameworkCommandInfo">The framework command info.</param>
        /// <returns>Options object to add to Command.</returns>
        public object GetInterceptorOptions <TOwner> (IFrameworkCommandInfo frameworkCommandInfo)
        {
            IRuleSelector ruleSelector;

            if (frameworkCommandInfo is IRuleCommandInfo)
            {
                ruleSelector = (frameworkCommandInfo as IRuleCommandInfo).RuleSelector;
            }
            else
            {
                ruleSelector =
                    new SelectAllRulesInRuleSetSelector(
                        frameworkCommandInfo.Name.EndsWith("RuleSet") ? frameworkCommandInfo.Name : frameworkCommandInfo.Name + "RuleSet");
            }

            IRuleEngine <TOwner> ruleEngine = null;
            var triedCreateRuleEngine       = false;

            var context = new RuleEngineContext <TOwner> (( TOwner )frameworkCommandInfo.Owner, ruleSelector);

            var ruleExecutor = new RuleExecutor
            {
                ExecuteRules = o =>
                {
                    if (!triedCreateRuleEngine)
                    {
                        triedCreateRuleEngine = true;
                        ruleEngine            = _ruleEngineFactory.CreateRuleEngine <TOwner>();
                    }
                    if (ruleEngine != null)
                    {
                        context.Refresh();
                        if (o != null)
                        {
                            context.WorkingMemory.AddContextObject(o);
                            if (context.RuleSelector is ITakeParameter)
                            {
                                (context.RuleSelector as ITakeParameter).Parameter = o;
                            }
                        }
                        return(ruleEngine.ExecuteRules(context));
                    }
                    return(new RuleExecutionResult(Enumerable.Empty <RuleViolation> ()));
                }
            };

            return(ruleExecutor);
        }