/// <summary> /// creates a new command /// </summary> /// <param name="method">the method</param> /// <param name="invokeInstance">the instance to invoke the method on (or null for static methods)</param> public void AddMethod(SpeechMethod method, object invokeInstance) { Dictionary <string, SpeechGroupTuple> langCommands; //create lang if not exists if (Commands.TryGetValue(method.Lang, out langCommands) == false) { langCommands = new Dictionary <string, SpeechGroupTuple>(); Commands.Add(method.Lang, langCommands); } //add the method to the right speech group SpeechGroupTuple speechGroup; if (langCommands.TryGetValue(method.SpeechGroupKey, out speechGroup) == false) { speechGroup = new SpeechGroupTuple(true); langCommands.Add(method.SpeechGroupKey, speechGroup); } //check all synonyms if (method.SpeechNames.Any(p => speechGroup.Commands.ContainsKey(p))) { //there is a synonyme that is already another speech name in this speech group -> invalid throw new Exception("speech dictionary already contains a method with speech name: " + method.SpeechNames + " and key: " + method.Key); } else { var cmd = new SpeechTuple(true, method, invokeInstance); foreach (var speechName in method.SpeechNames) { speechGroup.Commands.Add(speechName, cmd); //same command with different names... } } }
/// <summary> /// creates a new command /// </summary> /// <param name="method">the method</param> /// <param name="invokeInstance">the instance to invoke the method on (or null for static methods)</param> public void AddMethod(SpeechMethod method, object invokeInstance) { Dictionary<string, SpeechGroupTuple> langCommands; //create lang if not exists if (Commands.TryGetValue(method.Lang, out langCommands) == false) { langCommands = new Dictionary<string, SpeechGroupTuple>(); Commands.Add(method.Lang, langCommands); } //add the method to the right speech group SpeechGroupTuple speechGroup; if (langCommands.TryGetValue(method.SpeechGroupKey, out speechGroup) == false) { speechGroup = new SpeechGroupTuple(true); langCommands.Add(method.SpeechGroupKey, speechGroup); } //check all synonyms if (method.SpeechNames.Any(p => speechGroup.Commands.ContainsKey(p))) { //there is a synonyme that is already another speech name in this speech group -> invalid throw new Exception("speech dictionary already contains a method with speech name: " + method.SpeechNames + " and key: " + method.Key); } else { var cmd = new SpeechTuple(true, method, invokeInstance); foreach (var speechName in method.SpeechNames) speechGroup.Commands.Add(speechName, cmd); //same command with different names... } }