Ejemplo n.º 1
0
 public bool RemoveModule(InsightModule module)
 {
     if (_modules.ContainsKey(module.GetType()))
     {
         return(_modules.Remove(module.GetType()));
     }
     return(false);
 }
Ejemplo n.º 2
0
        public void AddModule(InsightModule module)
        {
            if (_modules.ContainsKey(module.GetType()))
            {
                throw new Exception("A module already exists in the server: " + module.GetType());
            }

            _modules[module.GetType()] = module;
        }
Ejemplo n.º 3
0
        private void AddModule(InsightModule _module)
        {
            if (modules.ContainsKey(_module.GetType()))
            {
                throw new Exception($"[ModuleManager] - A module already exists in the server: {_module.GetType()} !");
            }

            modules.Add(_module.GetType(), _module);
        }
Ejemplo n.º 4
0
        private void InitializeModule(InsightModule _module)
        {
            var moduleType = _module.GetType();

            // Module is already initialized
            if (initializedModules.Contains(moduleType))
            {
                return;
            }

            // Not all dependencies have been initialized
            if (!_module.Dependencies.All(_e => initializedModules.Any(_e.IsAssignableFrom)))
            {
                foreach (var dependencyType in _module.Dependencies)
                {
                    if (!modules.TryGetValue(dependencyType, out var dependency))
                    {
                        throw new Exception($"[ModuleManager] - {moduleType} module must have a {dependencyType} module !");
                    }
                    InitializeModule(dependency);
                }
            }

            // Not all OPTIONAL dependencies have been initialized
            if (!_module.OptionalDependencies.All(_e => initializedModules.Any(_e.IsAssignableFrom)))
            {
                foreach (var dependencyType in _module.Dependencies)
                {
                    if (modules.TryGetValue(dependencyType, out var dependency))
                    {
                        InitializeModule(dependency);
                    }
                }
            }

            // Initialize our module
            if (server)
            {
                _module.Initialize(server, this);
                Debug.Log($"[ModuleManager] - Loaded InsightServer Module: {moduleType}");
            }
            if (client)
            {
                _module.Initialize(client, this);
                Debug.Log($"[ModuleManager] - Loaded InsightClient Module: {moduleType}");
            }

            initializedModules.Add(moduleType);
        }