private void CreateGenericPart(Type importDefinitionType)
 {
     var type = TypeHelper.BuildGenericType(importDefinitionType, _genericTypes);
     _manufacturedParts.Add(type);
     var typeCatalog = new TypeCatalog(type);
     _catalog.Catalogs.Add(typeCatalog);
 }
示例#2
0
        public void CanImportSampleData()
        {
            // Arrange
            string httpClientFactoryContract = AttributedModelServices.GetContractName(typeof(IHttpClientFactory));
            string routeServiceFactoryContract = AttributedModelServices.GetContractName(typeof(IRouteServiceFactory));

            using (ApplicationCatalog initialCatalog = Program.BuildCompositionCatalog())
            using (FilteredCatalog filteredCatalog = initialCatalog.Filter(d => !d.Exports(httpClientFactoryContract) && !d.Exports(routeServiceFactoryContract)))
            using (TypeCatalog httpClientFactoryCatalog = new TypeCatalog(typeof(WtaResultFromEmbeddedResourceFactory)))
            using (TypeCatalog routeServiceFactoryCatalog = new TypeCatalog(typeof(RouteServiceFromCalculatedDistanceFactory)))
            using (AggregateCatalog aggregateCatalog = new AggregateCatalog(filteredCatalog, httpClientFactoryCatalog, routeServiceFactoryCatalog))
            using (CompositionContainer container = new CompositionContainer(aggregateCatalog))
            {
                // Act
                ITrailsImporter importer = container.GetExportedValue<ITrailsImporter>();
                importer.Run();
            }

            using (MyTrailsContext context = new MyTrailsContext())
            {
                // Assert
                ImportLogEntry logEntry = context.ImportLog
                    .OrderByDescending(le => le.Id)
                    .FirstOrDefault();

                Assert.IsNotNull(logEntry);
                Assert.IsNull(logEntry.ErrorString, message: logEntry.ErrorString);
                Assert.AreEqual(0, logEntry.ErrorsCount);

                Assert.IsTrue(context.Trails.Any());
                Assert.IsTrue(context.Guidebooks.Any());
                Assert.IsTrue(context.Passes.Any());
                Assert.IsTrue(context.TripReports.Any());
            }
        }
示例#3
0
文件: Program.cs 项目: coreafive/XLE
		static void Main()
		{
            var engine = new GUILayer.EngineDevice();
            GC.KeepAlive(engine);

            var catalog = new TypeCatalog(
                typeof(ShaderPatcherLayer.Manager),
                typeof(ShaderFragmentArchive.Archive),
                typeof(NodeEditorCore.ShaderFragmentArchiveModel),
                typeof(NodeEditorCore.ModelConversion),
                typeof(NodeEditorCore.ShaderFragmentNodeCreator),
                typeof(NodeEditorCore.DiagramDocument),
                typeof(ExampleForm)
            );

            using (var container = new CompositionContainer(catalog))
            {
                container.ComposeExportedValue<ExportProvider>(container);
                container.ComposeExportedValue<CompositionContainer>(container);

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(container.GetExport<ExampleForm>().Value);
            }

            engine.Dispose();
		}
 public void AnyCreationPolicyDefaultsToShared()
 {
     var builder = new ContainerBuilder();
     var catalog = new TypeCatalog(typeof(HasAnyCreationPolicy));
     builder.RegisterComposablePartCatalog(catalog);
     AssertDisposalTrackerIsSingleton(builder);
 }
示例#5
0
        protected override AggregateCatalog GetCatalog()
        {
            var typeCatalog = new TypeCatalog(
                typeof(SettingsService),                // persistent settings and user preferences dialog
                typeof(CommandService),                 // handles commands in menus and toolbars
                typeof(ControlHostService),             // docking control host
                typeof(AtfUsageLogger),                 // logs computer info to an ATF server
                typeof(CrashLogger),                    // logs unhandled exceptions to an ATF server
                typeof(UnhandledExceptionService),      // catches unhandled exceptions, displays info, and gives user a chance to save
                typeof(ContextRegistry),                // central context registry with change notification
                typeof(StandardFileExitCommand),        // standard File exit menu command
                typeof(FileDialogService),              // standard Windows file dialogs
                typeof(DocumentRegistry),               // central document registry with change notification
                typeof(StandardFileCommands),           // standard File menu commands for New, Open, Save, SaveAs, Close
                typeof(AutoDocumentService),            // opens documents from last session, or creates a new document, on startup
                typeof(RecentDocumentCommands),         // standard recent document commands in File menu
                typeof(MainWindowTitleService),         // tracks document changes and updates main form title
                typeof(WindowLayoutService),            // service to allow multiple window layouts
                typeof(WindowLayoutServiceCommands),    // command layer to allow easy switching between and managing of window layouts
                typeof(SchemaLoader),                   // loads schema and extends types
                typeof(MainWindow),                     // main app window (analog to 'MainForm' in WinFormsApp)
                typeof(Editor),                         // Sample editor class that creates and saves application documents
                typeof(PythonService),                  // scripting service for automated tests
                typeof(ScriptConsole),                  // provides a dockable command console for entering Python commands
                typeof(AtfScriptVariables),             // exposes common ATF services as script variables
                typeof(AutomationService)               // provides facilities to run an automated script using the .NET remoting service
            );

            return new AggregateCatalog(typeCatalog, StandardInteropParts.Catalog, StandardViewModels.Catalog);
        }
        public void WhenItemsInCollection_TryGetReturnsTrueAndCatalog()
        {
            // Prepare
            ModuleInfo moduleInfo1 = new ModuleInfo();
            ModuleInfo moduleInfo2 = new ModuleInfo();
            ModuleInfo moduleInfo3 = new ModuleInfo();

            ComposablePartCatalog catalog1 = new TypeCatalog();
            ComposablePartCatalog catalog2 = new TypeCatalog();
            ComposablePartCatalog catalog3 = new TypeCatalog();

            DownloadedPartCatalogCollection target = new DownloadedPartCatalogCollection();

            target.Add(moduleInfo1, catalog1);
            target.Add(moduleInfo2, catalog2);
            target.Add(moduleInfo3, catalog3);

            // Act
            bool actual = target.TryGet(moduleInfo3, out catalog3);    
        
            // Verify
            Assert.IsTrue(actual);
            Assert.AreSame(catalog3, target.Get(moduleInfo3));
            
        }
        public void Unity_registered_components_take_precedence_over_MEF_registered_components_if_querying_for_a_single_component_registered_in_both_containers()
        {
            // Setup
            var unityContainer = new UnityContainer();
            var typeCatalog = new TypeCatalog(typeof (Singleton));

            // Register catalog and types
            unityContainer.RegisterCatalog(typeCatalog);
            unityContainer.RegisterType<ISingleton, Singleton>(new ContainerControlledLifetimeManager());

            // Reset count
            Singleton.Count = 0;

            Assert.That(Singleton.Count, Is.EqualTo(0));
            var singleton = unityContainer.Resolve<ISingleton>();

            Assert.That(singleton, Is.Not.Null);
            Assert.That(Singleton.Count, Is.EqualTo(1));

            var mef = unityContainer.Resolve<CompositionContainer>();
            var mefSingleton = mef.GetExportedValue<ISingleton>();

            Assert.That(Singleton.Count, Is.EqualTo(1));
            Assert.That(singleton, Is.SameAs(mefSingleton));
        }
