コード例 #1
0
        IEnumerable <Expression> ParseInput(ITextCursor textCursor, CancellationToken cancellationToken, bool stop_on_first)
        {
            IRequestContext context = textCursor.Context;
            var             res     = new List <Expression>();

            foreach (var commandProcessor in CommandProcessors.ToList())
            {
                // Gets all the syntaxes that are of the same culture of the context or are culture invariant
                var syntaxes = commandProcessor.Syntaxes.Where(
                    s => s.Culture.Equals(context.Culture) || s.Culture.Equals(CultureInfo.InvariantCulture));

                foreach (var syntax in syntaxes)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    textCursor.RightToLeftParsing = syntax.RightToLeftParsing;
                    textCursor.Reset();

                    if (SyntaxParser.TryParse(textCursor, syntax, context, out Expression expression))
                    {
                        res.Add(expression);
                        if (stop_on_first)
                        {
                            return(res);
                        }
                    }
                }
            }
            return(res);
        }
コード例 #2
0
        public void AddProcessor(string syntaxPattern, Delegate fn = null)
        {
            var syntax = CsdlParser.Parse(syntaxPattern);

            fn = fn ?? (Func <Task <string> >)(() => Task.FromResult(string.Empty));
            // Now create the command processors, to bind the methods to the syntaxes
            var cmd_proc = new DelegateCommandProcessor(
                fn,
                true,
                this,
                syntax
                );

            CommandProcessors.Add(cmd_proc);
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: Someone999/InfoReader
 void ScanCommand()
 {
     Type[] t = GetType().Assembly.GetTypes();
     foreach (var type in t)
     {
         if (type.GetInterfaces().Any(i => i == typeof(ICommandProcessor)))
         {
             ICommandProcessor processor = type.GetConstructor(new Type[0])?.Invoke(new object[0]) as ICommandProcessor;
             if (!(processor is null))
             {
                 CommandProcessors.AddCommandProcessor(processor);
             }
         }
     }
 }
コード例 #4
0
        private async Task <List <ParsedInput> > ParseInput(string inputText, IRequestContext context, CancellationToken cancellationToken)
        {
            var parsedInputs       = new List <ParsedInput>();
            var processedInputText = inputText;
            var textPreprocessors  = TextPreprocessors.ToList().OrderBy(p => p.Priority);

            foreach (var preprocessor in textPreprocessors)
            {
                cancellationToken.ThrowIfCancellationRequested();
                processedInputText =
                    await
                    preprocessor.ProcessTextAsync(processedInputText, context, cancellationToken)
                    .ConfigureAwait(false);
            }

            var textCursor = new TextCursor(processedInputText, context);

            foreach (var commandProcessor in CommandProcessors.ToList())
            {
                // Gets all the syntaxes that are of the same culture of the context or are culture invariant
                var syntaxes =
                    commandProcessor.Syntaxes.Where(
                        s => s.Culture.Equals(context.Culture) || s.Culture.Equals(CultureInfo.InvariantCulture));

                foreach (var syntax in syntaxes)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    textCursor.RightToLeftParsing = syntax.RightToLeftParsing;
                    textCursor.Reset();

                    Expression expression;
                    if (SyntaxParser.TryParse(textCursor, syntax, context, out expression))
                    {
                        var commandParsedQuery = new ParsedInput(expression, commandProcessor);
                        parsedInputs.Add(commandParsedQuery);
                        break;
                    }
                }
            }
            return(parsedInputs);
        }