Example #1
0
            internal AYAPI(Object a, object b)
            {
                Instance              = this;
                actualAYAPI           = a;
                actualAYControllerAPI = b;

                getCrewablePartListMethod = AYControllerType.GetMethod("get_CrewablePartList", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
                getSubsystemToggleMethod  = AYControllerType.GetMethod("get_SubsystemToggle", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
                getHasPowerMethod         = AYControllerType.GetMethod("get_HasPower", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
                getManagerisActiveMethod  = AYControllerType.GetMethod("get_ManagerisActive", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
                getDeBuggingMethod        = AYControllerType.GetMethod("get_DeBugging", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
            }
Example #2
0
        /// <summary>
        /// This method will set up the AY object and wrap all the methods/functions
        /// </summary>
        /// <returns></returns>
        public static Boolean InitAYWrapper()
        {
            //reset the internal objects
            _AYWrapped = false;
            LogFormatted_DebugOnly("Attempting to Grab AmpYear Types...");

            //find the Controller base type
            AYType = AssemblyLoader.loadedAssemblies
                     .Select(a => a.assembly.GetExportedTypes())
                     .SelectMany(t => t)
                     .FirstOrDefault(t => t.FullName.Contains("AY.AmpYear"));

            if (AYType == null)
            {
                return(false);
            }

            LogFormatted("AmpYear Version:{0}", AYType.Assembly.GetName().Version.ToString());

            //now grab the running instance
            LogFormatted_DebugOnly("Got Assembly Types, grabbing Instances");
            try
            {
                actualAY = AYType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static).GetValue(null, null);
            }
            catch (Exception)
            {
                LogFormatted("No AmpYear Instance found");
                //throw;
            }

            if (actualAY == null)
            {
                LogFormatted("Failed grabbing Instance");
                return(false);
            }


            //find the Controller base type
            AYControllerType = AssemblyLoader.loadedAssemblies
                               .Select(a => a.assembly.GetExportedTypes())
                               .SelectMany(t => t)
                               .FirstOrDefault(t => t.FullName.Contains("AY.AYController"));

            if (AYControllerType == null)
            {
                return(false);
            }

            //now grab the running instance
            LogFormatted_DebugOnly("Got Assembly Types, grabbing Instances");
            try
            {
                actualAYController = AYControllerType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static).GetValue(null, null);
            }
            catch (Exception)
            {
                LogFormatted("No AmpYear Controller Instance found");
                //throw;
            }

            if (actualAYController == null)
            {
                LogFormatted("Failed grabbing Instance");
                return(false);
            }

            //If we get this far we can set up the local object and its methods/functions
            LogFormatted_DebugOnly("Got Instance, Creating Wrapper Objects");

            AYactualAPI = new AYAPI(actualAY, actualAYController);

            _AYWrapped = true;
            return(true);
        }