示例#8
0
 public void SetupSingleFactory()
 {
     var catalog = new TypeCatalog(typeof (PartA), typeof(PartThatUsesAFactory));
     var ep = new ExportFactoryProvider();
     _container = new CompositionContainer(catalog, ep);
     ep.SourceProvider = _container;
 }
示例#9
0
 public void SetupMultipleFactories()
 {
     var catalog = new TypeCatalog(typeof(PartA), typeof(PartB), typeof(PartThatUsesACollectionOfFactories));
     var ep = new ExportFactoryProvider();
     _container = new CompositionContainer(catalog, ep);
     ep.SourceProvider = _container;
 }
示例#10
0
        public void When_removing_a_part_from_the_intercepted_catalog_intercepting_catalog_is_recomposed_and_removes_that_part()
        {
            var innerCatalog1 = new TypeCatalog(typeof(RecomposablePart1), typeof(RecomposablePartImporter));
            var innerCatalog2 = new TypeCatalog(typeof(RecomposablePart2));
            var cfg = new InterceptionConfiguration().AddInterceptor(new RecomposablePartInterceptor());
            var aggregateCatalog = new AggregateCatalog(innerCatalog1, innerCatalog2);
            var catalog = new InterceptingCatalog(aggregateCatalog, cfg);
            container = new CompositionContainer(catalog);

            var importer = container.GetExportedValue<RecomposablePartImporter>();
            Assert.That(importer, Is.Not.Null);
            Assert.That(importer.Parts, Is.Not.Null);
            Assert.That(importer.Parts.Length, Is.EqualTo(2));
            Assert.That(importer.Parts[0].Count, Is.EqualTo(1));
            Assert.That(importer.Parts[1].Count, Is.EqualTo(1));
            Assert.That(catalog.Parts.Count(), Is.EqualTo(3));

            // Recompose
            aggregateCatalog.Catalogs.Remove(innerCatalog2);

            Assert.That(importer, Is.Not.Null);
            Assert.That(importer.Parts, Is.Not.Null);
            Assert.That(importer.Parts.Length, Is.EqualTo(1));
            Assert.That(importer.Parts[0].Count, Is.EqualTo(1));
            Assert.That(catalog.Parts.Count(), Is.EqualTo(2));
        }
        public override void Prepare()
        {
            var basic = this.CreateBasic();

            var propertyInjectionCatalog = new TypeCatalog(
                typeof(ComplexPropertyObject1),
                typeof(ComplexPropertyObject2),
                typeof(ComplexPropertyObject3),
                typeof(ServiceA),
                typeof(ServiceB),
                typeof(ServiceC),
                typeof(SubObjectA),
                typeof(SubObjectB),
                typeof(SubObjectC));

            var multipleCatalog = new TypeCatalog(
                typeof(SimpleAdapterOne),
                typeof(SimpleAdapterTwo),
                typeof(SimpleAdapterThree),
                typeof(SimpleAdapterFour),
                typeof(SimpleAdapterFive),
                typeof(ImportMultiple1),
                typeof(ImportMultiple2),
                typeof(ImportMultiple3));

            var openGenericCatalog = new TypeCatalog(typeof(ImportGeneric<>), typeof(GenericExport<>));

            this.container = new CompositionContainer(
                new AggregateCatalog(basic.Item1, basic.Item2, basic.Item3, propertyInjectionCatalog, multipleCatalog, openGenericCatalog), true);
        }
