コード例 #1
0
        public static string ToString(RuleInstance source)
        {
            var sb = new StringBuilder();

            sb.Append("{:");

            if (source.Name != null)
            {
                sb.Append($" {source.Name.NameValue}");
            }

            sb.Append(ToString(source.PrimaryPart));

            if (!source.SecondaryParts.IsNullOrEmpty())
            {
                sb.Append(" -> ");

                if (source.SecondaryParts.Count == 1)
                {
                    var firstSecondaryRulePart = source.SecondaryParts.Single();

                    sb.Append(ToString(firstSecondaryRulePart));
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            sb.Append(" :}");
            sb.Append(AnnotatedItemToString(source));

            return(sb.ToString());
        }
コード例 #2
0
 /// <inheritdoc/>
 public void Remove(RuleInstance ruleInstance)
 {
     lock (_lockObj)
     {
         NRemove(ruleInstance);
     }
 }
コード例 #3
0
        private void NRemove(RuleInstance ruleInstance)
        {
#if DEBUG
            //Log($"ruleInstance = {ruleInstance}");
#endif

            if (!_ruleInstancesList.Contains(ruleInstance))
            {
                return;
            }

            _ruleInstancesList.Remove(ruleInstance);

            var ruleInstanceName = ruleInstance.Name;

            _ruleInstancesDict.Remove(ruleInstanceName);

            var longHashCode = ruleInstance.GetLongHashCode();

            _ruleInstancesDictByHashCode.Remove(longHashCode);

            var ruleInstanceId = ruleInstance.Name.NameValue;

            _ruleInstancesDictById.Remove(ruleInstanceId);

            _commonPersistIndexedLogicalData.NRemoveIndexedRuleInstanceFromIndexData(ruleInstance.Normalized);

            EmitOnChanged(ruleInstance.UsedKeysList);
        }
コード例 #4
0
        /// <inheritdoc/>
        public void Append(RuleInstance ruleInstance, bool isPrimary)
        {
            lock (_lockObj)
            {
                ruleInstance.CheckDirty();

                var annotationsList = ruleInstance.GetAllAnnotations();

#if DEBUG
                //_gbcLogger.Info($"ruleInstance = {ruleInstance}");
                ////_gbcLogger.Info($"ruleInstance = {DebugHelperForRuleInstance.ToString(ruleInstance)}");
                //Log($"annotationsList = {annotationsList.WriteListToString()}");
#endif

                foreach (var annotationRuleInstance in annotationsList)
                {
                    NAppend(annotationRuleInstance, false);
                }

                NAppend(ruleInstance, isPrimary);

                //var indexedRuleInstance = ruleInstance.GetIndexed(_mainStorageContext);

                var usedKeysList = ruleInstance.Normalized.UsedKeysList.Concat(annotationsList.SelectMany(p => p.UsedKeysList)).Distinct().ToList();

                EmitOnChanged(usedKeysList);
            }
        }
コード例 #5
0
ファイル: RuleDefinition.cs プロジェクト: Denifia/RulesEngine
 public void Setup(RuleInstance ruleInstance)
 {
     _ruleInstance = ruleInstance;
     DeserializeParameters(ruleInstance.Parameters);
     if (!_parameters.IsValid())
     {
         throw new ApplicationException("Parameters are not valid");
     }
 }
コード例 #6
0
        private static void FillBaseRulePart(BaseRulePart source, BaseRulePart dest, RuleInstance ruleInstance, Dictionary <object, object> convertingContext)
        {
            dest.Parent   = ruleInstance;
            dest.IsActive = source.IsActive;

            dest.Expression = ConvertLogicalQueryNode(source.Expression, convertingContext);

            FillAnnotationsModalitiesAndSections(source, dest, convertingContext);
        }
コード例 #7
0
ファイル: RuleContext.cs プロジェクト: vsssunder/automatica
 public RuleContext(RuleInstance ruleInstance, IDispatcher dispatcher, IRuleInstanceVisuNotify notify, ILogger logger, IServerCloudApi api, ILicenseContract licenseContract)
 {
     RuleInstance    = ruleInstance;
     Dispatcher      = dispatcher;
     Notify          = notify;
     Logger          = logger;
     CloudApi        = api;
     LicenseContract = licenseContract;
 }
        public void MakeInactiveRuleInstance()
        {
            RuleInstance ruleInstance = null;;

            try
            {
                ruleInstance = _repository.GetAll <RuleInstance>().FirstOrDefault(l => l.InstanceName == Environment.MachineName);

                if (ruleInstance != null)
                {
                    ruleInstance.Active = false;
                    _repository.Save(ruleInstance);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #9
0
        private RuleInstance CreateInheritanceFact(InheritanceItem inheritanceItem)
        {
            var factName = NameHelper.CreateRuleOrFactName();

#if DEBUG
            //Log($"factName = {factName}");
#endif

            var fact = new RuleInstance();
            fact.Kind = KindOfRuleInstance.Fact;
            fact.AppendAnnotations(inheritanceItem);
            fact.Name = factName;
            //fact.KeysOfPrimaryRecords.Add(inheritanceItem.Id);

            var primaryPart = new PrimaryRulePart();
            fact.PrimaryPart   = primaryPart;
            primaryPart.Parent = fact;

            var isRelation = new LogicalQueryNode();
            isRelation.Name       = NameHelper.CreateName("is");
            isRelation.Kind       = KindOfLogicalQueryNode.Relation;
            isRelation.ParamsList = new List <LogicalQueryNode>();

            primaryPart.Expression = isRelation;

            var subItemNode = new LogicalQueryNode();
            isRelation.ParamsList.Add(subItemNode);
            subItemNode.Kind = KindOfLogicalQueryNode.Concept;
            subItemNode.Name = inheritanceItem.SubName;

            var superItemNode = new LogicalQueryNode();
            isRelation.ParamsList.Add(superItemNode);
            superItemNode.Kind = KindOfLogicalQueryNode.Concept;
            superItemNode.Name = inheritanceItem.SuperName;

            var rankNode = new LogicalQueryNode();
            isRelation.ParamsList.Add(rankNode);
            rankNode.Kind  = KindOfLogicalQueryNode.Value;
            rankNode.Value = inheritanceItem.Rank;

            return(fact);
        }
コード例 #10
0
        public static RuleInstance Convert(RuleInstance source, Dictionary <object, object> convertingContext)
        {
#if DEBUG
            //_gbcLogger.Info($"source = {source}");
#endif

            if (source == null)
            {
                return(null);
            }

            if (convertingContext.ContainsKey(source))
            {
                return((RuleInstance)convertingContext[source]);
            }

            var result = new RuleInstance()
            {
                IsSource = false, Original = source
            };
            convertingContext[source] = result;
            result.Normalized         = result;

            result.PrimaryPart = ConvertPrimaryRulePart(source.PrimaryPart, result, convertingContext);

            if (!source.SecondaryParts.IsNullOrEmpty())
            {
                foreach (var secondaryPart in source.SecondaryParts)
                {
                    result.SecondaryParts.Add(ConvertSecondaryRulePart(secondaryPart, result, convertingContext));
                }
            }

            FillAnnotationsModalitiesAndSections(source, result, convertingContext);

#if DEBUG
            //_gbcLogger.Info($"result = {result}");
#endif

            return(result);
        }
コード例 #11
0
        public void StoreConfiguration(IReadOnlyCollection <IRule> rules, string targetUri)
        {
            var ruleInstances = new List <RuleInstance>(rules.Count);

            foreach (var rule in rules)
            {
                var ruleInstance = new RuleInstance();
                ruleInstance.AssemblyQualifiedRuleTypeName = rule.GetType().AssemblyQualifiedName;
                ruleInstance.GeneralConfig = JsonConvert.SerializeObject(rule.Configuration, Formatting.Indented);
                var specificRule = rule as IRuleWithConfiguration <ISpecificConfiguration>;
                if (specificRule != null)
                {
                    ruleInstance.SpecificConfig = JsonConvert.SerializeObject(specificRule.SpecificConfiguration, Formatting.Indented, jsonSerializerSettings);
                }
                ruleInstances.Add(ruleInstance);
            }

            var serializedRuleInstances = JsonConvert.SerializeObject(ruleInstances, Formatting.Indented);

            storage.StoreString(serializedRuleInstances, targetUri);
        }
        public void CreateOrUpdateRuleInstance()
        {
            //_context.StartEventLog("CreateOrUpdateRuleInstance start");
            _logger.Info("CreateOrUpdateRuleInstance");
            RuleInstance ruleInstance = null;

            try
            {
                ruleInstance = _repository.GetAll <RuleInstance>().FirstOrDefault(l => l.InstanceName == Environment.MachineName);

                //if thre is not rule instance then create
                if (ruleInstance == null)
                {
                    ruleInstance = new RuleInstance
                    {
                        InstanceName = Environment.MachineName,
                        QueueSize    = int.Parse(ConfigurationManager.AppSettings["MaxQueueSize"]),
                        Active       = true
                    };

                    _repository.Save(ruleInstance);
                }
                else
                {
                    int queueSizeConfig = int.Parse(ConfigurationManager.AppSettings["MaxQueueSize"]);
                    //if exist rule instance check if is diference to updated.
                    if ((!ruleInstance.Active) || (ruleInstance.QueueSize != queueSizeConfig))
                    {
                        ruleInstance.QueueSize = queueSizeConfig;
                        ruleInstance.Active    = true;
                        _repository.Save(ruleInstance);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Error in locator CreateOrUpdateRuleInstance", ex);
            }
            //_context.EndEventLog();
        }
コード例 #13
0
        public RuleInstance CreateRuleInstanceFromTemplate(RuleTemplate template)
        {
            var rule = new RuleInstance();

            foreach (var i in template.RuleInterfaceTemplate)
            {
                var intInst = new RuleInterfaceInstance();

                intInst.This2RuleInstanceNavigation          = rule;
                intInst.This2RuleInterfaceTemplateNavigation = i;
                intInst.This2RuleInterfaceTemplate           = i.ObjId;
                intInst.Value = i.DefaultValue;

                rule.RuleInterfaceInstance.Add(intInst);
            }

            rule.Name = template.Name;
            rule.This2RuleTemplate           = template.ObjId;
            rule.This2RuleTemplateNavigation = template;


            return(rule);
        }
コード例 #14
0
 public async Task NotifyValueChanged(RuleInstance instance, object value)
 {
     await hub.Clients.All.SendAsync("RuleInstanceValueChanged", instance.ObjId, value);
 }
コード例 #15
0
 /// <inheritdoc/>
 public void Append(RuleInstance ruleInstance)
 {
     Append(ruleInstance, true);
 }
コード例 #16
0
 public RuleContextMock(RuleInstance instance)
 {
     RuleInstance = instance;
     Notify       = new RuleInstanceVisuNotifyMock();
 }
コード例 #17
0
        private void NAppend(RuleInstance ruleInstance, bool isPrimary)
        {
#if DEBUG
            //Log($"ruleInstance = {ruleInstance}");
            //Log($"isPrimary = {isPrimary}");
            //Log($"ruleInstance = {DebugHelperForRuleInstance.ToString(ruleInstance)}");
#endif

            if (_ruleInstancesList.Contains(ruleInstance))
            {
                return;
            }

            var ruleInstanceId = ruleInstance.Name.NameValue;

            if (_ruleInstancesDictById.ContainsKey(ruleInstanceId))
            {
                return;
            }

            //ruleInstance = ruleInstance.Clone();

#if DEBUG
            //Log($"ruleInstance (after) = {ruleInstance}");
#endif

            //var indexedRuleInstance = ruleInstance.GetIndexed(_realStorageContext.MainStorageContext);

#if DEBUG
            //Log($"indexedRuleInstance = {indexedRuleInstance}");
#endif

            var ruleInstanceName = ruleInstance.Name;

#if DEBUG
            //Log($"ruleInstanceName = {ruleInstanceName}");
#endif

            if (_ruleInstancesDict.ContainsKey(ruleInstanceName))
            {
                return;
            }

            var longHashCode = ruleInstance.GetLongHashCode();

#if DEBUG
            //Log($"longHashCode = {longHashCode}");
#endif

            if (_ruleInstancesDictByHashCode.ContainsKey(longHashCode))
            {
                return;
            }

            _ruleInstancesList.Add(ruleInstance);
            _ruleInstancesDict[ruleInstanceName]       = ruleInstance;
            _ruleInstancesDictByHashCode[longHashCode] = ruleInstance;
            _ruleInstancesDictById[ruleInstanceId]     = ruleInstance;

#if DEBUG
            //Log($"ruleInstance = {DebugHelperForRuleInstance.ToString(ruleInstance)}");
            //Log($"ruleInstance.Normalized = {DebugHelperForRuleInstance.ToString(ruleInstance.Normalized)}");
#endif

            _commonPersistIndexedLogicalData.NSetIndexedRuleInstanceToIndexData(ruleInstance.Normalized);

            if (isPrimary && _kind != KindOfStorage.PublicFacts && _kind != KindOfStorage.PerceptedFacts)
            {
#if DEBUG
                //Log($"_kind = {_kind}");
#endif

                var inheritanceRelationsList = ruleInstance.GetInheritanceRelations();
                //var ruleInstanceName = ruleInstance.Name.NameValue;

                if (inheritanceRelationsList.Any())
                {
                    var inheritanceStorage = _realStorageContext.InheritanceStorage;

                    foreach (var inheritanceRelation in inheritanceRelationsList)
                    {
#if DEBUG
                        //Log($"inheritanceRelation = {inheritanceRelation}");
#endif
                        var inheritanceItem = new InheritanceItem();

                        if (inheritanceRelation.Name == NameHelper.CreateName("is"))
                        {
                            var paramsCount = inheritanceRelation.ParamsList.Count;

                            switch (paramsCount)
                            {
                            case 2:
                                inheritanceItem.SuperName = inheritanceRelation.ParamsList[1].Name;
                                inheritanceItem.SubName   = inheritanceRelation.ParamsList[0].Name;
                                inheritanceItem.Rank      = new LogicalValue(1);
                                break;

                            case 3:
                                inheritanceItem.SuperName = inheritanceRelation.ParamsList[1].Name;
                                inheritanceItem.SubName   = inheritanceRelation.ParamsList[0].Name;
                                var thirdParameter       = inheritanceRelation.ParamsList[2];
                                var kindOfthirdParameter = thirdParameter.Kind;
                                switch (kindOfthirdParameter)
                                {
                                case KindOfLogicalQueryNode.Concept:
                                    inheritanceItem.Rank = thirdParameter.Name;
                                    break;

                                case KindOfLogicalQueryNode.FuzzyLogicNonNumericSequence:
                                    inheritanceItem.Rank = thirdParameter.FuzzyLogicNonNumericSequenceValue;
                                    break;

                                case KindOfLogicalQueryNode.Value:
                                    inheritanceItem.Rank = thirdParameter.Value;
                                    break;

                                default:
                                    throw new ArgumentOutOfRangeException(nameof(kindOfthirdParameter), kindOfthirdParameter, null);
                                }
                                break;

                            default:
                                throw new ArgumentOutOfRangeException(nameof(paramsCount), paramsCount, null);
                            }
                        }
                        else
                        {
                            inheritanceItem.SuperName = inheritanceRelation.Name;
                            inheritanceItem.SubName   = inheritanceRelation.ParamsList.Single().Name;
                            inheritanceItem.Rank      = new LogicalValue(1);
                        }

                        inheritanceItem.KeysOfPrimaryRecords.Add(ruleInstanceName);
#if DEBUG
                        //Log($"inheritanceItem = {inheritanceItem}");
#endif

                        inheritanceStorage.SetInheritance(inheritanceItem, false);
                    }
                }
            }

#if IMAGINE_WORKING
            //Log("End");
#else
            throw new NotImplementedException();
#endif
        }
コード例 #18
0
        private bool TestRule(BaseLogic protocolStep, BaseLogic initialAssumption)
        {
            bool added = false;

            #region ValidationRules
            AIsAuthenticated = protocolStep.GetType() == typeof(Believe) &&
                               ((Believe)protocolStep).Agent1.Equals(new Agent {
                Name = "A"
            }) &&
                               (bool)RuleInstance <AuthenticationRule> .GetResult(protocolStep);

            BIsAuthenticated = protocolStep.GetType() == typeof(Believe) &&
                               ((Believe)protocolStep).Agent1.Equals(new Agent {
                Name = "B"
            }) &&
                               (bool)RuleInstance <AuthenticationRule> .GetResult(protocolStep);

            AAuthenticationValidation = protocolStep.GetType() == typeof(Believe) &&
                                        ((Believe)protocolStep).Agent1.Equals(new Agent {
                Name = "A"
            }) &&
                                        (bool)RuleInstance <ConfirmationKeyRule> .GetResult(protocolStep);

            BAuthenticationValidation = protocolStep.GetType() == typeof(Believe) &&
                                        ((Believe)protocolStep).Agent1.Equals(new Agent {
                Name = "B"
            }) &&
                                        (bool)RuleInstance <ConfirmationKeyRule> .GetResult(protocolStep);

            if (AIsAuthenticated && BIsAuthenticated && AAuthenticationValidation && BAuthenticationValidation)
            {
                return(true);
            }
            #endregion

            #region FreshRule
            BaseLogic freshRule = (BaseLogic)RuleInstance <FreshRule> .GetResult(protocolStep, initialAssumption);

            if (freshRule != null)
            {
                if (!CurrentKnowledge.Contains(freshRule))
                {
                    CurrentKnowledge.Add(freshRule);
                    added = true;
                }
            }
            #endregion

            #region BelieveConcatenation
            BaseLogic believeConcatenationResult = (BaseLogic)RuleInstance <BelieveConcatenation> .GetResult(protocolStep, initialAssumption);

            if (believeConcatenationResult != null)
            {
                if (!CurrentKnowledge.Contains(believeConcatenationResult))
                {
                    CurrentKnowledge.Add(believeConcatenationResult);
                    added = true;
                }
            }
            BaseLogic believeConcatenation2Result = (BaseLogic)RuleInstance <BelieveConcatenation> .GetResult(initialAssumption, protocolStep);

            if (believeConcatenation2Result != null)
            {
                if (!CurrentKnowledge.Contains(believeConcatenation2Result))
                {
                    CurrentKnowledge.Add(believeConcatenation2Result);
                    added = true;
                }
            }
            #endregion

            #region BelieveDecomposition
            var believeDecompositionResult = (List <BaseLogic>) RuleInstance <BelieveDecomposition> .GetResult(protocolStep);

            if (believeDecompositionResult != null)
            {
                foreach (BaseLogic believeDecompositionLogic in believeDecompositionResult)
                {
                    if (!CurrentKnowledge.Contains(believeDecompositionLogic))
                    {
                        CurrentKnowledge.Add(believeDecompositionLogic);
                        added = true;
                    }
                }
            }
            #endregion

            #region BelieveSaidConcatenation
            var believeSaidConcatenationResult = (List <BaseLogic>) RuleInstance <BelieveSaidConcatenation> .GetResult(protocolStep, initialAssumption);

            if (believeSaidConcatenationResult != null)
            {
                foreach (BaseLogic believeSaidConcatenationLogic in believeSaidConcatenationResult)
                {
                    if (!CurrentKnowledge.Contains(believeSaidConcatenationLogic))
                    {
                        CurrentKnowledge.Add(believeSaidConcatenationLogic);
                        added = true;
                    }
                }
            }
            #endregion

            #region JurisdictionRule
            BaseLogic jurisdictionRuleResult = (BaseLogic)RuleInstance <JurisdictionRule> .GetResult(protocolStep, initialAssumption);

            if (jurisdictionRuleResult != null)
            {
                if (!CurrentKnowledge.Contains(jurisdictionRuleResult))
                {
                    CurrentKnowledge.Add(jurisdictionRuleResult);
                    added = true;
                }
            }
            BaseLogic jurisdictionRule2Result = (BaseLogic)RuleInstance <JurisdictionRule> .GetResult(initialAssumption, protocolStep);

            if (jurisdictionRule2Result != null)
            {
                if (!CurrentKnowledge.Contains(jurisdictionRule2Result))
                {
                    CurrentKnowledge.Add(jurisdictionRule2Result);
                    added = true;
                }
            }
            #endregion

            #region NonceVerificationRule
            BaseLogic nonceVerificationRuleResult = (BaseLogic)RuleInstance <NonceVerificationRule> .GetResult(protocolStep, initialAssumption);

            if (nonceVerificationRuleResult != null)
            {
                if (!CurrentKnowledge.Contains(nonceVerificationRuleResult))
                {
                    CurrentKnowledge.Add(nonceVerificationRuleResult);
                    added = true;
                }
            }
            BaseLogic nonceVerificationRule2Result = (BaseLogic)RuleInstance <NonceVerificationRule> .GetResult(initialAssumption, protocolStep);

            if (nonceVerificationRule2Result != null)
            {
                if (!CurrentKnowledge.Contains(nonceVerificationRule2Result))
                {
                    CurrentKnowledge.Add(nonceVerificationRule2Result);
                    added = true;
                }
            }
            #endregion

            #region ReceivePublicRule
            BaseLogic receivePublicRuleResult = (BaseLogic)RuleInstance <ReceivePublicRule> .GetResult(protocolStep, initialAssumption);

            if (receivePublicRuleResult != null)
            {
                if (!CurrentKnowledge.Contains(receivePublicRuleResult))
                {
                    CurrentKnowledge.Add(receivePublicRuleResult);
                    added = true;
                }
            }
            BaseLogic receivePublicRule2Result = (BaseLogic)RuleInstance <ReceivePublicRule> .GetResult(initialAssumption, protocolStep);

            if (receivePublicRule2Result != null)
            {
                if (!CurrentKnowledge.Contains(receivePublicRule2Result))
                {
                    CurrentKnowledge.Add(receivePublicRule2Result);
                    added = true;
                }
            }
            #endregion

            #region ReceiveRule
            BaseLogic receiveRuleResult = (BaseLogic)RuleInstance <ReceiveRule> .GetResult(protocolStep, initialAssumption);

            if (receiveRuleResult != null)
            {
                if (!CurrentKnowledge.Contains(receiveRuleResult))
                {
                    CurrentKnowledge.Add(receiveRuleResult);
                    added = true;
                }
            }
            BaseLogic receiveRule2Result = (BaseLogic)RuleInstance <ReceiveRule> .GetResult(initialAssumption, protocolStep);

            if (receiveRule2Result != null)
            {
                if (!CurrentKnowledge.Contains(receiveRule2Result))
                {
                    CurrentKnowledge.Add(receiveRule2Result);
                    added = true;
                }
            }
            #endregion

            #region ReceiveSecretRule
            BaseLogic receiveSecretRuleResult = (BaseLogic)RuleInstance <ReceiveSecretRule> .GetResult(protocolStep, initialAssumption);

            if (receiveSecretRuleResult != null)
            {
                if (!CurrentKnowledge.Contains(receiveSecretRuleResult))
                {
                    CurrentKnowledge.Add(receiveSecretRuleResult);
                    added = true;
                }
            }
            BaseLogic receiveSecretRule2Result = (BaseLogic)RuleInstance <ReceiveSecretRule> .GetResult(initialAssumption, protocolStep);

            if (receiveSecretRule2Result != null)
            {
                if (!CurrentKnowledge.Contains(receiveSecretRule2Result))
                {
                    CurrentKnowledge.Add(receiveSecretRule2Result);
                    added = true;
                }
            }
            #endregion

            #region ConcatenateRule
            var concatRules = (List <BaseLogic>) RuleInstance <ConcatenateRule> .GetResult(protocolStep);

            if (concatRules != null)
            {
                foreach (var concatRule in concatRules)
                {
                    if (!CurrentKnowledge.Contains(concatRule))
                    {
                        CurrentKnowledge.Add(concatRule);
                        added = true;
                    }
                }
            }
            #endregion

            return(added);
        }
コード例 #19
0
 public RuleContextMock(RuleInstance instance, IDispatcher dispatcher)
 {
     RuleInstance = instance;
     Notify       = new RuleInstanceVisuNotifyMock();
     Dispatcher   = dispatcher;
 }
コード例 #20
0
 public Task NotifyValueChanged(RuleInstance instance, object value)
 {
     return(Task.CompletedTask);
 }
コード例 #21
0
        public static async Task <LogicMock> CreateLogicMock(
            string name,
            IDispatcher dispatcher,
            ILogicInstanceCache instanceCache,
            ILogicInterfaceInstanceCache interfaceInstanceCache,
            ILogicInstancesStore logicInstances)
        {
            var ruleInstance = new RuleInstance
            {
                ObjId = Guid.NewGuid(),
                Name  = "Logic_" + name
            };

            var inputTemplate = new RuleInterfaceTemplate
            {
                ObjId               = Guid.NewGuid(),
                Name                = "Input",
                ParameterDataType   = RuleInterfaceParameterDataType.Integer,
                IsLinkableParameter = true
            };

            var input = new RuleInterfaceInstance
            {
                ObjId = Guid.NewGuid(),
                This2RuleInstanceNavigation          = ruleInstance,
                This2RuleInstance                    = ruleInstance.ObjId,
                This2RuleInterfaceTemplateNavigation = inputTemplate,
                This2RuleInterfaceTemplate           = inputTemplate.ObjId
            };


            var outputTemplate = new RuleInterfaceTemplate
            {
                ObjId               = Guid.NewGuid(),
                Name                = "Output",
                ParameterDataType   = RuleInterfaceParameterDataType.Integer,
                IsLinkableParameter = true
            };
            var output = new RuleInterfaceInstance
            {
                ObjId = Guid.NewGuid(),
                This2RuleInstanceNavigation          = ruleInstance,
                This2RuleInstance                    = ruleInstance.ObjId,
                This2RuleInterfaceTemplateNavigation = outputTemplate,
                This2RuleInterfaceTemplate           = outputTemplate.ObjId
            };

            ruleInstance.RuleInterfaceInstance.Add(input);
            ruleInstance.RuleInterfaceInstance.Add(output);

            var mock = new LogicMock(new RuleContextMock(ruleInstance, dispatcher));

            await mock.Start();

            instanceCache?.Add(ruleInstance.ObjId, ruleInstance);
            interfaceInstanceCache?.Add(input.ObjId, input);
            interfaceInstanceCache?.Add(output.ObjId, output);
            logicInstances?.Add(ruleInstance, mock);

            return(mock);
        }
コード例 #22
0
 /// <inheritdoc/>
 protected override void OnEnter()
 {
     Result = new RuleInstance();
 }
コード例 #23
0
        //private static ILogger _gbcLogger = LogManager.GetCurrentClassLogger();
#endif

        public static RuleInstance Convert(RuleInstance source)
        {
            var convertingContext = new Dictionary <object, object>();

            return(Convert(source, convertingContext));
        }
コード例 #24
0
        public void NSetIndexedRuleInstanceToIndexData(RuleInstance indexedRuleInstance)
        {
#if DEBUG
            //_gbcLogger.Info($"indexedRuleInstance = {indexedRuleInstance}");
            //_gbcLogger.Info($"indexedRuleInstance = {DebugHelperForRuleInstance.ToString(indexedRuleInstance)}");
#endif

            IndexedRuleInstancesDict[indexedRuleInstance.Name] = indexedRuleInstance;

            var kind = indexedRuleInstance.Kind;

            switch (kind)
            {
            case KindOfRuleInstance.Fact:
                //case KindOfRuleInstance.Annotation:
                //case KindOfRuleInstance.EntityCondition:
                NAddIndexedRulePartToKeysOfRelationsIndex(IndexedRulePartsOfFactsDict, indexedRuleInstance.PrimaryPart);
                break;

            case KindOfRuleInstance.Rule:
            {
                var part_1 = indexedRuleInstance.PrimaryPart;

                if (part_1.HasVars && part_1.IsActive && !part_1.HasQuestionVars && part_1.RelationsDict.Count == 1)
                {
                    NAddIndexedRulePartToKeysOfRelationsIndex(IndexedRulePartsWithOneRelationWithVarsDict, part_1);
                }

                foreach (var part_2 in indexedRuleInstance.SecondaryParts)
                {
                    if (part_2.HasVars && part_2.IsActive && !part_2.HasQuestionVars && part_2.RelationsDict.Count == 1)
                    {
                        NAddIndexedRulePartToKeysOfRelationsIndex(IndexedRulePartsWithOneRelationWithVarsDict, part_2);
                    }
                }
            }
            break;

            //case KindOfRuleInstance.EntityCondition:
            //break;

            case KindOfRuleInstance.Question:
                break;

            default: throw new ArgumentOutOfRangeException(nameof(kind), kind, null);
            }

            switch (kind)
            {
            case KindOfRuleInstance.Fact:
            case KindOfRuleInstance.Rule:
            case KindOfRuleInstance.Question:
                break;

            //case KindOfRuleInstance.Annotation:
            //case KindOfRuleInstance.EntityCondition:
            //AdditionalRuleInstancesDict[indexedRuleInstance.Key] = indexedRuleInstance;
            //break;

            default: throw new ArgumentOutOfRangeException(nameof(kind), kind, null);
            }

            //Log("End");
        }
コード例 #25
0
 public RuleInstance CreateRuleInstance(RuleTemplate template)
 {
     return(RuleInstance.CreateFromTemplate(template));
 }
コード例 #26
0
        private static PrimaryRulePart ConvertPrimaryRulePart(PrimaryRulePart source, RuleInstance ruleInstance, Dictionary <object, object> convertingContext)
        {
#if DEBUG
            //_gbcLogger.Info($"source = {source}");
#endif

            if (source == null)
            {
                return(null);
            }

            if (convertingContext.ContainsKey(source))
            {
                return((PrimaryRulePart)convertingContext[source]);
            }

            var result = new PrimaryRulePart();
            convertingContext[source] = result;

            FillBaseRulePart(source, result, ruleInstance, convertingContext);

            if (!source.SecondaryParts.IsNullOrEmpty())
            {
                foreach (var secondaryPart in source.SecondaryParts)
                {
                    result.SecondaryParts.Add(ConvertSecondaryRulePart(secondaryPart, ruleInstance, convertingContext));
                }
            }

#if DEBUG
            //_gbcLogger.Info($"result = {result}");
#endif

            return(result);
        }
コード例 #27
0
        private static SecondaryRulePart ConvertSecondaryRulePart(SecondaryRulePart source, RuleInstance ruleInstance, Dictionary <object, object> convertingContext)
        {
#if DEBUG
            //_gbcLogger.Info($"source = {source}");
#endif

            if (source == null)
            {
                return(null);
            }

            if (convertingContext.ContainsKey(source))
            {
                return((SecondaryRulePart)convertingContext[source]);
            }

            var result = new SecondaryRulePart();
            convertingContext[source] = result;

            FillBaseRulePart(source, result, ruleInstance, convertingContext);

            result.PrimaryPart = ConvertPrimaryRulePart(source.PrimaryPart, ruleInstance, convertingContext);

#if DEBUG
            //_gbcLogger.Info($"result = {result}");
#endif

            return(result);
        }