public void visible_command_has_documentation(ICommandDescriptor command)
 {
     if (command.Visible == false) return;
     command.Description.ShouldNotBeNullOrEmpty(string.Format("command '{0}-{1}' doesn't have a description",command.Verb, command.Noun));
     foreach (var commandInput in command.Inputs)
         commandInput.Value.Description.ShouldNotBeNullOrEmpty(string.Format("command input '{0}' for command '{1}-{2}' doesn't have a description", commandInput.Value.Name,command.Verb, command.Noun));
 }
        public void ui_command_has_label(ICommandDescriptor command)
        {
            var uiDescriptor = command as IUICommandDescriptor;
            if (uiDescriptor == null) return;

            uiDescriptor.Label.ShouldNotBeNullOrEmpty(string.Format("UI command '{0}-{1}' doesn't have a label", command.Verb, command.Noun));
        }
示例#3
0
 string CreateParameters(ICommandDescriptor command)
 {
     return(PositionalParameters(command)
            .Concat(NonPositionalParameters(command))
            .Select(x => CreateInputDescription(x))
            .Join("\r\n\r\n"));
 }
示例#4
0
        string CreateUsageLine(ICommandDescriptor command)
        {
            var positionedParameters   = CreatePositionedParameters(command);
            var unpositionedParameters = CreateUnpositionedParameters(command);

            return(new[] { CommandName, positionedParameters, unpositionedParameters }.NotNullOrEmpty().Join(" "));
        }
示例#5
0
 public command_context()
 {
     Command  = CecilCommandExporter.GetCommandFrom <T>();
     Commands = new CommandRepository {
         Command
     };
 }
示例#6
0
 public void SendCommand <TCommand, TRequest, TResponse>(
     ICommandDescriptor <TCommand, TRequest, TResponse> commandDescriptor, TRequest request,
     EntityId entityId, CommandCallback <TResponse> callback, TimeSpan?timeout = null, CommandDelivery commandDelivery = CommandDelivery.RoundTrip)
     where TCommand : ICommandMetaclass, new()
 {
     SendCommandInternal(null, SkipAuthorityCheck, commandDescriptor, request, entityId, callback, timeout, commandDelivery);
 }
 string CreateParameters(ICommandDescriptor command)
 {
     return PositionalParameters(command)
             .Concat(NonPositionalParameters(command))
             .Select(x => CreateInputDescription(x))
             .Join("\r\n\r\n");
 }
 public CommandDescriptionOutput(ICommandDescriptor command) : base(null)
 {
     Command = command;
     CommandName = string.Format("{0}-{1}", command.Verb, command.Noun);
     Description = command.Description;
     UsageLine = CreateUsageLine(command);
     Parameters = CreateParameters(command);
 }
示例#9
0
 public CommandDescriptionOutput(ICommandDescriptor command) : base(null)
 {
     Command     = command;
     CommandName = string.Format("{0}-{1}", command.Verb, command.Noun);
     Description = command.Description;
     UsageLine   = CreateUsageLine(command);
     Parameters  = CreateParameters(command);
 }
示例#10
0
        private ICommandDescriptor ThrowIfNullDescriptor(ICommandDescriptor descriptor)
        {
            if (descriptor == null)
            {
                throw new ArgumentException("A command descriptor is required for this registration.");
            }

            return(descriptor);
        }
示例#11
0
 public CommandLineHelpEventArgs(
     ICommandDescriptor commandInfo,
     IEnumerable <ICommandDescriptor> subCommandInfo,
     IDictionary <string, string> syntaxInfo)
 {
     CommandInfo    = commandInfo;
     SubCommandInfo = subCommandInfo;
     SyntaxInfo     = syntaxInfo;
 }