示例#12
0
文件: App.xaml.cs 项目: Joxx0r/ATF
        /// <summary>
        /// Gets MEF AggregateCatalog for application</summary>
        protected override AggregateCatalog GetCatalog()
        {
            // Because this app references both Atf.Gui.WinForms and Atf.Gui.Wpf, we need to explicitly call
            // this function to register resources. If only one or the other assembly were referenced, this
            // would be handled automatically by Atf.Gui.Resources, but since both are included it doesn't
            // know which one to choose.
            Sce.Atf.Wpf.Resources.Register();

            var typeCatalog = new TypeCatalog(
                typeof(SettingsService),                // persistent settings and user preferences dialog
                typeof(CommandService),                 // handles commands in menus and toolbars
                typeof(ControlHostService),             // docking control host
                typeof(AtfUsageLogger),                 // logs computer info to an ATF server
                typeof(CrashLogger),                    // logs unhandled exceptions to an ATF server
                typeof(UnhandledExceptionService),      // catches unhandled exceptions, displays info, and gives user a chance to save
                typeof(ContextRegistry),                // central context registry with change notification
                typeof(StandardFileExitCommand),        // standard File exit menu command
                typeof(FileDialogService),              // standard Windows file dialogs
                typeof(DocumentRegistry),               // central document registry with change notification
                typeof(StandardFileCommands),           // standard File menu commands for New, Open, Save, SaveAs, Close
                typeof(AutoDocumentService),            // opens documents from last session, or creates a new document, on startup
                typeof(RecentDocumentCommands),         // standard recent document commands in File menu
                typeof(MainWindowTitleService),         // tracks document changes and updates main form title
                typeof(WindowLayoutService),            // service to handle window layouts
                typeof(SchemaLoader),                   // loads schema and extends types
                typeof(MainWindow),                     // main app window (analog to 'MainForm' in WinFormsApp)
                typeof(Editor),                         // Sample editor class that creates and saves application documents
                typeof(PythonService),                  // scripting service for automated tests
                typeof(ScriptConsole),                  // provides a dockable command console for entering Python commands
                typeof(AtfScriptVariables),             // exposes common ATF services as script variables
                typeof(AutomationService)               // provides facilities to run an automated script using the .NET remoting service
            );

            return new AggregateCatalog(typeCatalog, StandardInteropParts.Catalog, StandardViewModels.Catalog);
        }
 public void DefaultLifetimeForMefComponentsIsSingleton()
 {
     var builder = new ContainerBuilder();
     var catalog = new TypeCatalog(typeof(HasDefaultCreationPolicy));
     builder.RegisterComposablePartCatalog(catalog);
     AssertDisposalTrackerIsSingleton(builder);
 }
示例#14
0
        public void ContainerDoesNotResolveIngredientToSauceBéarnaise()
        {
            var catalog = new TypeCatalog(typeof(Ploeh.Samples.Menu.Mef.Attributed.Unmodified.Concrete.SauceBéarnaise));
            var container = new CompositionContainer(catalog);

            Assert.Throws<ImportCardinalityMismatchException>(() =>
                container.GetExportedValue<Ploeh.Samples.MenuModel.IIngredient>());
        }
 private static IContainer RegisterTypeCatalogContaining(params Type[] types)
 {
     var builder = new ContainerBuilder();
     var catalog = new TypeCatalog(types);
     builder.RegisterComposablePartCatalog(catalog);
     var container = builder.Build();
     return container;
 }
示例#16
0
        public TypeHelperContext()
        {
            var catalog = new TypeCatalog(typeof(DummyPart));
            var part = catalog.Parts.First();
            DummyPartImports = part.ImportDefinitions;

            Context();
        }
示例#17
0
        public static EmbeddableDocumentStore GetDocumentStore(Type clientIndex)
        {
            var store = GetDocumentStore();
            var catalogue = new TypeCatalog(new[] { clientIndex });

            IndexCreation.CreateIndexes(new CompositionContainer(catalogue), store);
            return store;
        }
 public void MissingDependencyDetected()
 {
     var builder = new ContainerBuilder();
     var catalog = new TypeCatalog(typeof(HasMissingDependency));
     builder.RegisterComposablePartCatalog(catalog);
     var container = builder.Build();
     Assert.Throws<ComponentNotRegisteredException>(() => container.Resolve<HasMissingDependency>());
 }
 public void TestSetUp()
 {
     ConcreteTypeHandler = new ConcreteTypeExportHandler();
     var typeCatalog = new TypeCatalog(typeof(CustomerProcessor));
     var orderProcessorContract = AttributedModelServices.GetContractName(typeof(CustomerProcessor));
     var orderProcessPartDefinition = typeCatalog.Parts.Single(p => p.ExportDefinitions.Any(d => d.ContractName == orderProcessorContract));
     RepositoryImportDefinition = orderProcessPartDefinition.ImportDefinitions.First();
 }
 public void SatisfiesImportOnMefComponentFromMef()
 {
     var builder = new ContainerBuilder();
     var catalog = new TypeCatalog(typeof(MefDependency), typeof(ImportsMefDependency));
     builder.RegisterComposablePartCatalog(catalog);
     var container = builder.Build();
     var bar = container.Resolve<ImportsMefDependency>();
     Assert.IsNotNull(bar.Dependency);
 }
示例#21
0
        public void CanMakeAniseedRootObject()
        {
            TypeCatalog catalog = new TypeCatalog(typeof(AniseedSweetShop));
            CompositionContainer container = new CompositionContainer(catalog);

            SweetShop sweetShop = container.GetExport<SweetShop>().Value;

            Assert.AreEqual(Jellybean.Aniseed, sweetShop.DispenseJellyBean());
        }
示例#22
0
        public void CanMakeSweetShopWithVanillaJellybeans()
        {
            TypeCatalog catalog = new TypeCatalog(typeof(VanillaJellybeanDispenser), typeof(SweetVendingMachine), typeof(SweetShop));
            CompositionContainer container = new CompositionContainer(catalog);

            SweetShop sweetShop = container.GetExport<SweetShop>().Value;

            Assert.AreEqual(Jellybean.Vanilla, sweetShop.DispenseJellyBean());
        }
 public void RetrievesExportedInterfaceFromCatalogPart()
 {
     var builder = new ContainerBuilder();
     var catalog = new TypeCatalog(typeof(MefDependency));
     builder.RegisterComposablePartCatalog(catalog);
     var container = builder.Build();
     var foo = container.Resolve<IDependency>();
     Assert.IsAssignableFrom<MefDependency>(foo);
 }
