當前位置: 首頁>>代碼示例>>C#>>正文


C# CompositionBatch.AddPart方法代碼示例

本文整理匯總了C#中System.ComponentModel.Composition.Hosting.CompositionBatch.AddPart方法的典型用法代碼示例。如果您正苦於以下問題:C# CompositionBatch.AddPart方法的具體用法?C# CompositionBatch.AddPart怎麽用?C# CompositionBatch.AddPart使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.ComponentModel.Composition.Hosting.CompositionBatch的用法示例。


在下文中一共展示了CompositionBatch.AddPart方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SatisfyImportsOnce

        public void SatisfyImportsOnce(ComposablePart part)
        {
            if (this.DoNothingOnSatisfyImportsOnce)
            {
                return;
            }

            CompositionBatch batch = new CompositionBatch();

            // We only want to include the standard exports and parts to compose in the first composition
            if (!this.alreadyComposed)
            {
                foreach (object instance in this.PartsToCompose)
                {
                    batch.AddPart(instance);
                }

                foreach (Export export in this.ExportsToCompose)
                {
                    batch.AddExport(export);
                }
            }

            if (part != null)
            {
                batch.AddPart(part);
            }

            this.container.Compose(batch);
            this.alreadyComposed = true;
        }
開發者ID:SonarSource-VisualStudio,項目名稱:sonarlint-visualstudio,代碼行數:31,代碼來源:ConfigurableCompositionService.cs

示例2: Compose

        public void Compose(BaseParameters parameters)
        {
            try
            {
                var catalog = new AggregateCatalog(new AssemblyCatalog(Assembly.GetExecutingAssembly()),
                                                   new AssemblyCatalog(typeof(Logic.SanityCheck).Assembly));

                LoadPlugins(catalog, parameters);

                var container = new CompositionContainer(catalog);

                var batch = new CompositionBatch();
                batch.AddPart(this);
                batch.AddPart(parameters);

                var config = new Configuration(parameters.FileSystem, parameters.Path);
                config.ReadFromFile();
                batch.AddExportedValue((IConfiguration)config);

                container.Compose(batch);
            }
            catch (ReflectionTypeLoadException ex)
            {
                Console.WriteLine(@"Unable to load: \r\n{0}",
                    string.Join("\r\n", ex.LoaderExceptions.Select(e => e.Message)));

                throw;
            }
        }
開發者ID:Code52,項目名稱:pretzel,代碼行數:29,代碼來源:Program.cs

示例3: ComposeBatchTwo

        private static void ComposeBatchTwo(CompositionContainer container)
        {
            var batch = new CompositionBatch();
            batch.RemovePart(a);
            c = batch.AddPart(new PluginC());
            batch.AddPart(logger);

            container.Compose(batch);
        }
開發者ID:mikeminutillo,項目名稱:mef-sandbox,代碼行數:9,代碼來源:Program.cs

示例4: Main

        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();
        }
開發者ID:Joxx0r,項目名稱:ATF,代碼行數:57,代碼來源:Program.cs

示例5: ComposeBatchOne

        private static void ComposeBatchOne(CompositionContainer container)
        {
            var batch = new CompositionBatch();

            a = batch.AddPart(new PluginA());
            b = batch.AddPart(new PluginB());

            batch.AddPart(bootstrapper);

            container.Compose(batch);
        }
開發者ID:mikeminutillo,項目名稱:mef-sandbox,代碼行數:11,代碼來源:Program.cs

