当前位置: 首页>>代码示例>>C#>>正文


C# CompositionBatch.AddParts方法代码示例

本文整理汇总了C#中System.ComponentModel.Composition.Hosting.CompositionBatch.AddParts方法的典型用法代码示例。如果您正苦于以下问题:C# CompositionBatch.AddParts方法的具体用法?C# CompositionBatch.AddParts怎么用?C# CompositionBatch.AddParts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ComponentModel.Composition.Hosting.CompositionBatch的用法示例。


在下文中一共展示了CompositionBatch.AddParts方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ImportCompletedTest

        public void ImportCompletedTest()
        {
            var container = ContainerFactory.Create(); 
            CompositionBatch batch = new CompositionBatch();
            var entrypoint = new UpperCaseStringComponent();

            batch.AddParts(new LowerCaseString("abc"), entrypoint);
            container.Compose(batch);

            batch = new CompositionBatch();
            batch.AddParts(new object());
            container.Compose(batch);

            Assert.AreEqual(entrypoint.LowerCaseStrings.Count, 1);
            Assert.AreEqual(entrypoint.ImportCompletedCallCount, 1);
            Assert.AreEqual(entrypoint.UpperCaseStrings.Count, 1);
            Assert.AreEqual(entrypoint.LowerCaseStrings[0].Value.String, "abc");
            Assert.AreEqual(entrypoint.UpperCaseStrings[0], "ABC");
        }
开发者ID:nlhepler,项目名称:mono,代码行数:19,代码来源:INotifyImportTests.cs

