public ModuleService() { var path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var catalog = new DirectoryCatalog(path); _container = new CompositionContainer(catalog); _container.SatisfyImportsOnce(this); }
public MainApplication(string pluginFolder) { var catalog = new DirectoryCatalog(pluginFolder); _container = new CompositionContainer(catalog); LoadPlugins(); }
public void Initialize() { try { directoryCatalog = new DirectoryCatalog(PluginPath); var catalog = new AggregateCatalog(); catalog.Catalogs.Add(directoryCatalog); container = new CompositionContainer(catalog); container.ComposeParts(this); } catch (ReflectionTypeLoadException ex) { if (ex.LoaderExceptions.Length == 1) { throw ex.LoaderExceptions[0]; } var sb = new StringBuilder(); var i = 1; sb.AppendLine("Multiple Exception Occured Attempting to Intialize the Plugin Manager"); foreach (var exception in ex.LoaderExceptions) { sb.AppendLine("Exception " + i++); sb.AppendLine(exception.ToString()); sb.AppendLine(); sb.AppendLine(); } throw new ReflectionTypeLoadException(ex.Types, ex.LoaderExceptions, sb.ToString()); } }
void LoadPlugins() { try{ var pluginsPath = Utils.MapPath("~/plugins"); if (!Directory.Exists(pluginsPath)) { plugins = Enumerable.Empty<IPlugin>(); return; } var catalog = new DirectoryCatalog(pluginsPath); var container = new CompositionContainer(catalog); container.SatisfyImportsOnce(this); } catch (Exception err) { //swallow error log.WriteError(String.Format("error during loading plugins: {0}", err.Message)); dbg.Break(); plugins = Enumerable.Empty<IPlugin>(); } foreach (var p in plugins) { try { p.Init(); } catch (Exception err) { //swallow error log.WriteError(String.Format("error during plugin initialization: {0}", err.Message)); dbg.Break(); } } }
/// <summary> /// Creates a <see cref="CompositionContainer"/>. /// </summary> /// <returns>A <see cref="CompositionContainer"/>.</returns> public CompositionContainer CreateContainer() { string path = HostingEnvironment.MapPath("~/bin"); var catalog = new DirectoryCatalog(path); return new CompositionContainer(catalog); }
protected override void ConfigureAggregateCatalog() { base.ConfigureAggregateCatalog(); try { this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(GetType().Assembly)); //verify the need for this this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ICommandHandler).Assembly)); //modules loading this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(MyFirstMefPluginModule).Assembly)); this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(NavigationTreePluginModule).Assembly)); //this could be discovered dynamically (in case that behavior is needed) //NOTE: theres is an after build copy event that copies the plugin into the bin folder of this app var pluginsDirectory = Path.Combine(Directory.GetCurrentDirectory(), "plugins"); if (!Directory.Exists(pluginsDirectory)) Directory.CreateDirectory(pluginsDirectory); var directoryCatalog = new DirectoryCatalog(pluginsDirectory); this.AggregateCatalog.Catalogs.Add(directoryCatalog); } catch (CompositionException ex) { Console.WriteLine("#### COMPOSITION EXCEPTION:"); Console.WriteLine(ex.Message); } }
private static IDependencyResolver BuildDependencyResolver() { var catalog = new DirectoryCatalog("."); var container = new CompositionContainer(catalog); var resolver = container.GetExportedValue<IDependencyResolver>(); return resolver; }
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); } }
public void ComposeParts(object target) { var path = PathProvider.BinaryPath; var directoryCatalog = new DirectoryCatalog(path); var container = new CompositionContainer(directoryCatalog); container.ComposeParts(target); }
private static void ComposeConnectionFactory() { try { using (var catalog = new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory)) using (var container = new CompositionContainer(catalog)) { var export = container.GetExportedValueOrDefault<IConnectionFactory>(); if (export != null) { Factory = export; Console.WriteLine("Using {0}", Factory.GetType()); } } } catch (ImportCardinalityMismatchException) { Console.WriteLine("More than one IConnectionFactory import was found."); } catch (Exception e) { Console.WriteLine(e); } if (Factory == null) { Factory = new DefaultConnectionFactory(); Console.WriteLine("Using default connection factory..."); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); //Model去除前后空格 //ModelBinders.Binders.DefaultBinder = new TrimModelBinder(); //设置Controller工厂 //ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory()); //设置MEF依赖注入容器 DirectoryCatalog catalog = new DirectoryCatalog(AppDomain.CurrentDomain.SetupInformation.PrivateBinPath); MefDependencySolver solver = new MefDependencySolver(catalog); DependencyResolver.SetResolver(solver); //Unity注入 Ioc IUnityContainer container = new DependencyRegisterType().GetUnityContainer(); DependencyResolver.SetResolver(new UnityDependencyResolver(container)); //初始化策略 //Database.SetInitializer(new SampleDataInitializer()); //或者在仓储层封装个方法,把上句封装起来 //DatabaseInitializer.Initialize(); }
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; } }
private void AddSources() { var p = Path.Combine(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory), "bin"); var catalog = new DirectoryCatalog(p, "*.dll"); var container = new CompositionContainer(catalog); container.ComposeParts(this); if (null != this._eventSource) this.Application.Add("EventSource", this._eventSource); if(null != this._picSource) { if(this._picSource.RequiresCredentials) { PictureCredentials creds; string apiKey = ConfigurationManager.AppSettings["photoAPIKey"]; string secretKey = ConfigurationManager.AppSettings["photoSecretKey"]; if (!string.IsNullOrEmpty(apiKey)) creds = new PictureCredentials(apiKey, secretKey); else creds = new PictureCredentials(System.IO.File.ReadAllLines(@"c:\temp\flickrcred.txt")); this._picSource.Init(creds); } this.Application.Add("PhotoSource", this._picSource); } if(null != this._voteSource) this.Application.Add("VoteSource", this._voteSource); if(null != this._claimSource) this.Application.Add("ClaimSource", this._claimSource); if (null != this._doorSource) this.Application.Add("DoorSource", this._doorSource); }
public MefControllerFactory(string pluginPath) { this._pluginPath = pluginPath; this._catalog = new DirectoryCatalog(pluginPath); this._container = new CompositionContainer(_catalog); this._defaultControllerFactory = new DefaultControllerFactory(); }
public MainWindow() { InitializeComponent(); pathToGit = new FileInfo(@"C:\Program Files (x86)\Git\bin\git.exe"); try { DirectoryCatalog catalog = new DirectoryCatalog(new FileInfo(Assembly.GetAssembly(typeof (MainWindow)).Location).DirectoryName); CompositionContainer container = new CompositionContainer(catalog); container.ComposeParts(this); } catch (CompositionException) { sqlParser = null; } var vm = new MainWindowViewModel(Properties.Settings.Default.Databases); vm.SourceChangeset = (DvcsScriptRepositoryBase.RevisionIdentifierBase)Properties.Settings.Default.LastChangeset ?? Properties.Settings.Default.LastTag; if (vm.SourceChangeset != null) { vm.SelectedSourceType = RevisionIdentifierConverter.GetLabelFromType(vm.SourceChangeset.GetType()); } var riConverter = (RevisionIdentifierConverter)Resources["riConverter"]; riConverter.DataContext = vm; DataContext = vm; }
private static void DemoProgram(string serializedGraph = "AB5, BC4, CD8, DC8, DE6, AD5, CE2, EB3, AE7") { IRequestManager reqMan; // Production code would usually load the directory from config var catalog = new DirectoryCatalog(@"..\..\..\Plugins"); var container = new CompositionContainer(catalog); reqMan = container.GetExportedValue<IRequestManager>(); reqMan.LoadGraph(serializedGraph); //Questions 1 to 5 string routes = "ABC,AD,ADC,AEBCD,AED"; var number = 0; var answer = ""; routes.Split(',').ToList().ForEach(r => { number += 1; Console.WriteLine(reqMan.DistanceRequest(r, number)); }); //Question 6 Console.WriteLine(reqMan.NumberofTripsMaxStops('C', 'C', 3, 6)); //Question 7 Console.WriteLine(reqMan.NumberofTripsExactStops('A', 'C', 4, 7)); //Question 8 Console.WriteLine(reqMan.ShortestRoute('A', 'C', 8)); //Question 9 Console.WriteLine(reqMan.ShortestRoute('B', 'B', 9)); //Question 10 Console.WriteLine(reqMan.NumberOfTripsMaxDistance('C', 'C', 30, 10)); }
public void DiscoverServices(IServicePool pool) { var registration = new RegistrationBuilder(); registration.ForTypesDerivedFrom<IService>().SelectConstructor((ConstructorInfo[] cInfo) => { if (cInfo.Length == 0) return null; return cInfo[0]; }).Export<IService>(); var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); var catalog = new DirectoryCatalog(path, registration); var container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); var services = container.GetExportedValues<IService>(); foreach (var service in services) { service.ServicePool = pool; var interfaces = service.GetType().GetInterfaces(); Type interfaceType = null; foreach (var i in interfaces) { var name = i.FullName; if (!name.Contains("Contracts.IService") && !name.Contains("System.")) { interfaceType = i; break; } } pool.AddService(interfaceType, service); } }
public MainViewModel() { // Initialize MEF var catalog = new DirectoryCatalog("Tricks"); _container = new CompositionContainer(catalog); _container.ComposeParts(this); var tricks = new List<TrickViewModel>(); foreach (var trick in _tricks) { var Trick = new TrickViewModel { Name = trick.Metadata.Name, Description = trick.Metadata.Description }; tricks.Add(Trick); } Tabs = new ObservableCollection<TabItem> { new TabItem { Header = "All Tricks", IsSelected = true, Content = new TricksTab(tricks) } }; Messenger.Default.Register<LoadMessage>(this, (m) => OnLoadTab(m.Trick)); }
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 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); }
public PluginContainer() { var registration = new RegistrationBuilder(); registration.ForTypesDerivedFrom<BasicPlugin>() .SetCreationPolicy(CreationPolicy.Shared) .Export<BasicPlugin>(); bool tryAgain = true; while (tryAgain) { try { DirectoryCatalog dircat = new DirectoryCatalog(PluginDirectory, registration); tryAgain = false; Container = new CompositionContainer(dircat, CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe); Container.ComposeParts(); } catch (DirectoryNotFoundException) { Directory.CreateDirectory(PluginDirectory); } } }
private static IEnumerable<IPlugin> GetPlugins() { var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "."; var catalog = new DirectoryCatalog(path, PluginSearchPattern); var container = new CompositionContainer(catalog); return container.GetExportedValues<IPlugin>(); }
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"); }
public static void LoadContainer(IUnityContainer container, string path, string pattern) { var directoryCatalog = new DirectoryCatalog(path, pattern); var importDefinition = BuildImportDefinition(); try { using (var aggregateCatalog = new AggregateCatalog()) { aggregateCatalog.Catalogs.Add(directoryCatalog); using (var componsitionContainer = new CompositionContainer(aggregateCatalog)) { IEnumerable<Export> exports = componsitionContainer.GetExports(importDefinition); IEnumerable<IModule> modules = exports.Select(export => export.Value as IModule).Where(m => m != null); foreach (IModule module in modules) { module.Initialize(container); } } } } catch (ReflectionTypeLoadException typeLoadException) { var builder = new StringBuilder(); foreach (Exception loaderException in typeLoadException.LoaderExceptions) { builder.AppendFormat("{0}\n", loaderException.Message); } throw new TypeLoadException(builder.ToString(), typeLoadException); } }
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; }
public ExtensionRuleStore(string path, ILogger logger) { if (string.IsNullOrEmpty(path)) { throw new ArgumentException(Resource.ArgumentNotNullOrEmpty, "path"); } using (var catalog = new AggregateCatalog()) { try { var directoryCatalog = new DirectoryCatalog(path); catalog.Catalogs.Add(directoryCatalog); using (var container = new CompositionContainer(catalog)) { container.ComposeParts(this); } } catch (Exception ex) { if (!ExceptionHelper.IsCatchableExceptionType(ex)) { throw; } RuntimeException.WrapAndLog(ex, Resource.InvalidExtensionRules + ":" + path, logger); } } }
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; } }
private static CompositionContainer Init() { log.Debug("AddinHost.Init started"); DirectoryCatalog catalog = null; var aggregateCatalog = new AggregateCatalog(); if (ConfigHelper.GetConfigValue("AddinPath") != null && Directory.Exists(Directory.GetCurrentDirectory() + "\\" + ConfigHelper.GetConfigValue("AddinPath")) ) { var path = Directory.GetCurrentDirectory() + "\\" + ConfigHelper.GetConfigValue("AddinPath"); catalog = new DirectoryCatalog(path); log.Debug("AddinPath:" + path); aggregateCatalog.Catalogs.Add(catalog); } string currentpath = @".\"; var currentcatalog = new DirectoryCatalog(currentpath); aggregateCatalog.Catalogs.Add(currentcatalog); var container = new CompositionContainer(aggregateCatalog); log.Debug("AddinHost.Init finished"); return container; }
protected override void ConfigureAggregateCatalog() { base.ConfigureAggregateCatalog(); string AssemblyDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); AssemblyDir += System.IO.Path.DirectorySeparatorChar + "Modules"; //Load files in module directory and all sub directories IEnumerable<string> ModuleDirectories = System.IO.Directory.EnumerateDirectories(AssemblyDir, "*", SearchOption.TopDirectoryOnly); foreach (string dir in ModuleDirectories) { /* string[] files = System.IO.Directory.GetFiles(dir, "*.dll"); foreach(string dll in files) { System.Reflection.Assembly a = System.Reflection.Assembly.LoadFile(dll); AssemblyCatalog assemblyCat = new AssemblyCatalog(a); AggregateCatalog.Catalogs.Add(assemblyCat); } */ Trace.WriteLine("Adding aggregate catalog for " + dir); DirectoryCatalog dirCat = new DirectoryCatalog(dir); AggregateCatalog.Catalogs.Add(dirCat); } }
/// <summary> /// By default, we are configured to use MEF /// </summary> protected override void Configure() { // Add all assemblies to AssemblySource (using a temporary DirectoryCatalog). var directoryCatalog = new DirectoryCatalog(@"./"); AssemblySource.Instance.AddRange( directoryCatalog.Parts .Select(part => ReflectionModelServices.GetPartType(part).Value.Assembly) .Where(assembly => !AssemblySource.Instance.Contains(assembly))); // Prioritise the executable assembly. This allows the client project to override exports, including IShell. // The client project can override SelectAssemblies to choose which assemblies are prioritised. var priorityAssemblies = SelectAssemblies().ToList(); var priorityCatalog = new AggregateCatalog(priorityAssemblies.Select(x => new AssemblyCatalog(x))); var priorityProvider = new CatalogExportProvider(priorityCatalog); // Now get all other assemblies (excluding the priority assemblies). var mainCatalog = new AggregateCatalog( AssemblySource.Instance .Where(assembly => !priorityAssemblies.Contains(assembly)) .Select(x => new AssemblyCatalog(x))); var mainProvider = new CatalogExportProvider(mainCatalog); Container = new CompositionContainer(priorityProvider, mainProvider); priorityProvider.SourceProvider = Container; mainProvider.SourceProvider = Container; var batch = new CompositionBatch(); BindServices(batch); batch.AddExportedValue(mainCatalog); Container.Compose(batch); }
public void Init() { var catalogTypeOf = new System.ComponentModel.Composition.Hosting.DirectoryCatalog("."); var container = new CompositionContainer(catalogTypeOf); container.ComposeParts(this); Console.WriteLine(Import.Message); }
public static void LoadContainer(IUnityContainer container, string path, string pattern) { var dirCat = new System.ComponentModel.Composition.Hosting.DirectoryCatalog(path, pattern); var importDef = BuildImportDefinition(); try { using (var aggregateCatalog = new AggregateCatalog()) { aggregateCatalog.Catalogs.Add(dirCat); using (var componsitionContainer = new CompositionContainer(aggregateCatalog)) { IEnumerable <Export> exports = componsitionContainer.GetExports(importDef); IEnumerable <IComponent> modules = exports.Select(export => export.Value as IComponent).Where(m => m != null); var registerComponent = new RegisterComponent(container); foreach (IComponent module in modules) { module.SetUp(registerComponent); } } } } catch (ReflectionTypeLoadException typeLoadException) { var builder = new StringBuilder(); foreach (Exception loaderException in typeLoadException.LoaderExceptions) { builder.AppendFormat("{0}\n", loaderException.Message); } throw new TypeLoadException(builder.ToString(), typeLoadException); } }
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 }
public DirectoryCatalogDebuggerProxy(DirectoryCatalog catalog) { Requires.NotNull(catalog, "catalog"); this._catalog = catalog; }
public DirectoryCatalogDebuggerProxy(DirectoryCatalog 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(); }); }