本文整理汇总了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);
}
}
}
示例2: Bootstrapper
public Bootstrapper()
{
var catalog = new AssemblyCatalog(typeof(Bootstrapper).Assembly);
var compositionContainer = new CompositionContainer(catalog);
compositionContainer.ComposeParts(this);
}
示例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;
}
}
示例4: TreatyHelper
public TreatyHelper()
{
var catalog = new AssemblyCatalog(this.GetType().Assembly);
var container = new CompositionContainer(catalog);
this.treaties = container.GetExports<ITreatyProvider>().ToList();
}
示例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");
}
示例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.
{
}
}
}
示例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;
}
示例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);
}
}
}
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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);
}
示例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();
}
示例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;
}
}
}
示例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();
}