本文整理汇总了C#中System.ComponentModel.Composition.Hosting.AggregateCatalog类的典型用法代码示例。如果您正苦于以下问题:C# AggregateCatalog类的具体用法?C# AggregateCatalog怎么用?C# AggregateCatalog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AggregateCatalog类属于System.ComponentModel.Composition.Hosting命名空间,在下文中一共展示了AggregateCatalog类的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);
}
}
}
示例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!");
}
}
示例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());
}
}
示例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;
}
示例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);
}
示例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());
}
}
示例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);
}
}
示例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();
}
示例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;
}
}
示例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);
}
示例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");
}
示例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;
}
}
示例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);
}
}
}
}
示例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;
}
示例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");
}