Exemple #1
0
        /// <summary>
        /// Load an module
        /// </summary>
        /// <param name="module">Module that you want to load</param>
        public void LoadModule([NotNull] EssModule module)
        {
            Preconditions.IsTrue(RunningModules.Contains(module), "This module already loaded");

            module.Load();
            RunningModules.Add(module);
        }
Exemple #2
0
        /// <summary>
        /// Load module from an assembly
        /// </summary>
        /// <param name="moduleAssembly">Assembly that contains module that you want to load</param>
        public EssModule LoadModule(Assembly moduleAssembly)
        {
            Preconditions.NotNull(moduleAssembly, "ModuleAssembly cannot be null");

            // Prevents to load uEssentials dll accidently
            if (moduleAssembly.Equals(typeof(EssCore).Assembly))
            {
                return(null);
            }

            EssModule moduleInstance = null;

            foreach (var type in moduleAssembly.GetTypes())
            {
                if (!type.IsSubclassOf(typeof(EssModule)))
                {
                    continue;
                }

                moduleInstance          = (EssModule)Activator.CreateInstance(type);
                moduleInstance.Assembly = moduleAssembly;
            }

            Preconditions.NotNull(moduleInstance, "Could load module from assembly " +
                                  moduleAssembly.FullName +
                                  $" because it does not contains any class that extends '{typeof (EssModule)}");

            LoadModule(moduleInstance);

            return(moduleInstance);
        }
Exemple #3
0
        /// <summary>
        /// Load module from an assembly
        /// </summary>
        /// <param name="moduleAssembly">Assembly that contains module that you want to load</param>
        public EssModule LoadModule([NotNull] Assembly moduleAssembly)
        {
            // Prevents to load uEssentials dll accidently
            if (moduleAssembly.Equals(typeof(EssCore).Assembly))
            {
                return(null);
            }

            EssModule moduleInstance = null;

            foreach (var type in moduleAssembly.GetTypes().Where(type => type.IsSubclassOf(typeof(EssModule))))
            {
                moduleInstance          = (EssModule)Activator.CreateInstance(type);
                moduleInstance.Assembly = moduleAssembly;

                if (moduleInstance.Info.Version.EqualsIgnoreCase("$ASM_VERSION"))
                {
                    moduleInstance.Info.Version = moduleAssembly.GetCustomAttributes(false)
                                                  .Cast <AssemblyFileVersionAttribute>()
                                                  .Select(c => c.Version)
                                                  .FirstOrDefault();
                }
            }

            Preconditions.NotNull(moduleInstance, "Could load module from assembly " +
                                  moduleAssembly.FullName +
                                  $" because it does not contains any class that extends '{typeof(EssModule)}");

            LoadModule(moduleInstance);

            return(moduleInstance);
        }
Exemple #4
0
        /// <summary>
        /// Unload ab module
        /// </summary>
        /// <param name="module">Module that you want to unload</param>
        public void UnloadModule([NotNull] EssModule module)
        {
            Preconditions.IsFalse(RunningModules.Contains(module), "This module isn't running");

            module.Unload();
            RunningModules.Remove(module);
        }
Exemple #5
0
        /// <summary>
        /// Load an module
        /// </summary>
        /// <param name="module">Module that you want to load</param>
        public void LoadModule(EssModule module)
        {
            Preconditions.NotNull(module, "Module cannot be null");
            Preconditions.IsTrue(RunningModules.Contains(module), "This module already loaded");

            module.Load();
            RunningModules.Add(module);
        }
Exemple #6
0
        /// <summary>
        /// Unload ab module
        /// </summary>
        /// <param name="module">Module that you want to unload</param>
        public void UnloadModule(EssModule module)
        {
            Preconditions.NotNull(module, "Module cannot be null");
            Preconditions.IsFalse(RunningModules.Contains(module), "This module isn't running");

            module.Unload();
            RunningModules.Remove(module);
        }
        /// <summary>
        /// Unload ab module 
        /// </summary>
        /// <param name="module">Module that you want to unload</param>
        public void UnloadModule( EssModule module )
        {
            Preconditions.NotNull( module, "Module cannot be null" );
            Preconditions.IsFalse( RunningModules.Contains( module ), "This module isn't running" );

            module.Unload();
            RunningModules.Remove( module );
        }
        /// <summary>
        /// Load an module 
        /// </summary>
        /// <param name="module">Module that you want to load</param>
        public void LoadModule( EssModule module )
        {
            Preconditions.NotNull( module, "Module cannot be null" );
            Preconditions.IsTrue( RunningModules.Contains( module ), "This module already loaded" );

            module.Load();
            RunningModules.Add( module );
        }