示例#12
0
        public void ui_command_has_label(ICommandDescriptor command)
        {
            var uiDescriptor = command as IUICommandDescriptor;

            if (uiDescriptor == null)
            {
                return;
            }

            uiDescriptor.Label.ShouldNotBeNullOrEmpty(string.Format("UI command '{0}-{1}' doesn't have a label", command.Verb, command.Noun));
        }
示例#13
0
 IEnumerable <ICommandInputDescriptor> NonPositionalParameters(ICommandDescriptor command)
 {
     return(command.Inputs
            .Select(x => x.Value)
            .Where(x => x.Position == null && x.IsRequired)
            .OrderBy(x => x.Name, StringComparer.OrdinalIgnoreCase)
            .Concat(
                command.Inputs.Select(x => x.Value)
                .Where(x => x.Position == null && x.IsRequired == false)
                .OrderBy(x => x.Name, StringComparer.OrdinalIgnoreCase)
                ));
 }
示例#14
0
 public void visible_command_has_documentation(ICommandDescriptor command)
 {
     if (command.Visible == false)
     {
         return;
     }
     command.Description.ShouldNotBeNullOrEmpty(string.Format("command '{0}-{1}' doesn't have a description", command.Verb, command.Noun));
     foreach (var commandInput in command.Inputs)
     {
         commandInput.Value.Description.ShouldNotBeNullOrEmpty(string.Format("command input '{0}' for command '{1}-{2}' doesn't have a description", commandInput.Value.Name, command.Verb, command.Noun));
     }
 }
 static IEnumerable<ICommandInputDescriptor> NonPositionalParameters(ICommandDescriptor command)
 {
     return command.Inputs
         .Select(x => x.Value)
         .Where(x => x.Position == null && x.IsRequired)
         .OrderBy(x => x.Name, StringComparer.OrdinalIgnoreCase)
         .Concat(
             command.Inputs.Select(x => x.Value)
                 .Where(x => x.Position == null && x.IsRequired == false)
                 .OrderBy(x => x.Name, StringComparer.OrdinalIgnoreCase)
         );
 }
示例#16
0
        private ICommandDescriptor GetCommandDescriptor <TDescriptorContainer>(
            Func <TDescriptorContainer, ICommandDescriptor> getDescriptorFunc)
        {
            ICommandDescriptor descriptor = null;

            if (getDescriptorFunc != null)
            {
                var descriptorContainer = commandServiceProvider.Resolve <TDescriptorContainer>();
                descriptor = getDescriptorFunc(descriptorContainer);
            }

            return(descriptor);
        }
示例#17
0
        private void SendCommandInternal <TCommand, TRequest, TResponse>(IComponentWriter writer, bool requireAuthority,
                                                                         ICommandDescriptor <TCommand, TRequest, TResponse> commandDescriptor, TRequest request,
                                                                         EntityId entityId, CommandCallback <TResponse> callback, TimeSpan?timeout, CommandDelivery commandDelivery)
            where TCommand : ICommandMetaclass, new()
        {
            Action sendAction = () =>
            {
                var rawRequest = commandDescriptor.CreateRequest(request);
                Func <ICommandResponse <TCommand>, TResponse> extractResponse =
                    rawResponse => ExtractResponse(commandDescriptor, rawResponse);
                var requestId = componentCommander.SendCommandInternal(entityId, rawRequest, extractResponse, callback, timeout, commandDelivery);
                TrackRequest(writer, requestId);
            };

            SendGenericCommand(writer, requireAuthority, callback, sendAction);
        }
示例#18
0
        public void Add(ICommandDescriptor commandDescriptor)
        {
            if (commandDescriptor == null)
            {
                throw new ArgumentNullException("commandDescriptor");
            }

            if (commandDescriptor.Noun != null && !_nouns.Contains(commandDescriptor.Noun))
            {
                _nouns.Add(commandDescriptor.Noun);
            }
            if (commandDescriptor.Verb != null && !_commandVerbs.Contains(commandDescriptor.Verb))
            {
                _commandVerbs.Add(commandDescriptor.Verb);
            }

            _commands.Add(commandDescriptor);
        }
