public void LoadCommand(IRadegastCommand command) { command.StartCommand(instance); CommandsByName[command.Name.ToLower()] = command; lock (CommandsLoaded) CommandsLoaded.Add(command); }
/// <summary> /// Loads commands /// </summary> /// <param name="type">Type to try to load</param> /// <returns>True if useful types were found and loaded</returns> public bool LoadType(Type type) { bool loadedType = false; if (typeof(IRadegastCommand).IsAssignableFrom(type) && type != typeof(RadegastCommand)) { try { var c = type.GetConstructor(new Type[] { typeof(RadegastInstance) }); if (c != null) { IRadegastCommand plug = (IRadegastCommand)c.Invoke(new object[] { instance }); LoadCommand(plug); return(true); } c = type.GetConstructor(Type.EmptyTypes); if (c != null) { IRadegastCommand plug = (IRadegastCommand)c.Invoke(new object[0]); LoadCommand(plug); return(true); } } catch (Exception ex) { Logger.Log("ERROR in Radegast Command: " + type + " because " + ex.Message + " " + ex.StackTrace, Helpers.LogLevel.Debug); throw; } return(false); } if (typeof(ICommandInterpreter).IsAssignableFrom(type)) { if (GetType() == type) { return(false); } foreach (var ci in type.GetConstructors()) { if (ci.GetParameters().Length > 0) { continue; } try { ICommandInterpreter plug = (ICommandInterpreter)ci.Invoke(new object[0]); LoadInterpreter(plug); loadedType = true; break; } catch (Exception ex) { Logger.Log("ERROR in Radegast ICommandInterpreter: " + type + " because " + ex.Message + " " + ex.StackTrace, Helpers.LogLevel.Debug); throw; } } } return(loadedType); }