示例2: ImportCompletedWithRecomposing

        public void ImportCompletedWithRecomposing()
        {
            var container = ContainerFactory.Create(); 
            CompositionBatch batch = new CompositionBatch();
            var entrypoint = new UpperCaseStringComponent();

            batch.AddParts(new LowerCaseString("abc"), entrypoint);
            container.Compose(batch);

            Assert.AreEqual(entrypoint.LowerCaseStrings.Count, 1);
            Assert.AreEqual(entrypoint.ImportCompletedCallCount, 1);
            Assert.AreEqual(entrypoint.UpperCaseStrings.Count, 1);
            Assert.AreEqual(entrypoint.LowerCaseStrings[0].Value.String, "abc");
            Assert.AreEqual(entrypoint.UpperCaseStrings[0], "ABC");

            // Add another component to verify recomposing
            batch = new CompositionBatch();
            batch.AddParts(new LowerCaseString("def"));
            container.Compose(batch);

            Assert.AreEqual(entrypoint.LowerCaseStrings.Count, 2);
            Assert.AreEqual(entrypoint.ImportCompletedCallCount, 2);
            Assert.AreEqual(entrypoint.UpperCaseStrings.Count, 2);
            Assert.AreEqual(entrypoint.LowerCaseStrings[1].Value.String, "def");
            Assert.AreEqual(entrypoint.UpperCaseStrings[1], "DEF");

            // Verify that adding a random component doesn't cause
            // the OnImportsSatisfied to be called again.
            batch = new CompositionBatch();
            batch.AddParts(new object());
            container.Compose(batch);

            Assert.AreEqual(entrypoint.LowerCaseStrings.Count, 2);
            Assert.AreEqual(entrypoint.ImportCompletedCallCount, 2);
            Assert.AreEqual(entrypoint.UpperCaseStrings.Count, 2);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:36,代码来源:INotifyImportTests.cs

示例3: ImportCompletedBindChildIndirectlyThroughParentContainerBind

        public void ImportCompletedBindChildIndirectlyThroughParentContainerBind()
        {
            var cat = CatalogFactory.CreateDefaultAttributed();
            var parent = new CompositionContainer(cat);

            CompositionBatch parentBatch = new CompositionBatch();
            CompositionBatch childBatch = new CompositionBatch();

            parentBatch.AddExportedValue<ICompositionService>(parent);
            parent.Compose(parentBatch);
            var child = new CompositionContainer(parent);

            var parentImporter = new MyNotifyImportImporter(parent);
            var childImporter = new MyNotifyImportImporter(child);

            parentBatch = new CompositionBatch();
            parentBatch.AddPart(parentImporter);
            childBatch.AddParts(childImporter, new MyNotifyImportExporter());

            parent.Compose(parentBatch);
            child.Compose(childBatch);

            Assert.AreEqual(1, parentImporter.ImportCompletedCallCount);
            Assert.AreEqual(1, childImporter.ImportCompletedCallCount);

            MyNotifyImportExporter parentExporter = parent.GetExportedValue<MyNotifyImportExporter>("MyNotifyImportExporter");
            Assert.AreEqual(1, parentExporter.ImportCompletedCallCount);

            MyNotifyImportExporter childExporter = child.GetExportedValue<MyNotifyImportExporter>("MyNotifyImportExporter");
            Assert.AreEqual(1, childExporter.ImportCompletedCallCount);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:31,代码来源:INotifyImportTests.cs

示例4: ImportCompletedChildDoesnotNeedParentContainer

        public void ImportCompletedChildDoesnotNeedParentContainer()
        {
            var cat = CatalogFactory.CreateDefaultAttributed();
            var parent = new CompositionContainer(cat);

            CompositionBatch parentBatch = new CompositionBatch();
            CompositionBatch childBatch = new CompositionBatch();

            parentBatch.AddExportedValue<ICompositionService>(parent);
            parent.Compose(parentBatch);

            var child = new CompositionContainer(parent);

            var parentImporter = new MyNotifyImportImporter(parent);
            var childImporter = new MyNotifyImportImporter(child);

            parentBatch = new CompositionBatch();
            parentBatch.AddPart(parentImporter);

            childBatch.AddParts(childImporter, new MyNotifyImportExporter());

            child.Compose(childBatch);

            Assert.AreEqual(0, parentImporter.ImportCompletedCallCount);
            Assert.AreEqual(1, childImporter.ImportCompletedCallCount);

            // Parent will become bound at this point.
            MyNotifyImportExporter parentExporter = parent.GetExportedValue<MyNotifyImportExporter>("MyNotifyImportExporter");
            parent.Compose(parentBatch);
            Assert.AreEqual(1, parentImporter.ImportCompletedCallCount);
            Assert.AreEqual(1, parentExporter.ImportCompletedCallCount);

            MyNotifyImportExporter childExporter = child.GetExportedValue<MyNotifyImportExporter>("MyNotifyImportExporter");
            Assert.AreEqual(1, childExporter.ImportCompletedCallCount);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:35,代码来源:INotifyImportTests.cs

示例5: ImportCompletedAddPartAndBindComponent

        public void ImportCompletedAddPartAndBindComponent()
        {
            var container = ContainerFactory.Create();
            CompositionBatch batch = new CompositionBatch();
            batch.AddParts(new CallbackImportNotify(delegate
            {
                batch = new CompositionBatch();
                batch.AddPart(new object());
                container.Compose(batch);
            }));

            container.Compose(batch);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:13,代码来源:INotifyImportTests.cs

示例6: ImportCompletedCalledAfterAllImportsAreFullyComposed

        public void ImportCompletedCalledAfterAllImportsAreFullyComposed()
        {
            int importSatisfationCount = 0;
            var importer1 = new MyEventDrivenFullComposedNotifyImporter1();
            var importer2 = new MyEventDrivenFullComposedNotifyImporter2();

            Action<object, EventArgs> verificationAction = (object sender, EventArgs e) =>
            {
                Assert.IsTrue(importer1.AreAllImportsFullyComposed);
                Assert.IsTrue(importer2.AreAllImportsFullyComposed);
                ++importSatisfationCount;
            };

            importer1.ImportsSatisfied += new EventHandler(verificationAction);
            importer2.ImportsSatisfied += new EventHandler(verificationAction);

            // importer1 added first
            var batch = new CompositionBatch();
            batch.AddParts(importer1, importer2);

            var container = ContainerFactory.Create();
            container.ComposeExportedValue<ICompositionService>(container);
            container.Compose(batch);
            Assert.AreEqual(2, importSatisfationCount);

            // importer2 added first
            importSatisfationCount = 0;
            batch = new CompositionBatch();
            batch.AddParts(importer2, importer1);

            container = ContainerFactory.Create();
            container.ComposeExportedValue<ICompositionService>(container);
            container.Compose(batch);
            Assert.AreEqual(2, importSatisfationCount);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:35,代码来源:INotifyImportTests.cs

示例7: ImportCompletedUsingSatisfyImportsOnce

        public void ImportCompletedUsingSatisfyImportsOnce()
        {
            var container = ContainerFactory.Create();
            CompositionBatch batch = new CompositionBatch();
            var entrypoint = new UpperCaseStringComponent();
            var entrypointPart = AttributedModelServices.CreatePart(entrypoint);

            batch.AddParts(new LowerCaseString("abc"));
            container.Compose(batch);
            container.SatisfyImportsOnce(entrypointPart);
            
            Assert.AreEqual(1, entrypoint.LowerCaseStrings.Count);
            Assert.AreEqual(1, entrypoint.ImportCompletedCallCount);
            Assert.AreEqual(1, entrypoint.UpperCaseStrings.Count);
            Assert.AreEqual("abc", entrypoint.LowerCaseStrings[0].Value.String);
            Assert.AreEqual("ABC", entrypoint.UpperCaseStrings[0]);

            batch = new CompositionBatch();
            batch.AddParts(new object());
            container.Compose(batch);
            container.SatisfyImportsOnce(entrypointPart);

            Assert.AreEqual(1, entrypoint.LowerCaseStrings.Count);
            Assert.AreEqual(1, entrypoint.ImportCompletedCallCount);
            Assert.AreEqual(1, entrypoint.UpperCaseStrings.Count);
            Assert.AreEqual("abc", entrypoint.LowerCaseStrings[0].Value.String);
            Assert.AreEqual("ABC", entrypoint.UpperCaseStrings[0]);
            
            batch.AddParts(new LowerCaseString("def"));
            container.Compose(batch);
            container.SatisfyImportsOnce(entrypointPart);
            
            Assert.AreEqual(2, entrypoint.LowerCaseStrings.Count);
            Assert.AreEqual(2, entrypoint.ImportCompletedCallCount);
            Assert.AreEqual(2, entrypoint.UpperCaseStrings.Count);
            Assert.AreEqual("abc", entrypoint.LowerCaseStrings[0].Value.String);
            Assert.AreEqual("ABC", entrypoint.UpperCaseStrings[0]);
            Assert.AreEqual("def", entrypoint.LowerCaseStrings[1].Value.String);
            Assert.AreEqual("DEF", entrypoint.UpperCaseStrings[1]);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:40,代码来源:INotifyImportTests.cs

示例8: ThreadSafeCompositionContainer

        public void ThreadSafeCompositionContainer()
        {
            TypeCatalog catalog = new TypeCatalog(typeof(SimpleExporter));

            CompositionContainer container = new CompositionContainer(catalog, true);
            Int32Importer importer = new Int32Importer();

            CompositionBatch batch = new CompositionBatch();
            batch.AddParts(importer, new Int32Exporter(42));
            container.Compose(batch);

            Assert.IsNotNull(container.GetExportedValue<SimpleExporter>());
            Assert.AreEqual(42, importer.Value, "Expected value imported from export");

            container.Dispose();

        }
开发者ID:nlhepler,项目名称:mono,代码行数:17,代码来源:CompositionContainerTests.cs

示例9: ImportCollectionsFromContainerOnly

        public void ImportCollectionsFromContainerOnly()
        {
            var container = ContainerFactory.Create();
            Importer importer = new Importer();

            CompositionBatch batch = new CompositionBatch();
            batch.AddParts(importer
                , new ExporterDefault21()
                , new ExporterDefault21(22)
                , new ExporterDefault42()
                , new ExporterDefault42(43));

            container.Compose(batch);

            importer.VerifyImport(21, 22, 42, 43);
        }
开发者ID:JackFong,项目名称:FreeRadical,代码行数:16,代码来源:ExportCollectionTests.cs

示例10: ExceptionDuringNotify

        public void ExceptionDuringNotify()
        {
            var container = CreateCompositionContainer();
            CompositionBatch batch = new CompositionBatch();
            batch.AddParts(new CallbackImportNotify(delegate
            {
                throw new InvalidOperationException();
            }));

            CompositionAssert.ThrowsError(ErrorId.ImportEngine_PartCannotActivate,              // Cannot activate CallbackImportNotify because
                                          ErrorId.ReflectionModel_PartOnImportsSatisfiedThrewException, // OnImportsSatisfied threw an exception
                                          RetryMode.DoNotRetry, () =>
            {
                container.Compose(batch);
            });
        }
开发者ID:nlhepler,项目名称:mono,代码行数:16,代码来源:CompositionContainerTests.cs

示例11: ComposeSimple

        public void ComposeSimple()
        {
            var container = CreateCompositionContainer();
            Int32Importer importer = new Int32Importer();

            CompositionBatch batch = new CompositionBatch();
            batch.AddParts(importer, new Int32Exporter(42));
            container.Compose(batch);

            Assert.AreEqual(42, importer.Value, "Expected value imported from export");
        }
开发者ID:nlhepler,项目名称:mono,代码行数:11,代码来源:CompositionContainerTests.cs

示例12: ComposeReentrantChildContainerDisposed

        public void ComposeReentrantChildContainerDisposed()
        {
            var container = CreateCompositionContainer();
            Int32Importer outerImporter = new Int32Importer();
            Int32Importer innerImporter = new Int32Importer();
            Int32Exporter exporter = new Int32Exporter(42);
            CompositionBatch batch = new CompositionBatch();
            batch.AddPart(exporter);
            container.Compose(batch);
            CallbackExecuteCodeDuringCompose callback = new CallbackExecuteCodeDuringCompose(() =>
            {
                using (CompositionContainer innerContainer = new CompositionContainer(container))
                {
                    CompositionBatch nestedBatch = new CompositionBatch();
                    nestedBatch.AddPart(innerImporter);
                    innerContainer.Compose(nestedBatch);
                }
                Assert.AreEqual(42, innerImporter.Value, "Expected value imported from export");
            });

            batch = new CompositionBatch();
            batch.AddParts(outerImporter, callback);
            container.Compose(batch);

            Assert.AreEqual(42, outerImporter.Value, "Expected value imported from export");
            Assert.AreEqual(42, innerImporter.Value, "Expected value imported from export");
        }
开发者ID:nlhepler,项目名称:mono,代码行数:27,代码来源:CompositionContainerTests.cs

示例13: TryGetExportedValueWhileLockedForNotify

        public void TryGetExportedValueWhileLockedForNotify()
        {
            var container = CreateCompositionContainer();
            CompositionBatch batch = new CompositionBatch();
            batch.AddParts(new CallbackImportNotify(delegate
            {
                container.GetExportedValueOrDefault<int>();
            }));

            container.Compose(batch);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:11,代码来源:CompositionContainerTests.cs

示例14: TryComposeSimpleFail

        public void TryComposeSimpleFail()
        {
            var container = CreateCompositionContainer();
            Int32Importer importer = new Int32Importer();

            CompositionBatch batch = new CompositionBatch();
            batch.AddParts(importer);

            CompositionAssert.ThrowsChangeRejectedError(ErrorId.ImportEngine_PartCannotSetImport, ErrorId.ImportEngine_ImportCardinalityMismatch, RetryMode.DoNotRetry, () =>
            {
                container.Compose(batch);
            });

            Assert.AreEqual(0, importer.Value, "Expected default value to remain");
        }
开发者ID:nlhepler,项目名称:mono,代码行数:15,代码来源:CompositionContainerTests.cs

示例15: ImportCollectionsFormContainerAndCatalog

        public void ImportCollectionsFormContainerAndCatalog()
        {
            var cat = CatalogFactory.CreateDefaultAttributed();
            var container = new CompositionContainer(cat);
            Importer importer = new Importer();

            CompositionBatch batch = new CompositionBatch();
            batch.AddParts(importer
                , new ExporterDefault21(22)
                , new ExporterDefault42(43));

            container.Compose(batch);

            importer.VerifyImport(22, 43, 21, 42);
        }
开发者ID:JackFong,项目名称:FreeRadical,代码行数:15,代码来源:ExportCollectionTests.cs


注:本文中的System.ComponentModel.Composition.Hosting.CompositionBatch.AddParts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。