예제 #1
0
        public IEnumerable <Rule <TTarget, TComparison> > GetRules <TTarget, TComparison>()
        {
            var ruleDtos = _ruleStore.GetRules <TTarget, TComparison>();

            var targetTypeName = typeof(TTarget).Name;

            var matchingRecords = ruleDtos
                                  .Where(r => string.Equals(r.TargetTypeName, targetTypeName, StringComparison.CurrentCultureIgnoreCase));

            var targetRuleDefinitions = matchingRecords.Select(GetRuleDefinition);

            var applicableRulesDefinitions =
                targetRuleDefinitions.Where(
                    r => r.RuleConditions.All(
                        rc => string.Equals(typeof(TComparison).Name, rc.ComparisonTypeName, StringComparison.CurrentCultureIgnoreCase) ||
                        rc.ComparisonType == RuleObject.Constant));

            return(applicableRulesDefinitions.Join(matchingRecords,
                                                   def => def.Id,
                                                   dto => dto.Id,
                                                   (def, dto) => new { RuleDefinition = def, RuleDto = dto })
                   .Select(rule => new Rule <TTarget, TComparison>
            {
                Id = rule.RuleDto.Id,
                Name = rule.RuleDto.Name,
                Expression = rule.RuleDto.RuleExpression,
                Validate = _interpreter.Interpret <TTarget, TComparison>(rule.RuleDefinition)
            })
                   .ToList());
        }
예제 #2
0
            public async Task <IEnumerable <T> > Handle(SideEffect <T> sideEffect, CancellationToken cancellationToken = default)
            {
                var tasks = sideEffect.EffectList.Select(effect => _interpreter.Interpret(effect, cancellationToken)).ToList();
                await Task.WhenAll(tasks);

                return(tasks.Select(t => t.Result));
            }
예제 #3
0
        private async Task <bool> CheckStepCondition(BehaviorContext context, BehaviorStep step)
        {
            if (!string.IsNullOrEmpty(step.Condition?.Instruction))
            {
                if (step.Condition.Instruction.Equals(DefaultBehaviorInstructionNone))
                {
                    return(true);
                }
                if (step.Condition.Instruction.Equals(DefaultBehaviorInstructionNext))
                {
                    return(false);
                }
                return((await _interpreter.Interpret(step.Condition, context.Dialog, context.Database, context.ServiceContext.TransportName)).GetTypedResult <bool>());
            }

            return(false);
        }
예제 #4
0
파일: Enkel.cs 프로젝트: neistow/Enkel
        private void Run(params string[] sourceCode)
        {
            var scanner = new EnkelLexer(sourceCode);
            var tokens  = scanner.Tokens();

            var parser     = new EnkelParser(tokens);
            var statements = parser.Parse().ToList();

            var resolver = new Resolver(_interpreter);

            resolver.Resolve(statements);

            _interpreter.Interpret(statements);
        }
예제 #5
0
        public object Interpret(BaseSchema schema, object value, IProcessContext context, string path)
        {
            if (value == null || !CanInterpret(schema))
            {
                return(value);
            }

            if (value is MarkdownDocument val)
            {
                return(MarkupCore(val, context, path));
            }

            return(_inner.Interpret(schema, value, context, path));
        }
        public object Interpret(BaseSchema schema, object value, IProcessContext context, string path)
        {
            if (value == null || !CanInterpret(schema) || !(value is string val))
            {
                return(value);
            }

            // If *content is from an included file, it should be marked instead of consider it as a placeholder
            if ((schema == null || schema.Reference == ReferenceType.None) && context.ContentAnchorParser != null)
            {
                return(context.ContentAnchorParser.Parse(val));
            }

            return(_inner.Interpret(schema, value, context, path));
        }
예제 #7
0
        public bool ProcessCommand(string command, Entity entity)
        {
            var userId             = entity.GetComponent <PlayerInputComponent>().userId;
            var commandFound       = false;
            var cleanCommand       = command.Trim().ToLower();
            var interpretedCommand = _interpreter.Interpret(cleanCommand);

            foreach (KeyValuePair <string, Action <Entity, String> > cmd in CommandList)
            {
                if (cmd.Key.StartsWith(command))
                {
                    cmd.Value(entity, interpretedCommand.argument);
                    commandFound = true;
                }
            }
            return(commandFound);
        }
예제 #8
0
        public async Task Save <TData>(Instance <TData> instance, CancellationToken cancellationToken = default)
            where TData : new()
        {
            var events   = instance.GetUncommittedChanges().ToList();
            var effects  = instance.GetUncommittedEffects().ToList();
            var streamId = instance.GetStream();
            var aggregateLoadedAtVersion = instance.Version;

            instance.MarkChangesAsCommitted();

            await _eventStore.AppendEventsToStreamAsync(streamId, events, aggregateLoadedAtVersion, cancellationToken);

            foreach (var effect in effects)
            {
                await _interpreter.Interpret(effect, cancellationToken);
            }
        }
예제 #9
0
 public void Run()
 {
     if (_fileNames.Count == 0)
     {
         Console.WriteLine("No input files have been given!");
     }
     else
     {
         string input = GetInput();
         AST    ast   = _lexParse.Run(input, _printParseTree);
         _referenceHandler.InsertReferences(ast);
         _typeChecker.CheckTypes(ast);
         List <LabelGraph>       output    = _interpreter.Interpret(ast);
         List <ExtensionalGraph> gmlGraphs = _outputGenerator.Generate(output);
         _fileGenerator.Export(gmlGraphs, _output, _printOutput, _saveOutput, _projectFolder);
     }
 }
예제 #10
0
파일: Interpreter.cs 프로젝트: hfz-r/nbb
 public Task <T> Interpret <T>(Effect <T> effect, CancellationToken cancellationToken = default)
 => _interpreter.Interpret(effect, cancellationToken);
예제 #11
0
 public static async Task Interpret(this IInterpreter interpreter, IEffect effect, CancellationToken cancellationToken = default)
 {
     var _ = await interpreter.Interpret(effect, cancellationToken);
 }
예제 #12
0
 public void Interpret()
 {
     interpreter.Interpret();
 }
예제 #13
0
        public void Interpret_With_No_Arguments_IsSuccessful()
        {
            var output = interpreter.Interpret("look");

            Assert.Equal("look", output.commandName);
        }