/// <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; } }
protected void LoadModulesFromDirectory(IModuleDiscovery moduleDiscovery) { Manager.LoadModules(moduleDiscovery); }
public void basic_usage_scenerio_with_newer_versions_avaliable_automatic_update() { // create the updater module string updaterDir = NomadConfigurationSettings.ModuleDirectoryPath; ModuleCompiler.SetUpModuleWithManifest(updaterDir, @"..\Source\Nomad.Tests\FunctionalTests\Data\Updater\UpdaterModule.cs"); // set up two simple modules IModuleDiscovery v0Discovery = SetUpTwoSimpleModulesGetTheirDiscovery(); // override kernel configuration and initialize kernel NomadConfigurationSettings.UpdaterType = UpdaterType.Automatic; SetUpKernel(); // test against loading var discovery = new CompositeModuleDiscovery(new DirectoryModuleDiscovery(updaterDir, SearchOption.TopDirectoryOnly), v0Discovery); Kernel.LoadModules(discovery); // verify the versions of the loaded modules are proper IList <ModuleInfo> loadedModules = Kernel.ServiceLocator.Resolve <ILoadedModulesService>().GetLoadedModules(); Assert.AreEqual(3, loadedModules.Count); AssertVersion("1.0.0.0", loadedModules, "SimplestModulePossible1"); AssertVersion("1.0.0.0", loadedModules, "SimplestModulePossible2"); // check if all stages of update were done bool avaliableUpdates = false; bool readyUpdates = false; Kernel.EventAggregator.Subscribe <NomadAvailableUpdatesMessage>( message => { if (message.Error == false) { avaliableUpdates = true; } }); Kernel.EventAggregator.Subscribe <NomadUpdatesReadyMessage>(message => { if (message.Error == false) { readyUpdates = true; } }); var updater = Kernel.ServiceLocator.Resolve <IUpdater>(); // initialize the updating through updater module using event aggregator and publish Kernel.EventAggregator.Publish(new BeginUpdateMessage()); // verify stages Assert.IsTrue(avaliableUpdates, "Available updates message was not published."); Assert.IsTrue(readyUpdates, "Updates ready message was not published."); // verify the outcome of the updater after finishing (this wait is for test purposes) updater.UpdateFinished.WaitOne(); Assert.AreEqual(UpdaterStatus.Idle, Kernel.ServiceLocator.Resolve <IUpdater>().Status, "Problem with the state of the updater"); // verify the versions of the newest modules are loaded loadedModules = Kernel.ServiceLocator.Resolve <ILoadedModulesService>().GetLoadedModules(); Assert.AreEqual(3, loadedModules.Count); AssertVersion("2.0.0.0", loadedModules, "SimplestModulePossible1"); AssertVersion("2.0.0.0", loadedModules, "SimplestModulePossible2"); }
protected void LoadModulesFromDiscovery(IModuleDiscovery discovery) { Kernel.LoadModules(discovery); }
protected void LoadModulesFromDiscovery(IModuleDiscovery discovery) { Kernel.LoadModules(discovery); }
private void UpdateInThreadPerforming(IModuleDiscovery afterUpdateModulesToBeLoaded) { try { // FIXME: this sleep is totally wrong Thread.Sleep(100); _modulesOperations.UnloadModules(); // use packager for the each of the downloaded packages foreach (ModulePackage modulePackage in _modulesPackages) { var targetDirectory = _moduleFinder.FindDirectoryForPackage(_targetDirectory, modulePackage); _modulePackager.PerformUpdates(targetDirectory, modulePackage); } _modulesOperations.LoadModules(afterUpdateModulesToBeLoaded); } catch (Exception) { // catch exceptions, TODO: add logging for this Status = UpdaterStatus.Invalid; // make signal about finishing the update UpdateFinished.Set(); return; } // set result of the updates Status = UpdaterStatus.Idle; // make signal about finishing the update. UpdateFinished.Set(); }
/// <summary> /// Starts update process /// </summary> /// <remarks> /// <para> /// Using provided <see cref="IModulesOperations"/> it unloads all modules, /// than it places update files into modules directory, and loads modules back. /// </para> /// <para> /// This implementation creates the new thread to be used to unload modules. It is obligatory because of the /// <see cref="AppDomain.Unload"/> method, which can not be invoked by thread which used to be on unloading domain. /// </para> /// <para> /// Upon success or failure sets the flag <see cref="Status"/> with corresponding value. /// </para> /// </remarks> public void PerformUpdates(IModuleDiscovery afterUpdateModulesToBeLoaded) { Status = UpdaterStatus.Performing; // manage resources faster than GC would do if (UpdateFinished != null) UpdateFinished.Close(); UpdateFinished = new AutoResetEvent(false); ThreadPool.QueueUserWorkItem( delegate { UpdateInThreadPerforming(afterUpdateModulesToBeLoaded); }); }
protected void LoadModulesFromDirectory(IModuleDiscovery moduleDiscovery) { Manager.LoadModules(moduleDiscovery); }