示例6: FunctionsFieldsAndProperties2

        public void FunctionsFieldsAndProperties2()
        {
            Consumer c;
            var container = ContainerFactory.Create();

            CompositionBatch batch = new CompositionBatch();
            batch.AddPart(new SubtractProvider());
            batch.AddPart(c = new Consumer());
            container.Compose(batch);

            Assert.AreEqual(-1, c.op(c.a, c.b), "1 - 2 == -1");
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:12,代碼來源:AdvancedValueComposition.cs

示例7: App

        public App()
        {
            var catalog = new AggregateCatalog(new DirectoryCatalog(Path.GetDirectoryName(typeof(App).Assembly.Location)), new AssemblyCatalog(typeof(App).Assembly));

            _container = new CompositionContainer(catalog);

            var batch = new CompositionBatch();
            batch.AddPart(ExistingComposablePart.Create<ExportProvider>(_container));
            batch.AddPart(ExistingComposablePart.Create(_container));

            _container.Compose(batch);
        }
開發者ID:hugodahl,項目名稱:powershell-for-developers,代碼行數:12,代碼來源:App.xaml.cs

示例8: PrivateFromPublic

        public void PrivateFromPublic()
        {
            var container = ContainerFactory.Create();
            CompositionBatch batch = new CompositionBatch();
            var importer = new AllPrivateImportOnly();
            batch.AddPart(importer);
            batch.AddPart(new AllPublicExportOnly() { ExportA = 5, ExportB = 10 });
            container.Compose(batch);

            Assert.AreEqual(5, importer.PublicImportA);
            Assert.AreEqual(10, importer.PublicImportB);
        }
開發者ID:JackFong,項目名稱:FreeRadical,代碼行數:12,代碼來源:AllowNonPublicCompositionTests.cs

示例9: ImportSingleToInternal

        public void ImportSingleToInternal()
        {
            var container = ContainerFactory.Create();
            var importer = new Int32ImporterInternal();
            var exporter = new Int32Exporter(42);

            CompositionBatch batch = new CompositionBatch();
            batch.AddPart(importer);
            batch.AddPart(exporter);
            container.Compose(batch);

            Assert.AreEqual(42, importer.Value, "Expecting value to be imported");
        }
開發者ID:JackFong,項目名稱:FreeRadical,代碼行數:13,代碼來源:CompositionContainerImportTests.cs

示例10: ConstructorInjectionCycle

        public void ConstructorInjectionCycle()
        {
            var container = ContainerFactory.Create();
            CompositionBatch batch = new CompositionBatch();

            batch.AddPart(new ConstructorInjectionComposablePart(typeof(AClass)));
            batch.AddPart(new ConstructorInjectionComposablePart(typeof(BClass)));

            CompositionAssert.ThrowsErrors(ErrorId.ImportEngine_PartCannotSetImport,
                                           ErrorId.ImportEngine_PartCannotSetImport, RetryMode.DoNotRetry, () =>
            {
                container.Compose(batch);
            });
        }
開發者ID:whereisaaron,項目名稱:mono,代碼行數:14,代碼來源:ComposablePartExtensibilityTests.cs

示例11: ImportTest

        public void ImportTest()
        {
            var exporter = new TestExportBinder();
            var importer = new TestImportBinder();

            CompositionContainer container = ContainerFactory.Create();
            CompositionBatch batch = new CompositionBatch();

            batch.AddPart(importer);
            batch.AddPart(exporter);
            container.Compose(batch);

            ExportsAssert.AreEqual(importer.SetImports["single"], 42);
            ExportsAssert.AreEqual(importer.SetImports["multi"], 1, 2, 3);
        }
開發者ID:whereisaaron,項目名稱:mono,代碼行數:15,代碼來源:ComposablePartExtensibilityTests.cs

示例12: Compose

        public void Compose()
        {
            AssemblyCatalog assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            string executionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            string generatorsPath = Path.Combine(executionPath, "Generators");
            CreatePathIfRequied(generatorsPath);
            generatorsCatalog = new DirectoryCatalog(generatorsPath);

            string uiPath = Path.Combine(executionPath, "UI");
            CreatePathIfRequied(uiPath);
            UICatalog = new DirectoryCatalog(uiPath);

            AggregateCatalog catalog = new AggregateCatalog();
            catalog.Catalogs.Add(generatorsCatalog);
            catalog.Catalogs.Add(UICatalog);

            //Set the defaults....
            CatalogExportProvider mainProvider = new CatalogExportProvider(assemblyCatalog);
            CompositionContainer container = new CompositionContainer(catalog, mainProvider);
            mainProvider.SourceProvider = container;

            var batch = new CompositionBatch();
            batch.AddPart(this);

            RefreshCatalog refreshCatalog = new RefreshCatalog(generatorsCatalog, UICatalog);
            container.ComposeParts(refreshCatalog);
            container.Compose(batch);

            Logger.Write("Compose complete");
        }
開發者ID:BenHall,項目名稱:ExtendViaMEF,代碼行數:32,代碼來源:Extender.cs

示例13: MainForm

        /// <summary>
        /// Initialises a new instance of the <see cref="MainForm"/> class.
        /// </summary>
        public MainForm()
        {
            this.InitializeComponent();

            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new DirectoryCatalog("..\\..\\Crypto", "*.dll"));
            var batch = new CompositionBatch();
            batch.AddPart(this);
            this.compositionContainer = new CompositionContainer(catalog);
            ////get all the exports and load them into the appropriate list tagged with the importmany
            this.compositionContainer.Compose(batch);

            this.CryptoAlgorithmComboBox.DataSource = (new List<CryptoAlgorithm> { CryptoAlgorithm.None }).Union(
                this.CryptoProviders.Select(c => c.Metadata.Algorithm).Distinct()).ToList();

            this.JoinedUsers = new BindingList<User>();

            this.ConnectedUsersDataGridView.DataSource = this.JoinedUsers;
            this.userProxy = new UserServiceClient(new InstanceContext(this));

            this.userProxy.Open();
            this.messagingProxy = new MessagingServiceClient(new InstanceContext(this));
            this.messagingProxy.Open();

            this.userProxy.Subscribe();
            foreach (var u in this.userProxy.GetJoinedUsers())
            {
                this.AddUser(u);
            }

            this.uiSyncContext = SynchronizationContext.Current;
        }
開發者ID:famstutz,項目名稱:YAEM,代碼行數:35,代碼來源:MainForm.cs

示例14: Compose

 private void Compose()
 {
     var container = new CompositionContainer(directories);
       var batch = new CompositionBatch();
       batch.AddPart(this);
       container.Compose(batch);
 }
開發者ID:edgar-pek,項目名稱:VCDryad,代碼行數:7,代碼來源:PluginManager.cs

示例15: FunctionsFieldsAndProperties2_WithCatalog

        public void FunctionsFieldsAndProperties2_WithCatalog()
        {
            var container = ContainerFactory.CreateWithDefaultAttributedCatalog();

            ConsumerOfMultiple c = new ConsumerOfMultiple();
            CompositionBatch batch = new CompositionBatch();
            batch.AddPart(c);
            container.Compose(batch);

            foreach (var export in c.opInfo)
            {
                if ((string)export.Metadata["Var1"] == "add")
                {
                    Assert.AreEqual(3, export.Value(1, 2), "1 + 2 == 3");
                }
                else if ((string)export.Metadata["Var1"] == "sub")
                {
                    Assert.AreEqual(-1, export.Value(1, 2), "1 - 2 == -1");
                }
                else
                {
                    Assert.Fail("Unexpected value");
                }
            }
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:25,代碼來源:AdvancedValueComposition.cs


注:本文中的System.ComponentModel.Composition.Hosting.CompositionBatch.AddPart方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。