示例#24
0
文件: Program.cs 项目: Joxx0r/ATF
        static void Main() 
        {
            // important to call these before creating application host
            Application.EnableVisualStyles();
            Application.DoEvents(); // see http://www.codeproject.com/buglist/EnableVisualStylesBug.asp?df=100&forumid=25268&exp=0&select=984714

            // Set up localization support early on, so that user-readable strings will be localized
            //  during the initialization phase below. Use XML files that are embedded resources.
            Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.CurrentCulture;
            Localizer.SetStringLocalizer(new EmbeddedResourceStringLocalizer());

            // Create a catalog with all the components that make up the application, except for
            //  our MainForm.
            var catalog = new TypeCatalog(
                typeof(SettingsService),                // persistent settings and user preferences dialog
                typeof(CommandService),                 // handles commands in menus and toolbars
                typeof(AtfUsageLogger),                 // logs computer info to an ATF server
                typeof(CrashLogger),                    // logs unhandled exceptions to an ATF server
                typeof(UnhandledExceptionService),      // catches unhandled exceptions, displays info, and gives user a chance to save
                typeof(StandardFileExitCommand),        // standard File exit menu command
                typeof(HelpAboutCommand),               // Help -> About command
                typeof(FolderViewer),                   // manages TreeControl to display folder hierarchy
                typeof(FileViewer),                     // managed ListView to display last selected folder contents

                typeof(NameDataExtension),              // extension to display file name
                typeof(SizeDataExtension),              // extension to display file size
                typeof(CreationTimeDataExtension),      // extension to display file creation time

                typeof(UserFeedbackService),            // component to send feedback form to SHIP
                typeof(VersionUpdateService),           // component to update to latest version on SHIP

                typeof(PythonService),                  // scripting service for automated tests
                typeof(ScriptConsole),                  // provides a dockable command console for entering Python commands
                typeof(AtfScriptVariables),             // exposes common ATF services as script variables
                typeof(AutomationService)               // provides facilities to run an automated script using the .NET remoting service
                );          

            var container = new CompositionContainer(catalog);

            // manually add the MainForm
            var batch = new CompositionBatch();
            var mainForm = new MainForm
            {
                Icon = GdiUtil.CreateIcon(ResourceUtil.GetImage(Sce.Atf.Resources.AtfIconImage))
            };
            // our custom main Form with SplitContainer
            batch.AddPart(mainForm);
            batch.AddPart(new WebHelpCommands("https://github.com/SonyWWS/ATF/wiki/ATF-File-Explorer-Sample".Localize()));
            container.Compose(batch);

            // initialize all components which require it
            container.InitializeAll();
            
            Application.Run(mainForm);

            container.Dispose();
        }
        public void When_querying_for_a_part_not_being_intercepted_it_should_return_original_part_definition()
        {
            var innerCatalog = new TypeCatalog(typeof(Logger));
            var cfg = new InterceptionConfiguration();
            var catalog = new InterceptingCatalog(innerCatalog, cfg);

            var partDefinition = catalog.Parts.First();
            partDefinition.ShouldNotBeOfType<InterceptingComposablePartDefinition>();
        }
示例#26
0
 public void ClassExportsITemplateEditorOptionsForConsumptionByEditorClasses()
 {
     using (var catalog = new TypeCatalog(typeof(T4ToolboxOptions)))
     using (var container = new CompositionContainer(catalog))
     {
         Lazy<ITemplateEditorOptions> export = container.GetExport<ITemplateEditorOptions>();
         Assert.IsInstanceOfType(export.Value, typeof(T4ToolboxOptions));
     }
 }
        public void Ctor_should_throw_argument_null_exception_if_called_with_null_interceptor()
        {
            var partDefinition = new TypeCatalog(typeof (Part1)).Parts.First();
            Assert.That(delegate
            {

                new InterceptingComposablePartDefinition(partDefinition, null);
            }, Throws.TypeOf<ArgumentNullException>());
        }
示例#28
0
        public void Constructor2_ArrayAsTypesArgument_ShouldNotAllowModificationAfterConstruction()
        {
            var types = new Type[] { PartFactory.GetAttributedExporterType() };
            var catalog = new TypeCatalog(types);

            types[0] = null;

            Assert.IsNotNull(catalog.Parts.First());
        }
示例#29
0
        public void ContainerResolvesIngredientToSauceBéarnaise()
        {
            var catalog = new TypeCatalog(typeof(Ploeh.Samples.Menu.Mef.Attributed.Unmodified.Abstract.SauceBéarnaise));
            var container = new CompositionContainer(catalog);

            IIngredient ingredient = container.GetExportedValue<IIngredient>();

            Assert.IsAssignableFrom<SauceBéarnaise>(ingredient);
        }
示例#30
0
        public void ContainerResolvesSauceBéarnaise()
        {
            var catalog = new TypeCatalog(typeof(Ploeh.Samples.Menu.Mef.Attributed.Unmodified.Concrete.SauceBéarnaise));
            var container = new CompositionContainer(catalog);
            SauceBéarnaise sauce =
                container.GetExportedValue<SauceBéarnaise>();

            Assert.NotNull(sauce);
        }
