public void Initialize() { ValidationErrors = new Dictionary <string, string>(); try { directoryCatalog = new DirectoryCatalog(PluginPath); var catalog = new AggregateCatalog(); catalog.Catalogs.Add(directoryCatalog); container = new CompositionContainer(catalog); container.ComposeParts(this); ValidatePlugins(); } catch (ReflectionTypeLoadException ex) { ValidationErrors = new Dictionary <string, string>(); foreach (var exception in ex.LoaderExceptions) { var assemblies = ex.Types.Select(t => t?.Assembly.FullName ?? "").Distinct(); foreach (var assembly in assemblies) { ValidationErrors.Add(assembly, exception.Message); } } var ipForm = new InvalidPluginsForm(ValidationErrors); ipForm.TopMost = true; ipForm.ShowDialog(); throw; } }
public void Recompose() { try { directoryCatalog.Refresh(); container.ComposeParts(directoryCatalog.Parts); ValidatePlugins(); } catch (ReflectionTypeLoadException e) { ValidationErrors = new Dictionary <string, string>(); foreach (var exception in e.LoaderExceptions) { var assemblies = e.Types.Select(t => t?.Assembly.FullName ?? "").Distinct(); foreach (var assembly in assemblies) { if (!ValidationErrors.ContainsKey(assembly)) { ValidationErrors.Add(assembly, exception.Message); } } } var ipForm = new InvalidPluginsForm(ValidationErrors) { TopMost = true }; ipForm.ShowDialog(); } }
public void Initialize(Form parentForm) { ValidationErrors = new Dictionary <string, string>(); var watcher = new FileSystemWatcher(PluginPath) { EnableRaisingEvents = true, Filter = "*.dll", NotifyFilter = NotifyFilters.FileName, SynchronizingObject = parentForm }; watcher.Created += watcher_EventRaised; try { directoryCatalog = new DirectoryCatalog(PluginPath); var catalog = new AggregateCatalog(); catalog.Catalogs.Add(directoryCatalog); container = new CompositionContainer(catalog); container.ComposeParts(this); ValidatePlugins(); } catch (ReflectionTypeLoadException ex) { ValidationErrors = new Dictionary <string, string>(); foreach (var exception in ex.LoaderExceptions) { var assemblies = ex.Types.Select(t => t?.Assembly.FullName ?? "").Distinct(); foreach (var assembly in assemblies.Select(a => string.IsNullOrWhiteSpace(a) ? "unknown" : a)) { if (ValidationErrors.ContainsKey(assembly) && ValidationErrors[assembly] == exception.Message) { // Don't repeat exact same assembly/error continue; } var i = 0; var assemblykey = assembly; while (ValidationErrors.ContainsKey(assemblykey)) { // Don't try to add same assembly name, dictionary will explode assemblykey = $"{assembly} ({++i})"; } ValidationErrors.Add(assemblykey, exception.Message); } } var ipForm = new InvalidPluginsForm(ValidationErrors); ipForm.TopMost = true; ipForm.ShowDialog(); throw; } }
public void Initialize(Form parentForm) { ValidationErrors = new Dictionary <string, string>(); var watcher = new FileSystemWatcher(PluginPath) { EnableRaisingEvents = true, Filter = "*.dll", NotifyFilter = NotifyFilters.FileName, SynchronizingObject = parentForm }; watcher.Created += watcher_EventRaised; try { directoryCatalog = new DirectoryCatalog(PluginPath); var catalog = new AggregateCatalog(); catalog.Catalogs.Add(directoryCatalog); container = new CompositionContainer(catalog); container.ComposeParts(this); ValidatePlugins(); } catch (ReflectionTypeLoadException ex) { ValidationErrors = new Dictionary <string, string>(); foreach (var exception in ex.LoaderExceptions) { var assemblies = ex.Types.Select(t => t?.Assembly.FullName ?? "").Distinct(); foreach (var assembly in assemblies) { ValidationErrors.Add(assembly, exception.Message); } } var ipForm = new InvalidPluginsForm(ValidationErrors); ipForm.TopMost = true; ipForm.ShowDialog(); throw; } }