public void local_module_published_once_one_module_revieved()
        {
            PrepareSharedLibrary();

            string publishingModuleSrc = GetSourceCodePath(typeof (SDPublishingModule));
            string listeningModuleSrc = GetSourceCodePath(typeof (SDListeningModule));

            string listener1 = GenerateListener(RuntimePath, _sharedDll, listeningModuleSrc, 1);
            string listener2 = GenerateListener(RuntimePath, _sharedDll, listeningModuleSrc, 2);

            string publisherDll = Compiler.GenerateModuleFromCode(publishingModuleSrc, _sharedDll);
            ManifestBuilderConfiguration manifestConfiguration = ManifestBuilderConfiguration.Default;
            manifestConfiguration.ModulesDependenciesProvider = new SingleModulesDependencyProvider();
            Compiler.GenerateManifestForModule(publisherDll, KeyFile, manifestConfiguration);

            // use the default Nomad Configuration
            ListenerKernel = new NomadKernel();
            IModuleDiscovery listnerDiscovery =
                new CompositeModuleDiscovery(new SingleModuleDiscovery(listener1),
                                             new SingleModuleDiscovery(listener2)
                                             );

            ListenerKernel.LoadModules(listnerDiscovery);
            DistributedMessageCarrier firstCarrier = CreateCarrier(ListenerKernel);

            IModuleDiscovery publisherDiscovery = new SingleModuleDiscovery(publisherDll);
            ListenerKernel.LoadModules(publisherDiscovery);

            Thread.Sleep(PUBLISH_TIMEOUT);
            int firstMsg = firstCarrier.GetStatus.Count;

            Assert.AreEqual(5, firstMsg, "The number of delivered messages is not exactly 5");
        }
Ejemplo n.º 2
0
        private static void Main()
        {
            // signing the assemblies and creating the manifest using manifestBuilder api
            GenerateManifestUsingApi("WpfApplicationModule.exe", @".\Modules\WpfApplication");
            GenerateManifestUsingApi("WpfButtonModule.dll", @".\Modules\WpfButton");
            GenerateManifestUsingApi("WpfUpdaterModule.dll", @".\Modules\WpfUpdater");

            // setting up configuration for repository
            NomadConfiguration configuration = NomadConfiguration.Default;
            configuration.ModuleRepository = new WebModulesRepository("http://*****:*****@".\Modules\WpfApplication\WpfApplicationModule.exe"),
                new SingleModuleDiscovery(@".\Modules\WpfButton\WpfButtonModule.dll"),
                new SingleModuleDiscovery(@".\Modules\WpfUpdater\WpfUpdaterModule.dll")
                );

            kernel.LoadModules(discovery);

            // FIXME: what about ending the thread here ?
        }
        public void loading_module_fails_during_initialization_phase_throws_an_exception_callback()
        {
            const string dir1 = @"Modules\Dependent4\ModuleA\";
            const string dir2 = @"Modules\Dependent4\ModuleB\";

            // dependant module generation
            SetUpModuleWithManifest(dir1,
                                    @"..\Source\Nomad.Tests\FunctionalTests\Data\ErrorInitialize\DependencyModule1.cs");

            // second dependent module generation
            SetUpModuleWithManifest(dir2,
                                    @"..\Source\Nomad.Tests\FunctionalTests\Data\ErrorInitialize\ModuleWithDependency.cs",
                                    dir1 + "DependencyModule1.dll");

            // define discovery sequence
            var discovery = new CompositeModuleDiscovery(new IModuleDiscovery[]
                                                             {
                                                                 new DirectoryModuleDiscovery(
                                                                     dir2, SearchOption.TopDirectoryOnly),
                                                                 new DirectoryModuleDiscovery(
                                                                     dir1, SearchOption.TopDirectoryOnly),
                                                             });

            // perform test and assert
            Assert.Throws<NomadCouldNotLoadModuleException>(
                () => LoadModulesFromDiscovery(discovery));
        }