示例#31
0
        public void DisposeAggregatingCatalog()
        {
            int changedNotification = 0;

            var typePartCatalog1 = new TypeCatalog(typeof(SharedPartStuff));
            var typePartCatalog2 = new TypeCatalog(typeof(SharedPartStuff));
            var typePartCatalog3 = new TypeCatalog(typeof(SharedPartStuff));

            var assemblyPartCatalog1 = new AssemblyCatalog(typeof(SharedPartStuff).Assembly);
            var assemblyPartCatalog2 = new AssemblyCatalog(typeof(SharedPartStuff).Assembly);
            var assemblyPartCatalog3 = new AssemblyCatalog(typeof(SharedPartStuff).Assembly);

#if FEATURE_REFLECTIONFILEIO
            var dirPartCatalog1 = new DirectoryCatalog(FileIO.GetRootTemporaryDirectory());
            var dirPartCatalog2 = new DirectoryCatalog(FileIO.GetRootTemporaryDirectory());
            var dirPartCatalog3 = new DirectoryCatalog(FileIO.GetRootTemporaryDirectory());
#endif //FEATURE_REFLECTIONFILEIO
            using (var catalog = new AggregateCatalog())
            {
                catalog.Catalogs.Add(typePartCatalog1);
                catalog.Catalogs.Add(typePartCatalog2);
                catalog.Catalogs.Add(typePartCatalog3);

                catalog.Catalogs.Add(assemblyPartCatalog1);
                catalog.Catalogs.Add(assemblyPartCatalog2);
                catalog.Catalogs.Add(assemblyPartCatalog3);

#if FEATURE_REFLECTIONFILEIO
                catalog.Catalogs.Add(dirPartCatalog1);
                catalog.Catalogs.Add(dirPartCatalog2);
                catalog.Catalogs.Add(dirPartCatalog3);
#endif //FEATURE_REFLECTIONFILEIO

                // Add notifications
                catalog.Changed += delegate(object source, ComposablePartCatalogChangeEventArgs args)
                {
                    // Local code
                    ++changedNotification;
                };
            }

            Assert.IsTrue(changedNotification == 0, "No changed notifications");

            //Ensure that the other catalogs are
            ExceptionAssert.ThrowsDisposed(typePartCatalog1, () =>
            {
                var iEnum = typePartCatalog1.Parts.GetEnumerator();
            });

            ExceptionAssert.ThrowsDisposed(typePartCatalog2, () =>
            {
                var iEnum = typePartCatalog2.Parts.GetEnumerator();
            });

            ExceptionAssert.ThrowsDisposed(typePartCatalog3, () =>
            {
                var iEnum = typePartCatalog3.Parts.GetEnumerator();
            });

            //Ensure that the other catalogs are
            ExceptionAssert.ThrowsDisposed(assemblyPartCatalog1, () =>
            {
                var iEnum = assemblyPartCatalog1.Parts.GetEnumerator();
            });

            ExceptionAssert.ThrowsDisposed(assemblyPartCatalog2, () =>
            {
                var iEnum = assemblyPartCatalog2.Parts.GetEnumerator();
            });

            ExceptionAssert.ThrowsDisposed(assemblyPartCatalog3, () =>
            {
                var iEnum = assemblyPartCatalog3.Parts.GetEnumerator();
            });

#if FEATURE_REFLECTIONFILEIO
            //Ensure that the other catalogs are
            ExceptionAssert.ThrowsDisposed(dirPartCatalog1, () =>
            {
                var iEnum = dirPartCatalog1.Parts.GetEnumerator();
            });

            ExceptionAssert.ThrowsDisposed(dirPartCatalog2, () =>
            {
                var iEnum = dirPartCatalog2.Parts.GetEnumerator();
            });

            ExceptionAssert.ThrowsDisposed(dirPartCatalog3, () =>
            {
                var iEnum = dirPartCatalog3.Parts.GetEnumerator();
            });
#endif //FEATURE_REFLECTIONFILEIO
        }
示例#32
0
 public CachedTypeCatalog(params Type[] types)
 {
     this._typeCatalog = new TypeCatalog(types);
 }
示例#33
0
 public CachedTypeCatalog(IEnumerable <Type> types)
 {
     this._typeCatalog = new TypeCatalog(types);
 }
