Esempio n. 1
0
        /// <summary>
        /// Validates the command before executing
        /// </summary>
        /// <param name="args">List of arguments</param>
        /// <returns>Results from validation</returns>
        public OperationResult Validate(string[] args)
        {
            var operationResult = new Operation.OperationResult();

            ValidateInternal(args, operationResult);
            return(operationResult);
        }
Esempio n. 2
0
        /// <summary>
        /// Validates the configuration after parsing
        /// </summary>
        /// <param name="countDefaultCommands">Count of default commands found</param>
        /// <returns>Operation result</returns>
        internal Operation.OperationResult Validate(int countDefaultCommands)
        {
            var operationResult = new Operation.OperationResult();

            // Run user actions
            var b = ConfigurationValidationAction?.Invoke(this, operationResult);

            if (b.HasValue && !b.Value)
            {
                operationResult.Messages.Add(Resources.ConfigurationValidationAction);
            }

            // Ensure there is at least one command
            if (!Commands.Any())
            {
                operationResult.Messages.Add(Resources.NoCommandFound);
            }

            // Ensure there is at most one default command
            if (countDefaultCommands > 1)
            {
                operationResult.Messages.Add(Resources.CommandDefaultMostOne);
            }

            // Ensure no command has a space in it
            var spacedParameters = Commands.Where(i => i.Name.Contains(" "));

            spacedParameters.ForEach(i => operationResult.Messages.Add(String.Format(Resources.CommandCanNotHaveSpace, i)));

            // Ensure no command has a reserved keyword
            if (Commands.Any(i => HelpCommandNames.Any(j => String.Compare(j, i.Name, true) == 0)))
            {
                operationResult.Messages.Add(String.Format(Resources.CommandReservedKeywords, String.Join("', '", HelpCommandNames)));
            }

            // Ensure all commands have distinct names
            var groups = Commands.Select(i => i.Name.ToLower()).ToLookup(i => i);

            if (groups.Any(i => i.Count() > 1))
            {
                var duplicate = groups.First(i => i.Count() > 1).Key;
                operationResult.Messages.Add(String.Format(Resources.CommandDuplicate, duplicate));
            }

            // Ensure each command is valid
            Commands.ForEach(i => i.ValidateConfigurationInternal(operationResult));

            return(operationResult);
        }
Esempio n. 3
0
 /// <summary>
 /// Evaluates the rule before execution
 /// </summary>
 /// <param name="inputArguments">Parsed input arguments</param>
 /// <param name="operationResult">Operation message to write in</param>
 /// <returns>True if successful evaluation, otherwise false</returns>
 public abstract bool Evaluate(Parser.InputArguments inputArguments, Operation.OperationResult operationResult);