Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            UnityContainer container = new UnityContainer();
            container.RegisterInstance<IServiceLocator>(new UnityServiceLocatorAdapter(container));

            container.RegisterType<IModuleInitializer, ModuleInitializer>();

            TextLogger logger = new TextLogger();
            container.RegisterInstance<ILoggerFacade>(logger);

            IEventAggregator eventAggregator = new EventAggregator();
            container.RegisterInstance<IEventAggregator>(eventAggregator);

            ModuleCatalog catalog = new ModuleCatalog();
            //catalog.AddModule(typeof(RFID.RFIDModule));
            catalog.AddModule(typeof(BookInformation.BookInformationModule));
            catalog.AddModule(typeof(BookLocation.BookLocationModule));
            container.RegisterInstance<IModuleCatalog>(catalog);

            container.RegisterType<IModuleManager, ModuleManager>();
            IModuleManager manager = container.Resolve<IModuleManager>();
            manager.Run();
            //测试RFID服务模块的功能
            //RFIDUnitTest.testRFID(container);
            /******/
            //测试串口服务的功能
            //SerialUnitTest.testSerial(container);
            //测试数据库功能
            DatabaseUnitTest.testAllDatabase(container);
        }
        public void ModuleInUnreferencedAssemblyInitializedByModuleInitializer()
        {
            AssemblyCatalog assemblyCatalog = new AssemblyCatalog(GetPathToModuleDll());
            CompositionContainer compositionContainer = new CompositionContainer(assemblyCatalog);

            ModuleCatalog moduleCatalog = new ModuleCatalog();

            Mock<MefFileModuleTypeLoader> mockFileTypeLoader = new Mock<MefFileModuleTypeLoader>();

            compositionContainer.ComposeExportedValue<IModuleCatalog>(moduleCatalog);
            compositionContainer.ComposeExportedValue<MefFileModuleTypeLoader>(mockFileTypeLoader.Object);

            bool wasInit = false;
            var mockModuleInitializer = new Mock<IModuleInitializer>();
            mockModuleInitializer.Setup(x => x.Initialize(It.IsAny<ModuleInfo>())).Callback(() => wasInit = true);

            var mockLoggerFacade = new Mock<ILoggerFacade>();

            MefModuleManager moduleManager = new MefModuleManager(
                mockModuleInitializer.Object,
                moduleCatalog,
                mockLoggerFacade.Object);

            compositionContainer.SatisfyImportsOnce(moduleManager);

            moduleManager.Run();

            Assert.IsTrue(wasInit);
        }
        protected override IModuleCatalog CreateModuleCatalog()
        {
            ModuleCatalog moduleCatalog = new Prism.Modularity.ModuleCatalog();

            moduleCatalog.AddModule(typeof(HeroVirtualTabletopModule), InitializationMode.OnDemand);

            return(moduleCatalog);
        }
Ejemplo n.º 4
0
        protected override IModuleCatalog CreateModuleCatalog()
        {
            ModuleCatalog moduleCatalog = new Prism.Modularity.ModuleCatalog();

            moduleCatalog.AddModule(typeof(ToolBarModule));
            moduleCatalog.AddModule(typeof(ServicesModule));
            moduleCatalog.AddModule(typeof(ProductsModule));
            return(moduleCatalog);
        }
Ejemplo n.º 5
0
        public void CanCreateCatalogFromList()
        {
            var moduleInfo = new ModuleInfo("MockModule", "type");
            List<ModuleInfo> moduleInfos = new List<ModuleInfo> { moduleInfo };

            var moduleCatalog = new ModuleCatalog(moduleInfos);

            Assert.AreEqual(1, moduleCatalog.Modules.Count());
            Assert.AreEqual(moduleInfo, moduleCatalog.Modules.ElementAt(0));
        }
Ejemplo n.º 6
0
        public void CanGetDependenciesForModule()
        {
            // A <- B
            var moduleInfoA = CreateModuleInfo("A");
            var moduleInfoB = CreateModuleInfo("B", "A");
            List<ModuleInfo> moduleInfos = new List<ModuleInfo>
                                               {
                                                   moduleInfoA
                                                   , moduleInfoB
                                               };
            var moduleCatalog = new ModuleCatalog(moduleInfos);

            IEnumerable<ModuleInfo> dependentModules = moduleCatalog.GetDependentModules(moduleInfoB);

            Assert.AreEqual(1, dependentModules.Count());
            Assert.AreEqual(moduleInfoA, dependentModules.ElementAt(0));
        }
