示例#1
0
        /// <summary>
        /// This method will set up the ResearchBodies object and wrap all the methods/functions
        /// </summary>
        /// <returns>Bool success of method</returns>
        public static Boolean InitRBWrapper()
        {
            //reset the internal objects
            _RBWrapped = false;
            actualRB   = null;
            actualRBSC = null;
            actualRBDB = null;

            LogFormatted("Attempting to Grab ResearchBodies Types...");

            //find the base type
            RBAPIType = AssemblyLoader.loadedAssemblies
                        .Select(a => a.assembly.GetExportedTypes())
                        .SelectMany(t => t)
                        .FirstOrDefault(t => t.FullName == "ResearchBodies.ResearchBodies");

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

            LogFormatted("ResearchBodies Version:{0}", RBAPIType.Assembly.GetName().Version.ToString());

            //find the base type
            RBSCAPIType = AssemblyLoader.loadedAssemblies
                          .Select(a => a.assembly.GetExportedTypes())
                          .SelectMany(t => t)
                          .FirstOrDefault(t => t.FullName == "ResearchBodies.ResearchBodiesController");

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

            //find the base type
            RBDBAPIType = AssemblyLoader.loadedAssemblies
                          .Select(a => a.assembly.GetExportedTypes())
                          .SelectMany(t => t)
                          .FirstOrDefault(t => t.FullName == "ResearchBodies.Database");

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

            //find the CelestialBodyInfo type
            RBDBCelestialBodyType = AssemblyLoader.loadedAssemblies
                                    .Select(a => a.assembly.GetExportedTypes())
                                    .SelectMany(t => t)
                                    .FirstOrDefault(t => t.FullName == "ResearchBodies.CelestialBodyInfo");

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

            //now grab the running instances
            LogFormatted("Got Assembly Types, grabbing Instances");
            try
            {
                actualRB = RBAPIType.GetField("Instance", BindingFlags.Public | BindingFlags.Static).GetValue(null);
            }
            catch (Exception)
            {
                LogFormatted("No ResearchBodies.ResearchBodies Instance found");
                //throw;
            }

            if (actualRB == null)
            {
                LogFormatted("Failed grabbing ResearchBodies.ResearchBodies Instance");
                return(false);
            }

            try
            {
                actualRBSC = RBSCAPIType.GetField("instance", BindingFlags.Public | BindingFlags.Static).GetValue(null);
            }
            catch (Exception)
            {
                LogFormatted("No ResearchBodies.ResearchBodiesController Instance found");
                //throw;
            }

            if (actualRBSC == null)
            {
                LogFormatted("Failed grabbing ResearchBodies.ResearchBodiesController Instance");
                return(false);
            }

            try
            {
                actualRBDB = RBDBAPIType.GetField("instance", BindingFlags.Public | BindingFlags.Static).GetValue(null);
            }
            catch (Exception)
            {
                LogFormatted("No ResearchBodies.Database Instance found");
                //throw;
            }

            if (actualRBDB == null)
            {
                LogFormatted("Failed grabbing ResearchBodies.Database Instance");
                return(false);
            }

            //If we get this far we can set up the local object and its methods/functions
            RBactualAPI = new RBAPI(actualRB, actualRBSC, actualRBDB);
            _RBWrapped  = true;
            return(true);
        }
        /// <summary>
        /// This method will set up the ResearchBodies object and wrap all the methods/functions
        /// </summary>
        /// <returns>Bool success of method</returns>
        public static Boolean InitRBWrapper()
        {
            //reset the internal objects
            _RBWrapped = false;
            actualRB = null;
            actualRBSC = null;
            actualRBDB = null;

            LogFormatted_DebugOnly("Attempting to Grab ResearchBodies Types...");

            //find the base type
            RBAPIType = AssemblyLoader.loadedAssemblies
                .Select(a => a.assembly.GetExportedTypes())
                .SelectMany(t => t)
                .FirstOrDefault(t => t.FullName == "ResearchBodies.ResearchBodies");

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

            LogFormatted_DebugOnly("ResearchBodies Version:{0}", RBAPIType.Assembly.GetName().Version.ToString());

            //find the base type
            RBSCAPIType = AssemblyLoader.loadedAssemblies
                .Select(a => a.assembly.GetExportedTypes())
                .SelectMany(t => t)
                .FirstOrDefault(t => t.FullName == "ResearchBodies.ResearchBodiesController");

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

            //find the base type
            RBDBAPIType = AssemblyLoader.loadedAssemblies
                .Select(a => a.assembly.GetExportedTypes())
                .SelectMany(t => t)
                .FirstOrDefault(t => t.FullName == "ResearchBodies.Database");

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

            //find the CelestialBodyInfo type
            RBDBCelestialBodyType = AssemblyLoader.loadedAssemblies
                .Select(a => a.assembly.GetExportedTypes())
                .SelectMany(t => t)
                .FirstOrDefault(t => t.FullName == "ResearchBodies.CelestialBodyInfo");

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

            //now grab the running instances
            LogFormatted_DebugOnly("Got Assembly Types, grabbing Instances");
            try
            {
                actualRB = RBAPIType.GetField("Instance", BindingFlags.Public | BindingFlags.Static).GetValue(null);
            }
            catch (Exception)
            {
                LogFormatted("No ResearchBodies.ResearchBodies Instance found");
                //throw;
            }

            if (actualRB == null)
            {
                LogFormatted("Failed grabbing ResearchBodies.ResearchBodies Instance");
                return false;
            }

            try
            {
                actualRBSC = RBSCAPIType.GetField("instance", BindingFlags.Public | BindingFlags.Static).GetValue(null);
            }
            catch (Exception)
            {
                LogFormatted("No ResearchBodies.ResearchBodiesController Instance found");
                //throw;
            }

            if (actualRBSC == null)
            {
                LogFormatted("Failed grabbing ResearchBodies.ResearchBodiesController Instance");
                return false;
            }

            try
            {
                actualRBDB = RBDBAPIType.GetField("instance", BindingFlags.Public | BindingFlags.Static).GetValue(null);
            }
            catch (Exception)
            {
                LogFormatted("No ResearchBodies.Database Instance found");
                //throw;
            }

            if (actualRBDB == null)
            {
                LogFormatted("Failed grabbing ResearchBodies.Database 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");
            RBactualAPI = new RBAPI(actualRB, actualRBSC, actualRBDB);
            _RBWrapped = true;
            return true;
        }