• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Hosting.AggregateCatalog类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



AggregateCatalog类属于System.ComponentModel.Composition.Hosting命名空间,在下文中一共展示了AggregateCatalog类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SafeDirectoryCatalog

        public SafeDirectoryCatalog(string path)
        {
            exceptions = new List<Exception>();
            var files = Directory.EnumerateFiles(GetFullPath(path), "*.dll", SearchOption.AllDirectories);

            aggregateCatalog = new AggregateCatalog();

            foreach (var file in files)
            {
                try
                {
                    var assemblyCatalog = new AssemblyCatalog(file);

                    if (assemblyCatalog.Parts.ToList().Count > 0)
                        aggregateCatalog.Catalogs.Add(assemblyCatalog);
                }
                catch (ReflectionTypeLoadException ex)
                {
                    foreach (var exception in ex.LoaderExceptions)
                    {
                        exceptions.Add(exception);
                    }
                }
                catch (Exception ex)
                {
                    exceptions.Add(ex);
                }
            }
        }
开发者ID:RobertTheGrey,项目名称:Glimpse,代码行数:29,代码来源:SafeDirectoryCatalog.cs


示例2: Start

        public void Start()
        {
            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new AssemblyCatalog(typeof(SearchDemo).Assembly));
            var container = new CompositionContainer(catalog);
            container.ComposeParts();

            try
            {
                var component = container.GetExport<ITestComponent>();
                if (component != null)
                    Console.WriteLine(component.Value.Message);
            }
            catch (Exception exp)
            {
                //Why does our call to 'GetExport' throw an exception?

                //Search for the string "Test" on the container variable
                //You'll find 3 instances in the Catalog.
                //Then search for ITestComponent.
                //You'll need to click "Search Deeper" to expand the search.

                //Another way to do this is to view "container.Catalog.Parts", right click it,
                //select 'Edit Filter' and enter the following predicate:
                //         [obj].Exports(typoef(ITestComponent)

                MessageBox.Show(exp.Message, "Exception caught!");
            }
        }
开发者ID:OmerRaviv,项目名称:OzCodeDemo,代码行数:30,代码来源:SearchDemo.cs


示例3: LoadPlugins

        public void LoadPlugins(IEnumerable<ComposablePartCatalog> catalogs = null)
        {
            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new AssemblyCatalog(GetType().Assembly));

            if (catalogs != null)
            {
                foreach (var additionalCatalog in catalogs)
                {
                    catalog.Catalogs.Add(additionalCatalog);
                }
            }

            //Create the CompositionContainer with the parts in the catalog
            Container = new CompositionContainer(catalog);

            //Fill the imports of this object
            try
            {
                Container.ComposeParts(this);
            }
            catch (CompositionException compositionException)
            {
                Console.WriteLine(compositionException.ToString());
            }
        }
开发者ID:EdwardSalter,项目名称:NCubeSolver,代码行数:26,代码来源:PluginLoader.cs


示例4: Compose

        private bool Compose()
        {
            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(IMefShapesGame).Assembly));
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(DefaultDimensions).Assembly));
            var partCreatorEP = new DynamicInstantiationExportProvider();

            this._container = new CompositionContainer(catalog, partCreatorEP);
            partCreatorEP.SourceProvider = this._container;

            CompositionBatch batch = new CompositionBatch();
            batch.AddPart(this);
            batch.AddExportedValue<ICompositionService>(this._container);
            batch.AddExportedValue<AggregateCatalog>(catalog);

            try
            {
                this._container.Compose(batch);
            }
            catch (CompositionException compositionException)
            {
                MessageBox.Show(compositionException.ToString());
                Shutdown(1);
                return false;
            }
            return true;
        }
开发者ID:JackFong,项目名称:FreeRadical,代码行数:27,代码来源:App.cs


示例5: GetContainer

 internal static CompositionContainer GetContainer()
 {
     var catalog = new AggregateCatalog();
     catalog.Catalogs.Add(new AssemblyCatalog(typeof(IApplicationController).Assembly));
     catalog.Catalogs.Add(new AssemblyCatalog(typeof(ValidationModel).Assembly));
     return new CompositionContainer(catalog);
 }
开发者ID:nootn,项目名称:ClinImIm,代码行数:7,代码来源:CompositionHelper.cs


