Esempio n. 1
0
        private void SetDependencies()
        {
            foreach (var moduleInfo in _modules)
            {
                //Set dependencies according to assembly dependency
                foreach (var referencedAssemblyName in moduleInfo.Assembly.GetReferencedAssemblies())
                {
                    var referencedAssembly = Assembly.Load(referencedAssemblyName);
                    var dependedModuleList = _modules.Where(m => m.Assembly == referencedAssembly).ToList();
                    if (dependedModuleList.Count > 0)
                    {
                        moduleInfo.Dependencies.AddRange(dependedModuleList);
                    }
                }

                //Set dependencies for defined DependsOnAttribute attribute(s).
                foreach (var dependedModuleType in HozaruModule.FindDependedModuleTypes(moduleInfo.Type))
                {
                    var dependedModuleInfo = _modules.FirstOrDefault(m => m.Type == dependedModuleType);
                    if (dependedModuleInfo == null)
                    {
                        throw new HozaruInitializationException("Could not find a depended module " + dependedModuleType.AssemblyQualifiedName + " for " + moduleInfo.Type.AssemblyQualifiedName);
                    }

                    if ((moduleInfo.Dependencies.FirstOrDefault(dm => dm.Type == dependedModuleType) == null))
                    {
                        moduleInfo.Dependencies.Add(dependedModuleInfo);
                    }
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Creates a new HozaruModuleInfo object.
 /// </summary>
 /// <param name="instance"></param>
 public HozaruModuleInfo(HozaruModule instance)
 {
     Dependencies = new List <HozaruModuleInfo>();
     Type         = instance.GetType();
     Instance     = instance;
     Assembly     = Type.Assembly;
 }
Esempio n. 3
0
 private static void FillDependedModules(Type module, ICollection <Type> allModules)
 {
     foreach (var dependedModule in HozaruModule.FindDependedModuleTypes(module))
     {
         if (!allModules.Contains(dependedModule))
         {
             allModules.Add(dependedModule);
             FillDependedModules(dependedModule, allModules);
         }
     }
 }
Esempio n. 4
0
        private void LoadAll()
        {
            Logger.Debug("Loading Hozaru modules...");

            var moduleTypes = AddMissingDependedModules(_moduleFinder.FindAll());

            Logger.Debug("Found " + moduleTypes.Count + " Hozaru modules in total.");

            //Register to IOC container.
            foreach (var moduleType in moduleTypes)
            {
                if (!HozaruModule.IsHozaruModule(moduleType))
                {
                    throw new HozaruInitializationException("This type is not an Hozaru module: " + moduleType.AssemblyQualifiedName);
                }

                if (!_iocManager.IsRegistered(moduleType))
                {
                    _iocManager.Register(moduleType);
                }
            }

            //Add to module collection
            foreach (var moduleType in moduleTypes)
            {
                var moduleObject = (HozaruModule)_iocManager.Resolve(moduleType);

                moduleObject.IocManager    = _iocManager;
                moduleObject.Configuration = _iocManager.Resolve <IHozaruStartupConfiguration>();

                _modules.Add(new HozaruModuleInfo(moduleObject));

                Logger.DebugFormat("Loaded module: " + moduleType.AssemblyQualifiedName);
            }

            EnsureKernelModuleToBeFirst();

            SetDependencies();

            Logger.DebugFormat("{0} modules loaded.", _modules.Count);
        }