public static bool Initialize() { if (!inited) { inited = true; // do this only once, assemblies won't change AssemblyLoader.LoadedAssembly KASAPIasm = null; AssemblyLoader.LoadedAssembly KASasm = null; AssemblyLoader.LoadedAssembly KASLegacyasm = null; foreach (var la in AssemblyLoader.loadedAssemblies) { if (la.assembly.GetName().Name.Equals("KAS-API-v1", StringComparison.InvariantCultureIgnoreCase)) { KASAPIasm = la; } else if (la.assembly.GetName().Name.Equals("KAS", StringComparison.InvariantCultureIgnoreCase)) { if (KASLegacyasm == null) { KASLegacyasm = la; } else { KASasm = la; } } } haveKAS = false; if (KASAPIasm != null && KASasm != null) { haveKAS = true; ILinkPeer.Initialize(KASAPIasm.assembly); ILinkSource.Initialize(KASAPIasm.assembly); ILinkTarget.Initialize(KASAPIasm.assembly); ILinkJoint.Initialize(KASAPIasm.assembly); IKasLinkEvent.Initialize(KASAPIasm.assembly); IKasEvents.Initialize(KASAPIasm.assembly); KASJointCableBase.Initialize(KASasm.assembly); } if (KASLegacyasm != null) { haveKAS = true; KASModuleStrut.Initialize(KASLegacyasm.assembly); } } return(haveKAS); }
internal static void Initialize(Assembly KASasm) { if (KasEvents == null) { ikasEvents = new IKasEvents(); var KASAPI = KASasm.GetTypes().Where(t => t.Name.Equals("KASAPI")).FirstOrDefault(); var kaf = KASAPI.GetField("KasEvents", BindingFlags.Static | BindingFlags.Public); KasEvents = kaf.GetValue(null); IKasEvents_iface = KASasm.GetTypes().Where(t => t.Name.Equals("IKasEvents")).FirstOrDefault(); IKE_OnLinkCreated = IKasEvents_iface.GetProperty("OnLinkCreated"); IKE_OnLinkBroken = IKasEvents_iface.GetProperty("OnLinkBroken"); var olc = IKE_OnLinkCreated.GetValue(KasEvents, null); AddEvent(olc, GetMethodInfo((Action <object, object>)onLinkCreated)); var olb = IKE_OnLinkBroken.GetValue(KasEvents, null); AddEvent(olb, GetMethodInfo((Action <object, object>)onLinkBroken)); } }
public static bool Initialize() { if (!inited) { inited = true; // do this only once, assemblies won't change AssemblyLoader.LoadedAssembly KASAPIasm = null; AssemblyLoader.LoadedAssembly KASasm = null; AssemblyLoader.LoadedAssembly KASLegacyasm = null; int apiVersion = 0; foreach (var la in AssemblyLoader.loadedAssemblies) { string asmName = la.assembly.GetName().Name; if (asmName.Equals("KAS-API-v2", StringComparison.InvariantCultureIgnoreCase)) { KASAPIasm = la; apiVersion = 2; } else if (asmName.Equals("KAS-API-v1", StringComparison.InvariantCultureIgnoreCase)) { KASAPIasm = la; apiVersion = 1; } else if (asmName.Equals("KAS", StringComparison.InvariantCultureIgnoreCase)) { if (KASLegacyasm == null) { KASLegacyasm = la; } else { KASasm = la; } } } haveKAS = false; if (apiVersion == 2) { // With API version 2, legacy has gone away and now there's // just the API dll and the main dll // however, the main dll gets picked up as legacy KASasm = KASLegacyasm; KASLegacyasm = null; } if (KASAPIasm != null && KASasm != null) { haveKAS = true; ILinkPeer.Initialize(KASAPIasm.assembly); ILinkSource.Initialize(KASAPIasm.assembly); ILinkTarget.Initialize(KASAPIasm.assembly); ILinkJoint.Initialize(KASAPIasm.assembly); IKasLinkEvent.Initialize(KASAPIasm.assembly); IKasEvents.Initialize(KASAPIasm.assembly); KASJointCableBase.Initialize(KASasm.assembly); } if (KASLegacyasm != null) { haveKAS = true; KASModuleStrut.Initialize(KASLegacyasm.assembly); } } return(haveKAS); }