Esempio n. 1
0
 /// <summary>
 /// returns true if alias contains a child matching the given command
 /// </summary>
 /// <param name="alias">alias to cross-check children</param>
 /// <param name="command">command to match</param>
 /// <returns>true if command matches a child</returns>
 private static bool IsAStateCommand(ToggleAlias toggleAlias, Command command)
 {
     bool result = false;
     // check to see if the command starts with the same prefix
     // saves processing time iterating unnecessarilly
     if (command.Name.BeginsWith(toggleAlias.Name))
     {
         // iterate through the children to see if there's an alias match defined
         foreach (Alias child in toggleAlias.Children.Keys)
         {
             if (child.ToString().Equals(command.ToString()))
             {
                 result = true;
             }
         }
     }
     return result;
 }
Esempio n. 2
0
        /// <summary>
        /// Checks a list of commands in order to find the last command call for a given alias.
        /// </summary>
        /// <param name="toggleAlias">alias to check</param>
        /// <param name="commandList">list of commands to search</param>
        /// <param name="children">children of alias in question in case commands do not contain any calls</param>
        /// <returns></returns>
        static Command FindDefaultState(ToggleAlias toggleAlias, List<Command> commandList, Dictionary<Alias, string> children)
        {
            Command result = null;
            foreach (Command command in commandList)
            {
                if (IsAStateCommand(toggleAlias, command))
                {
                    toggleAlias.NumberOfDefaultChanges++;
                    result = command;
                }
            }
            if (result == null)
                result = new Command(children.Keys.First().Name);

            return result;
        }