示例#34
0
        public void MutableCatalogNotifications()
        {
            int step        = 0;
            int changedStep = 0;
            var catalog     = new AggregateCatalog();

            var typePartCatalog  = new TypeCatalog(typeof(SharedPartStuff));
            var typePartCatalog1 = new TypeCatalog(typeof(SharedPartStuff));
            var typePartCatalog2 = new TypeCatalog(typeof(SharedPartStuff));
            var typePartCatalog3 = new TypeCatalog(typeof(SharedPartStuff));
            var typePartCatalog4 = new TypeCatalog(typeof(SharedPartStuff));
            var typePartCatalog5 = new TypeCatalog(typeof(SharedPartStuff));

            // Smoke test on inner collection
            catalog.Catalogs.Add(typePartCatalog);
            catalog.Catalogs.Remove(typePartCatalog);
            catalog.Catalogs.Clear();
            Assert.True(catalog.Catalogs.Count == 0);

            // Add notifications
            catalog.Changed += delegate(object source, ComposablePartCatalogChangeEventArgs args)
            {
                // Local code
                ++step;
                ++step;
                changedStep = step;
            };

            //Add something then verify counters
            catalog.Catalogs.Add(typePartCatalog);
            Assert.True(catalog.Catalogs.Count == 1);
            Assert.True(changedStep == 2);

            // Reset counters
            step = changedStep = 0;

            // Remove something then verify counters
            catalog.Catalogs.Remove(typePartCatalog);
            Assert.True(catalog.Catalogs.Count == 0);
            Assert.True(changedStep == 2);

            //Now Add it back
            catalog.Catalogs.Add(typePartCatalog);
            Assert.True(catalog.Catalogs.Count == 1);

            step = changedStep = 0;
            // Now clear the collection and verify counters
            catalog.Catalogs.Clear();
            Assert.True(catalog.Catalogs.Count == 0);
            Assert.True(changedStep == 2);

            // Now remove a non existent item and verify counters
            step = changedStep = 0;
            bool removed = catalog.Catalogs.Remove(typePartCatalog);

            Assert.True(removed == false);
            Assert.True(changedStep == 0);

            // Add a bunch
            step = changedStep = 0;
            catalog.Catalogs.Add(typePartCatalog);
            Assert.True(catalog.Catalogs.Count == 1);
            Assert.True(changedStep == 2);

            catalog.Catalogs.Add(typePartCatalog1);
            Assert.True(catalog.Catalogs.Count == 2);
            Assert.True(changedStep == 4);

            catalog.Catalogs.Add(typePartCatalog2);
            catalog.Catalogs.Add(typePartCatalog3);
            catalog.Catalogs.Add(typePartCatalog4);
            catalog.Catalogs.Add(typePartCatalog5);
            Assert.True(catalog.Catalogs.Count == 6);
            Assert.True(changedStep == 12);

            removed = catalog.Catalogs.Remove(typePartCatalog3);
            Assert.True(catalog.Catalogs.Count == 5);
            Assert.True(removed == true);
            Assert.True(changedStep == 14);
            removed = catalog.Catalogs.Remove(typePartCatalog2);
            removed = catalog.Catalogs.Remove(typePartCatalog1);
            removed = catalog.Catalogs.Remove(typePartCatalog4);
            removed = catalog.Catalogs.Remove(typePartCatalog);
            removed = catalog.Catalogs.Remove(typePartCatalog5);
            Assert.True(catalog.Catalogs.Count == 0);
            Assert.True(removed == true);
            Assert.True(changedStep == 24);

            // Add and then clear a lot
            step = changedStep = 0;
            catalog.Catalogs.Add(typePartCatalog);
            catalog.Catalogs.Add(typePartCatalog1);
            catalog.Catalogs.Add(typePartCatalog2);
            catalog.Catalogs.Add(typePartCatalog3);
            catalog.Catalogs.Add(typePartCatalog4);
            catalog.Catalogs.Add(typePartCatalog5);
            Assert.True(catalog.Catalogs.Count == 6);
            Assert.True(changedStep == 12);

            catalog.Catalogs.Clear();
            Assert.True(catalog.Catalogs.Count == 0);

            step = changedStep = 0;
            int step2        = 100;
            int changedStep2 = 0;

            catalog.Changed += delegate(object source, ComposablePartCatalogChangeEventArgs args)
            {
                // Local code
                --step2;
                --step2;
                changedStep2 = step2;
            };

            catalog.Catalogs.Add(typePartCatalog);
            Assert.True(catalog.Catalogs.Count == 1);
            Assert.True(changedStep == 2);
            Assert.True(changedStep2 == 98);

            catalog.Catalogs.Add(typePartCatalog1);
            Assert.True(catalog.Catalogs.Count == 2);
            Assert.True(changedStep == 4);
            Assert.True(changedStep2 == 96);

            catalog.Catalogs.Remove(typePartCatalog);
            Assert.True(catalog.Catalogs.Count == 1);
            Assert.True(changedStep == 6);
            Assert.True(changedStep2 == 94);

            catalog.Catalogs.Clear();
            Assert.True(catalog.Catalogs.Count == 0);
            Assert.True(changedStep == 8);
            Assert.True(changedStep2 == 92);
        }
示例#35
0
        public void DisposeAggregatingCatalog()
        {
            int changedNotification = 0;

            var typePartCatalog1 = new TypeCatalog(typeof(SharedPartStuff));
            var typePartCatalog2 = new TypeCatalog(typeof(SharedPartStuff));
            var typePartCatalog3 = new TypeCatalog(typeof(SharedPartStuff));

            var assemblyPartCatalog1 = new AssemblyCatalog(typeof(SharedPartStuff).Assembly);
            var assemblyPartCatalog2 = new AssemblyCatalog(typeof(SharedPartStuff).Assembly);
            var assemblyPartCatalog3 = new AssemblyCatalog(typeof(SharedPartStuff).Assembly);

            var dirPartCatalog1 = new DirectoryCatalog(Path.GetTempPath());
            var dirPartCatalog2 = new DirectoryCatalog(Path.GetTempPath());
            var dirPartCatalog3 = new DirectoryCatalog(Path.GetTempPath());

            using (var catalog = new AggregateCatalog())
            {
                catalog.Catalogs.Add(typePartCatalog1);
                catalog.Catalogs.Add(typePartCatalog2);
                catalog.Catalogs.Add(typePartCatalog3);

                catalog.Catalogs.Add(assemblyPartCatalog1);
                catalog.Catalogs.Add(assemblyPartCatalog2);
                catalog.Catalogs.Add(assemblyPartCatalog3);

                catalog.Catalogs.Add(dirPartCatalog1);
                catalog.Catalogs.Add(dirPartCatalog2);
                catalog.Catalogs.Add(dirPartCatalog3);

                // Add notifications
                catalog.Changed += delegate(object source, ComposablePartCatalogChangeEventArgs args)
                {
                    // Local code
                    ++changedNotification;
                };
            }

            Assert.True(changedNotification == 0);

            //Ensure that the other catalogs are
            ExceptionAssert.ThrowsDisposed(typePartCatalog1, () =>
            {
                var iEnum = typePartCatalog1.Parts.GetEnumerator();
            });

            ExceptionAssert.ThrowsDisposed(typePartCatalog2, () =>
            {
                var iEnum = typePartCatalog2.Parts.GetEnumerator();
            });

            ExceptionAssert.ThrowsDisposed(typePartCatalog3, () =>
            {
                var iEnum = typePartCatalog3.Parts.GetEnumerator();
            });

            //Ensure that the other catalogs are
            ExceptionAssert.ThrowsDisposed(assemblyPartCatalog1, () =>
            {
                var iEnum = assemblyPartCatalog1.Parts.GetEnumerator();
            });

            ExceptionAssert.ThrowsDisposed(assemblyPartCatalog2, () =>
            {
                var iEnum = assemblyPartCatalog2.Parts.GetEnumerator();
            });

            ExceptionAssert.ThrowsDisposed(assemblyPartCatalog3, () =>
            {
                var iEnum = assemblyPartCatalog3.Parts.GetEnumerator();
            });

            //Ensure that the other catalogs are
            ExceptionAssert.ThrowsDisposed(dirPartCatalog1, () =>
            {
                var iEnum = dirPartCatalog1.Parts.GetEnumerator();
            });

            ExceptionAssert.ThrowsDisposed(dirPartCatalog2, () =>
            {
                var iEnum = dirPartCatalog2.Parts.GetEnumerator();
            });

            ExceptionAssert.ThrowsDisposed(dirPartCatalog3, () =>
            {
                var iEnum = dirPartCatalog3.Parts.GetEnumerator();
            });
        }
