Esempio n. 1
0
        public static void SetupManagersFromAssembly(Assembly assembly)
        {
            Type[] types = null;
            try
            {
                types = (from type in assembly.GetTypes()
                         where Attribute.IsDefined(type, typeof(BismuthManagerInfo))
                         select type).ToArray();
            }
            catch
            {
                //Could only cause an exception error on a plugin
                LogManager.Error("STARTUP", "Could not load types from plugin '" + assembly.Location + "'. This plugin may be corrupt and has been skipped.");
                return;
            }

            for (int i = 0; i < types.Length; ++i)
            {
                BismuthManagerInfo    managerInfo = types[i].GetCustomAttribute <BismuthManagerInfo>();
                BismuthGenericManager manager     = (BismuthGenericManager)Activator.CreateInstance(types[i]);

                try
                {
                    if (manager.Setup())
                    {
                        LogManager.Log("STARTUP", "Successfully setup " + managerInfo.Name);
                        Tuple <BismuthManagerInfo, BismuthGenericManager> managerTuple = new Tuple <BismuthManagerInfo, BismuthGenericManager>(managerInfo, manager);
                        managers.Add(managerTuple);
                    }
                    else
                    {
                        LogManager.Warn("STARTUP", managerInfo.Name + " did not setup successfully and has been skipped.");
                    }
                }
                catch (Exception e)
                {
                    LogManager.Error("STARTUP", "Exception when setting up " + managerInfo.Name + "\r\n" + e.ToString());
                }
            }
        }