示例#19
0
 protected void when_executing(string line)
 {
     this.Result   = Handler.Execute(ref line);
     ResultingLine = line;
 }
示例#20
0
 public CommandListResult(ICommandDescriptor repository)
 {
     _command = repository;
 }
示例#21
0
 public PluginB_v2()
 {
     Descriptor = new CommandDescriptor("pluginB_dependency", "command B");
 }
示例#22
0
        public IEnumerable <ICommandOutput> Run(ICommandDescriptor command, string line)
        {
            var commandInstance  = LastCommand = command.Create();
            var parsedInput      = new InputParser().Parse(line).ToList();
            var unassignedInputs = new List <Input>();
            var assignedInputs   = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var input in parsedInput)
            {
                var inputName = input.Name;
                if (!string.IsNullOrEmpty(inputName))
                {
                    ICommandInputDescriptor assigner;
                    if (!command.Inputs.TryGetValue(inputName, out assigner))
                    {
                        var potentialInputs = inputName.SelectHumps(command.Inputs.Keys).ToList();
                        if (potentialInputs.Count == 1)
                        {
                            inputName = potentialInputs.Single();
                        }
                        else if (potentialInputs.Count > 1)
                        {
                            yield return(new AmbiguousInputName(inputName, potentialInputs));

                            yield break;
                        }
                    }
                    if (assignedInputs.Contains(inputName))
                    {
                        yield return(new CommandInputTooManyTimes(inputName));

                        yield break;
                    }

                    bool canIgnore = OptionalInputs.ContainsNoCase(inputName);
                    if (!command.Inputs.TryGetValue(inputName, out assigner) && !canIgnore)
                    {
                        yield return(new UnknownCommandInput(inputName));

                        yield break;
                    }

                    if (assigner != null && !AssignValue(input, commandInstance, assigner))
                    {
                        yield return(new InputParsingError(inputName, GetLinearValue(input)));

                        yield break;
                    }
                    assignedInputs.Add(inputName);
                }
                else
                {
                    unassignedInputs.Add(input);
                }
            }
            if (unassignedInputs.Count > 0)
            {
                foreach (var positioned in command.Inputs
                         .Where(x => x.Value.Position != null && !assignedInputs.Contains(x.Key))
                         .Select(x => x.Value)
                         .OrderBy(x => x.Position))
                {
                    if (unassignedInputs.Count == 0)
                    {
                        break;
                    }

                    if (!AssignValue(unassignedInputs[0], commandInstance, positioned))
                    {
                        yield return(new InputParsingError(positioned.Name, GetLinearValue(unassignedInputs[0])));

                        yield
                        break;
                    }

                    assignedInputs.Add(positioned.Name);

                    unassignedInputs.RemoveAt(0);
                }
            }
            var missingInputs = command.Inputs.Where(x => x.Value.IsRequired && !assignedInputs.Contains(x.Key)).Select(x => x.Value);

            if (missingInputs.Any())
            {
                yield return(new MissingInput(missingInputs));

                yield break;
            }
            foreach (var output in commandInstance.Execute())
            {
                yield return(output);
            }
        }
示例#23
0
 public CommandExportItem(string path, IPackage package, ICommandDescriptor descriptor)
 {
     Path = path;
     Package = package;
     Descriptor = descriptor;
 }
        ICommandInputDescriptor FindCommandInputDescriptor(ICommandDescriptor command, string name)
        {
            ICommandInputDescriptor descriptor;
            // Try to find by full name match first.
            if (command.Inputs.TryGetValue(name, out descriptor))
            {
                return descriptor;
            }
            var potentialInputs = (from input in command.Inputs
                                  where name.MatchesHumps(input.Key)
                                  select input.Value).ToList();

            if (potentialInputs.Count > 1)
                throw new AmbiguousInputNameException(name, potentialInputs.Select(x=>x.Name).ToArray());

            return potentialInputs.SingleOrDefault();
        }