Ejemplo n.º 7
0
        protected override IModuleCatalog CreateModuleCatalog()
        {
            ModuleCatalog catalog = new ModuleCatalog();
            catalog.AddModule(typeof(BLModule));
            catalog.AddModule(typeof(ModuleCateogryModule));
            catalog.AddModule(typeof(ModuleSubCateogryModule));
            catalog.AddModule(typeof(ModulePaSModule));
            //catalog.AddModule(typeof(PersonServiceModule));
            //catalog.AddModule(typeof(ModuleAModule));

            //catalog.AddModule(typeof(ServicesModule));
            //catalog.AddModule(typeof(ToolbarModule));
            //catalog.AddModule(typeof (PeopleModule));
            catalog.AddModule(typeof(StatusBarModule));


            //catalog.AddModule(typeof(SubCatModule));            
            return catalog;
        }
Ejemplo n.º 8
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            var catalog = new ModuleCatalog();
            catalog.AddModule(typeof(ShellServicesModule));
            catalog.AddModule(typeof(FlatDarkThemeModule));
            catalog.AddModule(typeof(FlatLightThemeModule));
            catalog.AddModule(typeof(PreferencesModule));
            catalog.AddModule(typeof(ThemeModule));
            catalog.AddModule(typeof(SupportModule));
            catalog.AddModule(typeof(UtilitiesModule));
            catalog.AddModule(typeof(ConnectivityModule));

            var host = new UnityDesktopHost(Resources);
            host.Container.RegisterInstance(typeof(IModuleCatalog), catalog, new ContainerControlledLifetimeManager());
            host.UseNLog();
            host.Run();
        }
Ejemplo n.º 9
0
        protected override IModuleCatalog CreateModuleCatalog()
        {
            ModuleCatalog catalog = new ModuleCatalog();
            catalog.AddModule(new ModuleInfo()
            {
                ModuleName = typeof (Modules.RS485Port.RS485PortModule).Name,
                ModuleType = typeof (Modules.RS485Port.RS485PortModule).AssemblyQualifiedName
            });
            catalog.AddModule(new ModuleInfo()
            {
                ModuleName = typeof (Modules.TMCLCommands.TMCLCommandModule).Name,
                ModuleType = typeof (Modules.TMCLCommands.TMCLCommandModule).AssemblyQualifiedName
            });
            catalog.AddModule(new ModuleInfo()
            {
                ModuleName = typeof(Modules.DisplayCommander.DisplayCommanderModule).Name,
                ModuleType = typeof(Modules.DisplayCommander.DisplayCommanderModule).AssemblyQualifiedName
            });

            return catalog;
        }
Ejemplo n.º 10
0
        public void CanCompleteListWithTheirDependencies()
        {
            // A <- B <- C
            var moduleInfoA = CreateModuleInfo("A");
            var moduleInfoB = CreateModuleInfo("B", "A");
            var moduleInfoC = CreateModuleInfo("C", "B");
            var moduleInfoOrphan = CreateModuleInfo("X", "B");

            List<ModuleInfo> moduleInfos = new List<ModuleInfo>
                                               {
                                                   moduleInfoA
                                                   , moduleInfoB
                                                   , moduleInfoC
                                                   , moduleInfoOrphan
                                               };
            var moduleCatalog = new ModuleCatalog(moduleInfos);

            IEnumerable<ModuleInfo> dependantModules = moduleCatalog.CompleteListWithDependencies(new[] { moduleInfoC });

            Assert.AreEqual(3, dependantModules.Count());
            Assert.IsTrue(dependantModules.Contains(moduleInfoA));
            Assert.IsTrue(dependantModules.Contains(moduleInfoB));
            Assert.IsTrue(dependantModules.Contains(moduleInfoC));
        }
Ejemplo n.º 11
0
        public void ModuleInGroupDependsOnModuleInOtherGroupThrows()
        {
            var catalog = new ModuleCatalog();
            catalog.Items.Add(new ModuleInfoGroup() { CreateModuleInfo("ModuleA") });
            catalog.Items.Add(new ModuleInfoGroup() { CreateModuleInfo("ModuleB", "ModuleA") });

            try
            {
                catalog.Validate();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ModularityException));
                Assert.AreEqual("ModuleB", ((ModularityException)ex).ModuleName);

                return;
            }

            Assert.Fail("Exception not thrown.");
        }
Ejemplo n.º 12
0
        public void CanAddModule4()
        {
            ModuleCatalog catalog = new ModuleCatalog();

            catalog.AddModule(typeof(MockModule), "DependsOn1", "DependsOn2");

            Assert.AreEqual(1, catalog.Modules.Count());
            Assert.AreEqual("MockModule", catalog.Modules.First().ModuleName);
            Assert.AreEqual(typeof(MockModule).AssemblyQualifiedName, catalog.Modules.First().ModuleType);
            Assert.AreEqual(InitializationMode.WhenAvailable, catalog.Modules.First().InitializationMode);
            Assert.AreEqual(2, catalog.Modules.First().DependsOn.Count);
            Assert.AreEqual("DependsOn1", catalog.Modules.First().DependsOn[0]);
            Assert.AreEqual("DependsOn2", catalog.Modules.First().DependsOn[1]);

        }