示例#36
0
        public void MutableMultithreadedEnumerations()
        {
            var catalog = new AggregateCatalog();

            ThreadStart func = delegate()
            {
                var typePart  = new TypeCatalog(typeof(SharedPartStuff));
                var typePart1 = new TypeCatalog(typeof(SharedPartStuff));
                var typePart2 = new TypeCatalog(typeof(SharedPartStuff));
                var typePart3 = new TypeCatalog(typeof(SharedPartStuff));
                var typePart4 = new TypeCatalog(typeof(SharedPartStuff));
                var typePart5 = new TypeCatalog(typeof(SharedPartStuff));

                for (int i = 0; i < 100; i++)
                {
                    catalog.Catalogs.Add(typePart);
                    catalog.Catalogs.Add(typePart1);
                    catalog.Catalogs.Add(typePart2);
                    catalog.Catalogs.Add(typePart3);
                    catalog.Catalogs.Add(typePart4);
                    catalog.Catalogs.Add(typePart5);

                    Assert.True(catalog.Catalogs.Count >= 6);

                    for (int k = 0; k < 5; k++)
                    {
                        int j;
                        // Ensure that iterating the returned queryable is okay even though there are many threads mutationg it
                        // We are really just looking to ensure that ollection changed exceptions are not thrown
                        j = 0;
                        var iq = catalog.Parts.GetEnumerator();
                        while (iq.MoveNext())
                        {
                            ++j;
                        }

                        Assert.True(j >= 6);

                        // Ensure that iterating the returned enumerator is okay even though there are many threads mutationg it
                        // We are really just looking to ensure that collection changed exceptions are not thrown
                        j = 0;
                        var ie = catalog.Catalogs.GetEnumerator();
                        while (ie.MoveNext())
                        {
                            ++j;
                        }
                        Assert.True(j >= 6);
                    }

                    catalog.Catalogs.Remove(typePart);
                    catalog.Catalogs.Remove(typePart1);
                    catalog.Catalogs.Remove(typePart2);
                    catalog.Catalogs.Remove(typePart3);
                    catalog.Catalogs.Remove(typePart4);
                    catalog.Catalogs.Remove(typePart5);
                }
            };

            Thread[] threads = new Thread[100];
            for (int i = 0; i < threads.Length; i++)
            {
                threads[i] = new Thread(func);
            }

            for (int i = 0; i < threads.Length; i++)
            {
                threads[i].Start();
            }
            for (int i = 0; i < threads.Length; i++)
            {
                threads[i].Join();
            }

            Assert.True(catalog.Catalogs.Count == 0);
        }
