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


C# Hosting.AssemblyCatalog类代码示例

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


AssemblyCatalog类属于System.ComponentModel.Composition.Hosting命名空间,在下文中一共展示了AssemblyCatalog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Bootstrapper

        public Bootstrapper()
        {
            var catalog = new AssemblyCatalog(typeof(Bootstrapper).Assembly);
            var compositionContainer = new CompositionContainer(catalog);

            compositionContainer.ComposeParts(this);
        }
开发者ID:pwlodek,项目名称:CodeGallery,代码行数:7,代码来源:Bootstrapper.cs

示例3: 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

示例4: TreatyHelper

 public TreatyHelper()
 {
     var catalog = new AssemblyCatalog(this.GetType().Assembly);
     var container = new CompositionContainer(catalog);
     
     this.treaties = container.GetExports<ITreatyProvider>().ToList();
 }
开发者ID:JaredReisinger,项目名称:TreatyOfBabel.NET,代码行数:7,代码来源:TreatyHelper.cs

示例5: 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

示例6: SafeDirectoryCatalog

        public SafeDirectoryCatalog(string directory)
        {
            var files = Directory.EnumerateFiles(directory, "*.dll", SearchOption.AllDirectories);

            _catalog = new AggregateCatalog();

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

	                //Force MEF to load the plugin and figure out if there are any exports
	                // good assemblies will not throw the RTLE exception and can be added to the catalog
	                if (asmCat.Parts.ToList().Count > 0) _catalog.Catalogs.Add(asmCat);
                }
                catch (ReflectionTypeLoadException)
                {
                }
                catch (BadImageFormatException)
                {
                }
                catch (FileLoadException) //ignore when the assembly load failed.
                {

                }
            }
        }
开发者ID:rut5949,项目名称:Dnn.Platform,代码行数:28,代码来源:SafeDirectoryCatalog.cs

示例7: ModuleLoader

        public ModuleLoader(IAssemblyResolver resolver, ILog logger, Action<Assembly, AggregateCatalog> addToCatalog, Func<CompositionContainer, IEnumerable<Lazy<IModule, IModuleMetadata>>> getLazyModules, IFileSystem fileSystem, IAssemblyUtility assemblyUtility)
        {
            _resolver = resolver;
            _logger = logger;

            if (addToCatalog == null)
            {
                addToCatalog = (assembly, catalog) =>
                {
                    try
                    {
                        var assemblyCatalog = new AssemblyCatalog(assembly);
                        catalog.Catalogs.Add(assemblyCatalog);
                    }
                    catch (Exception exception)
                    {
                        logger.DebugFormat("Module Loader exception: {0}", exception.Message);
                    }
                };
            }

            _addToCatalog = addToCatalog;

            if (getLazyModules == null)
            {
                getLazyModules = container => container.GetExports<IModule, IModuleMetadata>();
            }

            _getLazyModules = getLazyModules;
            _fileSystem = fileSystem;
            _assemblyUtility = assemblyUtility;
        }
开发者ID:nagyistoce,项目名称:scriptcs,代码行数:32,代码来源:ModuleLoader.cs

