예제 #1
0
        private InputCommand CreateInputCommand(CommandResolver resolver, IHostInterface host)
        {
            // instantiate input command

            if (resolver.CommandDefinition == null)
            {
                throw new InvalidOperationException("Cannot load input command because a command definition could not be resolved");
            }

            InputCommand cmd = host.CommandActivatorContainer.Get(resolver.CommandDefinition.InputCommandType);

            // initialize switches to false

            foreach (var item in resolver.CommandDefinition.Switches)
            {
                item.PropertyInfo.SetValue(cmd, new SwitchParameter()
                {
                    IsPresent = false
                });
            }

            // set node values

            foreach (var node in resolver.Nodes.Where(n => n.IsComplete))
            {
                node.SetValue(cmd);
            }

            return(cmd);
        }
예제 #2
0
        public InputCommand Create(CommandResolver resolver, IHostInterface host)
        {
            // load command from resolver

            InputCommand cmd = CreateInputCommand(resolver, host);

            // set internal properties

            cmd.ActiveParameterSet = resolver.ActiveParameterSet;
            cmd.InstallInterfaceServices(host);

            return(cmd);
        }
        public CommandParameterAnalysis(CommandResolver resolver)
        {
            // get parameters in set - all parameters available for the active set

            ParametersInSet = resolver.CommandDefinition.Parameters;
            if (!string.IsNullOrEmpty(resolver.ActiveParameterSet))
            {
                ParametersInSet = ParametersInSet
                                  .Where(p => string.IsNullOrEmpty(p.ParameterSet) ||
                                         p.ParameterSet.Equals(resolver.ActiveParameterSet)).ToList();
            }

            // get missing required parameters in set - where a complete parameter node is missing for a required parameter in the current set

            List <ParameterDef> completedParameters = resolver.Nodes.Where(n => n.Parameter != null &&
                                                                           n.IsComplete).Select(n => n.Parameter).ToList();

            MissingRequiredParameters = ParametersInSet.Where(p => p.IsRequired &&
                                                              !completedParameters.Contains(p)).ToList();

            // get superflous parameters - where at least a named parameter switch is defined for a parameter that is not included in the current set

            List <ParameterDef> parameters = resolver.Nodes.Where(n => n.Parameter != null).Select(n => n.Parameter).ToList();

            SuperflousParameters = parameters.Where(p => !ParametersInSet.Contains(p)).ToList();

            // get available parameters in set - all remaining parameters where at least a named parameter switch has not been defined for the current set

            AvailableParameters = ParametersInSet.Where(p => !parameters.Contains(p)).ToList();

            // get available switches

            AvaliableSwitches = resolver.CommandDefinition.Switches
                                .Where(s => !resolver.Nodes.Where(n => n.Type == CRNodeType.Switch).Select(n => n.Switch).Contains(s))
                                .ToList();
        }
예제 #4
0
        public static List <string> GetParameterAutoCompleteValues(CommandResolver resolver, ParameterDef paramDef, IHostInterface host)
        {
            if (string.IsNullOrWhiteSpace(paramDef.AutoCompleteValuesFunction))
            {
                throw new ArgumentException(string.Format("Parameter definition for parameter {0} does not define an auto complete values function"
                                                          , paramDef.Name));
            }

            var cmd = new CommandActivator().Create(resolver, host);

            var methodInfo = cmd.GetType().GetMethod(paramDef.AutoCompleteValuesFunction);

            if (methodInfo == null)
            {
                throw new ArgumentException(string.Format("Auto complete values function '{0}' cannot be found for parameter {0}"
                                                          , paramDef.AutoCompleteValuesFunction, paramDef.Name));
            }

            var context = new AutoCompleteValuesFunctionContext();

            methodInfo.Invoke(cmd, new object[] { context });

            return(context.Values);
        }