示例#37
0
        public void MutableCatalogNotifications()
        {
            int step        = 0;
            int changedStep = 0;
            var catalog     = new AggregateCatalog();

            var typePartCatalog  = new TypeCatalog(typeof(SharedPartStuff));
            var typePartCatalog1 = new TypeCatalog(typeof(SharedPartStuff));
            var typePartCatalog2 = new TypeCatalog(typeof(SharedPartStuff));
            var typePartCatalog3 = new TypeCatalog(typeof(SharedPartStuff));
            var typePartCatalog4 = new TypeCatalog(typeof(SharedPartStuff));
            var typePartCatalog5 = new TypeCatalog(typeof(SharedPartStuff));

            // Smoke test on inner collection
            catalog.Catalogs.Add(typePartCatalog);
            catalog.Catalogs.Remove(typePartCatalog);
            catalog.Catalogs.Clear();
            Assert.IsTrue(catalog.Catalogs.Count == 0, "Add/Remove/Clear -- PartsAsCollection.Count is now 0");

            // Add notifications
            catalog.Changed += delegate(object source, ComposablePartCatalogChangeEventArgs args)
            {
                // Local code
                ++step; ++step;
                changedStep = step;
            };

            //Add something then verify counters
            catalog.Catalogs.Add(typePartCatalog);
            Assert.IsTrue(catalog.Catalogs.Count == 1, "Add -- Catalogs.Count is now 1");
            Assert.IsTrue(changedStep == 2, "Add -- Changed must be fired after");

            // Reset counters
            step = changedStep = 0;

            // Remove something then verify counters
            catalog.Catalogs.Remove(typePartCatalog);
            Assert.IsTrue(catalog.Catalogs.Count == 0, "Add -- Catalogs.Count is now 0");
            Assert.IsTrue(changedStep == 2, "Remove -- Changed must be fired after");


            //Now Add it back
            catalog.Catalogs.Add(typePartCatalog);
            Assert.IsTrue(catalog.Catalogs.Count == 1, "Add -- Catalogs.Count is now 1");

            step = changedStep = 0;
            // Now clear the collection and verify counters
            catalog.Catalogs.Clear();
            Assert.IsTrue(catalog.Catalogs.Count == 0, "Add -- Catalogs.Count is now 0");
            Assert.IsTrue(changedStep == 2, "Remove -- Changed must be fired after");

            // Now remove a non existent item and verify counters
            step = changedStep = 0;
            bool removed = catalog.Catalogs.Remove(typePartCatalog);

            Assert.IsTrue(removed == false, "Remove -- correctly returned false");
            Assert.IsTrue(changedStep == 0, "Remove -- Changed should not fire if nothing changed");

            // Add a bunch
            step = changedStep = 0;
            catalog.Catalogs.Add(typePartCatalog);
            Assert.IsTrue(catalog.Catalogs.Count == 1, "Add -- Catalogs.Count is now 1");
            Assert.IsTrue(changedStep == 2, "Add -- Changed must be fired after");

            catalog.Catalogs.Add(typePartCatalog1);
            Assert.IsTrue(catalog.Catalogs.Count == 2, "Add -- Catalogs.Count is now 1");
            Assert.IsTrue(changedStep == 4, "Add -- Changing must be fired after");

            catalog.Catalogs.Add(typePartCatalog2);
            catalog.Catalogs.Add(typePartCatalog3);
            catalog.Catalogs.Add(typePartCatalog4);
            catalog.Catalogs.Add(typePartCatalog5);
            Assert.IsTrue(catalog.Catalogs.Count == 6, "Add -- Catalogs.Count is now 1");
            Assert.IsTrue(changedStep == 12, "Add -- Changing must be fired after");

            removed = catalog.Catalogs.Remove(typePartCatalog3);
            Assert.IsTrue(catalog.Catalogs.Count == 5, "Add -- Catalogs.Count is now 5");
            Assert.IsTrue(removed == true, "Remove should have succeeded");
            Assert.IsTrue(changedStep == 14, "Remove -- Changed must be fired after");
            removed = catalog.Catalogs.Remove(typePartCatalog2);
            removed = catalog.Catalogs.Remove(typePartCatalog1);
            removed = catalog.Catalogs.Remove(typePartCatalog4);
            removed = catalog.Catalogs.Remove(typePartCatalog);
            removed = catalog.Catalogs.Remove(typePartCatalog5);
            Assert.IsTrue(catalog.Catalogs.Count == 0, "Add -- Catalogs.Count is now 0");
            Assert.IsTrue(removed == true, "Remove should have succeeded");
            Assert.IsTrue(changedStep == 24, "Remove -- Changing must be fired after");

            // Add and then clear a lot
            step = changedStep = 0;
            catalog.Catalogs.Add(typePartCatalog);
            catalog.Catalogs.Add(typePartCatalog1);
            catalog.Catalogs.Add(typePartCatalog2);
            catalog.Catalogs.Add(typePartCatalog3);
            catalog.Catalogs.Add(typePartCatalog4);
            catalog.Catalogs.Add(typePartCatalog5);
            Assert.IsTrue(catalog.Catalogs.Count == 6, "Add -- Catalogs.Count should be 6");
            Assert.IsTrue(changedStep == 12, "Add -- Changing must be fired after");

            catalog.Catalogs.Clear();
            Assert.IsTrue(catalog.Catalogs.Count == 0, "Add -- Catalogs.Count should be 0");

            step = changedStep = 0;
            int step2        = 100;
            int changedStep2 = 0;

            catalog.Changed += delegate(object source, ComposablePartCatalogChangeEventArgs args)
            {
                // Local code
                --step2; --step2;
                changedStep2 = step2;
            };

            catalog.Catalogs.Add(typePartCatalog);
            Assert.IsTrue(catalog.Catalogs.Count == 1, "Add -- Catalogs.Count is now 1");
            Assert.IsTrue(changedStep == 2, "Add handler 1 -- Changed must be fired after");
            Assert.IsTrue(changedStep2 == 98, "Add handler 2 -- Changed must be fired after");

            catalog.Catalogs.Add(typePartCatalog1);
            Assert.IsTrue(catalog.Catalogs.Count == 2, "Add -- Catalogs.Count is now 1");
            Assert.IsTrue(changedStep == 4, "Add handler 1 -- Changed must be fired after");
            Assert.IsTrue(changedStep2 == 96, "Add handler 2 -- Changed must be firedafter");

            catalog.Catalogs.Remove(typePartCatalog);
            Assert.IsTrue(catalog.Catalogs.Count == 1, "Add -- PartsAsCollection.Count is now 1");
            Assert.IsTrue(changedStep == 6, "Add handler 1 -- Changed must be fired and fired after");
            Assert.IsTrue(changedStep2 == 94, "Add handler 2 -- Changed must be fired and fired after");

            catalog.Catalogs.Clear();
            Assert.IsTrue(catalog.Catalogs.Count == 0, "Add -- PartsAsCollection.Count is now 0");
            Assert.IsTrue(changedStep == 8, "Add handler 1 -- Changed must be fired after");
            Assert.IsTrue(changedStep2 == 92, "Add handler 2 -- Changed must be fired after");
        }