using System; using System.Data; using System.IO; using System.ServiceProcess; using FilterAPI; using FilterRest.LocalHandlers; using FilterRest.LocalNetworking; using FilterRest.RestNetworking; namespace FilterRest { public partial class _FilterRest : ServiceBase { public _FilterRest() { } public void Init() { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Program.Conf = new Config(); Program.SQL = new Database(Program.Conf); Program.LocalHandlers = new LocalHandlerLoader(); Program.LocalClient = new LocalClient(); RestListener RListen = new RestListener(); } protected override void OnStart(string[] args) { Init(); } protected override void OnStop() { var SQLState = Program.SQL.Connection.State; if (SQLState.HasFlag(ConnectionState.Open)) { Program.SQL.Connection.Close(); } Program.LocalClient.Dispose(); Environment.Exit(0); } private void CurrentDomain_UnhandledException(Object Sender, UnhandledExceptionEventArgs Args) { File.WriteAllLines(String.Format("{0}{1}Crash.txt", AppDomain.CurrentDomain.BaseDirectory, AppDomain.CurrentDomain.FriendlyName.Replace(".exe", "")), new String[] { ((Exception)Args.ExceptionObject).ToString() }); Program.SendConsoleText(ConsoleColor.Red, ((Exception)Args.ExceptionObject).ToString()); } } }