示例#25
0
 public static TResponse ExtractResponse <TCommand, TRequest, TResponse>
     (ICommandDescriptor <TCommand, TRequest, TResponse> commandDescriptor, ICommandResponse <TCommand> rawResponse)
     where TCommand : ICommandMetaclass, new()
 {
     return(commandDescriptor.ExtractResponse(rawResponse));
 }
示例#26
0
 public bool Remove(ICommandDescriptor item)
 {
     return(_commands.Remove(item));
 }
示例#27
0
 public CommandExportItem(string path, IPackage package, ICommandDescriptor descriptor)
 {
     Path       = path;
     Package    = package;
     Descriptor = descriptor;
 }
示例#28
0
 /// <inheritdoc />
 public ICommandResponseHandler <TResponse> SendCommand <TCommand, TRequest, TResponse>(IComponentWriter writer, ICommandDescriptor <TCommand, TRequest, TResponse> commandDescriptor,
                                                                                        TRequest request, EntityId entityId, TimeSpan?timeout, CommandDelivery commandDelivery = CommandDelivery.RoundTrip) where TCommand : ICommandMetaclass, new()
 {
     return(CommandResponseHandler <TResponse> .Wrap(callback => SendCommandInternal(writer, PerformAuthorityCheck, commandDescriptor, request, entityId, callback, timeout, commandDelivery)));
 }
示例#29
0
 public PluginB_v1()
 {
     Descriptor = new CommandDescriptor("pluginB_stright", "command B");
 }
示例#30
0
 public VerbSlice(ICommandDescriptor commandDescriptor)
 {
     Verb         = commandDescriptor.Verb;
     this.Command = commandDescriptor;
 }
示例#31
0
 public cecil_command()
 {
     CommandDescriptor = CecilCommandExporter.GetCommandFrom <T>();
 }
示例#32
0
        public IEnumerable<ICommandOutput> Run(ICommandDescriptor command, string line)
        {
            var commandInstance = LastCommand = command.Create();
            var parsedInput = InputParser.Parse(line).ToList();
            var unassignedInputs = new List<Input>();
            var assignedInputs = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

            foreach (var input in parsedInput)
            {
                var inputName = input.Name;
                if (!string.IsNullOrEmpty(inputName))
                {
                    ICommandInputDescriptor assigner;
                    if (!command.Inputs.TryGetValue(inputName, out assigner))
                    {
                        var potentialInputs = inputName.SelectHumps(command.Inputs.Keys).ToList();
                        if (potentialInputs.Count == 1)
                            inputName = potentialInputs.Single();
                        else if (potentialInputs.Count > 1)
                        {
                            yield return new AmbiguousInputName(inputName, potentialInputs);
                            yield break;
                        }
                    }
                    if (assignedInputs.Contains(inputName))
                    {
                        yield return new CommandInputTooManyTimes(inputName);
                        yield break;
                    }

                    bool canIgnore = OptionalInputs.ContainsNoCase(inputName);
                    if (!command.Inputs.TryGetValue(inputName, out assigner) && !canIgnore)
                    {
                        yield return new UnknownCommandInput(inputName);
                        yield break;
                    }

                    if (assigner != null && !AssignValue(input, commandInstance, assigner))
                    {
                        yield return new InputParsingError(inputName, GetLinearValue(input));
                        yield break;
                    }
                    assignedInputs.Add(inputName);
                }
                else
                {
                    unassignedInputs.Add(input);
                }
            }
            if (unassignedInputs.Count > 0)
            {
                foreach (var positioned in command.Inputs
                    .Where(x => x.Value.Position != null && !assignedInputs.Contains(x.Key))
                    .Select(x => x.Value)
                    .OrderBy(x => x.Position))
                {
                    if (unassignedInputs.Count == 0) break;

                    if (!AssignValue(unassignedInputs[0], commandInstance, positioned))
                    {
                        yield return new InputParsingError(positioned.Name, GetLinearValue(unassignedInputs[0]));
                        yield
                            break;
                    }

                    assignedInputs.Add(positioned.Name);

                    unassignedInputs.RemoveAt(0);
                }
            }
            var missingInputs = command.Inputs.Where(x => x.Value.IsRequired && !assignedInputs.Contains(x.Key)).Select(x => x.Value);
            if (missingInputs.Any())
            {
                yield return new MissingInput(missingInputs);
                yield break;
            }
            foreach (var output in commandInstance.Execute())
                yield return output;
        }
 string CreateUnpositionedParameters(ICommandDescriptor command)
 {
     return NonPositionalParameters(command)
             .Select(CreateUnpositionedParameter)
             .Join(" ");
 }