示例6: TestHarness

        public TestHarness(string pluginDirectoryPath, Type pluginAssemblyType, string pluginType)
        {
            var catalog = new AggregateCatalog();
            this._pluginType = pluginType;

            try
            {
                Assembly[] assemblies = new Assembly[]{ Assembly.GetCallingAssembly(), Assembly.GetExecutingAssembly(), Assembly.GetEntryAssembly() };
                foreach (Assembly assembly in assemblies)
                {
                    catalog.Catalogs.Add(new AssemblyCatalog(assembly));
                    catalog.Catalogs.Add(new DirectoryCatalog(Path.GetDirectoryName(assembly.Location)));
                }

                if (!Object.ReferenceEquals(pluginAssemblyType, null))
                {
                    catalog.Catalogs.Add(new AssemblyCatalog(pluginAssemblyType.Assembly));
                }

                if (!Object.ReferenceEquals(pluginDirectoryPath, null))
                {
                    if (Directory.Exists(pluginDirectoryPath))
                    {
                        catalog.Catalogs.Add(new DirectoryCatalog(pluginDirectoryPath));
                    }
                }

                this.container = new CompositionContainer(catalog);
                this.container.ComposeParts(this);
            }
            catch (CompositionException cex)
            {
                Console.WriteLine(cex.ToString());
            }
        }
开发者ID:mercenary-automation,项目名称:dotnet-api,代码行数:35,代码来源:TestHarness.cs


示例7: DoImport

        public void DoImport()
        {
            //An aggregate catalog that combines multiple catalogs
            var catalog = new AggregateCatalog();

            directoryCatalog = new DirectoryCatalog(GetDirectory());
            directoryCatalog.Changing += directoryCatalog_Changing;
            directoryCatalog.Changed += directoryCatalog_Changed;

            //Adds all the parts found in all assemblies in 
            //the same directory as the executing program
            catalog.Catalogs.Add(directoryCatalog);

            //Create the CompositionContainer with the parts in the catalog
            var container = new CompositionContainer(catalog);

            try
            {
                //Fill the imports of this object
                container.ComposeParts(this);
            }
            catch (Exception ex)
            {
                Out.WriteLine("Unable to load plugins: {0}", ex.Message);
            }

        }
开发者ID:Olezhka,项目名称:Hipbot,代码行数:27,代码来源:Program.cs


示例8: Main

		public static void Main (string[] args)
		{
			var bootStrapper = new Bootstrapper();

            //An aggregate catalog that combines multiple catalogs
            var catalog = new AggregateCatalog();
            //Adds all the parts found in same directory where the application is running!
            var currentPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(MainClass)).Location) ?? "./";
            catalog.Catalogs.Add(new DirectoryCatalog(currentPath));

            //Create the CompositionContainer with the parts in the catalog
            var container = new CompositionContainer(catalog);
            
            //Fill the imports of this object
            try
            {
                container.ComposeParts(bootStrapper);
            }
            catch (CompositionException compositionException)
            {
                Console.WriteLine(compositionException.ToString());
            }

            //Prints all the languages that were found into the application directory
            var i = 0;
            foreach (var language in bootStrapper.Languages)
            {
                Console.WriteLine("[{0}] {1} by {2}.\n\t{3}\n", language.Version, language.Name, language.Author, language.Description);
                i++;
            }
            Console.WriteLine("It has been found {0} supported languages",i);
            Console.ReadKey();
		}
开发者ID:jorgeds001,项目名称:CodeSamples,代码行数:33,代码来源:Main.cs


