예제 #1
0
 internal CommandSyntax(Command underlying)
 {
     if (null == underlying)
     {
         throw new ArgumentNullException("underlying");
     }
     Underlying = underlying;
     Items      = new CommandsSyntax();
 }
예제 #2
0
        private void CheckCommandCombination(List <string> list)
        {
            Commands       commands            = new Commands();
            CommandsSyntax commandsSyntax      = commands.Syntax;
            string         rootCommandArgument = null;
            CommandSyntax  rootCommandSyntax   = null;

            int rootCommandsCount = 0;

            foreach (string item in list)
            {
                foreach (CommandSyntax command in commandsSyntax)
                {
                    if (item.StartsWith(command.Underlying.Name, StringComparison.CurrentCultureIgnoreCase))
                    {
                        rootCommandSyntax   = command;
                        rootCommandArgument = item;
                        rootCommandsCount++;
                    }
                }
            }

            if (rootCommandsCount < 1)
            {
                foreach (var item in list)
                {
                    System.Windows.Forms.MessageBox.Show(item);
                }
                throw new RegAddinException("MissingCommandOption");
            }
            if (rootCommandsCount > 2)
            {
                throw new RegAddinException("AmbiguousArguments");
            }

            foreach (string item in list)
            {
                if (item == rootCommandArgument)
                {
                    continue;
                }
                Command targetCommand = GetTargetCommand(item, false);
                if (null == targetCommand)
                {
                    continue;
                }

                bool foundInAllowedSyntax = rootCommandSyntax.Items.Count() == 0;
                foreach (CommandSyntax syntax in rootCommandSyntax.Items)
                {
                    if (item.StartsWith(syntax.Underlying.Name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        foundInAllowedSyntax = true;
                        break;
                    }
                }
                if (!foundInAllowedSyntax)
                {
                    throw new RegAddinException("InvalidCombination");
                }
            }
        }