Ejemplo n.º 13
0
        public void CanAddGroup()
        {
            ModuleCatalog catalog = new ModuleCatalog();

            catalog.Items.Add(new ModuleInfoGroup());

            catalog.AddGroup(InitializationMode.OnDemand, "Ref1",
                             new ModuleInfo("M1", "T1"),
                             new ModuleInfo("M2", "T2", "M1"));

            Assert.AreEqual(2, catalog.Modules.Count());

            var module1 = catalog.Modules.First();
            var module2 = catalog.Modules.Skip(1).First();


            Assert.AreEqual("M1", module1.ModuleName);
            Assert.AreEqual("T1", module1.ModuleType);
            Assert.AreEqual("Ref1", module1.Ref);
            Assert.AreEqual(InitializationMode.OnDemand, module1.InitializationMode);

            Assert.AreEqual("M2", module2.ModuleName);
            Assert.AreEqual("T2", module2.ModuleType);
            Assert.AreEqual("Ref1", module2.Ref);
            Assert.AreEqual(InitializationMode.OnDemand, module2.InitializationMode);
        }
Ejemplo n.º 14
0
        public void CanAddModules()
        {
            var catalog = new ModuleCatalog();

            catalog.AddModule(typeof(MockModule));

            Assert.AreEqual(1, catalog.Modules.Count());
            Assert.AreEqual("MockModule", catalog.Modules.First().ModuleName);
        }
Ejemplo n.º 15
0
        public void CanAddModule1()
        {
            ModuleCatalog catalog = new ModuleCatalog();

            catalog.AddModule("Module", "ModuleType", InitializationMode.OnDemand, "DependsOn1", "DependsOn2");

            Assert.AreEqual(1, catalog.Modules.Count());
            Assert.AreEqual("Module", catalog.Modules.First().ModuleName);
            Assert.AreEqual("ModuleType", catalog.Modules.First().ModuleType);
            Assert.AreEqual(InitializationMode.OnDemand, catalog.Modules.First().InitializationMode);
            Assert.AreEqual(2, catalog.Modules.First().DependsOn.Count);
            Assert.AreEqual("DependsOn1", catalog.Modules.First().DependsOn[0]);
            Assert.AreEqual("DependsOn2", catalog.Modules.First().DependsOn[1]);

        }
Ejemplo n.º 16
0
        public void StartupModuleDependentOnAnOnDemandModuleThrows()
        {
            var catalog = new ModuleCatalog();
            var moduleOnDemand = CreateModuleInfo("ModuleA");
            moduleOnDemand.InitializationMode = InitializationMode.OnDemand;
            catalog.AddModule(moduleOnDemand);
            catalog.AddModule(CreateModuleInfo("ModuleB", "ModuleA"));

            try
            {
                catalog.Validate();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ModularityException));
                Assert.AreEqual("ModuleB", ((ModularityException)ex).ModuleName);

                return;
            }

            Assert.Fail("Exception not thrown.");
        }
Ejemplo n.º 17
0
        public void ShouldReturnInCorrectRetrieveOrderWhenCompletingListWithDependencies()
        {
            // A <- B <- C <- D,    C <- X
            var moduleA = CreateModuleInfo("A");
            var moduleB = CreateModuleInfo("B", "A");
            var moduleC = CreateModuleInfo("C", "B");
            var moduleD = CreateModuleInfo("D", "C");
            var moduleX = CreateModuleInfo("X", "C");

            var moduleCatalog = new ModuleCatalog();
            // Add the modules in random order
            moduleCatalog.AddModule(moduleB);
            moduleCatalog.AddModule(moduleA);
            moduleCatalog.AddModule(moduleD);
            moduleCatalog.AddModule(moduleX);
            moduleCatalog.AddModule(moduleC);

            var dependantModules = moduleCatalog.CompleteListWithDependencies(new[] { moduleD, moduleX }).ToList();

            Assert.AreEqual(5, dependantModules.Count);
            Assert.IsTrue(dependantModules.IndexOf(moduleA) < dependantModules.IndexOf(moduleB));
            Assert.IsTrue(dependantModules.IndexOf(moduleB) < dependantModules.IndexOf(moduleC));
            Assert.IsTrue(dependantModules.IndexOf(moduleC) < dependantModules.IndexOf(moduleD));
            Assert.IsTrue(dependantModules.IndexOf(moduleC) < dependantModules.IndexOf(moduleX));
        }
