/// <include file='doc\UserNTServiceDesigner.uex' path='docs/doc[@for="UserNTServiceDesigner.OnAddInstallerVerb"]/*' /> /// <devdoc> /// called when the user clicks the Add Installer hotlink for a service /// </devdoc> private void OnAddInstallerVerb(object sender, EventArgs e) { IComponent ourComponent = Component; // the thing we're the designer for. // find the Installer document in the project that holds all the installers. IDesignerHost host = InstallerDesign.GetProjectInstallerDocument(ourComponent); // create the ServiceInstaller for this service ServiceInstaller serviceInstaller = new ServiceInstaller(); // make sure the installer knows about this service. This will add a new // ServiceInstaller to the Installers collection on the ServiceProcessInstaller. serviceInstaller.CopyFromComponent(ourComponent); // get the components in our container IContainer container = host.Container; ComponentCollection components = container.Components; ServiceProcessInstaller processInstaller = null; // see if there is already an equivalent installer added foreach (IComponent comp in components) { ServiceInstaller other = comp as ServiceInstaller; if (other != null) { if (serviceInstaller.IsEquivalentInstaller(other)) { InstallerDesign.SelectComponent(other); return; } } } // go through the installers in that document and look for a ServiceProcessInstaller foreach (IComponent comp in components) { if (comp is ServiceProcessInstaller) { // we found one processInstaller = (ServiceProcessInstaller)comp; break; } } if (processInstaller == null) { // there weren't any UserNTServiceProcessInstallers. // create a new one, and add it to the document processInstaller = new ServiceProcessInstaller(); container.Add(processInstaller); } // now add that installer to the document too. container.Add(serviceInstaller); // select it InstallerDesign.SelectComponent(serviceInstaller); }
/// <include file='doc\PerformanceCounterDesigner.uex' path='docs/doc[@for="PerformanceCounterDesigner.OnAddInstallerVerb"]/*' /> /// <devdoc> /// called when the user clicks the Add Installer hotlink for a PerformanceCounter /// </devdoc> private void OnAddInstallerVerb(object sender, EventArgs e) { IComponent ourComponent = Component; // the thing we're the designer for. // counter is the component we're installing PerformanceCounter counter = (PerformanceCounter)ourComponent; PerformanceCounterInstaller newInstaller = new PerformanceCounterInstaller(); newInstaller.CopyFromComponent(counter); // find the Installer document in the project that holds all the installers. IDesignerHost host = InstallerDesign.GetProjectInstallerDocument(ourComponent); // go through the installers in that document and look for one that // is already installing the same category as our component. IContainer container = host.Container; ComponentCollection components = container.Components; PerformanceCounterInstaller installer = null; foreach (IComponent comp in components) { if (comp is PerformanceCounterInstaller && ((PerformanceCounterInstaller)comp).CategoryName.Equals(counter.CategoryName)) { // we found one that we can use installer = (PerformanceCounterInstaller)comp; break; } } if (installer == null) { installer = newInstaller; container.Add(installer); } // select the installer InstallerDesign.SelectComponent(installer); }
private void OnAddInstallerVerb(object sender, EventArgs e) { InstallerDesign.AddInstaller(Component); }