public void Parse(CommandBlockParser blockParser, ICommandParameterParser parameterParser)
 {
     this.blocks = blockParser.Parse(this.originLine).ToArray();
     this.CommandBlock = this.blocks.FirstOrDefault();
     this.blocks = this.blocks.Skip(1).ToArray();
     this.parameters = parameterParser.Parse(this.blocks).ToArray();
 }
Пример #2
0
        private void PopuplateParsers()
        {
            var quoted   = new CommandParameterParser(true);
            var unquoted = new CommandParameterParser(false);

            DefaultParser = unquoted;
            Parsers.Add("String", quoted);
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandParameterInfo" /> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="parser">The parser.</param>
 /// <param name="isRequired">If set to <c>true</c> the parameter is required.</param>
 /// <param name="defaultValue">The default value of this parameter</param>
 /// <param name="parameterIndex">Index of the parameter.</param>
 public CommandParameterInfo(string name, ICommandParameterParser parser, bool isRequired, object defaultValue, int parameterIndex)
 {
     Name         = name;
     Parser       = parser;
     IsRequired   = isRequired;
     DefaultValue = defaultValue;
     Index        = parameterIndex;
 }
 public void Format(IOutput output, CommandMapper commandMapper, IEnumerable<IParameterMapper> mappers,
     ICommandParameterParser parser)
 {
     foreach (var line in this.Format(commandMapper, mappers, parser))
     {
         output.WriteLine(line);
     }
 }
Пример #5
0
        private void PopulateParsers()
        {
            var quoted = new CommandParameterParser(true);
            var unquoted = new CommandParameterParser(false);

            DefaultParser = unquoted;
            Parsers.Add("String", quoted);
            Parsers.Add("AnsiString", quoted);
        }
 public IEnumerable<FormatedString> Format(CommandMapper commandMapper, IEnumerable<IParameterMapper> mappers,
     ICommandParameterParser parser)
 {
     foreach (var mapper in mappers)
     {
         yield return $"{parser.GetInputSytle(mapper.Name)}\t\t\t{mapper.Desciption}";
         yield return $"  alias: {string.Join("; ", mapper.GetNames())}";
         yield return "";
     }
 }
Пример #7
0
        /// <summary>
        /// Tries to collect parameter information.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="prefixParameters">The number of prefix parameters.</param>
        /// <param name="result">The collected parameter information.</param>
        /// <returns><c>true</c> if the parameters could be collected; otherwise <c>false</c>.</returns>
        protected virtual bool TryCollectParameters(ParameterInfo[] parameters, int prefixParameters, out CommandParameterInfo[] result)
        {
            if (parameters.Length < prefixParameters)
            {
                result = null;
                return(false);
            }

            var list = new List <CommandParameterInfo>();

            // Parameter index in intermediate parameters array between parsing and invoking.
            var parameterIndex = prefixParameters;
            var optionalFound  = false;

            for (var i = prefixParameters; i < parameters.Length; i++)
            {
                var parameter = parameters[i];
                var attribute = parameter.GetCustomAttribute <CommandParameterAttribute>();

                var name = parameter.Name;
                ICommandParameterParser parser = null;

                if (!string.IsNullOrWhiteSpace(attribute?.Name))
                {
                    name = attribute.Name;
                }

                // Prefer parser supplied by parameter attribute
                if (attribute?.Parser != null && typeof(ICommandParameterParser).IsAssignableFrom(attribute.Parser))
                {
                    parser = Activator.CreateInstance(attribute.Parser) as ICommandParameterParser;
                }

                if (parser == null)
                {
                    parser = CreateParameterParser(parameters, i);
                }

                if (parser == null)
                {
                    // The parameter is injected by DI.
                    parameterIndex++;
                    continue;
                }

                var optional = parameter.HasDefaultValue;

                // Don't allow required parameters after optional parameters.
                if (!optional && optionalFound)
                {
                    result = null;
                    return(false);
                }

                optionalFound |= optional;

                list.Add(new CommandParameterInfo(name, parser, !optional, parameter.DefaultValue, parameterIndex++));
            }

            result = list.ToArray();
            return(true);
        }
Пример #8
0
 public TestServer(ICommandParser commandParser, ICommandParameterParser commandParameterParser)
     : this()
 {
     CommandParser          = commandParser;
     CommandParameterParser = commandParameterParser;
 }
Пример #9
0
 public CommandBase(ICommandParameterParser commandParameterParser)
 {
     m_CommandParameterParser = commandParameterParser;
 }
 public IEnumerable<FormatedString> Format(CommandMapper commandMapper, IEnumerable<IParameterMapper> mappers,
     ICommandParameterParser parser)
 {
     var names = string.Join(", ", mappers.Select(z => z.Name));
     yield return $"missing parameter: {names}.";
 }
 public abstract OperationResult SetCommandLine(CommandLine commandLine,
     ICommandParameterParser parameterParser, ConverterAgent converters);