Exemplo n.º 1
0
 /// <summary>Adds rule set and context object for this rule engine execution.</summary>
 /// <param name="ruleEngineExecutor">The rule engine executor.</param>
 /// <param name="itemInstance">The item instance.</param>
 /// <param name="callingMethod">The calling method.</param>
 /// <returns>A <see cref="RuleEngineExecutor{AssessmentInstance}" />.</returns>
 public static RuleEngineExecutor <AssessmentInstance> ForItemInstance(
     this RuleEngineExecutor <AssessmentInstance> ruleEngineExecutor,
     ItemInstance itemInstance,
     [CallerMemberName] string callingMethod = "")
 {
     Check.IsNotNull(itemInstance, "itemInstance is required");
     return(ruleEngineExecutor
            .ForRuleSet(callingMethod + "RuleSet" + itemInstance.ItemDefinitionCode)
            .WithContext(itemInstance, itemInstance.ItemDefinitionCode));
 }
Exemplo n.º 2
0
        private void Apply(ItemUpdatedEvent itemUpdatedEvent)
        {
            var itemInstance = ItemInstances.FirstOrDefault(ii => ii.ItemDefinitionCode == itemUpdatedEvent.ItemDefinitionCode);
            var isNull       = itemUpdatedEvent.Value == null || string.IsNullOrEmpty(itemUpdatedEvent.Value.ToString());

            if (itemInstance != null && isNull)
            {
                _itemInstances.Remove(itemInstance);
            }

            if (itemInstance == null)
            {
                itemInstance = new ItemInstance(itemUpdatedEvent.ItemDefinitionCode, itemUpdatedEvent.Value, itemUpdatedEvent.IsRequired);
                if (!isNull)
                {
                    _itemInstances.Add(itemInstance);
                }
            }
            else
            {
                itemInstance.Apply(itemUpdatedEvent);
            }

            var skippingContext = new SkippingContext();

            if (_cachedRuleEngineExecutor == null)
            {
                var assessmentRuleCollectionFactory = new AssessmentRuleCollectionFactory();
                _cachedRuleEngineExecutor = new RuleEngineExecutor <AssessmentInstance> (
                    this,
                    assessmentRuleCollectionFactory.CreateRuleCollection(this.AssessmentName));
            }
            _cachedRuleEngineExecutor
            .ForRuleSet("ItemUpdatedRuleSet" + itemInstance.ItemDefinitionCode)
            .WithContext(itemInstance, itemInstance.ItemDefinitionCode)
            .WithContext(skippingContext)
            .Execute();

            skippingContext.SkippedItemDefinitions.ForEach(
                item =>
            {
                if (item.GetIsRequired() && !_skippedItemDefinitions.Contains(item))
                {
                    _skippedItemDefinitions.Add(item);
                }
                if (ItemInstances.Any(i => i.ItemDefinitionCode == item.CodedConcept.Code))
                {
                    UpdateItem(item, null);
                }
            });
            skippingContext.UnSkippedItemDefinitions.ForEach(item => _skippedItemDefinitions.Remove(item));
        }
 public static RuleEngineExecutor <AssessmentInstance> ForItemDefinitionCode(this RuleEngineExecutor <AssessmentInstance> ruleEngineExecutor, string itemDefinitionCode)
 {
     return(ruleEngineExecutor.ForRuleSet("RuleSet" + itemDefinitionCode));
 }
Exemplo n.º 4
0
 /// <summary>
 ///     Fors the calling method rule set.
 /// </summary>
 /// <typeparam name="T">Type of rule engine subject.</typeparam>
 /// <param name="ruleEngineExecutor">The rule engine executor.</param>
 /// <param name="caller">The caller.</param>
 /// <returns>
 ///     A rule engine executor.
 /// </returns>
 public static RuleEngineExecutor <T> ForCallingMethodRuleSet <T> (
     this RuleEngineExecutor <T> ruleEngineExecutor,
     [CallerMemberName] string caller = null)
 {
     return(ruleEngineExecutor.ForRuleSet(caller + "RuleSet"));
 }