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); } } }
public CompositionContainer CreateContainer() { var binPath = HostingEnvironment.MapPath("~/bin"); if (binPath == null) { throw new Exception("Unable to find the path"); } var files = Directory.EnumerateFiles(binPath, "*.dll", SearchOption.AllDirectories).ToList(); var catalog = new AggregateCatalog(); foreach (var file in files) { try { var asmCat = new AssemblyCatalog(file); // We should only be interested in assemblies that contain at least one export // otherwise we just log the exception and continue if (asmCat.Parts.Any()) { catalog.Catalogs.Add(asmCat); } } catch (ReflectionTypeLoadException e) { Log.Error(e); } } return new CompositionContainer(catalog); }
private void Application_Startup(object sender, StartupEventArgs e) { var assembly = new AssemblyCatalog(Assembly.GetEntryAssembly()); var catalog = new AggregateCatalog(); catalog.Catalogs.Add(assembly); catalog.Catalogs.Add(new DirectoryCatalog(".")); var compositionContainer = new CompositionContainer(catalog); compositionContainer.ComposeParts(this); var locator = new MefServiceLocator(compositionContainer); ServiceLocator.SetLocatorProvider(() => locator); ViewModelManager.ViewModelShowEvent += vm => ViewManager.ViewShow(vm); ViewModelManager.ViewModelCloseEvent += vm => ViewManager.ViewClose(vm); var mainWindowViewModel = new MainWindowViewModel(); compositionContainer.ComposeParts(mainWindowViewModel); MainWindow mainWindow = new MainWindow {DataContext = mainWindowViewModel}; mainWindow.Show(); }
private void ComposeConfiguration() { _configuration = new Configuration(); var catalog = new AssemblyCatalog(Assembly.GetEntryAssembly()); var container = new CompositionContainer(catalog); container.ComposeParts(_configuration); }
protected override void OnStartup( StartupEventArgs e ) { base.OnStartup( e ); new UnhandledExceptionHook( this ); Application.Current.Exit += OnShutdown; var catalog = new AssemblyCatalog( GetType().Assembly ); myContainer = new CompositionContainer( catalog, CompositionOptions.DisableSilentRejection ); myContainer.Compose( new CompositionBatch() ); var shell = myContainer.GetExportedValue<Shell>(); myContainer.SatisfyImportsOnce( shell.myDesigner ); ( ( Shell )MainWindow ).myProperties.DataContext = shell.myDesigner.SelectionService; Application.Current.MainWindow = shell; Application.Current.MainWindow.Show(); var args = Environment.GetCommandLineArgs(); if( args.Length == 2 ) { shell.myDesigner.Open( args[ 1 ] ); } }
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; }
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. { } } }
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(); }
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; } }
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; }
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); }
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(); }
/// <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; } } }
public Bootstrapper() { var catalog = new AssemblyCatalog(typeof(Bootstrapper).Assembly); var compositionContainer = new CompositionContainer(catalog); compositionContainer.ComposeParts(this); }
public static IView CreateView(object viewModel) { var viewName = viewModel.GetType().Name.Replace("ViewModel", "View"); IView view = null; if (IsTesting) { view = new TestView(); } else { // View anhand des Namens ermitteln & exportieren var registration = new RegistrationBuilder(); registration.ForTypesMatching<IView>(item=>item.Name.Equals(viewName)) .Export<IView>() .SetCreationPolicy(CreationPolicy.NonShared); // View erstellen var catalog = new AssemblyCatalog(viewModel.GetType().Assembly, registration); var container = new CompositionContainer(catalog); view = container.GetExportedValue<IView>(); } if (view != null) view.DataContext = viewModel; return view; }
private static void LoadOneProvider( ICatalogLog log, string codebase, AggregateCatalog catalog ) { AssemblyCatalog assemblyCatalog = null; const string FailedToLoadAssemblyMessage = "Failed to load interpreter provider assembly {0} {1}"; try { assemblyCatalog = new AssemblyCatalog(codebase); } catch (Exception ex) { log.Log(String.Format(FailedToLoadAssemblyMessage, codebase, ex)); } if (assemblyCatalog == null) { return; } const string FailedToLoadMessage = "Failed to load interpreter provider {0} {1}"; try { catalog.Catalogs.Add(assemblyCatalog); } catch (Exception ex) { log.Log(String.Format(FailedToLoadMessage, codebase, ex)); } }
static void Main(string[] args) { try { var parameters = GetParameters(args); var core = new Core(parameters); var extrasFolderCatalog = new DirectoryCatalog(@".\extras\"); var currentAssemblyCatalog = new AssemblyCatalog(typeof(Program).Assembly); var aggregateCatalog = new AggregateCatalog(extrasFolderCatalog, currentAssemblyCatalog); var container = new CompositionContainer(aggregateCatalog); container.ComposeParts(core); core.Run(); Console.WriteLine("Static site created successfully"); if (Debugger.IsAttached) Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); if (Debugger.IsAttached) Console.ReadLine(); Environment.ExitCode = 1; } }
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); } } } }
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; } }
public void runs_script_with_operations_from_both_csharp_and_python() { var currentAssemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly()); var ironPythonScriptCatalog = new IronPythonScriptCatalog( new CompositionHelper().GetResourceScript("Operations.Python.py"), typeof (IMathCheatSheet), typeof (IOperation)); var masterCatalog = new AggregateCatalog(currentAssemblyCatalog, ironPythonScriptCatalog); var container = new CompositionContainer(masterCatalog); var mathWiz = container.GetExportedValue<MathWizard>(); const string mathScript = @"fib 6 fac 6 abs -99 pow 2 4 crc 3 "; var results = mathWiz.ExecuteScript(mathScript).ToList(); Assert.AreEqual(5, results.Count); Assert.AreEqual(8, results[0]); Assert.AreEqual(720, results[1]); Assert.AreEqual(99f, results[2]); Assert.AreEqual(16m, results[3]); Assert.AreEqual(9.4247782230377197d, results[4]); }
public SafeDirectoryCatalog(string directoryPath, string assemblyName = "") { var files = Directory.EnumerateFiles(directoryPath, "*.dll", SearchOption.AllDirectories); _catalog = new AggregateCatalog(); foreach (var file in files) { if (!string.IsNullOrEmpty(assemblyName) && !file.Contains(assemblyName + ".dll")) continue; 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 _catalog.Catalogs.Add(asmCat); } catch (BadImageFormatException) { Console.WriteLine("Ignoring file: " + file); } catch (ReflectionTypeLoadException) { Console.WriteLine("Ignoring file: " + file); } catch (FileLoadException) { Console.WriteLine("Ignoring file: " + file); } } }
public void Init() { try { AggregateCatalog catalog = new AggregateCatalog(); var c1 = new DirectoryCatalog("Extensions"); c1.Refresh(); var c2 = new DirectoryCatalog("EventHandlers"); c2.Refresh(); var c3 = new AssemblyCatalog(Assembly.GetExecutingAssembly()); catalog.Catalogs.Add(c1); catalog.Catalogs.Add(c2); catalog.Catalogs.Add(c3); CompositionContainer container = new CompositionContainer(catalog); container.ComposeParts(this); } catch (Exception ex) { WindowsLogWriter.LogMessage("Error occurred while composing Denso Extensions", System.Diagnostics.EventLogEntryType.Error); WindowsLogWriter.LogException(ex); } foreach (var plugin in Extensions) { plugin.Init(); } EventHandlerManager.AnalyzeCommandHandlers(ImportedHandlers); }
/// <summary> /// This method loads the plugins. /// </summary> private void AssembleComponents() { var catalog = new AggregateCatalog(); //Note: we load not only from the plugins folder, but from this assembly as well. var executingAssemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly()); if (Directory.Exists(Environment.CurrentDirectory + "\\Plugins")) { catalog.Catalogs.Add(new DirectoryCatalog("Plugins")); } catalog.Catalogs.Add(executingAssemblyCatalog); var container = new CompositionContainer(catalog); try { container.ComposeParts(this); } catch (CompositionException compositionException) { _dialogService.ShowMessageAsync(_mainVm, "Error", string.Format("There was an error loading plugins: {0}", compositionException)).Forget(); } }
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; } }
protected override void Initialize() { base.Initialize(); var exceptionDialog = new ExceptionDialog("http://code.google.com/p/notifypropertyweaver/issues/list", "NotifyPropertyWeaver"); try { using (var catalog = new AssemblyCatalog(GetType().Assembly)) using (var container = new CompositionContainer(catalog)) { var menuCommandService = (IMenuCommandService) GetService(typeof (IMenuCommandService)); var errorListProvider = new ErrorListProvider(ServiceProvider.GlobalProvider); container.ComposeExportedValue(exceptionDialog); container.ComposeExportedValue(menuCommandService); container.ComposeExportedValue(errorListProvider); container.GetExportedValue<MenuConfigure>().RegisterMenus(); container.GetExportedValue<SolutionEvents>().RegisterSolutionEvents(); container.GetExportedValue<TaskFileReplacer>().CheckForFilesToUpdate(); } } catch (Exception exception) { exceptionDialog.HandleException(exception); } }
public void ModuleInUnreferencedAssemblyInitializedByModuleInitializer() { AssemblyCatalog assemblyCatalog = new AssemblyCatalog(GetPathToModuleDll()); CompositionContainer compositionContainer = new CompositionContainer(assemblyCatalog); ModuleCatalog moduleCatalog = new ModuleCatalog(); Mock<MefFileModuleTypeLoader> mockFileTypeLoader = new Mock<MefFileModuleTypeLoader>(); compositionContainer.ComposeExportedValue<IModuleCatalog>(moduleCatalog); compositionContainer.ComposeExportedValue<MefFileModuleTypeLoader>(mockFileTypeLoader.Object); bool wasInit = false; var mockModuleInitializer = new Mock<IModuleInitializer>(); mockModuleInitializer.Setup(x => x.Initialize(It.IsAny<ModuleInfo>())).Callback(() => wasInit = true); var mockLoggerFacade = new Mock<ILoggerFacade>(); MefModuleManager moduleManager = new MefModuleManager( mockModuleInitializer.Object, moduleCatalog, mockLoggerFacade.Object); compositionContainer.SatisfyImportsOnce(moduleManager); moduleManager.Run(); Assert.IsTrue(wasInit); }
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"); }
private void Application_Startup(object sender, StartupEventArgs e) { var catalog = new AssemblyCatalog(typeof(App).Assembly); var aggregateCatalog = new AggregateCatalog(catalog); aggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ITopLevelWindow).Assembly)); aggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(MainViewModel).Assembly)); aggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(BaseViewModel).Assembly)); aggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(IExpressionServiceBase).Assembly)); var container = new CompositionContainer(aggregateCatalog); this.Container = container; CompositionHost.Initialize(container); CompositionInitializer.SatisfyImports(this); var settings = UnitTestSystem.CreateDefaultSettings(); var testAssemblies = Deployment.Current.Parts.Where(p => p.Source.Contains("Tests")).ToList(); foreach (var assemblyPart in testAssemblies) { var assembly = new AssemblyPart().Load(GetResourceStream(new Uri(assemblyPart.Source, UriKind.Relative)).Stream); if (!settings.TestAssemblies.Contains(assembly)) { settings.TestAssemblies.Add(assembly); } } RootVisual = UnitTestSystem.CreateTestPage(settings); }
public TreatyHelper() { var catalog = new AssemblyCatalog(this.GetType().Assembly); var container = new CompositionContainer(catalog); this.treaties = container.GetExports<ITreatyProvider>().ToList(); }
/// <summary> /// Конструктор. /// </summary> /// <param name="assemblyDirectory">Путь к каталогу со сборками.</param> /// <param name="searchPattern">Шаблон поиска сборок.</param> /// <exception cref="ArgumentNullException"></exception> public DirectoryAssemblyCatalog(string assemblyDirectory = ".", string searchPattern = "*.dll") { if (string.IsNullOrEmpty(assemblyDirectory)) { throw new ArgumentNullException(nameof(assemblyDirectory)); } if (string.IsNullOrEmpty(searchPattern)) { throw new ArgumentNullException(nameof(searchPattern)); } var catalog = new AggregateCatalog(); var files = Directory.EnumerateFiles(assemblyDirectory, searchPattern, SearchOption.AllDirectories); foreach (var file in files) { try { var assemblyCatalog = new AssemblyCatalog(file); if (assemblyCatalog.Parts.Any()) { catalog.Catalogs.Add(assemblyCatalog); } } catch { } } _catalog = catalog; }
private static void Main(string[] args) { var catalogs = new AggregateCatalog(); var catalog = new System.ComponentModel.Composition.Hosting.AssemblyCatalog(Assembly.GetExecutingAssembly()); catalogs.Catalogs.Add(catalog); var sessionModel = new SessionModel(3); var container = new CompositionContainer(catalog); ISomeService someService = container.GetExportedValueOrDefault <ISomeService>(sessionModel.cname); if (someService != null) { someService.DoSomething(); } }
private void Initialize(string path, string searchPattern) { _path = path; _fullPath = GetFullPath(path); _searchPattern = searchPattern; _assemblyCatalogs = new Dictionary <string, AssemblyCatalog>(); _catalogCollection = new ComposablePartCatalogCollection(null, null, null); _loadedFiles = GetFiles().ToReadOnlyCollection(); foreach (string file in _loadedFiles) { AssemblyCatalog assemblyCatalog = null; assemblyCatalog = CreateAssemblyCatalogGuarded(file); if (assemblyCatalog != null) { _assemblyCatalogs.Add(file, assemblyCatalog); _catalogCollection.Add(assemblyCatalog); } } }
private void Initialize(string path, string searchPattern) { this._path = path; this._fullPath = GetFullPath(path); this._searchPattern = searchPattern; this._assemblyCatalogs = new Dictionary<string, AssemblyCatalog>(); this._catalogCollection = new ComposablePartCatalogCollection(null); this._loadedFiles = GetFiles().ToReadOnlyCollection(); foreach (string file in this._loadedFiles) { AssemblyCatalog assemblyCatalog = null; assemblyCatalog = CreateAssemblyCatalogGuarded(file); if (assemblyCatalog != null) { this._assemblyCatalogs.Add(file, assemblyCatalog); this._catalogCollection.Add(assemblyCatalog); } } this._partsQuery = this._catalogCollection.AsQueryable().SelectMany(catalog => catalog.Parts); }
public void DisposeAggregatingCatalog() { int changedNotification = 0; var typePartCatalog1 = new TypeCatalog(typeof(SharedPartStuff)); var typePartCatalog2 = new TypeCatalog(typeof(SharedPartStuff)); var typePartCatalog3 = new TypeCatalog(typeof(SharedPartStuff)); var assemblyPartCatalog1 = new AssemblyCatalog(typeof(SharedPartStuff).Assembly); var assemblyPartCatalog2 = new AssemblyCatalog(typeof(SharedPartStuff).Assembly); var assemblyPartCatalog3 = new AssemblyCatalog(typeof(SharedPartStuff).Assembly); #if FEATURE_REFLECTIONFILEIO var dirPartCatalog1 = new DirectoryCatalog(FileIO.GetRootTemporaryDirectory()); var dirPartCatalog2 = new DirectoryCatalog(FileIO.GetRootTemporaryDirectory()); var dirPartCatalog3 = new DirectoryCatalog(FileIO.GetRootTemporaryDirectory()); #endif //FEATURE_REFLECTIONFILEIO using (var catalog = new AggregateCatalog()) { catalog.Catalogs.Add(typePartCatalog1); catalog.Catalogs.Add(typePartCatalog2); catalog.Catalogs.Add(typePartCatalog3); catalog.Catalogs.Add(assemblyPartCatalog1); catalog.Catalogs.Add(assemblyPartCatalog2); catalog.Catalogs.Add(assemblyPartCatalog3); #if FEATURE_REFLECTIONFILEIO catalog.Catalogs.Add(dirPartCatalog1); catalog.Catalogs.Add(dirPartCatalog2); catalog.Catalogs.Add(dirPartCatalog3); #endif //FEATURE_REFLECTIONFILEIO // Add notifications catalog.Changed += delegate(object source, ComposablePartCatalogChangeEventArgs args) { // Local code ++changedNotification; }; } Assert.IsTrue(changedNotification == 0, "No changed notifications"); //Ensure that the other catalogs are ExceptionAssert.ThrowsDisposed(typePartCatalog1, () => { var iEnum = typePartCatalog1.Parts.GetEnumerator(); }); ExceptionAssert.ThrowsDisposed(typePartCatalog2, () => { var iEnum = typePartCatalog2.Parts.GetEnumerator(); }); ExceptionAssert.ThrowsDisposed(typePartCatalog3, () => { var iEnum = typePartCatalog3.Parts.GetEnumerator(); }); //Ensure that the other catalogs are ExceptionAssert.ThrowsDisposed(assemblyPartCatalog1, () => { var iEnum = assemblyPartCatalog1.Parts.GetEnumerator(); }); ExceptionAssert.ThrowsDisposed(assemblyPartCatalog2, () => { var iEnum = assemblyPartCatalog2.Parts.GetEnumerator(); }); ExceptionAssert.ThrowsDisposed(assemblyPartCatalog3, () => { var iEnum = assemblyPartCatalog3.Parts.GetEnumerator(); }); #if FEATURE_REFLECTIONFILEIO //Ensure that the other catalogs are ExceptionAssert.ThrowsDisposed(dirPartCatalog1, () => { var iEnum = dirPartCatalog1.Parts.GetEnumerator(); }); ExceptionAssert.ThrowsDisposed(dirPartCatalog2, () => { var iEnum = dirPartCatalog2.Parts.GetEnumerator(); }); ExceptionAssert.ThrowsDisposed(dirPartCatalog3, () => { var iEnum = dirPartCatalog3.Parts.GetEnumerator(); }); #endif //FEATURE_REFLECTIONFILEIO }
private AssemblyCatalogDebuggerProxy CreateAssemblyDebuggerProxy(AssemblyCatalog catalog) { return(new AssemblyCatalogDebuggerProxy(catalog)); }
public AssemblyCatalogDebuggerProxy(AssemblyCatalog catalog) { Requires.NotNull(catalog, nameof(catalog)); _catalog = catalog; }
public void DisposeAggregatingCatalog() { int changedNotification = 0; var typePartCatalog1 = new TypeCatalog(typeof(SharedPartStuff)); var typePartCatalog2 = new TypeCatalog(typeof(SharedPartStuff)); var typePartCatalog3 = new TypeCatalog(typeof(SharedPartStuff)); var assemblyPartCatalog1 = new AssemblyCatalog(typeof(SharedPartStuff).Assembly); var assemblyPartCatalog2 = new AssemblyCatalog(typeof(SharedPartStuff).Assembly); var assemblyPartCatalog3 = new AssemblyCatalog(typeof(SharedPartStuff).Assembly); var dirPartCatalog1 = new DirectoryCatalog(Path.GetTempPath()); var dirPartCatalog2 = new DirectoryCatalog(Path.GetTempPath()); var dirPartCatalog3 = new DirectoryCatalog(Path.GetTempPath()); using (var catalog = new AggregateCatalog()) { catalog.Catalogs.Add(typePartCatalog1); catalog.Catalogs.Add(typePartCatalog2); catalog.Catalogs.Add(typePartCatalog3); catalog.Catalogs.Add(assemblyPartCatalog1); catalog.Catalogs.Add(assemblyPartCatalog2); catalog.Catalogs.Add(assemblyPartCatalog3); catalog.Catalogs.Add(dirPartCatalog1); catalog.Catalogs.Add(dirPartCatalog2); catalog.Catalogs.Add(dirPartCatalog3); // Add notifications catalog.Changed += delegate(object source, ComposablePartCatalogChangeEventArgs args) { // Local code ++changedNotification; }; } Assert.True(changedNotification == 0); //Ensure that the other catalogs are ExceptionAssert.ThrowsDisposed(typePartCatalog1, () => { var iEnum = typePartCatalog1.Parts.GetEnumerator(); }); ExceptionAssert.ThrowsDisposed(typePartCatalog2, () => { var iEnum = typePartCatalog2.Parts.GetEnumerator(); }); ExceptionAssert.ThrowsDisposed(typePartCatalog3, () => { var iEnum = typePartCatalog3.Parts.GetEnumerator(); }); //Ensure that the other catalogs are ExceptionAssert.ThrowsDisposed(assemblyPartCatalog1, () => { var iEnum = assemblyPartCatalog1.Parts.GetEnumerator(); }); ExceptionAssert.ThrowsDisposed(assemblyPartCatalog2, () => { var iEnum = assemblyPartCatalog2.Parts.GetEnumerator(); }); ExceptionAssert.ThrowsDisposed(assemblyPartCatalog3, () => { var iEnum = assemblyPartCatalog3.Parts.GetEnumerator(); }); //Ensure that the other catalogs are ExceptionAssert.ThrowsDisposed(dirPartCatalog1, () => { var iEnum = dirPartCatalog1.Parts.GetEnumerator(); }); ExceptionAssert.ThrowsDisposed(dirPartCatalog2, () => { var iEnum = dirPartCatalog2.Parts.GetEnumerator(); }); ExceptionAssert.ThrowsDisposed(dirPartCatalog3, () => { var iEnum = dirPartCatalog3.Parts.GetEnumerator(); }); }
public AssemblyCatalogDebuggerProxy(AssemblyCatalog catalog) { Requires.NotNull(catalog, "catalog"); this._catalog = catalog; }