/// <summary> /// Rolls back to the state of the counter, and performs the normal rollback. /// </summary> /// <param name="savedState">The saved state for the installation.</param> public override void Rollback(System.Collections.IDictionary savedState) { ConsoleHarness.WriteToConsole(ConsoleColor.White, "Rolling back service {0}.", Configuration.Name); // load the assembly file name and the config ConfigureInstallers(); base.Rollback(savedState); }
/// <summary> /// Installer class, to use run InstallUtil against this .exe /// </summary> /// <param name="savedState">The saved state for the installation.</param> public override void Install(System.Collections.IDictionary savedState) { ConsoleHarness.WriteToConsole(ConsoleColor.White, "Installing service {0}.", Configuration.Name); // install the service ConfigureInstallers(); base.Install(savedState); // wire up the event log source, if provided if (!string.IsNullOrEmpty(Configuration.EventLogSource)) { // create the source if it doesn't exist if (!EventLog.SourceExists(Configuration.EventLogSource)) { EventLog.CreateEventSource(Configuration.EventLogSource, "Application"); } } }
/// <summary> /// Removes the counters, then calls the base uninstall. /// </summary> /// <param name="savedState">The saved state for the installation.</param> public override void Uninstall(System.Collections.IDictionary savedState) { ConsoleHarness.WriteToConsole(ConsoleColor.White, "Un-Installing service {0}.", Configuration.Name); // load the assembly file name and the config ConfigureInstallers(); base.Uninstall(savedState); // wire up the event log source, if provided if (!string.IsNullOrEmpty(Configuration.EventLogSource)) { // create the source if it doesn't exist if (EventLog.SourceExists(Configuration.EventLogSource)) { EventLog.DeleteEventSource(Configuration.EventLogSource); } } }
// Point d'entrée principal de l'application static void Main(string[] args) { try { // si la commande était -i (installer), installation du service au niveau runtime if (args.Contains("-i", StringComparer.InvariantCultureIgnoreCase)) { WindowsServiceInstaller.RuntimeInstall <ServiceImplementation>(); } // si la commande était -u (désinstaller), désinstallation du service au niveau runtime else if (args.Contains("-u", StringComparer.InvariantCultureIgnoreCase)) { WindowsServiceInstaller.RuntimeUnInstall <ServiceImplementation>(); } // Sinon, on lance le service en mode console (program interactif lancé en console ou par l'explorateur) ou en mode service (autres cas) else { var implementation = new ServiceImplementation(); // lancé depuis la console ou l'explorateur windows, on lance dans une console... if (Environment.UserInteractive) { ConsoleHarness.Run(args, implementation); } else // Sinon, on lance en mode service { ServiceBase.Run(new WindowsServiceHarness(implementation)); } } } catch (Exception ex) { ConsoleHarness.WriteToConsole(ConsoleColor.Red, "Exception levée dans Main(): {0}", ex); } }