Ejemplo n.º 18
0
        public void CanAddGroups()
        {
            var catalog = new ModuleCatalog();

            ModuleInfo moduleInfo = new ModuleInfo();
            ModuleInfoGroup group = new ModuleInfoGroup { moduleInfo };
            catalog.Items.Add(group);

            Assert.AreEqual(1, catalog.Modules.Count());
            Assert.AreSame(moduleInfo, catalog.Modules.ElementAt(0));
        }
Ejemplo n.º 19
0
 protected override IModuleCatalog CreateModuleCatalog()
 {
     ModuleCatalog moduleCatalog = new ModuleCatalog();
     moduleCatalog.AddModule(typeof(AirlineModule.AirlineModuleModule));
     return moduleCatalog;
 }
        public void DeclaredModuleWithTypeInUnreferencedAssemblyIsUpdatedWithTypeNameFromExportAttribute()
        {
            AggregateCatalog aggregateCatalog = new AggregateCatalog();
            CompositionContainer compositionContainer = new CompositionContainer(aggregateCatalog);

            var mockFileTypeLoader = new Mock<MefFileModuleTypeLoader>();
            mockFileTypeLoader.Setup(tl => tl.CanLoadModuleType(It.IsAny<ModuleInfo>())).Returns(true);


            ModuleCatalog moduleCatalog = new ModuleCatalog();
            ModuleInfo moduleInfo = new ModuleInfo { ModuleName = "MefModuleOne", ModuleType = "some type" };
            moduleCatalog.AddModule(moduleInfo);

            compositionContainer.ComposeExportedValue<IModuleCatalog>(moduleCatalog);
            compositionContainer.ComposeExportedValue<MefFileModuleTypeLoader>(mockFileTypeLoader.Object);

            bool wasInit = false;
            var mockModuleInitializer = new Mock<IModuleInitializer>();
            mockModuleInitializer.Setup(x => x.Initialize(It.IsAny<ModuleInfo>())).Callback(() => wasInit = true);

            var mockLoggerFacade = new Mock<ILoggerFacade>();

            MefModuleManager moduleManager = new MefModuleManager(
                mockModuleInitializer.Object,
                moduleCatalog,
                mockLoggerFacade.Object);

            compositionContainer.SatisfyImportsOnce(moduleManager);
            moduleManager.Run();

            Assert.IsFalse(wasInit);

            AssemblyCatalog assemblyCatalog = new AssemblyCatalog(GetPathToModuleDll());
            aggregateCatalog.Catalogs.Add(assemblyCatalog);

            compositionContainer.SatisfyImportsOnce(moduleManager);

            mockFileTypeLoader.Raise(tl => tl.LoadModuleCompleted += null, new LoadModuleCompletedEventArgs(moduleInfo, null));

            Assert.AreEqual(BuildMefSupportTypeName(), moduleInfo.ModuleType);
            Assert.IsTrue(wasInit);
        }
Ejemplo n.º 21
0
 public void CompleteListWithDependenciesThrowsWithNull()
 {
     var catalog = new ModuleCatalog();
     catalog.CompleteListWithDependencies(null);
 }
Ejemplo n.º 22
0
        public void ShouldAggregateGroupsAndLooseModuleInfos()
        {
            var catalog = new ModuleCatalog();
            ModuleInfo moduleInfo1 = new ModuleInfo();
            ModuleInfo moduleInfo2 = new ModuleInfo();
            ModuleInfo moduleInfo3 = new ModuleInfo();

            catalog.Items.Add(new ModuleInfoGroup() { moduleInfo1 });
            catalog.Items.Add(new ModuleInfoGroup() { moduleInfo2 });
            catalog.AddModule(moduleInfo3);

            Assert.AreEqual(3, catalog.Modules.Count());
            Assert.IsTrue(catalog.Modules.Contains(moduleInfo1));
            Assert.IsTrue(catalog.Modules.Contains(moduleInfo2));
            Assert.IsTrue(catalog.Modules.Contains(moduleInfo3));
        }
Ejemplo n.º 23
0
 protected override IModuleCatalog CreateModuleCatalog()
 {
     ModuleCatalog catalog = new ModuleCatalog();
     catalog.AddModule(typeof (ModuleAModule.ModuleAModule), InitializationMode.WhenAvailable);
     return catalog;
 }
Ejemplo n.º 24
0
        public void ModuleInGroupCanDependOnModuleInSameGroup()
        {
            var catalog = new ModuleCatalog();
            var moduleA = CreateModuleInfo("ModuleA");
            var moduleB = CreateModuleInfo("ModuleB", "ModuleA");
            catalog.Items.Add(new ModuleInfoGroup()
                                  {
                                      moduleA,
                                      moduleB
                                  });

            var moduleBDependencies = catalog.GetDependentModules(moduleB);

            Assert.AreEqual(1, moduleBDependencies.Count());
            Assert.AreEqual(moduleA, moduleBDependencies.First());

        }