示例9: CreateCatalog

        protected override ComposablePartCatalog CreateCatalog() {
            _idePath = GetDevEnvIdePath();

            EnumerateAssemblies(_knownProductAssemblyPaths, Path.GetDirectoryName(GetType().Assembly.GetAssemblyPath()));
            EnumerateAssemblies(_knownVsAssemblyPaths, Path.Combine(_idePath, @"PrivateAssemblies\"));
            EnumerateAssemblies(_knownVsAssemblyPaths, Path.Combine(_idePath, @"CommonExtensions\"));

            var aggregateCatalog = new AggregateCatalog();
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            try {
                var nugetAssemblies = GetNugetAssemblies().ToList();
                if (nugetAssemblies.Any()) {
                    FindInCurrentAssemblyFolder(nugetAssemblies, aggregateCatalog);
                }

                foreach (var assemblyName in GetBinDirectoryAssemblies()) {
                    LoadAssembly(assemblyName, _knownProductAssemblyPaths, aggregateCatalog);
                }

                foreach (var assemblyName in GetVsAssemblies()) {
                    LoadAssembly(assemblyName, _knownVsAssemblyPaths, aggregateCatalog);
                }

                ValidateCatalog(aggregateCatalog);
                return aggregateCatalog;
            } finally {
                AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
            }
        }
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:29,代码来源:AssemblyMefCatalogFixture.cs


示例10: Init

 public static void Init()
 {
     AggregateCatalog catalog = new AggregateCatalog();
     catalog.Catalogs.Add(new AssemblyCatalog(typeof (DataAccessAssembly).Assembly));
     catalog.Catalogs.Add(new AssemblyCatalog(typeof (AzureUtilitiesMockAssembly).Assembly));
     MefBase.Container = new CompositionContainer(catalog, true);
 }
开发者ID:jsucupira,项目名称:table-storage-geo-redundancy-demo,代码行数:7,代码来源:MefLoader.cs


示例11: Program

 private Program()
 {
     var catalog = new AggregateCatalog();
     catalog.Catalogs.Add(new AssemblyCatalog(typeof(Program).Assembly));
     catalog.Catalogs.Add(new DirectoryCatalog(Environment.CurrentDirectory));
     _container = new CompositionContainer(catalog);
     try
     {
         _container.ComposeParts(this);
     }
     catch (System.Reflection.ReflectionTypeLoadException v)
     {
         foreach (var c in v.LoaderExceptions)
             Console.WriteLine(c.ToString());
     }
     catch (CompositionException e) {
         Console.WriteLine(e.ToString());
     }
     if (plugins != null)
     {
         foreach (var q in plugins)
         {
             Console.WriteLine(q.Metadata.name);
         }
         PluginContainer.plugins= plugins;
     }
     else
         Console.WriteLine("No plugins loaded");
 }
开发者ID:modulexcite,项目名称:cDashboard,代码行数:29,代码来源:Program.cs


示例12: InitializePlugins

    private void InitializePlugins()
    {
      // We look for plugins in our own assembly and in any DLLs that live next to our EXE.
      // We could force all plugins to be in a "Plugins" directory, but it seems more straightforward
      // to just leave everything in one directory
      var builtinPlugins = new AssemblyCatalog(GetType().Assembly);
      var externalPlugins = new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory, "*.dll");
      
      _catalog = new AggregateCatalog(builtinPlugins, externalPlugins);
      _container = new CompositionContainer(_catalog);

      try
      {
        _container.SatisfyImportsOnce(this);       
      }
      catch (CompositionException ex)
      {
        if (_log.IsErrorEnabled)
        {
          _log.ErrorFormat("MEF Composition Exception: {0}", ex.Message);

          var errors = String.Join("\n    ", ex.Errors.Select(x => x.Description));
          _log.ErrorFormat("Composition Errors: {0}", errors);
        }
        throw;
      }
    }
开发者ID:BookSwapSteve,项目名称:statsd.net,代码行数:27,代码来源:StatsdnetConfiguration.cs


示例13: Initialize

        /// <summary>
        /// Initializes the MEF Container.
        /// </summary>
        /// <param name="root">The root.</param>
        public static void Initialize(object root)
        {
            if (root == null)
            throw new NullReferenceException("MEF root");

             if (_instance == null) {
            lock (_syncRoot) {
               if (_instance == null) {
                  string exePath = null;
                  string path = null;
                  if (Assembly.GetEntryAssembly() != null) {
                     exePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                  } else {
                     exePath = Path.GetDirectoryName(root.GetType().Assembly.Location);
                  }
                  path = Path.Combine(exePath, "\\plugins");
                  if (!Directory.Exists(path))
                     Directory.CreateDirectory(path);

                  var catalog = new AggregateCatalog();
                  if (path != null)
                     catalog.Catalogs.Add(new DirectoryCatalog(path));
                  if (exePath != null)
                     catalog.Catalogs.Add(new DirectoryCatalog(exePath));
                  catalog.Catalogs.Add(new AssemblyCatalog(root.GetType().Assembly));

                  _instance = new CompositionContainer(catalog);
                  _instance.ComposeParts(root);

               }
            }
             }
        }
开发者ID:Cappinator,项目名称:chiiilp-pbem,代码行数:37,代码来源:MEFContainer.cs


示例14: GetPlugins

        public static IPlugins GetPlugins(ITranslator translator, IAssemblyInfo config)
        {
            string path = null;
            if (!string.IsNullOrWhiteSpace(config.PluginsPath))
            {
                path = Path.Combine(translator.FolderMode ? translator.Location : Path.GetDirectoryName(translator.Location), config.PluginsPath);
            }
            else
            {
                path = Path.Combine(translator.FolderMode ? translator.Location : Path.GetDirectoryName(translator.Location), "Bridge" + Path.DirectorySeparatorChar + "plugins");
            }

            if (!System.IO.Directory.Exists(path))
            {
                return new Plugins() { plugins = new IPlugin[0] };
            }

            DirectoryCatalog dirCatalog = new DirectoryCatalog(path, "*.dll");
            var catalog = new AggregateCatalog(dirCatalog);

            CompositionContainer container = new CompositionContainer(catalog);
            var plugins = new Plugins();
            container.ComposeParts(plugins);

            return plugins;
        }
开发者ID:txdv,项目名称:Builder,代码行数:26,代码来源:Plugins.cs


示例15: Load

        public void Load(IModuleConfiguration config, string modulePackagesPath, string extension, params string[] moduleNames)
        {
            _logger.Debug("Loading modules from: " + modulePackagesPath);
            var paths = _resolver.GetAssemblyPaths(modulePackagesPath, string.Empty);
            var catalog = new AggregateCatalog();
            foreach (var path in paths)
            {
                _addToCatalog(path, catalog);
            }

            var container = new CompositionContainer(catalog);
            var lazyModules = _getModules(container);
            var modules = lazyModules
                .Where(m => moduleNames.Contains(m.Metadata.Name) ||
                    (extension != null && m.Metadata.Extensions != null && (m.Metadata.Extensions.Split(',').Contains(extension))))
                .Select(m => m.Value);

            _logger.Debug("Initializing modules");
            foreach (var module in modules)
            {
                _logger.Debug(string.Format("Initializing module:{0}", module.GetType().FullName));
                module.Initialize(config);
            }

            _logger.Debug("Modules initialized");
        }
开发者ID:jden,项目名称:scriptcs,代码行数:26,代码来源:ModuleLoader.cs


示例16: WhenInitializingAModuleWithNoCatalogPendingToBeLoaded_ThenInitializesTheModule

        public void WhenInitializingAModuleWithNoCatalogPendingToBeLoaded_ThenInitializesTheModule()
        {
            var aggregateCatalog = new AggregateCatalog(new AssemblyCatalog(typeof(MefModuleInitializer).Assembly));
            var compositionContainer = new CompositionContainer(aggregateCatalog);
            compositionContainer.ComposeExportedValue(aggregateCatalog);

            var serviceLocatorMock = new Mock<IServiceLocator>();
            var loggerFacadeMock = new Mock<ILoggerFacade>();

            var serviceLocator = serviceLocatorMock.Object;
            var loggerFacade = loggerFacadeMock.Object;

            compositionContainer.ComposeExportedValue(serviceLocator);
            compositionContainer.ComposeExportedValue(loggerFacade);

            aggregateCatalog.Catalogs.Add(new TypeCatalog(typeof(TestModuleForInitializer)));

            var moduleInitializer = compositionContainer.GetExportedValue<IModuleInitializer>();

            var moduleInfo = new ModuleInfo("TestModuleForInitializer", typeof(TestModuleForInitializer).AssemblyQualifiedName);

            var module = compositionContainer.GetExportedValues<IModule>().OfType<TestModuleForInitializer>().First();

            Assert.IsFalse(module.Initialized);

            moduleInitializer.Initialize(moduleInfo);

            Assert.IsTrue(module.Initialized);
        }
开发者ID:Citringo,项目名称:Prism,代码行数:29,代码来源:MefModuleInitializerFixture.cs


示例17: Init

        public Runner Init(IFeedbackProvider feedbackProvider, string[] args)
        {
            var catalog = new AggregateCatalog(new AssemblyCatalog(typeof(Bootstrapper).Assembly));

            var currentDir = Environment.CurrentDirectory;
            var assemblyDir = new FileInfo(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath).Directory.FullName;

            var paths = new string[]
            {
                assemblyDir,
                Path.Combine(assemblyDir, "Tasks"),
                currentDir,
                Path.Combine(currentDir, "Tasks")
            }.Unique();

            var dirCatalogs = paths.Where(x => Directory.Exists(x))
                                   .Select(x => new DirectoryCatalog(x, "*.Tasks.dll"));
            dirCatalogs.Apply(x => catalog.Catalogs.Add(x));

            var container = new CompositionContainer(catalog);

            var parsed = new ArgumentParser().Parse(args);
            var runner = new Runner(parsed.ActualArgs.ToArray());

            var batch = new CompositionBatch();
            batch.AddExportedValue<IFeedbackProvider>(feedbackProvider);
            parsed.Options.Apply(x => batch.AddExportedValue<string>(x.Item1, x.Item2));
            parsed.Switches.Apply(x => batch.AddExportedValue<bool>(x, true));
            batch.AddPart(runner);
            container.Compose(batch);

            return runner;
        }
开发者ID:mikeminutillo,项目名称:task,代码行数:33,代码来源:Bootstrapper.cs


示例18: WhenInitializingAModuleWithACatalogPendingToBeLoaded_ThenLoadsTheCatalogInitializesTheModule

        public void WhenInitializingAModuleWithACatalogPendingToBeLoaded_ThenLoadsTheCatalogInitializesTheModule()
        {
            var aggregateCatalog = new AggregateCatalog(new AssemblyCatalog(typeof(MefModuleInitializer).Assembly));
            var compositionContainer = new CompositionContainer(aggregateCatalog);
            compositionContainer.ComposeExportedValue(aggregateCatalog);

            var serviceLocatorMock = new Mock<IServiceLocator>();
            var loggerFacadeMock = new Mock<ILoggerFacade>();

            var serviceLocator = serviceLocatorMock.Object;
            var loggerFacade = loggerFacadeMock.Object;

            compositionContainer.ComposeExportedValue(serviceLocator);
            compositionContainer.ComposeExportedValue(loggerFacade);

            var moduleInitializer = compositionContainer.GetExportedValue<IModuleInitializer>();
            var repository = compositionContainer.GetExportedValue<DownloadedPartCatalogCollection>();

            var moduleInfo = new ModuleInfo("TestModuleForInitializer", typeof(TestModuleForInitializer).AssemblyQualifiedName);

            repository.Add(moduleInfo, new TypeCatalog(typeof(TestModuleForInitializer)));

            moduleInitializer.Initialize(moduleInfo);

            ComposablePartCatalog existingCatalog;
            Assert.IsFalse(repository.TryGet(moduleInfo, out existingCatalog));

            var module = compositionContainer.GetExportedValues<IModule>().OfType<TestModuleForInitializer>().First();

            Assert.IsTrue(module.Initialized);
        }
开发者ID:Citringo,项目名称:Prism,代码行数:31,代码来源:MefModuleInitializerFixture.cs


示例19: Compose

        private bool Compose()
        {
            var catalog = new System.ComponentModel.Composition.Hosting.AggregateCatalog();
            //            var catalog = new AggregatingComposablePartCatalog();
            catalog.Catalogs.Add(
                new RubyCatalog(new RubyPartFile("calculator_ops.rb")));
            catalog.Catalogs.Add(
                new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            _container = new System.ComponentModel.Composition.Hosting.CompositionContainer(catalog);
            //_container. AddPart(this);
            var batch = new System.ComponentModel.Composition.Hosting.CompositionBatch();
            batch.AddPart(this);
            //_container.AddPart(this);
            //_container.Compose(this);

            try
            {
                _container.Compose(batch);
            }
            catch (CompositionException compositionException)
            {
                MessageBox.Show(compositionException.ToString());
                return false;
            }
            return true;
        }
开发者ID:JogoShugh,项目名称:IronRubyMef,代码行数:26,代码来源:App.xaml.cs


示例20: ExtensionManager

        /// <summary>
        /// Default private constructor.
        /// </summary>
        private ExtensionManager()
        {
            if (!Config.DisableComposition)
            {
                // Let MEF scan for imports
                var catalog = new AggregateCatalog();

                catalog.Catalogs.Add(Config.DisableCatalogSearch ? new DirectoryCatalog("Bin", "Piranha*.dll") : new DirectoryCatalog("Bin"));

            #if !NET40
                if (!System.Web.Compilation.BuildManager.IsPrecompiledApp)
                {
            #endif
                    try
                    {
                        // This feature only exists for Web Pages
                        catalog.Catalogs.Add(new AssemblyCatalog(Assembly.Load("App_Code")));
                    }
                    catch { }
            #if !NET40
                }
            #endif

                Container = new CompositionContainer(catalog);
                Container.ComposeParts(this);
            }
        }
开发者ID:cnascimento,项目名称:Paladino,代码行数:30,代码来源:ExtensionManager.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Hosting.DirectoryCatalog类代码示例发布时间:2022-05-26
下一篇:
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap