private static void LoadPlugins(PluginManager instance, MainWindow mainWindow) { #region Get the Catalog instance.mError = false; ResolveEventHandler reh = new ResolveEventHandler(instance.currentDomain_AssemblyResolve); try { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += reh; AggregateCatalog catalog = instance.CreateCatalog(); var container = new CompositionContainer(catalog); container.ComposeParts(instance); } catch (Exception e) { string error = "Error loading plugins\n"; if (e is ReflectionTypeLoadException) { error += "Error is a reflection type load exception\n"; var loaderExceptions = (e as ReflectionTypeLoadException).LoaderExceptions; foreach (var loaderException in loaderExceptions) { error += "\n" + loaderException.ToString(); } } else { error += "\n" + e.Message; if (e.InnerException != null) { error += "\n Inner Exception:\n" + e.InnerException.Message; } } MessageBox.Show(error); instance.Plugins = new List <PluginBase>(); return; } finally { AppDomain.CurrentDomain.AssemblyResolve -= reh; } #endregion #region Start all plugins foreach (PluginBase plugin in instance.Plugins) { // We used to do this all in an assign references method, // but we now do it here so that the Startup function can have // access to these references. if (plugin is MainWindowPlugin) { ((MainWindowPlugin)plugin).MainWindow = mainWindow; } plugin.MenuStrip = mainWindow.MainMenuStrip; StartupPlugin(plugin, instance); } #endregion }
private static void LoadPlugins(PluginManager instance, MainWindow mainWindow) { #region Get the Catalog instance.mError = false; ResolveEventHandler reh = new ResolveEventHandler(instance.currentDomain_AssemblyResolve); try { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += reh; AggregateCatalog catalog = instance.CreateCatalog(); var container = new CompositionContainer(catalog); container.ComposeParts(instance); } catch (Exception e) { //MessageBox.Show("Error trying to load plugins: \r\n\r\n" + e.ToString(), "Error trying to load plugins"); //instance.TreeViewPlugins = new List<ITreeViewRightClick>(); //instance.PropertyGridRightClickPlugins = new List<IPropertyGridRightClick>(); //instance.NewObjectPlugins = new List<INewObject>(); //instance.OpenVisualStudioPlugins = new List<IOpenVisualStudio>(); //instance.TreeItemSelectPlugins = new List<ITreeItemSelect>(); //instance.NewFilePlugins = new List<INewFile>(); //instance.MenuStripPlugins = new List<IMenuStripPlugin>(); //instance.TopTabPlugins = new List<ITopTab>(); //instance.LeftTabPlugins = new List<ILeftTab>(); //instance.BottomTabPlugins = new List<IBottomTab>(); //instance.RightTabPlugins = new List<IRightTab>(); //instance.CenterTabPlugins = new List<ICenterTab>(); //instance.GluxLoadPlugins = new List<IGluxLoad>(); //instance.NamedObjectsPlugins = new List<INamedObject>(); //instance.CurrentElementPlugins = new List<ICurrentElement>(); //instance.PropertyChangePlugins = new List<IPropertyChange>(); //instance.CodeGeneratorPlugins = new List<ICodeGeneratorPlugin>(); //instance.ContentFileChangePlugins = new List<IContentFileChange>(); //instance.OutputReceiverPlugins = new List<IOutputReceiver>(); string error = "Error loading plugins"; if (e is ReflectionTypeLoadException) { error += "Error is a reflection type load exception\n"; var loaderExceptions = (e as ReflectionTypeLoadException).LoaderExceptions; foreach(var loaderException in loaderExceptions) { error += "\n" + loaderException.ToString(); } } else { error += "\n" + e.Message; if(e.InnerException != null) { error += "\n Inner Exception:\n" + e.InnerException.Message; } } MessageBox.Show(error); instance.Plugins = new List<PluginBase>(); return; } finally { AppDomain.CurrentDomain.AssemblyResolve -= reh; } #endregion #region Start all plugins foreach (PluginBase plugin in instance.Plugins) { // We used to do this all in an assign references method, // but we now do it here so that the Startup function can have // access to these references. if (plugin is MainWindowPlugin) { ((MainWindowPlugin)plugin).MainWindow = mainWindow; } plugin.MenuStrip = mainWindow.MainMenuStrip; StartupPlugin(plugin, instance); } #endregion }
private static void LoadPlugins(PluginManager instance, MainWindow mainWindow) { #region Get the Catalog instance.mError = false; ResolveEventHandler reh = new ResolveEventHandler(instance.currentDomain_AssemblyResolve); try { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += reh; AggregateCatalog catalog = instance.CreateCatalog(); var container = new CompositionContainer(catalog); container.ComposeParts(instance); } catch (Exception e) { //MessageBox.Show("Error trying to load plugins: \r\n\r\n" + e.ToString(), "Error trying to load plugins"); //instance.TreeViewPlugins = new List<ITreeViewRightClick>(); //instance.PropertyGridRightClickPlugins = new List<IPropertyGridRightClick>(); //instance.NewObjectPlugins = new List<INewObject>(); //instance.OpenVisualStudioPlugins = new List<IOpenVisualStudio>(); //instance.TreeItemSelectPlugins = new List<ITreeItemSelect>(); //instance.NewFilePlugins = new List<INewFile>(); //instance.MenuStripPlugins = new List<IMenuStripPlugin>(); //instance.TopTabPlugins = new List<ITopTab>(); //instance.LeftTabPlugins = new List<ILeftTab>(); //instance.BottomTabPlugins = new List<IBottomTab>(); //instance.RightTabPlugins = new List<IRightTab>(); //instance.CenterTabPlugins = new List<ICenterTab>(); //instance.GluxLoadPlugins = new List<IGluxLoad>(); //instance.NamedObjectsPlugins = new List<INamedObject>(); //instance.CurrentElementPlugins = new List<ICurrentElement>(); //instance.PropertyChangePlugins = new List<IPropertyChange>(); //instance.CodeGeneratorPlugins = new List<ICodeGeneratorPlugin>(); //instance.ContentFileChangePlugins = new List<IContentFileChange>(); //instance.OutputReceiverPlugins = new List<IOutputReceiver>(); string error = "Error loading plugins"; if (e is ReflectionTypeLoadException) { error += "Error is a reflection type load exception\n"; var loaderExceptions = (e as ReflectionTypeLoadException).LoaderExceptions; foreach (var loaderException in loaderExceptions) { error += "\n" + loaderException.ToString(); } } else { error += "\n" + e.Message; if (e.InnerException != null) { error += "\n Inner Exception:\n" + e.InnerException.Message; } } MessageBox.Show(error); instance.Plugins = new List <PluginBase>(); return; } finally { AppDomain.CurrentDomain.AssemblyResolve -= reh; } #endregion #region Start all plugins foreach (PluginBase plugin in instance.Plugins) { // We used to do this all in an assign references method, // but we now do it here so that the Startup function can have // access to these references. if (plugin is MainWindowPlugin) { ((MainWindowPlugin)plugin).MainWindow = mainWindow; } plugin.MenuStrip = mainWindow.MainMenuStrip; StartupPlugin(plugin, instance); } #endregion }