/// <summary> /// Handle the service shutting down. /// </summary> protected override void OnStop() { if (RunThread != null && RunThread.ThreadState == ThreadState.Running) { RunThread.Abort(); } MM_Notification.Notify("Macomber Map Service Shutting Down", "The Macomber Map Service is shutting down."); }
/// <summary> /// Start up the full Macomber Map server /// </summary> public static void StartServer() { ApplicationName = Assembly.GetCallingAssembly().GetCustomAttribute <AssemblyProductAttribute>().Product; ApplicationVersion = Assembly.GetCallingAssembly().GetCustomAttribute <AssemblyFileVersionAttribute>().Version; MM_Notification.WriteLine(ConsoleColor.Green, ApplicationName + " " + ApplicationVersion + " starting up."); MM_Notification.Notify("SERVER: Macomber Map Service starting", "The Macomber Map Service is starting, ConsoleMode=" + Environment.UserInteractive.ToString()); StartTime = DateTime.Now; //Start our EMS TCP listener MM_EMSReader_TCP.Initialize(); MM_EMSReader_File.Initialize(); //Start our database service MM_Database_Connector.StartServer(); //Start our PI interface MM_Historic_Reader.StartServer(); //If we have commands, pull them in DateTime BatchDate = DateTime.Now; if (File.Exists(Properties.Settings.Default.CommandFileLocation)) { using (StreamReader sRd = new StreamReader(Properties.Settings.Default.CommandFileLocation)) MM_EMSReader_File.ProcessStreamRead(sRd, Properties.Settings.Default.CommandFileLocation, typeof(MM_EMS_Command), ref BatchDate); } //Start our WCF interfaces MacomberMapServerAddress = Settings.Default.MacomberMapServerAddress.Split(',')[0].Replace("localhost", Dns.GetHostEntry(IPAddress.Loopback).HostName); ServerURI = new Uri(MacomberMapServerAddress); Instance_MMServer = StartWCFServer <MM_WCF_Interface>(Settings.Default.MacomberMapServerAddress.Split(',')); Instance_AdminServer = StartWCFServer <MM_Administrator_Types>(Settings.Default.MacomberMapAdministratorAddress.Split(',')); ThreadPool.QueueUserWorkItem(new WaitCallback(MeasureSystemState)); ThreadPool.QueueUserWorkItem(new WaitCallback(SendUDPMessage)); ThreadPool.QueueUserWorkItem(new WaitCallback(WriteTrainingGameHtmlFile)); Thread.Sleep(Timeout.Infinite); }