Ejemplo n.º 4
0
 private void LoadSimpleModules()
 {
     var compositeDiscovery =
         new CompositeModuleDiscovery(new IModuleDiscovery[]
                                          {
                                              new DirectoryModuleDiscovery
                                                  (@"Modules\Simple\SimplestModulePossible1\", SearchOption.TopDirectoryOnly)
                                              ,
                                              new DirectoryModuleDiscovery
                                                  (@"Modules\Simple\SimplestModulePossible2\", SearchOption.TopDirectoryOnly)
                                          });
     LoadModulesFromDirectory(compositeDiscovery);
 }
Ejemplo n.º 5
0
        private static void Main()
        {
            // signing the assemblies and creating the manifest using manifestBuilder api
            GenerateManifestUsingApi("Controlling_Publisher_Module.dll", @".\Modules\ControllingPublisher");
            GenerateManifestUsingApi("Simple_Publisher_Module.dll", @".\Modules\SimplePublisher");

            // using default configuration
            var kernel = new NomadKernel();

            // loading modules using single module discovery pattern
            var discovery = new CompositeModuleDiscovery(
                new DirectoryModuleDiscovery(@".\Modules\ControllingPublisher", SearchOption.TopDirectoryOnly),
                new DirectoryModuleDiscovery(@".\Modules\SimplePublisher", SearchOption.TopDirectoryOnly));
            kernel.LoadModules(discovery);

            //wait for input
            Console.ReadLine();
        }
        public void loading_chain_of_depenedent_modules_callback()
        {
            const string dir = @"Modules\Dependent2\ModuleA\";
            const string dir2 = @"Modules\Dependent2\ModuleB\";
            const string dir3 = @"Modules\Dependent2\ModuleC\";

            // dependant module generation
            SetUpModuleWithManifest(dir,
                                    @"..\Source\Nomad.Tests\FunctionalTests\Data\ChainDependencies\DependencyModule1.cs");

            // second dependent module generation
            SetUpModuleWithManifest(dir3,
                                    @"..\Source\Nomad.Tests\FunctionalTests\Data\ChainDependencies\DependencyModule2.cs",
                                    dir + "DependencyModule1.dll");

            // third dependent module generation
            SetUpModuleWithManifest(dir2,
                                    @"..\Source\Nomad.Tests\FunctionalTests\Data\ChainDependencies\ModuleWithDependency.cs",
                                    dir3 + "DependencyModule2.dll");

            // define discovery sequence
            var discovery = new CompositeModuleDiscovery(new IModuleDiscovery[]
                                                             {
                                                                 new DirectoryModuleDiscovery(
                                                                     dir2, SearchOption.TopDirectoryOnly),
                                                                 new DirectoryModuleDiscovery(
                                                                     dir, SearchOption.TopDirectoryOnly),
                                                                 new DirectoryModuleDiscovery(
                                                                     dir3, SearchOption.TopDirectoryOnly),
                                                             });

            // perform test and assert
            LoadModulesFromDiscovery(discovery);
            AssertModulesLoadedAreEqualTo("DependencyModule1", "DependencyModule2",
                                          "ModuleWithDependency");
        }
        public void loading_module_with_dependency_with_no_dependency_present_results_in_exception_callback()
        {
            const string dir = @"Modules\Dependent3\ModuleA\";
            const string dir2 = @"Modules\Dependent3\ModuleB\";
            const string dir3 = @"Modules\Dependent3\ModuleC\";

            // dependant module generation
            SetUpModuleWithManifest(dir,
                                    @"..\Source\Nomad.Tests\FunctionalTests\Data\ChainDependencies\DependencyModule1.cs");

            // second dependent module generation
            SetUpModuleWithManifest(dir3,
                                    @"..\Source\Nomad.Tests\FunctionalTests\Data\ChainDependencies\DependencyModule2.cs",
                                    dir + "DependencyModule1.dll");

            // third dependent module generation
            SetUpModuleWithManifest(dir2,
                                    @"..\Source\Nomad.Tests\FunctionalTests\Data\ChainDependencies\ModuleWithDependency.cs",
                                    dir3 + "DependencyModule2.dll");

            // remove dependency
            Directory.Delete(dir3, true);

            // define discovery sequence
            var discovery = new CompositeModuleDiscovery(new IModuleDiscovery[]
                                                             {
                                                                 new DirectoryModuleDiscovery(
                                                                     dir2, SearchOption.TopDirectoryOnly),
                                                                 new DirectoryModuleDiscovery(
                                                                     dir, SearchOption.TopDirectoryOnly),
                                                             });

            // perform test and assert
            Assert.Throws<NomadCouldNotLoadModuleException>(
                () => LoadModulesFromDiscovery(discovery));
        }
Ejemplo n.º 8
0
        public void basic_update_scenario_when_installing_new_module()
        {
            // create the updater module
            string updaterDir = NomadConfigurationSettings.ModuleDirectoryPath;
            ModuleCompiler.SetUpModuleWithManifest(updaterDir,
                                    @"..\Source\Nomad.Tests\FunctionalTests\Data\Updater\UpdaterModule.cs");

            // set up two simple modules -- to be loaded into kernel
            string modulaADir = Path.Combine(NomadConfigurationSettings.ModuleDirectoryPath,"moduleA");
            string modulaBDir = Path.Combine(NomadConfigurationSettings.ModuleDirectoryPath,"moduleB");
            ModuleCompiler.SetUpModuleWithManifest(modulaADir,ModuleCompiler.DefaultSimpleModuleSource);
            ModuleCompiler.SetUpModuleWithManifest(modulaBDir, ModuleCompiler.DefaultSimpleModuleSourceAlternative);
            var twoSimpleModules = new CompositeModuleDiscovery(
                new DirectoryModuleDiscovery(modulaADir, SearchOption.TopDirectoryOnly),
                new DirectoryModuleDiscovery(modulaBDir, SearchOption.TopDirectoryOnly)
                    );

            // set up third simple module -- completely independent to be placed in remote repository
            string moduleCDir = Path.Combine(NomadConfigurationSettings.ModuleDirectoryPath, "moduleC");
            ModuleCompiler.SetUpModuleWithManifest(moduleCDir,ModuleCompiler.DefaultSimpleModuleSourceLastAlternative);

            // put the third one in repository
            var listOfModuleInRepositoryInfos = twoSimpleModules.GetModules();
            var listOfModuleInRepository = new List<ModuleManifest>(twoSimpleModules.GetModules().Select(x => x.Manifest));

            SetUpModulesRepository(listOfModuleInRepository,listOfModuleInRepositoryInfos);

            // initialize kernel
            NomadConfigurationSettings.UpdaterType = UpdaterType.Automatic;
            SetUpKernel();

            // set up the subscribers for stages of update
            bool updatesChecked = false;
            bool updatesReady = false;
            Kernel.EventAggregator.Subscribe<NomadAvailableUpdatesMessage>((m) =>
                {
                    Assert.IsFalse(m.Error, "There should no error in checking");
                    updatesChecked = true;
                });

            Kernel.EventAggregator.Subscribe<NomadUpdatesReadyMessage>((m) =>
                {
                    Assert.IsFalse(m.Error, "There should no error in preparing");
                    updatesReady = true;
                });

            // load those two modules into kernel
            var discovery = new CompositeModuleDiscovery(twoSimpleModules,
                                                         new DirectoryModuleDiscovery(updaterDir,SearchOption.TopDirectoryOnly));
            Kernel.LoadModules(discovery);

            // invoke automatic update process
            var updater = Kernel.ServiceLocator.Resolve<IUpdater>();
            Kernel.EventAggregator.Publish(new BeginUpdateMessage());

            // check stages of update
            Assert.IsTrue(updatesChecked,"Updates checked message has never been invoked");
            Assert.IsTrue(updatesReady,"Updates ready message has never been invoked ");

            // wait for updater to finish and being in a good state
            Assert.NotNull(updater.UpdateFinished,"Update finshed object is null, meaning that no one has started perform update");
            updater.UpdateFinished.WaitOne();
            Assert.AreEqual(UpdaterStatus.Idle,Kernel.ServiceLocator.Resolve<IUpdater>().Status, "Problem with the state of the updater after reload");

            // assert that there are 4 modules installed and running - 3 simples and one updater
            var loadedModules = Kernel.ServiceLocator.Resolve<ILoadedModulesService>().GetLoadedModules();
            Assert.AreEqual(4, loadedModules.Count);
        }
Ejemplo n.º 9
0
        public void resolve_updater_thorugh_service_locator_after_nomad_start_up_and_unload()
        {
            // invoke setting up kernel with current state
            SetUpKernel();

            Assert.DoesNotThrow(() => Kernel.ServiceLocator.Resolve<IUpdater>());

            Kernel.UnloadModules();
            Assert.DoesNotThrow(() => Kernel.ServiceLocator.Resolve<IUpdater>());

            var discovery = new CompositeModuleDiscovery();

            Kernel.LoadModules(discovery);
            Assert.DoesNotThrow(() => Kernel.ServiceLocator.Resolve<IUpdater>());

            Kernel.UnloadModules();
            Assert.DoesNotThrow(() => Kernel.ServiceLocator.Resolve<IUpdater>());
        }
Ejemplo n.º 10
0
        public void failing_update_beacause_of_the_missing_dependencies()
        {
            // create the updater module
            string updaterDir = NomadConfigurationSettings.ModuleDirectoryPath;
            ModuleCompiler.SetUpModuleWithManifest(updaterDir,
                                    @"..\Source\Nomad.Tests\FunctionalTests\Data\Updater\UpdaterModule.cs");

            // version for modules A, B and C
            const string versionString = "1.0.0.0";

            // create modules A with version v0 (this version and dependencies are only in manifest - not in assembly)
            var moduelADir = Path.Combine(NomadConfigurationSettings.ModuleDirectoryPath, @"ModuleADir");
            var moduleAConfiguration = ManifestBuilderConfiguration.Default;

            moduleAConfiguration.VersionProvider = GetVersionProviderForVersion(versionString);
            moduleAConfiguration.ModulesDependenciesProvider = GetModuleDependenciesOnSingleModule("SimplestModulePossible2",versionString);

            ModuleCompiler.SetUpModuleWithManifest(moduelADir,ModuleCompiler.DefaultSimpleModuleSource,moduleAConfiguration);

            // create module B with the same setting as A (with version v0)
            var moduelBDir = Path.Combine(NomadConfigurationSettings.ModuleDirectoryPath, @"ModuleBDir");
            moduleAConfiguration = ManifestBuilderConfiguration.Default;

            moduleAConfiguration.VersionProvider = GetVersionProviderForVersion(versionString);
            moduleAConfiguration.ModulesDependenciesProvider = GetModuleDependenciesOnSingleModule("SimplestModulePossible3", versionString);

            ModuleCompiler.SetUpModuleWithManifest(moduelBDir, ModuleCompiler.DefaultSimpleModuleSourceAlternative, moduleAConfiguration);

            // create module C with no dependency on any other module with version v0
            var moduleCDir = Path.Combine(NomadConfigurationSettings.ModuleDirectoryPath, @"ModuleCDir");
            moduleAConfiguration = ManifestBuilderConfiguration.Default;

            moduleAConfiguration.VersionProvider = GetVersionProviderForVersion(versionString);
            ModuleCompiler.SetUpModuleWithManifest(moduleCDir, ModuleCompiler.DefaultSimpleModuleSourceLastAlternative, moduleAConfiguration);

            // create module B in version v1 which depends on module C in version v1
            var moduleBVersionUpperDir = Path.Combine(NomadConfigurationSettings.ModuleDirectoryPath,@"ModuleBUpperDir");
            moduleAConfiguration = ManifestBuilderConfiguration.Default;

            moduleAConfiguration.VersionProvider = GetVersionProviderForVersion("2.0.0.0");
            moduleAConfiguration.ModulesDependenciesProvider = GetModuleDependenciesOnSingleModule("SimplestModulePossible3", "2.0.0.0");

            ModuleCompiler.SetUpModuleWithManifest(moduleBVersionUpperDir, ModuleCompiler.DefaultSimpleModuleSourceAlternative, moduleAConfiguration);

            // put module B into repository
            var bRepoModuleInfo = new DirectoryModuleDiscovery(moduleBVersionUpperDir, SearchOption.TopDirectoryOnly)
                .GetModules()
                .Select(x => x)
                .Single();

            ModulesRepository.Setup(x => x.GetAvailableModules())
                .Returns(new AvailableModules(new List<ModuleManifest>(){bRepoModuleInfo.Manifest}));

            ModulesRepository
                .Setup(x => x.GetModule(It.IsAny<string>()))
                .Returns(new ModulePackage()
                             {
                                 ModuleManifest = bRepoModuleInfo.Manifest,
                                 ModuleZip = GetZippedData(new List<ModuleInfo>(){bRepoModuleInfo},bRepoModuleInfo.Manifest.ModuleName )
                             });

            // configure kernel
            NomadConfigurationSettings.UpdaterType = UpdaterType.Automatic;
            SetUpKernel();

            // load modules A,B,C in version v0 into Nomad
            var discovery = new CompositeModuleDiscovery(new DirectoryModuleDiscovery(moduelADir, SearchOption.TopDirectoryOnly),
                                                         new DirectoryModuleDiscovery(moduelBDir, SearchOption.TopDirectoryOnly),
                                                         new DirectoryModuleDiscovery(moduleCDir, SearchOption.TopDirectoryOnly),
                                                         new DirectoryModuleDiscovery(updaterDir, SearchOption.TopDirectoryOnly));
            Kernel.LoadModules(discovery);

            // register for updates available message
            var hasBeenInvoked = false;
            Kernel.EventAggregator.Subscribe<NomadUpdatesReadyMessage>(message =>
                                                                           {
                                                                               hasBeenInvoked = true;
                                                                               Assert.IsTrue(message.Error,"The error should be reported");

                                                                               // list of non valid modules is accurate
                                                                               Assert.AreEqual("SimplestModulePossible2", message.ModuleManifests[0].ModuleName);
                                                                           });

            // initialize check updates (automatic mode)
            Kernel.EventAggregator.Publish(new BeginUpdateMessage());

            // verify that update can not be done
            Assert.IsTrue(hasBeenInvoked,"The updates ready message was not invoked");
            Assert.AreEqual(UpdaterStatus.Invalid,Kernel.ServiceLocator.Resolve<IUpdater>().Status);
        }
Ejemplo n.º 11
0
        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");
        }
        public void loading_module_fails_during_loading_assembly_phase_throws_an_exception_callback()
        {
            const string dir1 = @"Modules\Dependent5\ModuleA\";
            const string dir2 = @"Modules\Dependent5\ModuleB\";

            // dependant module generation
            ModuleCompiler.SetUpModuleWithManifest(dir1,
                                    @"..\Source\Nomad.Tests\FunctionalTests\Data\ErrorLoad\DependencyModule1.cs");

            // second dependent module generation
            ModuleCompiler.SetUpModuleWithManifest(dir2,
                                    @"..\Source\Nomad.Tests\FunctionalTests\Data\ErrorLoad\ModuleWithDependency.cs",
                                    dir1 + "DependencyModule1.dll");

            // overwriting the dll file, causing BadImageFormatException
            File.Create(dir1 + "DependencyModule1.dll");

            // define discovery sequence
            var discovery = new CompositeModuleDiscovery(new IModuleDiscovery[]
                                                             {
                                                                 new DirectoryModuleDiscovery(
                                                                     dir2, SearchOption.TopDirectoryOnly),
                                                                 new DirectoryModuleDiscovery(
                                                                     dir1, SearchOption.TopDirectoryOnly),
                                                             });

            // perform test and assert
            Assert.Throws<NomadCouldNotLoadModuleException>(
                () => LoadModulesFromDiscovery(discovery));
        }