Ejemplo n.º 1
0
 /// <summary>
 /// Registers a new handler for a command
 /// </summary>
 /// <param name="Command"></param>
 /// <param name="handler"></param>
 public void RegisterHandler(string Command, AerInputHandler handler)
 {
     if (!_EventRegistry.ContainsKey(Command))
     {
         _EventRegistry.Add(Command, handler);
     }
     else
     {
         AerDebug.LogError("Re-registered command to new handler, command=" + Command);
         _EventRegistry[Command] = handler; //Maybe it should just be thrown away?
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Uses reflection to pull out all SpeechHandlerAttribute tags and creates a Rule->Delegate dictionary
        /// from the data.
        /// </summary>
        private void _RegisterDefaultHandlers()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            IEnumerable <MemberInfo> handlers = assembly.GetTypes().SelectMany(type => type.GetMembers())
                                                .Union(assembly.GetTypes())
                                                .Where(type => Attribute.IsDefined(type, typeof(SpeechHandlerAttribute)));

            foreach (MemberInfo mi in handlers)
            {
                Object[] attribs = mi.GetCustomAttributes(typeof(SpeechHandlerAttribute), false);
                for (int i = 0; i < attribs.Length; i++)
                {
                    //AerDebug.Log("Found Handler: " + ((SpeechHandlerAttribute)attribs[i]).GrammarRule);
                    if (mi.MemberType == MemberTypes.Method)
                    {
                        AerInputHandler Call = (AerInputHandler)Delegate.CreateDelegate(typeof(AerInputHandler), this, mi.Name);


                        RegisterHandler(((SpeechHandlerAttribute)attribs[i]).GrammarRule, Call);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Registers a new handler for a command
 /// </summary>
 /// <param name="Command"></param>
 /// <param name="handler"></param>
 public void RegisterHandler(string Command, AerInputHandler handler)
 {
     if (!_EventRegistry.ContainsKey(Command))
         _EventRegistry.Add(Command, handler);
     else
     {
         NMDebug.LogError("Re-registered command to new handler, command=" + Command);
         _EventRegistry[Command] = handler; //Maybe it should just be thrown away?
     }
 }