From d25b62823c5ff6e8b80ce26c3f66f19b6519fd4f Mon Sep 17 00:00:00 2001 From: Eric Fontana Date: Wed, 1 Oct 2014 07:47:51 -0400 Subject: [PATCH] Fixed problem with Uninstaller and Shutdown handling of Diagnostic service. --- .../Properties/AssemblyInfo.cs | 4 +- TimberWinR/Diagnostics/Diagnostics.cs | 45 +++++++++++++------ TimberWinR/Manager.cs | 2 + TimberWix/Product.wxs | 4 +- 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/TimberWinR.ServiceHost/Properties/AssemblyInfo.cs b/TimberWinR.ServiceHost/Properties/AssemblyInfo.cs index 043414a..dcbc49a 100644 --- a/TimberWinR.ServiceHost/Properties/AssemblyInfo.cs +++ b/TimberWinR.ServiceHost/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.2.0")] -[assembly: AssemblyFileVersion("1.3.2.0")] +[assembly: AssemblyVersion("1.3.3.0")] +[assembly: AssemblyFileVersion("1.3.3.0")] diff --git a/TimberWinR/Diagnostics/Diagnostics.cs b/TimberWinR/Diagnostics/Diagnostics.cs index ad8dde8..e3f1d78 100644 --- a/TimberWinR/Diagnostics/Diagnostics.cs +++ b/TimberWinR/Diagnostics/Diagnostics.cs @@ -20,7 +20,7 @@ namespace TimberWinR.Diagnostics private CancellationToken CancelToken { get; set; } public int Port { get; set; } public Manager Manager { get; set; } - + private HttpListener web; public Diagnostics(Manager manager, CancellationToken cancelToken, int port = 5141) @@ -29,7 +29,7 @@ namespace TimberWinR.Diagnostics CancelToken = cancelToken; Manager = manager; - LogManager.GetCurrentClassLogger().Info("Diagnostic(v4/v6) on Port {0} Ready", Port); + LogManager.GetCurrentClassLogger().Info("Diagnostic(v4/v6) on Port {0} Ready", Port); var hl = new Thread(new ParameterizedThreadStart(HttpListen)); hl.Start(null); @@ -42,11 +42,13 @@ namespace TimberWinR.Diagnostics } private void DiagnosticCallback(IAsyncResult result) - { + { + if (web == null) + return; + var context = web.EndGetContext(result); var response = context.Response; - JObject json = new JObject( new JProperty("timberwinr", new JObject( @@ -80,16 +82,20 @@ namespace TimberWinR.Diagnostics private void HttpListen(object o) { web = new HttpListener(); - web.Prefixes.Add(string.Format("http://*:{0}/", Port)); - web.Start(); - - while (web.IsListening) + try { - processRequest(); + web.Prefixes.Add(string.Format("http://*:{0}/", Port)); + web.Start(); + + while (web != null && web.IsListening) + { + processRequest(); + } } - - web.Stop(); - + catch (Exception ex) + { + LogManager.GetCurrentClassLogger().Error("Diagnostic Listener Error: {0}", ex.ToString()); + } } private void ListenForClients(object olistener) @@ -168,7 +174,20 @@ namespace TimberWinR.Diagnostics public void Shutdown() { - + + try + { + if (web != null && web.IsListening) + { + LogManager.GetCurrentClassLogger().Info("Shutting down diagnostics listener"); + web.Close(); + web = null; + } + } + catch (Exception ex) + { + LogManager.GetCurrentClassLogger().Error(ex); + } } } diff --git a/TimberWinR/Manager.cs b/TimberWinR/Manager.cs index f7b8901..52dca6e 100644 --- a/TimberWinR/Manager.cs +++ b/TimberWinR/Manager.cs @@ -91,6 +91,8 @@ namespace TimberWinR LogManager.GlobalThreshold = LogLevel.FromString(logLevel); + LogManager.GetCurrentClassLogger() + .Info("TimberWinR Version {0}", GetAssemblyByName("TimberWinR.ServiceHost").GetName().Version.ToString()); // Is it a directory? if (Directory.Exists(jsonConfigFile)) diff --git a/TimberWix/Product.wxs b/TimberWix/Product.wxs index 04e183c..2ea72df 100644 --- a/TimberWix/Product.wxs +++ b/TimberWix/Product.wxs @@ -1,6 +1,6 @@ - + default.json c:\logs @@ -17,7 +17,7 @@ - +