Exemplo n.º 1
0
 /// <inheritdoc />
 public ICommandParseResult <TModel> ParseCommand <TModel>(string input) where TModel : class, new()
 {
     try
     {
         var request = new SingleCommandParseRequest <TModel>(input);
         return(ParseStrategy.ParseCommand(request));
     }
     catch (Exception e)
     {
         throw new CommandParserException($"Ошибка при разборе команды '{input}' типа '{typeof(TModel)}'", e);
     }
 }
        /// <inheritdoc />
        public virtual ICommandParseResult <TModel> ParseCommand <TModel>(SingleCommandParseRequest <TModel> request)
            where TModel : class, new()
        {
            try
            {
                var untypedCommandCreator = TokenizerProvider();
                if (untypedCommandCreator == null)
                {
                    throw new CommandParserException($"Не удалось получить парсер команд для запроса {request}");
                }

                var tokenizeResult = untypedCommandCreator.Tokenize(request);
                if (!tokenizeResult.IsSucceed)
                {
                    return(new UnparsedCommand <TModel>(
                               new CommandParseError(tokenizeResult.ErrorsText, tokenizeResult.ErrorCode)));
                }

                var initializationRequest = new CommandInitializationRequest(
                    typeof(TModel), new TModel(), tokenizeResult.Command, request);

                var initializer          = InitializerProvider();
                var initializationResult = initializer.Initialize(initializationRequest);
                if (!initializationResult.IsSucceed)
                {
                    return(new UnparsedCommand <TModel>(
                               new CommandParseError(initializationResult.ErrorsText, initializationResult.ErrorCode)));
                }

                return(new ParsedCommand <TModel>((TModel)initializationResult.InitializedCommand));
            }
            catch (CommandParserException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new CommandParserException($"Не удалось выполнить разбор команды для запроса {request}", e);
            }
        }
Exemplo n.º 3
0
 public override ICommandParseResult <TModel> ParseCommand <TModel>(SingleCommandParseRequest <TModel> request)
 {
     return(base.ParseCommand(request));
 }