Assembly FindAddInAssemblyFromRuntimes(IAddIn addIn) { IAddInRuntime runtime = FindRuntime(addIn); if (runtime != null) { return runtime.LoadedAssembly; } return null; }
public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { try { if (Application is Microsoft.Vbe.Interop.VBE) { var vbe = (VBE)Application; _ide = new VBEditor.SafeComWrappers.VBA.VBE(vbe); VBENativeServices.HookEvents(_ide); var addin = (AddIn)AddInInst; _addin = new VBEditor.SafeComWrappers.VBA.AddIn(addin) { Object = this }; } else if (Application is Microsoft.VB6.Interop.VBIDE.VBE) { var vbe = Application as Microsoft.VB6.Interop.VBIDE.VBE; _ide = new VBEditor.SafeComWrappers.VB6.VBE(vbe); var addin = (Microsoft.VB6.Interop.VBIDE.AddIn)AddInInst; _addin = new VBEditor.SafeComWrappers.VB6.AddIn(addin); } switch (ConnectMode) { case ext_ConnectMode.ext_cm_Startup: // normal execution path - don't initialize just yet, wait for OnStartupComplete to be called by the host. break; case ext_ConnectMode.ext_cm_AfterStartup: InitializeAddIn(); break; } } catch (Exception e) { Console.WriteLine(e); } }
/// <summary> /// Loads the plug in. /// </summary> /// <param name="File">The file.</param> private void LoadPlugIn(FileInfo File) { Assembly ass; try { ass = Assembly.LoadFrom(File.FullName); foreach (Type t in ass.GetTypes()) { foreach (Type i in t.GetInterfaces()) { if (i.FullName == typeof(IAddIn).FullName) { IAddIn plugIn = (IAddIn)System.Activator.CreateInstance(t); BuildButton(plugIn); } } } } catch { throw; } }
/// <summary> /// Returns or creates the local store. /// </summary> /// <returns>The store, or null on error. If a store is returned, the caller is responsible for disposing.</returns> public static IStore GetInstance(IAddIn addIn) { IStore store = OpenOrCreateInstance(addIn); if (store == null) { return(null); } try { HideAllFolders(store); return(store); } catch (Exception e) { store.Dispose(); throw e; } }
private void btnConfigure_Click(object sender, EventArgs e) { if (this.lstLoadedAddIns.SelectedItems.Count > 0) { ListViewItem selected = this.lstLoadedAddIns.SelectedItems[0]; try { IAddIn addIn = (IAddIn)selected.Tag; foreach (IAddInPackage package in addIn.AddInPackages) { IAddInPackageConfiguration cfg = package as IAddInPackageConfiguration; if (cfg != null && cfg.HasConfigurationUI) { cfg.ShowConfigurationUI(this); } } }catch (Exception ex) { MessageBox.Show(this, String.Format(SR.AddInGeneralFailure, ex.Message, selected.SubItems[0].Text)); } } }
void load_file(Assembly assembly) { try { // Load add-ins from this DLL Type[] types = assembly.GetTypes(); foreach (Type t in types) { if (!is_addin(t)) { continue; } // Get the default constructor ConstructorInfo ci = t.GetConstructor(Type.EmptyTypes); if (ci != null) { IAddIn addin = ci.Invoke(null) as IAddIn; if (addin != null) { install(addin); } } } } catch (ReflectionTypeLoadException rtle) { string name = assembly.ManifestModule.Name; LogSystem.Trace("The add-in '" + name + "' could not be loaded; contact the developer for an updated version."); foreach (Exception ex in rtle.LoaderExceptions) { Console.WriteLine(ex); } } catch (Exception ex) { LogSystem.Trace(ex); } }
private void btnAdd_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog() == DialogResult.OK) { // add Add-in try { IAddIn addIn = manager.Load(openFileDialog.FileName); if (addIn != null) { foreach (IAddInPackage package in addIn.AddInPackages) { package.Load(IoC.Resolve <IServiceProvider>()); } ListViewItem item = this.lstLoadedAddIns.Items.Add(new ListViewItem(new string[] { addIn.Name, addIn.Location })); item.Tag = addIn; } } catch (Exception ex) { MessageBox.Show(this, String.Format(SR.AddInLoadFailure, ex.Message, openFileDialog.FileName)); } } }
public IEnumerable <IAddIn> LoadAddIns(string fileSpec) { List <IAddIn> list = new List <IAddIn>(); fileSpec = Environment.ExpandEnvironmentVariables(fileSpec); string path = Path.Combine(Path.GetDirectoryName(this.GetType().Module.FullyQualifiedName), Path.GetDirectoryName(fileSpec)); if (Microsoft.Expression.Framework.Documents.PathHelper.DirectoryExists(path)) { string fileName1 = Path.GetFileName(fileSpec); foreach (string fileName2 in Directory.GetFiles(path, fileName1)) { IAddIn addIn = this.LoadAddIn(fileName2); if (addIn != null) { list.Add(addIn); } } } return((IEnumerable <IAddIn>)list); }
private bool AddInHasConfigurationUI() { if (this.lstLoadedAddIns.SelectedItems.Count > 0) { ListViewItem selected = this.lstLoadedAddIns.SelectedItems[0]; try { IAddIn addIn = (IAddIn)selected.Tag; foreach (IAddInPackage package in addIn.AddInPackages) { IAddInPackageConfiguration cfg = package as IAddInPackageConfiguration; if (cfg != null && cfg.HasConfigurationUI) { return(true); } } }catch (Exception ex) { MessageBox.Show(this, String.Format(SR.AddInGeneralFailure, ex.Message, selected.SubItems[0].Text)); } } return(false); }
/// <summary> /// Builds the button. /// </summary> /// <param name="PlugIn">The plug in.</param> private void BuildButton(IAddIn PlugIn) { ButtonItem PlugInButton = new ButtonItem(); PlugInButton.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton; PlugInButton.ColorTable = DevComponents.DotNetBar.eButtonColor.Office2007WithBackground; if (!string.IsNullOrEmpty(PlugIn.ImageIcon)) { PlugInButton.Image = new Bitmap(new FileStream(PlugIn.ImageIcon, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)); } PlugInButton.Shortcuts.Add(DevComponents.DotNetBar.eShortcut.F5); PlugInButton.Size = new System.Drawing.Size(158, 23); PlugInButton.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; PlugInButton.Text = PlugIn.ButtonName; PlugInButton.Tag = PlugIn; PlugInButton.Click += new EventHandler( delegate(object sender, EventArgs e) { dockAddIn.Visible = true; dockAddIn.Selected = true; dockAddIn.Control.Controls.Clear(); if (!string.IsNullOrEmpty(((sender as ButtonItem).Tag as BaseAddIn).ImageIcon)) { dockAddIn.Image = (sender as ButtonItem).Image; } dockAddIn.Text = (sender as ButtonItem).Text; ((sender as ButtonItem).Tag as BaseAddIn).ASyncSetup = LicenceManager.Instance.LicenceBody; dockAddIn.Control.Controls.Add((sender as ButtonItem).Tag as BaseAddIn); } ); PlugInButton.MouseHover += new EventHandler( delegate(object sender, EventArgs e) { PlugInBar.Text = ((sender as ButtonItem).Tag as BaseAddIn).ButtonName; } ); PlugInButton.ButtonStyle = eButtonStyle.ImageAndText; PlugInButton.Name = string.Format(@"btn_{0}", PlugIn.ButtonName); AppendAddInButton(PlugInButton); }
private void check_dll(string filename, IApplication app) { try { foreach (Type type in Assembly.LoadFrom(filename).GetTypes()) { if (type.GetInterface(typeof(IAddIn).Name) != null) { ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes); if (constructor != null) { try { IAddIn addIn = constructor.Invoke((object[])null) as IAddIn; if (addIn != null) { if (addIn.Load(app)) { this.fAddIns.Add((object)addIn); } else { addIn.Unload(); } } } catch (Exception ex) { LabyrinthData.Log((object)ex); } } } } } catch (Exception ex) { LabyrinthData.Log((object)ex); } }
public static void Main() { // Find the directory that contains the Host exe String AddInDir = Path.GetDirectoryName( Assembly.GetEntryAssembly().Location); // Assume AddIn assemblies are in same directory as host's EXE file String[] AddInAssemblies = Directory.GetFiles(AddInDir, "*.dll"); // Create a collection of usable Add-In Types List <Type> AddInTypes = new List <Type>(); // Load Add-In assemblies; discover which types are usable by the host foreach (String file in AddInAssemblies) { Assembly AddInAssembly = Assembly.LoadFrom(file); // Examine each publicly-exported type foreach (Type t in AddInAssembly.GetExportedTypes()) { // If the type is a class that implements the IAddIn // interface, then the type is usable by the host if (t.IsClass && typeof(IAddIn).IsAssignableFrom(t)) { AddInTypes.Add(t); } } } // Initialization complete: the host has discovered the usable Add-Ins // Here's how the host can construct Add-In objects and use them foreach (Type t in AddInTypes) { IAddIn ai = (IAddIn)Activator.CreateInstance(t); Console.WriteLine(ai.DoSomething(5)); } }
private void load_file(Assembly assembly) { try { Type[] types = assembly.GetTypes(); for (int i = 0; i < (int)types.Length; i++) { Type type = types[i]; if (this.is_addin(type)) { ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes); if (constructor != null) { IAddIn addIn = constructor.Invoke(null) as IAddIn; if (addIn != null) { this.install(addIn); } } } } } catch (ReflectionTypeLoadException reflectionTypeLoadException1) { ReflectionTypeLoadException reflectionTypeLoadException = reflectionTypeLoadException1; string name = assembly.ManifestModule.Name; LogSystem.Trace(string.Concat("The add-in '", name, "' could not be loaded; contact the developer for an updated version.")); Exception[] loaderExceptions = reflectionTypeLoadException.LoaderExceptions; for (int j = 0; j < (int)loaderExceptions.Length; j++) { Console.WriteLine(loaderExceptions[j]); } } catch (Exception exception) { LogSystem.Trace(exception); } }
private void RegisterPipelineRecursive(IAddIn addin, IApplicationBuilder app, IHostEnvironment env, IConfiguration configuration) { addin.AddInPipelineDependencies.ToList().ForEach(dependency => { if (!scannedAddIns.Any(scannedAddIn => scannedAddIn.AddInId == dependency)) { throw new KeyNotFoundException($"The Pipeline AddIn with the id '{dependency}' required by '{addin.AddInId}' was not found."); } }); scannedAddIns .Where(scannedAddIn => scannedAddIn.PipelineState == AddInState.UNLOADED) .Where(scannedAddIn => addin.AddInPipelineDependencies.Any(dependency => dependency == scannedAddIn.AddInId)) .ToList() .ForEach(scannedAddIn => { RegisterPipelineRecursive(scannedAddIn, app, env, configuration); scannedAddIn.Configure(app, env, configuration); scannedAddIn.PipelineState = AddInState.LOADED; }); }
private void RegisterServicesRecursive(IAddIn addin, IServiceCollection services, IConfiguration configuration) { addin.AddInServicesDependencies.ToList().ForEach(dependency => { if (!scannedAddIns.Any(scannedAddIn => scannedAddIn.AddInId == dependency)) { throw new KeyNotFoundException($"The Service AddIn with the id '{dependency}' required by '{addin.AddInId}' was not found."); } }); scannedAddIns .Where(scannedAddIn => scannedAddIn.PipelineState == AddInState.UNLOADED) .Where(scannedAddIn => addin.AddInServicesDependencies.Any(dependency => dependency == scannedAddIn.AddInId)) .ToList() .ForEach(scannedAddIn => { RegisterServicesRecursive(scannedAddIn, services, configuration); scannedAddIn.ConfigureService(services, configuration); scannedAddIn.ServicesState = AddInState.LOADED; }); }
public CodeExplorerDockablePresenter(IVBE vbe, IAddIn addIn, CodeExplorerWindow view, IConfigurationService <WindowSettings> settings) : base(vbe, addIn, view, settings) { }
public InspectionResultsDockablePresenter(IVBE vbe, IAddIn addin, InspectionResultsWindow window, IConfigProvider <WindowSettings> settings) : base(vbe, addin, window, settings) { }
public async Task OnStart(IAddIn addIn) { this.AddIn = addIn; }
private static List <AddInDefinition> LoadAddInDefinitions() { string addInPath = GetAddInDirectory(); if (!Directory.Exists(addInPath)) { return(new List <AddInDefinition>()); } string[] addinAssemblyFilenames = Directory.GetFiles(addInPath, "*.addin", SearchOption.AllDirectories); List <AddInDefinition> result = new List <AddInDefinition>(); List <Type> addInTypes = new List <Type>(); foreach (string addinAssemblyFilename in addinAssemblyFilenames) { Assembly addInAssembly = Assembly.LoadFrom(addinAssemblyFilename); Type[] exportedTypes = addInAssembly.GetExportedTypes(); foreach (Type exportedType in exportedTypes) { if (!exportedType.IsAbstract && !exportedType.IsInterface) { Type[] interfaces = exportedType.GetInterfaces(); bool implementsIAddIn = Array.IndexOf(interfaces, typeof(IAddIn)) >= 0; if (implementsIAddIn) { ConstructorInfo defaultConstructor = exportedType.GetConstructor(new Type[0]); if (defaultConstructor != null) { addInTypes.Add(exportedType); } else { string error = String.Format("Add-in type '{0}' does not provide a public default constructor.", exportedType.FullName); AddInDefinition addInDefinition = new AddInDefinition(exportedType, null, error); result.Add(addInDefinition); } } } } } foreach (Type addInType in addInTypes) { AddInDefinition addInDefinition; try { IAddIn addIn = (IAddIn)Activator.CreateInstance(addInType); addInDefinition = new AddInDefinition(addInType, addIn, null); } catch (Exception ex) { string error = String.Format("Cannot create instance of add-in type '{0}': {1}", addInType.FullName, ex); addInDefinition = new AddInDefinition(addInType, null, error); } result.Add(addInDefinition); } return(result); }
public AddInDefinition(Type addInType, IAddIn instance, string error) { _addInType = addInType; _instance = instance; _error = error; }
public ToolWindowInfo CreateToolWindow(IAddIn addInInst, string progId, string caption, string guidPosition) { var window = new Mock <IWindow>(); return(new ToolWindowInfo(window.Object, null)); }
public TestExplorerDockablePresenter(IVBE vbe, IAddIn addin, TestExplorerWindow view, IConfigProvider <WindowSettings> settings) : base(vbe, addin, view, settings) { }
public ImplementationsListDockablePresenter(IVBE vbe, IAddIn addin, IDockableUserControl control, IEnumerable <Declaration> implementations) : base(vbe, addin, control, null) { BindTarget(implementations); }
public SearchResultsDockablePresenter(IVBE vbe, IAddIn addin, IDockableUserControl view) : base(vbe, addin, view, null) { }
IAddInRuntime FindRuntime(IAddIn addIn) { var addinRuntime = new AddInAssemblyRuntime(addIn); return addinRuntime.Runtime; }
private void ShutdownAddIn() { var currentDomain = AppDomain.CurrentDomain; try { _logger.Log(LogLevel.Info, "Rubberduck is shutting down."); _logger.Log(LogLevel.Trace, "Unhooking VBENativeServices events..."); VbeNativeServices.UnhookEvents(); VbeProvider.Terminate(); _logger.Log(LogLevel.Trace, "Releasing dockable hosts..."); using (var windows = _vbe.Windows) { windows.ReleaseDockableHosts(); } if (_app != null) { _logger.Log(LogLevel.Trace, "Initiating App.Shutdown..."); _app.Shutdown(); _app = null; } if (_container != null) { _logger.Log(LogLevel.Trace, "Disposing IoC container..."); _container.Dispose(); _container = null; } } catch (Exception e) { _logger.Error(e); _logger.Log(LogLevel.Warn, "Exception is swallowed."); //throw; // <<~ uncomment to crash the process } finally { try { _logger.Log(LogLevel.Trace, "Disposing COM safe..."); ComSafeManager.DisposeAndResetComSafe(); _addin = null; _vbe = null; _isInitialized = false; _logger.Log(LogLevel.Info, "No exceptions were thrown."); } catch (Exception e) { _logger.Error(e); _logger.Log(LogLevel.Warn, "Exception disposing the ComSafe has been swallowed."); //throw; // <<~ uncomment to crash the process } finally { _logger.Log(LogLevel.Trace, "Unregistering AppDomain handlers...."); currentDomain.AssemblyResolve -= LoadFromSameFolder; currentDomain.UnhandledException -= HandlAppDomainException; _logger.Log(LogLevel.Trace, "Done. Main Shutdown completed. Toolwindows follow. Quack!"); _isInitialized = false; } } }
public async Task OnStart(IAddIn addIn) { await Task.Run(() => { this.AddIn = addIn; }); }
public SearchResultPresenterInstanceManager(IVBE vbe, IAddIn addin) { _vbe = vbe; _addin = addin; _view = new SearchResultWindow(); }
public AddInAssemblyRuntime(IAddIn addIn) { this.addIn = addIn; GetFileName(); GetRuntime(); }
public RubberduckIoCInstaller(IVBE vbe, IAddIn addin, GeneralSettings initialSettings) { _vbe = vbe; _addin = addin; _initialSettings = initialSettings; }
/// <summary> /// Builds the button. /// </summary> /// <param name="PlugIn">The plug in.</param> private void BuildButton(IAddIn PlugIn) { ButtonX PlugInButton = new ButtonX(); PlugInButton.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton; PlugInButton.ColorTable = DevComponents.DotNetBar.eButtonColor.Office2007WithBackground; PlugInButton.Dock = System.Windows.Forms.DockStyle.Top; if(!string.IsNullOrEmpty(PlugIn.ImageIcon)) PlugInButton.Image = new Bitmap(new FileStream(PlugIn.ImageIcon, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) ; PlugInButton.Location = new System.Drawing.Point(0, 0); PlugInButton.Shortcuts.Add(DevComponents.DotNetBar.eShortcut.F5); PlugInButton.Size = new System.Drawing.Size(158, 23); PlugInButton.TextAlignment = eButtonTextAlignment.Left; PlugInButton.Padding = new System.Windows.Forms.Padding(20); PlugInButton.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; PlugInButton.Text = PlugIn.ButtonName ; PlugInButton.Tag = PlugIn; PlugInButton.Click += new EventHandler( delegate(object sender, EventArgs e) { dockAddIn.Visible = true; dockAddIn.Control.Controls.Clear(); if(!string.IsNullOrEmpty(((sender as ButtonX).Tag as BaseAddIn).ImageIcon)) dockAddIn.Image = (sender as ButtonX).Image; dockAddIn.Text = (sender as ButtonX).Text; ((sender as ButtonX).Tag as BaseAddIn).ASyncSetup = LicenceManager.Instance.LicenceBody; dockAddIn.Control.Controls.Add((sender as ButtonX).Tag as BaseAddIn); //MessageBox.Show((sender as ButtonX).Text); } ); PlugInButton.Name = string.Format(@"btn_{0}", PlugIn.ButtonName); AppendAddInButton(PlugInButton); }
IAddInRuntime FindRuntime(IAddIn addIn) { var addinRuntime = new AddInAssemblyRuntime(addIn); return(addinRuntime.Runtime); }
public ZPushAccounts(ZPushWatcher watcher, IAddIn addIn) { this._watcher = watcher; this._addIn = addIn; this._stores = addIn.Stores; }
private static int compare_addins(IAddIn x, IAddIn y) { return(x.Name.CompareTo(y.Name)); }
public bool Matches(IAddIn addIn) { return CompareIgnoringCase(assemblyShortName, addIn.PrimaryIdentity); }