/// <summary> /// Initializes internal variables and creates the <see cref="Controller"/> that is specified by /// the given <see cref="ControllerInformation"/>. /// </summary> /// <param name="targetControllerInfo">The <see cref="ControllerInformation"/> to create a /// <see cref="Controller"/> from.</param> public ControllerUser(ControllerInformation targetControllerInfo) { this.controllerInfo = targetControllerInfo; this.timeElapsed = new Stopwatch(); this.maxTimeout = Configuration.Global.GetValue<int>("mbc_controller_thread_timeout"); controller = (Controller)Activator.CreateInstance(targetControllerInfo.Controller); controller.ControllerMessageEvent += ReceiveMessage; }
/// <summary> /// Loads a list of <see cref="ControllerInformation"/> from a single .DLL file. /// </summary> /// <param name="filePath">The absolute path to the .DLL file.</param> /// <returns>A list of successfully loaded <see cref="ControllerInformation"/>s.</returns> public static List<ControllerInformation> LoadControllerDLL(string filePath) { var results = new List<ControllerInformation>(); try { var dllInfo = Assembly.LoadFile(filePath); var types = dllInfo.GetTypes(); foreach (Type cont in types) { //Iterating through each class in this assembly. if (cont.IsSubclassOf(typeof(Controller))) { NameAttribute nameAttrib = (NameAttribute)cont.GetCustomAttributes(typeof(NameAttribute), false)[0]; VersionAttribute verAttrib = (VersionAttribute)cont.GetCustomAttributes(typeof(VersionAttribute), false)[0]; CapabilitiesAttribute capAttrib = (CapabilitiesAttribute)cont.GetCustomAttributes(typeof(CapabilitiesAttribute), false)[0]; if (nameAttrib != null && verAttrib != null && capAttrib != null) { //Split the absolute path. We only want the name of the DLL file. string[] pathSplit = filePath.Split('\\'); ControllerInformation info = new ControllerInformation(nameAttrib, verAttrib, (DescriptionAttribute)cont.GetCustomAttributes(typeof(DescriptionAttribute), false)[0], (AuthorAttribute)cont.GetCustomAttributes(typeof(AuthorAttribute), false)[0], (AcademicInfoAttribute)cont.GetCustomAttributes(typeof(AcademicInfoAttribute), false)[0], capAttrib, pathSplit[pathSplit.Count() - 1], cont); results.Add(info); } } } } catch { //Unable to load a .DLL file; we don't care about this assembly. } return results; }
/// <summary> /// Attaches the <see cref="ControllerInformation"/> that is incompatible with the given /// <see cref="GameMode"/>. /// </summary> /// <param name="incompatibleController">The incompatible <see cref="ControllerInformation"/>.</param> /// <param name="mode">The <see cref="GameMode"/> incompatible with the <see cref="ControllerInformation"/>.</param> public ControllerIncompatibleException(ControllerInformation incompatibleController, GameMode mode) : base(incompatibleController + " cannot be played with the " + Enum.GetName(typeof(GameMode), mode) + " game mode.") { this.incompatible = incompatibleController; this.mode = mode; }