예제 #1
0
        private static IRemoteTechAPIv1 InitializeAPI()
        {
            var loadedAssembly = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.assembly.GetName().Name.Equals(REMOTE_TECH_ASSEMBLY));
            if (loadedAssembly == null) return null;

            var type = loadedAssembly.assembly.GetTypes().FirstOrDefault(t => t.FullName.Equals(REMOTE_TECH_API));
            if (type == null) return null;

            var methods = type.GetMethods();
            var api = new RemoteTechAPI();

            try
            {
                foreach (var property in api.GetType().GetProperties())
                {
                    var method = methods.FirstOrDefault(m => { UnityEngine.Debug.Log(m.Name); return m.Name.Equals(property.Name); });
                    if (method == null) throw new ArgumentNullException(property.Name);
                    var del = Delegate.CreateDelegate(property.PropertyType, type, method.Name);
                    property.SetValue(api, del, null);
                }
            }
            catch (Exception e)
            {
                UnityEngine.Debug.Log("kOS: Error creating RemoteTech2 interface: " + e);
                return null;
            }

            UnityEngine.Debug.Log("kOS: RemoteTech2 interface successfully created.");
            return api;
        }
예제 #2
0
        private static IRemoteTechAPIv1 InitializeAPI()
        {
            Safe.Utilities.Debug.Logger.Log(string.Format("Looking for RemoteTech"));
            var loadedAssembly = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.assembly.GetName().Name.Equals(REMOTE_TECH_ASSEMBLY));

            if (loadedAssembly == null)
            {
                return(null);
            }
            Safe.Utilities.Debug.Logger.Log(string.Format("Found RemoteTech! Version: {0}.{1}", loadedAssembly.versionMajor, loadedAssembly.versionMinor));

            var type = loadedAssembly.assembly.GetTypes().FirstOrDefault(t => t.FullName.Equals(REMOTE_TECH_API)) ??
                       loadedAssembly.assembly.GetTypes().FirstOrDefault(t => t.FullName.Equals(ALT_REMOTE_TECH_API));

            if (type == null)
            {
                return(null);
            }

            Safe.Utilities.Debug.Logger.Log(string.Format("Found API! {0} ", type.Name));
            var methods = type.GetMethods();
            var api     = new RemoteTechAPI();

            try
            {
                foreach (var property in api.GetType().GetProperties())
                {
                    var method = methods.FirstOrDefault(m =>
                    {
                        if (m.Name.Equals(property.Name))
                        {
                            Safe.Utilities.Debug.Logger.Log(string.Format("Found Endpoint: {0}", m.Name));
                            return(true);
                        }
                        return(false);
                    });

                    if (method == null)
                    {
                        throw new ArgumentNullException(property.Name);
                    }

                    var del = Delegate.CreateDelegate(property.PropertyType, type, method.Name);
                    property.SetValue(api, del, null);
                }
            }
            catch (Exception e)
            {
                Safe.Utilities.Debug.Logger.Log("kOS: Error creating RemoteTech2 interface: " + e);
                return(null);
            }

            Safe.Utilities.Debug.Logger.Log("kOS: RemoteTech2 interface successfully created.");
            return(api);
        }
예제 #3
0
        private static IRemoteTechAPIv1 InitializeAPI()
        {  
            SafeHouse.Logger.Log(string.Format("Looking for RemoteTech")); 
            var loadedAssembly = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.assembly.GetName().Name.Equals(REMOTE_TECH_ASSEMBLY));
            if (loadedAssembly == null) return null;
            SafeHouse.Logger.Log(string.Format("Found RemoteTech! Version: {0}.{1}", loadedAssembly.versionMajor, loadedAssembly.versionMinor)); 

            var type = loadedAssembly.assembly.GetTypes().FirstOrDefault(t => t.FullName.Equals(REMOTE_TECH_API)) ??
                       loadedAssembly.assembly.GetTypes().FirstOrDefault(t => t.FullName.Equals(ALT_REMOTE_TECH_API));

            if (type == null) return null;

            SafeHouse.Logger.Log(string.Format("Found API! {0} ", type.Name)); 
            var methods = type.GetMethods();
            var api = new RemoteTechAPI();

            try
            {
                foreach (var property in api.GetType().GetProperties())
                {
                    var method = methods.FirstOrDefault(m =>
                    {
                        if (m.Name.Equals(property.Name))
                        {
                            SafeHouse.Logger.Log(string.Format("Found Endpoint: {0}", m.Name)); 
                            return true;
                        }
                        return false;
                    });

                    if (method == null)
                    {
                        throw new ArgumentNullException(property.Name);
                    }

                    var del = Delegate.CreateDelegate(property.PropertyType, type, method.Name);
                    property.SetValue(api, del, null);
                }
            }
            catch (Exception e)
            {
                SafeHouse.Logger.Log("Error creating RemoteTech2 interface: " + e); 
                return null;
            }

            SafeHouse.Logger.Log("RemoteTech2 interface successfully created."); 
            return api;
        }
예제 #4
0
        private static IRemoteTechAPIv1 InitializeAPI()
        {
            var loadedAssembly = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.assembly.GetName().Name.Equals(REMOTE_TECH_ASSEMBLY));

            if (loadedAssembly == null)
            {
                return(null);
            }

            var type = loadedAssembly.assembly.GetTypes().FirstOrDefault(t => t.FullName.Equals(REMOTE_TECH_API));

            if (type == null)
            {
                return(null);
            }

            var methods = type.GetMethods();
            var api     = new RemoteTechAPI();

            try
            {
                foreach (var property in api.GetType().GetProperties())
                {
                    var method = methods.FirstOrDefault(m => { UnityEngine.Debug.Log(m.Name); return(m.Name.Equals(property.Name)); });
                    if (method == null)
                    {
                        throw new ArgumentNullException(property.Name);
                    }
                    var del = Delegate.CreateDelegate(property.PropertyType, type, method.Name);
                    property.SetValue(api, del, null);
                }
            }
            catch (Exception e)
            {
                UnityEngine.Debug.Log("kOS: Error creating RemoteTech2 interface: " + e);
                return(null);
            }

            UnityEngine.Debug.Log("kOS: RemoteTech2 interface successfully created.");
            return(api);
        }