示例8: BlacklistedSafeDirectoryCatalog

        public BlacklistedSafeDirectoryCatalog(IEnumerable<string> paths, IEnumerable<string> typesBlacklist)
        {
            Exceptions = new List<Exception>();
            TypesBlacklist = typesBlacklist;

            AggregateCatalog = new AggregateCatalog();

            foreach (var path in paths)
            {
                var files = Directory.EnumerateFiles(GetFullPath(path), "*.dll", SearchOption.AllDirectories);

                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:elerch,项目名称:Glimpse,代码行数:34,代码来源:BlacklistedSafeDirectoryCatalog.cs

示例9: ComposeParts

        public static void ComposeParts(params object[] attributedParts)
        {
            try
            {

                AssemblyCatalog catalog = new AssemblyCatalog(typeof(PluginLocator).Assembly);

                AggregateCatalog catalogs = new AggregateCatalog(catalog);
                var pluginDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "plugins");
                if (Directory.Exists(pluginDirectory))
                {
                    DirectoryCatalog dirCatalog = new DirectoryCatalog(pluginDirectory);
                    catalogs.Catalogs.Add(dirCatalog);
                }

                //pluginDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory);
                //if (Directory.Exists(pluginDirectory))
                //{
                //    DirectoryCatalog dirCatalog = new DirectoryCatalog(pluginDirectory);
                //    catalogs.Catalogs.Add(dirCatalog);
                //}

                CompositionContainer container = new CompositionContainer(catalogs);

                container.ComposeParts(attributedParts);

            }
            catch (Exception)
            {
                System.Diagnostics.Debugger.Break();
                throw;
            }
        }
开发者ID:ishwormali,项目名称:practices,代码行数:33,代码来源:PluginLocator.cs

示例10: RegisterMef

 internal static void RegisterMef(HttpConfiguration config)
 {
     var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
     var container = new CompositionContainer(catalog);
     var resolver = new MefDependencyResolver(container);
     config.DependencyResolver = resolver;
 }
开发者ID:RConDev,项目名称:RaptoRCon,代码行数:7,代码来源:MefConfig.cs

示例11: LoadServer

        public static ServerEntry LoadServer(string path)
        {
            try
            {
                //  Create a server entry for the server.
                var serverEntry = new ServerEntry();

                //  Set the data.
                serverEntry.ServerName = Path.GetFileNameWithoutExtension(path);
                serverEntry.ServerPath = path;

                //  Create an assembly catalog for the assembly and a container from it.
                var catalog = new AssemblyCatalog(Path.GetFullPath(path));
                var container = new CompositionContainer(catalog);

                //  Get the exported server.
                var server = container.GetExport<ISharpShellServer>().Value;

                serverEntry.ServerType = server.ServerType;
                serverEntry.ClassId = server.GetType().GUID;
                serverEntry.Server = server;

                return serverEntry;
            }
            catch (Exception)
            {
                //  It's almost certainly not a COM server.
                MessageBox.Show("The file '" + Path.GetFileName(path) + "' is not a SharpShell Server.", "Warning");
                return null;
            }
        }
开发者ID:xieguigang,项目名称:Reference_SharedLib,代码行数:31,代码来源:ServerManagerApi.cs

示例12: ComposeWithTypesExportedFromPythonAndCSharp

        public void ComposeWithTypesExportedFromPythonAndCSharp(
            object compositionTarget,
            string scriptsToImport,
            params Type[] typesToImport)
        {
            ScriptSource script;
            var engine = Python.CreateEngine();
            using (var scriptStream = GetType().Assembly.
                GetManifestResourceStream(GetType(), scriptsToImport))
            using (var scriptText = new StreamReader(scriptStream))
            {
                script = engine.CreateScriptSourceFromString(scriptText.ReadToEnd());
            }

            var typeExtractor = new ExtractTypesFromScript(engine);
            var exports = typeExtractor.GetPartsFromScript(script, typesToImport).ToList();

            var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            var container = new CompositionContainer(catalog);
            var batch = new CompositionBatch(exports, new ComposablePart[] { });
            container.Compose(batch);

            container.SatisfyImportsOnce(compositionTarget);
        }
开发者ID:orthros,项目名称:IronPythonMef,代码行数:25,代码来源:CompositionHelper.cs

示例13: GetSpells

 private static IList<ISpellCast> GetSpells()
 {
     // Use MEF to locate the content providers in this assembly
     var catalog = new AssemblyCatalog(typeof(SpellManager).Assembly);
     var compositionContainer = new CompositionContainer(catalog);
     return compositionContainer.GetExportedValues<ISpellCast>().ToList();
 }
开发者ID:bbqchickenrobot,项目名称:Legend,代码行数:7,代码来源:SpellManager.cs

示例14: SafeDirectoryCatalog

    /// <summary>
    /// Initializes a new instance of the <see cref="SafeDirectoryCatalog" /> class.
    /// </summary>
    /// <param name="directory">The directory.</param>
    public SafeDirectoryCatalog( string directory )
    {
        var files = Directory.EnumerateFiles( directory, "*.dll", SearchOption.AllDirectories );

        _catalog = new AggregateCatalog();

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

                //Force MEF to load the plugin and figure out if there are any exports
                // good assemblies will not throw the RTLE exception and can be added to the catalog
                if ( asmCat.Parts.ToList().Count > 0 )
                    _catalog.Catalogs.Add( asmCat );
            }

            catch ( ReflectionTypeLoadException e)
            {
                //TODO: Add error logging
                string msg = e.Message;
            }
        }
    }
开发者ID:Ganon11,项目名称:Rock,代码行数:29,代码来源:SafeDirectoryCatalog.cs

示例15: App_OnStartup

 private void App_OnStartup(object sender, StartupEventArgs e)
 {
     var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
     var container = new CompositionContainer(catalog);
     var mainWindow = container.GetExportedValue<MainWindow>();
     mainWindow.Show();
 }
开发者ID:omikad,项目名称:MinesweeperSolver,代码行数:7,代码来源:App.xaml.cs


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