public void Refresh_AssemblyRemoved_ShouldFireOnChanged() { string file = Path.Combine(TemporaryFileCopier.GetNewTemporaryDirectory(), "Test.dll"); File.Copy(Assembly.GetExecutingAssembly().Location, file); bool changedFired = false; var cat = new DirectoryCatalog(TemporaryFileCopier.GetNewTemporaryDirectory()); cat.Changed += new EventHandler <ComposablePartCatalogChangeEventArgs>((o, e) => changedFired = true); // This assembly can be deleted because it was already loaded by the CLR in another context // in another location so it isn't locked on disk. File.Delete(file); cat.Refresh(); Assert.True(changedFired); }
private void LoadPlugins() { try { if (!Directory.Exists(@".\Plugins")) { return; } var catalog = new DirectoryCatalog(@".\Plugins", "CInject.Plugin.*.dll"); catalog.Refresh(); var container = new CompositionContainer(catalog); Plugins = container.GetExportedValues <IPlugin>(); var pluginArray = Plugins as IPlugin[] ?? Plugins.ToArray(); PluginList = pluginArray.ToList(); Parallel.ForEach(pluginArray, (current) => { try { if (current.Menu != null) { PopulatePluginMenu(current); } } catch { } }); } catch (AggregateException aggregateException) { string message = String.Concat(aggregateException.InnerExceptions.Select(x => x.Message)); MessageBox.Show(Resources.PluginLoadErrorAggregate + message); } catch (Exception exception) { MessageBox.Show(Resources.PluginLoadErrorAggregate + exception.Message); } }
private void RescanIfRequired() { if (Manifest == null) { Manifest = ManifestLoader.LoadDefaultManifest(); PluginsExt = ManifestLoader.LoadPlugins(Manifest); } directoryCatalog.Refresh(); var loadedFiles = directoryCatalog.LoadedFiles; var scannedFiles = Manifest?.ScannedAssemblies ?? Array.Empty <AssemblyInfo>(); var isRequireScan = loadedFiles.Count != scannedFiles.Length; if (!isRequireScan) { for (var i = 0; i < loadedFiles.Count; i++) { var loadedFileName = loadedFiles[i].ToLower(); var scannedFile = scannedFiles[i]; var loadedVersion = AssemblyName.GetAssemblyName(loadedFileName).Version.ToString(); var scannedVersion = scannedFile.Version; if (loadedFileName != scannedFile.Name.ToLower() || loadedVersion != scannedVersion) { isRequireScan = true; break; } } } if (isRequireScan) { LoadParts(); } if (Plugins == null) { Plugins = ManifestLoader.LoadPlugins <IPluginMetadata>(Manifest); } }
public void Run() { var catalog = new AggregateCatalog(); var directoryCatalog = new DirectoryCatalog(Directory.GetCurrentDirectory()); catalog.Catalogs.Add(new AssemblyCatalog(typeof(Program).Assembly)); catalog.Catalogs.Add(directoryCatalog); var container = new CompositionContainer(catalog); container.ComposeExportedValue(Logger.GetLogger()); container.ComposeParts(this); while (true) { directoryCatalog.Refresh(); Transformer.Transform(); Console.ReadLine(); } }
public void InitializeContainer() { catalog = new DirectoryCatalog(Properties.Settings.Default.AddInDirectory); container = new CompositionContainer(catalog); calImport = new CalculatorImport(); calcExtensionImport = new CalculatorExtensionImport(); container.ComposeParts(calImport); catalog.Refresh(); container.ComposeParts(calcExtensionImport); InitializeOperations(); InitializeCalculatorExtensions(); }
public void Run() { var catalog = new AggregateCatalog(); var directoryCatalog = new DirectoryCatalog( @"C:\Users\Jeremy Likness\Documents\Wintellect\Projects\Pearson\Code\MyFirstMEFSln\MyFirstMEF\bin\Debug\plugins"); catalog.Catalogs.Add(new AssemblyCatalog(typeof(Program).Assembly)); catalog.Catalogs.Add(new AssemblyCatalog(typeof(IDataTransform).Assembly)); catalog.Catalogs.Add(directoryCatalog); var container = new CompositionContainer(catalog); container.ComposeParts(this); while (true) { directoryCatalog.Refresh(); Transformer.Transform(); Console.ReadLine(); } }
static void Main() { DirectoryCatalog dirCat = new DirectoryCatalog(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "*.dll"); AggregateCatalog catalog = new AggregateCatalog(new AssemblyCatalog(Assembly.GetExecutingAssembly()), dirCat); CompositionContainer container = new CompositionContainer(catalog); AddinManager mgr = container.GetExportedValue <AddinManager>(); // AddinManager mgr = new AddinManager(); // container.ComposeParts(mgr); mgr.InitPlugins(); mgr.Display(); Console.WriteLine("Press ENTER to recompose"); Console.ReadLine(); // recompose dirCat.Refresh(); mgr.InitPlugins(); Console.ReadLine(); }
public void RefreshExtensions() { dirCatalog.Refresh(); menuAddins.Items.Clear(); foreach (var extension in imports.readerExtCollection) { var menuItemHeader = new StackPanel { Orientation = Orientation.Horizontal }; menuItemHeader.Children.Add(new Label { Content = extension.Value.Name }); var menuItem = new MenuItem { Header = menuItemHeader, ToolTip = extension.Value.Description, Tag = extension }; menuItem.Click += ShowAddIn; menuAddins.Items.Add(menuItem); } }
private void _ButtonClick(object sender, RoutedEventArgs e) { try { var compositionBatch = new CompositionBatch(); compositionBatch.AddExportedValue <IPluginPart>(new DynamicPart(new SquarePart())); compositionBatch.AddExportedValue <IPluginPart>(new DynamicPart(new TextPart())); _mainContainer.Compose(compositionBatch); if (_directoryCatalog == null) { _directoryCatalog = new DirectoryCatalog(Directory.GetCurrentDirectory()); _mainCatalog.Catalogs.Add(_directoryCatalog); } else { _directoryCatalog.Refresh(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Refresh the plugin catalog. /// </summary> public void Load() { // Check if environmental settings are correct: if (!Directory.Exists(PluginDirectory)) { throw new PluginHostException("Could not find plug-in directory!"); } if (Simulators != null || Widgets != null || Extensions != null) { throw new PluginHostException("Can only load plug-ins from a clean set of lists."); } var simulatorsToDrop = new List <IPluginSimulator>(); var widgetsToDrop = new List <IPluginWidget>(); var extensionsToDrop = new List <IPluginExtension>(); Simulators = new List <IPluginSimulator>(); Widgets = new List <IPluginWidget>(); Extensions = new List <IPluginExtension>(); // Try to refresh DLL's from the plugin directory: try { PluginCatalog = new DirectoryCatalog(PluginDirectory, "SimTelemetry.Plugins.*.dll"); PluginCatalog.Refresh(); PluginContainer = new CompositionContainer(PluginCatalog); PluginContainer.ComposeParts(this); } catch (ReflectionTypeLoadException ex) { foreach (var exc in ex.LoaderExceptions) { GlobalEvents.Fire(new DebugWarning("Error whilst importing plugin namespaces; the following type couldn't be loaded correctly.", exc), false); } throw new PluginHostException("Could not initialize plug-ins!", ex); } catch (CompositionException ex) { foreach (var exc in ex.Errors) { GlobalEvents.Fire(new DebugWarning("Error whilst importing plugin namespaces; the following type couldn't be loaded correctly.", exc.Exception), false); } throw new PluginHostException("Could not initialize plug-ins!", ex); } catch (Exception ex) { throw new PluginHostException("Could not initialize plug-ins!", ex); } if (Simulators == null) { throw new PluginHostException("Simulators aren't properly initialized"); } if (Widgets == null) { throw new PluginHostException("Widgets aren't properly initialized"); } if (Extensions == null) { throw new PluginHostException("Extensions aren't properly initialized"); } // Initialize all plug-ins foreach (var sim in Simulators) { string simName = "??"; try { simName = sim.Name; sim.Initialize(); } catch (Exception ex) { simulatorsToDrop.Add(sim); GlobalEvents.Fire(new DebugWarning("Unloading simulator plugin '" + simName + "' (assembly " + ex.Source + "), exception was thrown during initialize()", ex), false); } } Simulators = Simulators.Where(x => !simulatorsToDrop.Contains(x)).ToList(); foreach (var widget in Widgets) { string widgetName = "??"; try { widgetName = widget.Name; widget.Initialize(); } catch (Exception ex) { widgetsToDrop.Add(widget); GlobalEvents.Fire(new DebugWarning("Unloading widget plugin '" + widgetName + "' (assembly " + ex.Source + "), exception was thrown during initialize()", ex), false); } } Widgets = Widgets.Where(x => !widgetsToDrop.Contains(x)).ToList(); foreach (var ext in Extensions) { string extName = "??"; try { extName = ext.Name; ext.Initialize(); } catch (Exception ex) { extensionsToDrop.Add(ext); GlobalEvents.Fire(new DebugWarning("Unloading extension plugin '" + extName + "' (assembly " + ex.Source + "), exception was thrown during initialize()", ex), false); } } Extensions = Extensions.Where(x => !extensionsToDrop.Contains(x)).ToList(); // Fire PluginsLoaded event var loadEvent = new PluginsLoaded { Simulators = Simulators, Widgets = Widgets, Extensions = Extensions, FailedSimulators = simulatorsToDrop, FailedWidgets = widgetsToDrop, FailedExtensions = extensionsToDrop }; GlobalEvents.Fire(loadEvent, true); }
private void OnAssemblyChanged(object sender, FileSystemEventArgs e) { dirCatalog.Refresh(); FilterModules(); }
public void Recompose() { _pluginCatalog.Refresh(); }
/// <summary> /// Reloads plugins from the directory associated to this object. /// </summary> public void Refresh() { _catalog.Refresh(); }
private void OnDependencyChanged(FileChangedEventArgs e) { _directoryCatalog.Refresh(); }
void OnChanged(object o, FileSystemEventArgs a) { DirectoryCatalog.Refresh(); }
void watcher_Renamed(object sender, RenamedEventArgs e) { Out.WriteLine("Plugins Renamed"); directoryCatalog.Refresh(); }
private void OnExtensionCatalogChanged(object source, FileSystemEventArgs e) { _dirCatalog.Refresh(); ComposeExtensions(); }
public void Recompose() { directoryCatalog.Refresh(); container.ComposeParts(directoryCatalog.Parts); }
public void Refresh() { _pluginsdirectoryCatalog.Refresh(); }