示例#34
0
 public CommandsSniffer()
     : base(new SortedDictionary <ReadOnlyMemory <char>, ICommandArgumentCountDictionary>(new MemoryStringComparer()), typeof(ICommandHandler <>))
 {
     NotFoundCommand         = new CommandDescriptor <Application, NotFoundCommandArgument>();
     BadArgumentCountCommand = new CommandDescriptor <Application, BadArgumentCountCommandArgument>();
 }
 IOrderedEnumerable<ICommandInputDescriptor> PositionalParameters(ICommandDescriptor command)
 {
     return command.Inputs.Select(x=>x.Value)
             .Where(x => x.Position != null)
             .OrderBy(x => x.Position);
 }
示例#36
0
 public VerbSlice(ICommandDescriptor commandDescriptor)
 {
     Verb = commandDescriptor.Verb;
     this.Command = commandDescriptor;
 }
示例#37
0
 IEnumerable <ICommandOutput> CommandDescription(ICommandDescriptor matchingCommand)
 {
     yield return(new CommandDescriptionOutput(matchingCommand));
 }
示例#38
0
 public PluginB_v1()
 {
     Descriptor = new CommandDescriptor("pluginB_stright", "command B");
 }
示例#39
0
        protected void when_executing(string line)
        {

            this.Result = Handler.Execute(ref line);
            ResultingLine = line;
        }
示例#40
0
 public UniqueNameAndOneLongArgumentCommandArgumentCountDictionary(ICommandDescriptor descriptor)
     : base(descriptor)
 {
 }
示例#41
0
 IEnumerable<ICommandOutput> CommandDescription(ICommandDescriptor matchingCommand)
 {
     yield return new CommandDescriptionOutput(matchingCommand);
 }
示例#42
0
 public CommandListResult(ICommandDescriptor repository)
 {
     _command = repository;
 }
示例#43
0
 // Helper for one argument and one command actions.
 static InvokersParametersPair JustOneArgument(ICommandDescriptor command, object o)
 => JustOneArgument(command.AsSingleEnumerable(), o);
 string CreateUsageLine(ICommandDescriptor command)
 {
     var positionedParameters = CreatePositionedParameters(command);
     var unpositionedParameters = CreateUnpositionedParameters(command);
     return new[] { CommandName, positionedParameters, unpositionedParameters }.NotNullOrEmpty().Join(" ");
 }
示例#45
0
 string CreatePositionedParameters(ICommandDescriptor command)
 {
     return(PositionalParameters(command)
            .Select(CreatePositionedParameter)
            .Join(" "));
 }
示例#46
0
 IOrderedEnumerable <ICommandInputDescriptor> PositionalParameters(ICommandDescriptor command)
 {
     return(command.Inputs.Select(x => x.Value)
            .Where(x => x.Position != null)
            .OrderBy(x => x.Position));
 }
示例#47
0
 public PluginB_v2()
 {
     Descriptor = new CommandDescriptor("pluginB_dependency", "command B");
 }