/// <summary> /// Loads all modules that are discoverable by provided <paramref name="moduleDiscovery"/>, /// and are not filtered out by provided <see cref="IModuleFilter"/>. /// </summary> /// <remarks> /// This method will try to load all modules that match requirements regardless to whether /// other modules succeed to load or fail to. /// </remarks> /// <param name="moduleDiscovery">Source of all modules that can and should be loaded.</param> /// <exception cref="ArgumentNullException">When <paramref name="moduleDiscovery"/> is <c>null</c></exception> /// <exception cref="NomadCouldNotLoadModuleException"> /// If any of the modules fail to load for any reason, exception will be raised, /// and some information about the failure will be provided. /// </exception> public void LoadModules(IModuleDiscovery moduleDiscovery) { if (moduleDiscovery == null) { throw new ArgumentNullException("moduleDiscovery"); } // pass to filtering var allModules = moduleDiscovery.GetModules(); var filteredModules = allModules.Where(module => _moduleFilter.Matches(module)); var modulesToSort = filteredModules.Union(_moduleLoader.GetLoadedModules()); // perform fail safe dependency checking IEnumerable <ModuleInfo> dependencyCheckedModules; try { dependencyCheckedModules = _dependencyChecker.SortModules(modulesToSort); } catch (ArgumentException e) { throw new NomadCouldNotLoadModuleException("Dependency resolving failed due to arguments.", e, e.ParamName); } catch (Exception e) { throw new NomadCouldNotLoadModuleException( "Unknown error during dependency resolving", e); } // perform fail safe loading try { //skip items which are loaded var modulesToLoad = dependencyCheckedModules.Where(x => filteredModules.Contains(x)); foreach (var moduleInfo in modulesToLoad) { LoadSingleModule(moduleInfo); } } catch (Exception e) { throw new NomadCouldNotLoadModuleException("Loading one of modules failed", e); } }
/// <summary> /// Loads modules into their domain. /// </summary> /// <param name="moduleDiscovery">ModuleDiscovery specifying modules to be loaded.</param> /// <remarks> /// This method provides feedback to already loaded modules about any possible failure. /// </remarks> /// <exception cref="NomadCouldNotLoadModuleException"> /// This exception will be raised when <see cref="ModuleManager"/> object responsible for /// loading modules encounter any problems. Any exception will be changed to the message <see cref="NomadCouldNotLoadModuleMessage"/> responsible for /// informing other modules about failure. /// </exception> public void LoadModules(IModuleDiscovery moduleDiscovery) { try { _moduleManager.LoadModules(moduleDiscovery); EventAggregator.Publish( new NomadAllModulesLoadedMessage( new List <ModuleInfo>(moduleDiscovery.GetModules()), "Modules loaded successfully.")); } catch (NomadCouldNotLoadModuleException e) { // publish event about not loading module to other modules. EventAggregator.Publish(new NomadCouldNotLoadModuleMessage( "Could not load modules", e.ModuleName)); // rethrow this exception to kernel domain throw; } }
/// <summary> /// Set Ups two simple modles with versions, makes them into repository. /// </summary> /// <returns></returns> protected IModuleDiscovery SetUpTwoSimpleModulesGetTheirDiscovery() { string repositoryDir = Path.Combine(TestSpacePath, "Repository"); // create the modules with specific version (mocking the version provider) and use the special manifest builder IModuleDiscovery v0Discovery = SetUpModulesWithVersion(NomadConfigurationSettings.ModuleDirectoryPath, "1.0.0.0"); // prepare module for this test with versions v1 (only of module A and module B) and put them into repository IModuleDiscovery v1Discovery = SetUpModulesWithVersion(repositoryDir, "2.0.0.0"); // putting them into repo var updateModuleInfos = new List <ModuleInfo>(v1Discovery.GetModules()); List <ModuleManifest> updateManifests = (from moduleInfo in updateModuleInfos select moduleInfo.Manifest).ToList(); SetUpModulesRepository(updateManifests, updateModuleInfos); return(v0Discovery); }
/// <summary> /// Loads all modules that are discoverable by provided <paramref name="moduleDiscovery"/>, /// and are not filtered out by provided <see cref="IModuleFilter"/>. /// </summary> /// <remarks> /// This method will try to load all modules that match requirements regardless to whether /// other modules succeed to load or fail to. /// </remarks> /// <param name="moduleDiscovery">Source of all modules that can and should be loaded.</param> /// <exception cref="ArgumentNullException">When <paramref name="moduleDiscovery"/> is <c>null</c></exception> /// <exception cref="NomadCouldNotLoadModuleException"> /// If any of the modules fail to load for any reason, exception will be raised, /// and some information about the failure will be provided. /// </exception> public void LoadModules(IModuleDiscovery moduleDiscovery) { if (moduleDiscovery == null) throw new ArgumentNullException("moduleDiscovery"); // pass to filtering var allModules = moduleDiscovery.GetModules(); var filteredModules = allModules.Where(module => _moduleFilter.Matches(module)); var modulesToSort = filteredModules.Union(_moduleLoader.GetLoadedModules()); // perform fail safe dependency checking IEnumerable<ModuleInfo> dependencyCheckedModules; try { dependencyCheckedModules = _dependencyChecker.SortModules(modulesToSort); } catch (ArgumentException e) { throw new NomadCouldNotLoadModuleException("Dependency resolving failed due to arguments.",e,e.ParamName); } catch(Exception e) { throw new NomadCouldNotLoadModuleException( "Unknown error during dependency resolving", e); } // perform fail safe loading try { //skip items which are loaded var modulesToLoad = dependencyCheckedModules.Where(x => filteredModules.Contains(x)); foreach (var moduleInfo in modulesToLoad) LoadSingleModule(moduleInfo); } catch (Exception e) { throw new NomadCouldNotLoadModuleException("Loading one of modules failed",e); } }
/// <summary> /// Loads modules into their domain. /// </summary> /// <param name="moduleDiscovery">ModuleDiscovery specifying modules to be loaded.</param> /// <remarks> /// This method provides feedback to already loaded modules about any possible failure. /// </remarks> /// <exception cref="NomadCouldNotLoadModuleException"> /// This exception will be raised when <see cref="ModuleManager"/> object responsible for /// loading modules encounter any problems. Any exception will be changed to the message <see cref="NomadCouldNotLoadModuleMessage"/> responsible for /// informing other modules about failure. /// </exception> public void LoadModules(IModuleDiscovery moduleDiscovery) { try { _moduleManager.LoadModules(moduleDiscovery); EventAggregator.Publish( new NomadAllModulesLoadedMessage( new List<ModuleInfo>(moduleDiscovery.GetModules()), "Modules loaded successfully.")); } catch (NomadCouldNotLoadModuleException e) { // publish event about not loading module to other modules. EventAggregator.Publish(new NomadCouldNotLoadModuleMessage( "Could not load modules", e.ModuleName)); // rethrow this exception to kernel domain throw; } }