internal static bool InitWrapper() { isWrapped = false; ActualController = null; IRController = null; LogFormatted("Attempting to Grab IR Types..."); IRControllerType = null; AssemblyLoader.loadedAssemblies.TypeOperation(t => { if (t.FullName == "InfernalRobotics_v3.Command.Controller") { IRControllerType = t; } }); if (IRControllerType == null) { return(false); } LogFormatted("IR Version:{0}", IRControllerType.Assembly.GetName().Version.ToString()); IRMotorType = null; AssemblyLoader.loadedAssemblies.TypeOperation(t => { if (t.FullName == "InfernalRobotics_v3.Interfaces.IMotor") { IRMotorType = t; } }); if (IRMotorType == null) { LogFormatted("[IR Wrapper] Failed to grab Motor Type"); return(false); } IRServoType = null; AssemblyLoader.loadedAssemblies.TypeOperation(t => { if (t.FullName == "InfernalRobotics_v3.Interfaces.IServo") { IRServoType = t; } }); if (IRServoType == null) { LogFormatted("[IR Wrapper] Failed to grab Servo Type"); return(false); } IRControlGroupType = null; AssemblyLoader.loadedAssemblies.TypeOperation(t => { if (t.FullName == "InfernalRobotics_v3.Command.ControlGroup") { IRControlGroupType = t; } }); if (IRControlGroupType == null) { LogFormatted("[IR Wrapper] Failed to grab ControlGroup Type"); return(false); } LogFormatted("Got Assembly Types, grabbing Instance"); try { var propertyInfo = IRControllerType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static); if (propertyInfo == null) { LogFormatted("[IR Wrapper] Cannot find Instance Property"); } else { ActualController = propertyInfo.GetValue(null, null); } } catch (Exception e) { LogFormatted("No Instance found, " + e.Message); } if (ActualController == null) { LogFormatted("Failed grabbing Instance"); return(false); } LogFormatted("Got Instance, Creating Wrapper Objects"); IRController = new InfernalRoboticsAPI(); isWrapped = true; return(true); }
internal static bool InitWrapper() { isWrapped = false; ActualServoController = null; IRController = null; LogFormatted("Attempting to Grab IR Types..."); IRServoControllerType = AssemblyLoader.loadedAssemblies .Select(a => a.assembly.GetExportedTypes()) .SelectMany(t => t) .FirstOrDefault(t => t.FullName == "InfernalRobotics.Command.ServoController"); if (IRServoControllerType == null) { return(false); } LogFormatted("IR Version:{0}", IRServoControllerType.Assembly.GetName().Version.ToString()); IRServoMechanismType = AssemblyLoader.loadedAssemblies .Select(a => a.assembly.GetExportedTypes()) .SelectMany(t => t) .FirstOrDefault(t => t.FullName == "InfernalRobotics.Control.IMechanism"); if (IRServoMechanismType == null) { LogFormatted("[IR Wrapper] Failed to grab Mechanism Type"); return(false); } IRServoMotorType = AssemblyLoader.loadedAssemblies .Select(a => a.assembly.GetExportedTypes()) .SelectMany(t => t) .FirstOrDefault(t => t.FullName == "InfernalRobotics.Control.IServoMotor"); if (IRServoMotorType == null) { LogFormatted("[IR Wrapper] Failed to grab ServoMotor Type"); return(false); } IRServoType = AssemblyLoader.loadedAssemblies .Select(a => a.assembly.GetExportedTypes()) .SelectMany(t => t) .FirstOrDefault(t => t.FullName == "InfernalRobotics.Control.IServo"); if (IRServoType == null) { LogFormatted("[IR Wrapper] Failed to grab Servo Type"); return(false); } IRServoPartType = AssemblyLoader.loadedAssemblies .Select(a => a.assembly.GetExportedTypes()) .SelectMany(t => t) .FirstOrDefault(t => t.FullName == "InfernalRobotics.Control.IPart"); if (IRServoType == null) { LogFormatted("[IR Wrapper] Failed to grab ServoPart Type"); return(false); } IRControlGroupType = AssemblyLoader.loadedAssemblies .Select(a => a.assembly.GetExportedTypes()) .SelectMany(t => t) .FirstOrDefault(t => t.FullName == "InfernalRobotics.Command.ServoController+ControlGroup"); if (IRControlGroupType == null) { var irassembly = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.assembly.FullName.Contains("InfernalRobotics")); if (irassembly == null) { LogFormatted("[IR Wrapper] cannot find InvernalRobotics.dll"); return(false); } foreach (Type t in irassembly.assembly.GetExportedTypes()) { LogFormatted("[IR Wrapper] Exported type: " + t.FullName); } LogFormatted("[IR Wrapper] Failed to grab ControlGroup Type"); return(false); } LogFormatted("Got Assembly Types, grabbing Instance"); try { var propertyInfo = IRServoControllerType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static); if (propertyInfo == null) { LogFormatted("[IR Wrapper] Cannot find Instance Property"); } else { ActualServoController = propertyInfo.GetValue(null, null); } } catch (Exception e) { LogFormatted("No Instance found, " + e.Message); } if (ActualServoController == null) { LogFormatted("Failed grabbing Instance"); return(false); } LogFormatted("Got Instance, Creating Wrapper Objects"); IRController = new InfernalRoboticsAPI(); isWrapped = true; return(true); }
internal static bool InitWrapper() { // Prevent the init function from continuing to initialize if InfernalRobotics is not installed. if (hasAssembly == null) { LogFormatted("Attempting to Grab IR3 Assembly..."); hasAssembly = AssemblyLoader.loadedAssemblies.Any(a => a.dllName.Equals("InfernalRobotics_v3")); if (hasAssembly.Value) { LogFormatted("Found IR3 Assembly!"); } else { LogFormatted("Did not find IR3 Assembly."); } } if (!hasAssembly.Value) { isWrapped = false; return(isWrapped); } isWrapped = false; ActualServoController = null; IR3Controller = null; LogFormatted("Attempting to Grab IR3 Types..."); IR3ServoControllerType = GetType("InfernalRobotics_v3.Command.Controller"); if (IR3ServoControllerType == null) { return(false); } LogFormatted("IR3 Version:{0}", IR3ServoControllerType.Assembly.GetName().Version.ToString()); IR3ServoMechanismType = GetType("InfernalRobotics_v3.Control.IServo"); if (IR3ServoMechanismType == null) { LogFormatted("[IR3 Wrapper] Failed to grab Mechanism Type"); return(false); } IR3ServoMotorType = GetType("InfernalRobotics_v3.Control.IMotor"); if (IR3ServoMotorType == null) { LogFormatted("[IR3 Wrapper] Failed to grab ServoMotor Type"); return(false); } IR3ServoType = GetType("InfernalRobotics_v3.Control.IServo"); if (IR3ServoType == null) { LogFormatted("[IR3 Wrapper] Failed to grab Servo Type"); return(false); } IR3ServoPartType = GetType("InfernalRobotics_v3.Control.IServo"); if (IR3ServoType == null) { LogFormatted("[IR3 Wrapper] Failed to grab ServoPart Type"); return(false); } IR3ControlGroupType = GetType("InfernalRobotics_v3.Command.ControlGroup"); if (IR3ControlGroupType == null) { var IR3assembly = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.assembly.FullName.Contains("InfernalRobotics_v3")); if (IR3assembly == null) { LogFormatted("[IR3 Wrapper] cannot find InfernalRobotics_v3.dll"); return(false); } foreach (Type t in IR3assembly.assembly.GetExportedTypes()) { LogFormatted("[IR3 Wrapper] Exported type: " + t.FullName); } LogFormatted("[IR3 Wrapper] Failed to grab ControlGroup Type"); return(false); } LogFormatted("Got Assembly Types, grabbing Instance"); try { var propertyInfo = IR3ServoControllerType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static); if (propertyInfo == null) { LogFormatted("[IR3 Wrapper] Cannot find Instance Property"); } else { ActualServoController = propertyInfo.GetValue(null, null); } } catch (Exception e) { LogFormatted("No Instance found, " + e.Message); } if (ActualServoController == null) { LogFormatted("Failed grabbing Instance"); return(false); } LogFormatted("Got Instance, Creating Wrapper Objects"); IR3Controller = new InfernalRoboticsAPI(); isWrapped = true; return(true); }
internal bool InternalInitWrapper() { instance = this; isWrapped = false; IRController = null; LogFormatted("Attempting to Grab IR Types..."); IRControllerType = null; AssemblyLoader.loadedAssemblies.TypeOperation(t => { if (t.FullName == "InfernalRobotics_v3.Command.Controller") { IRControllerType = t; } }); if (IRControllerType == null) { return(false); } LogFormatted("IR Version:{0}", IRControllerType.Assembly.GetName().Version.ToString()); IRMotorType = null; AssemblyLoader.loadedAssemblies.TypeOperation(t => { if (t.FullName == "InfernalRobotics_v3.Interfaces.IMotor") { IRMotorType = t; } }); if (IRMotorType == null) { LogFormatted("[IR Wrapper] Failed to grab Motor Type"); return(false); } IRServoType = null; AssemblyLoader.loadedAssemblies.TypeOperation(t => { if (t.FullName == "InfernalRobotics_v3.Interfaces.IServo") { IRServoType = t; } }); if (IRServoType == null) { LogFormatted("[IR Wrapper] Failed to grab Servo Type"); return(false); } IRControlGroupType = null; AssemblyLoader.loadedAssemblies.TypeOperation(t => { if (t.FullName == "InfernalRobotics_v3.Command.ControlGroup") { IRControlGroupType = t; } }); if (IRControlGroupType == null) { LogFormatted("[IR Wrapper] Failed to grab ControlGroup Type"); return(false); } LogFormatted("Got Assembly Types, grabbing Instance"); Controller = IRControllerType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static); if (Controller == null) { LogFormatted("[IR Wrapper] Cannot find Instance Property"); return(false); } LogFormatted("Got Instance, Creating Wrapper Objects"); IRController = new InfernalRoboticsAPI(); isWrapped = true; return(true); }