/// <summary> /// OnStop stops the service, aborting the init thread, and terminating the program. This replaces the /// ShutdownCommon function, as this will be the exit of the program. /// </summary> protected override void OnStop() { logger.IfInfo("Stopping..."); // Abort main thread, nullify the WaveBox object init.Abort(); // Destroy temp folder if (Directory.Exists(TempFolder)) { // Count of files deleted int i = 0; // Remove any files in folder foreach (string f in Directory.GetFiles(TempFolder)) { File.Delete(f); i++; } // Remove folder Directory.Delete(TempFolder); logger.IfInfo("Deleted temp folder: " + TempFolder + " (" + i + " files)"); } // Stop the server wavebox.Stop(); wavebox = null; logger.IfInfo("Stopped!"); // Gracefully terminate Environment.Exit(0); }
/// <summary> /// Constructor for WaveBox service. Initializes the service and sets up the graceful shutdown /// </summary> public WaveBoxService() { logger.IfInfo("Initializing WaveBoxService"); try { // Name the service this.ServiceName = "WaveBox"; // Register shutdown handlers for Unix or Windows this.RegisterShutdownHandler(); // Detect operating system OS = ServerUtility.DetectOS(); // Now that platform is detected, inject platform-specific classes InjectPlatformSpecificClasses(); // Store version var assembly = Assembly.GetExecutingAssembly().GetName(); BuildVersion = String.Format("{0}.{1}.{2}.{3}", assembly.Version.Major, assembly.Version.Minor, assembly.Version.Build, assembly.Version.Revision); // Build date detection BuildDate = ServerUtility.GetBuildDate(); logger.IfInfo("BuildDate timestamp: " + BuildDate.ToUnixTime()); // Get start up time StartTime = DateTime.UtcNow; // Create WaveBox's temporary folder if (!Directory.Exists(TempFolder)) { Directory.CreateDirectory(TempFolder); logger.IfInfo("Created temp folder: " + TempFolder); } // Instantiate a WaveBox object wavebox = new WaveBoxMain(); // Start it! this.OnStart(); } // Handle any uncaught exceptions catch (Exception e) { ServerUtility.ReportCrash(e, false); } }