/// <summary> /// Removes a component from the manager. If the component is a /// package, it is disabled for execution. All components are disposed upon removal. /// </summary> /// <param name="component">The component to remove.</param> public override void Remove(IComponent component) { if (component is GuidancePackage) { GuidancePackage package = (GuidancePackage)component; if (DisablingPackage != null) { CancelPackageEventArgs args = new CancelPackageEventArgs( package, false); DisablingPackage(this, args); if (args.Cancel) { return; } } base.Remove(package); if (DisabledPackage != null) { DisabledPackage(this, new PackageEventArgs(package)); } package.Dispose(); } else { base.Remove(component); component.Dispose(); } }
void OnEnablingPackage(object sender, CancelPackageEventArgs e) { if (recipeFrameworkOutputWindow == null) { recipeFrameworkOutputWindow = new OutputWindowService(); recipeFrameworkOutputWindow.Site = new Site((IServiceContainer)this, recipeFrameworkOutputWindow, recipeFrameworkOutputWindow.WindowName); ((IServiceContainer)this).AddService(typeof(IOutputWindowService), recipeFrameworkOutputWindow); } // if a new solution is being created this means packages are enabled for the first time // so gNav should show by default if (!isOpeningSolution) { // if the user explicitly added a 'AutoShowGuidanceNavigator' set to 0 in the registry // the following condition won't match and then we'll refrain from showing if (AutoShowGuidanceNavigator()) { ShowGuidanceNavigatorWindow(); } } // if a solution is being opened else { DTE dte = (DTE)GetService(typeof(DTE)); if (dte.Globals.get_VariableExists(GNavAutoClosedKey)) { bool autoClosed = (bool)dte.Globals[GNavAutoClosedKey]; if (autoClosed) { ShowGuidanceNavigatorWindow(); } } } }
void rms_EnablingPackage(object sender, CancelPackageEventArgs e) { enabledGuidancePackages = rms.GetEnabledPackages(); if (BindedPackagesChange != null) { BindedPackagesChange(sender, e); } }
/// <summary> /// Adds a package to the manager, enabling it for use. /// </summary> /// <param name="component">The package component.</param> /// <param name="name">Optional name (can be <see langword="null"/>) /// that must match the package name.</param> /// <remarks> /// This method is also called to add to the container services that /// inherit from <see cref="IComponent"/>, so the type of the component /// is not enforced. Just special logic is applied to package component types. /// </remarks> public override void Add(IComponent component, string name) { if (component == null) { throw new ArgumentNullException("component"); } if (component is GuidancePackage) { GuidancePackage package = (GuidancePackage)component; if (name != null && name != package.Configuration.Name) { throw new ArgumentException(String.Format( System.Globalization.CultureInfo.CurrentCulture, Properties.Resources.RecipeManager_NameDoesntMatch, name, package.Configuration.Caption)); } // If there's a host listening, query for name to see if they match. IHostService host = GetService <IHostService>(); if (host != null && host.HostName != package.Configuration.Host) { throw new ArgumentException(String.Format( System.Globalization.CultureInfo.CurrentCulture, Properties.Resources.RecipeManager_PackageHostMismatch, package.Configuration.Caption, package.Configuration.Host, host.HostName)); } try { // Force the package to be sited at Enabling event time also. base.Add(component, package.Configuration.Name); bool executebinding = true; if (EnablingPackage != null) { CancelPackageEventArgs args = new CancelPackageEventArgs( package, false); EnablingPackage(this, args); if (args.Cancel) { base.Remove(component); return; } executebinding = args.ExecuteBindingRecipe; } if (executebinding && package.Configuration.BindingRecipe != null && package.Configuration.BindingRecipe.Length > 0) { package.TurnOnOutput(); package.Execute(package.Configuration.BindingRecipe); package.TurnOffOutput(); } if (EnabledPackage != null) { EnabledPackage(this, new PackageEventArgs(package)); } } catch { // Notify host that we're disabling. if (DisablingPackage != null) { DisablingPackage(this, new CancelPackageEventArgs(package, false)); } // Don't let the package be enabled if an exception happened. base.Remove(component); if (DisabledPackage != null) { DisabledPackage(this, new PackageEventArgs(package)); } package.GetService <IPersistenceService>(true).ClearState(package.Configuration.Name); throw; } } else { // Just add the component so it gets sited. // Services that implement IComponent will arrive here. base.Add(component, name); } }
public void DisablingPackage(object sender, CancelPackageEventArgs args) { Flags[1] = true; args.Cancel = cancelDisable; }