protected override void Dispose(bool disposing) { FileSystemWatcher.Dispose(); DirectoryCatalog.Dispose(); base.Dispose(disposing); }
public void Unload() { pluginCatalog.Dispose(); pluginCatalog = null; WorldDocuments.Clear(); TreeEntries.Clear(); WorldDocuments = null; }
protected virtual void Dispose(bool disposing) { if (!isDisposed) { if (disposing) { _catalog.Dispose(); _container.Dispose(); } } isDisposed = true; }
internal static Collection <T> GetExportedPlugins <T>(string directory, string searchPattern = "*.dll") { Collection <T> plugins = new Collection <T>(); DirectoryCatalog catalog = new DirectoryCatalog(directory, searchPattern); CompositionContainer container = new CompositionContainer(catalog); try { foreach (var plugin in container.GetExportedValues <T>()) { plugins.Add(plugin); } } finally { catalog.Dispose(); container.Dispose(); } return(plugins); }
private IImportClient FindClient( string pluginDirectory, ImportConnectionInfo connectionInfo, ImportContext context) { container?.Dispose(); catalog?.Dispose(); // We can add logic here to check for multiple constructions of the import client from the same app domain, // but with different version requests. Compare the plugin directory that was passed in, against a static plugin // directory variable -----------------NOTE - is this not already happening in the calling method? // Note: You MUST use a specific enough filename filter for your plugins and prevent MEF from trying // to do things like load native binaries. this.catalog = new DirectoryCatalog(pluginDirectory, "Relativity.DataExchange.Wrapper.*.dll"); this.container = new CompositionContainer(catalog); this.ImportClients.Clear(); container.ComposeExportedValue("ImportConnectionInfo", connectionInfo); container.ComposeExportedValue("ImportContext", context); container.ComposeParts(this); if (this.ImportClients.Count == 0) { throw new InvalidOperationException( "The import cannot be completed because no plugins were discovered."); } List <Lazy <IImportClient> > candidates = this.ImportClients.ToList(); if (candidates.Count > 1) { throw new InvalidOperationException( "The import cannot be completed because more than 1 plugin was discovered."); } IImportClient client = candidates[0].Value; return(client); }
public void Dispose() { catalog.Dispose(); container.Dispose(); }
public void Dispose() { _catalog.Dispose(); _container.Dispose(); }
public void Dispose() { RootContainer.Dispose(); _rootCatalog.Dispose(); }
public void Dispose() { _fileWatcher?.Dispose(); _container?.Dispose(); _catalog?.Dispose(); }
internal void Register(IList <Tuple <string, string> > pathsToScan) { RegisteringEventArgs rea = new RegisteringEventArgs(); OnRegistering(rea); AggregateCatalog aggc = new AggregateCatalog(); List <DirectoryCatalog> catalogs = new List <DirectoryCatalog>(); List <ComposablePartDefinition> parts = new List <ComposablePartDefinition>(); foreach (var pathScan in pathsToScan) { string folder = String.IsNullOrEmpty(pathScan.Item1) ? System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) : pathScan.Item1; //Default if empty string path = System.IO.Path.Combine(folder, pathScan.Item2); //Full path if (!catalogs.Exists(x => System.IO.Path.Combine(x.FullPath.ToUpperInvariant(), x.SearchPattern).ToUpperInvariant() == path.ToUpperInvariant())) { //Check if same path is already loaded DirectoryCatalog dc = new DirectoryCatalog(folder, pathScan.Item2); if (dc.Parts.All(x => parts.Exists(y => y.ToString() == x.ToString()))) {//Check all parts, same assembly with different name or same assembly in two differents locations dc.Dispose(); } else { parts.AddRange(dc.Parts); if (dc.LoadedFiles.Count() > 0) {//Only add if assemblies loaded catalogs.Add(dc); for (int i = 0; i < catalogs.IndexOf(dc); i++) { if (catalogs.ElementAt(i).LoadedFiles.Intersect(dc.LoadedFiles).Count() > 0) { //There are similar files if (catalogs.ElementAt(i).LoadedFiles.Count() > dc.LoadedFiles.Count()) { //One of them could have more files than another, take the higher catalogs.Remove(dc); } else { catalogs.Remove(catalogs.ElementAt(i)); } } } } } } } catalogs.ForEach(x => aggc.Catalogs.Add(x)); aggc.Catalogs.Add(rea.TypeCatalog); ContainerSimple = new CompositionContainer(aggc, CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe); var scopeDefDependent = new CompositionScopeDefinition(ContainerSimple.Catalog, null); var appCatalog = new TypeCatalog(typeof(ApplicationFactory <>)); var scopeDefRoot = new CompositionScopeDefinition(appCatalog, new[] { scopeDefDependent }); ContainerFactory = new CompositionContainer(scopeDefRoot, CompositionOptions.IsThreadSafe); OnRegistered(new RegisteredEventArgs(this.ContainerSimple, this.ContainerFactory)); }