Пример #1
0
        bool MatchStack(object[] keys)
        {
#if CHECK
            System.Diagnostics.Trace.Write("Current:\t");
            foreach (Keys k in keys)
            {
                System.Diagnostics.Trace.Write("(" + k + ") ");
            }
            System.Diagnostics.Trace.WriteLine("");
#endif
            if (tree.Contains(keys))
            {
                ArrayList hs = (tree[keys] as ArrayList);

#if CHECK
                System.Diagnostics.Trace.Write("Accepts:\t");
                foreach (Keys k in keys)
                {
                    System.Diagnostics.Trace.Write("(" + k + ") ");
                }
#endif
                bool success = false;

                foreach (Action h in new ArrayList(hs))
                {
                    success = h.StartInvoke();
                    if (success)
                    {
                        break;
                    }
                }
#if CHECK
                if (!success)
                {
                    System.Diagnostics.Trace.WriteLine("Action: No action bound at current state, ignoring.");
                }
#endif
                stack.Clear();
                return(success);
            }
            else
            {
                if (keys.Length == 1)
                {
                    return(false);
                }

                object[] subkeys = new object[keys.Length - 1];
                Array.Copy(keys, 1, subkeys, 0, subkeys.Length);

                if (MatchStack(subkeys))
                {
                    return(true);
                }

                if (!tree.IsInPath(keys))
                {
                    object[] current = stack.ToArray();
                    Array.Reverse(current);
                    stack.Clear();
                    for (int i = 1; i < current.Length; i++)
                    {
                        stack.Push(current[i]);
                    }
                }
            }
            return(false);
        }