From 92a9adeca8d6eacfbfa61bc49afb9a0703ee0c60 Mon Sep 17 00:00:00 2001 From: Eric Fontana Date: Tue, 3 Mar 2015 08:23:25 -0500 Subject: [PATCH] Handle quit condition gracefully. --- TimberWinR/Inputs/LogsListener.cs | 26 ++++++++++++++++++-------- TimberWinR/Inputs/TailFileListener.cs | 14 ++++++++++++-- chocolateyUninstall.ps1.template | 2 +- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/TimberWinR/Inputs/LogsListener.cs b/TimberWinR/Inputs/LogsListener.cs index e984f2b..d35ea43 100644 --- a/TimberWinR/Inputs/LogsListener.cs +++ b/TimberWinR/Inputs/LogsListener.cs @@ -21,7 +21,7 @@ using LogRecordSet = Interop.MSUtil.ILogRecordset; using TimberWinR.Parser; namespace TimberWinR.Inputs -{ +{ /// /// Tail a file. /// @@ -317,15 +317,15 @@ namespace TimberWinR.Inputs rs.close(); rs = null; GC.Collect(); - } + } } catch (FileNotFoundException fnfex) { string fn = fnfex.FileName; if (!_fnfmap.ContainsKey(fn)) - LogManager.GetCurrentClassLogger().Warn(fnfex.Message); - + LogManager.GetCurrentClassLogger().Warn(fnfex.Message); + _fnfmap[fn] = fn; } catch (OperationCanceledException oce) @@ -338,10 +338,20 @@ namespace TimberWinR.Inputs } finally { - oLogQuery = null; - // Sleep - if (!Stop) - syncHandle.Wait(TimeSpan.FromSeconds(_pollingIntervalInSeconds), CancelToken); + try + { + oLogQuery = null; + // Sleep + if (!Stop) + syncHandle.Wait(TimeSpan.FromSeconds(_pollingIntervalInSeconds), CancelToken); + } + catch (OperationCanceledException oce) + { + } + catch (Exception ex1) + { + LogManager.GetCurrentClassLogger().Warn(ex1); + } } } } diff --git a/TimberWinR/Inputs/TailFileListener.cs b/TimberWinR/Inputs/TailFileListener.cs index 363b82a..874d191 100644 --- a/TimberWinR/Inputs/TailFileListener.cs +++ b/TimberWinR/Inputs/TailFileListener.cs @@ -306,8 +306,18 @@ namespace TimberWinR.Inputs } finally { - if (!Stop) - syncHandle.Wait(TimeSpan.FromSeconds(_pollingIntervalInSeconds), CancelToken); + try + { + if (!Stop) + syncHandle.Wait(TimeSpan.FromSeconds(_pollingIntervalInSeconds), CancelToken); + } + catch (OperationCanceledException) + { + } + catch (Exception ex1) + { + LogManager.GetCurrentClassLogger().Warn(ex1); + } } } } diff --git a/chocolateyUninstall.ps1.template b/chocolateyUninstall.ps1.template index 7659c85..3e5d46a 100644 --- a/chocolateyUninstall.ps1.template +++ b/chocolateyUninstall.ps1.template @@ -1,7 +1,7 @@ $packageName = 'TimberWinR-${version}' # arbitrary name for the package, used in messages $installerType = 'msi' #only one of these: exe, msi, msu $url = 'http://www.ericfontana.com/TimberWinR/TimberWinR-${version}.0.msi' # download url -$silentArgs = '${PROJECTGUID} /quiet' +$silentArgs = '{593EF0C4-54E0-40D5-A3E3-922CD1C25B9E} /quiet' $validExitCodes = @(0) #please insert other valid exit codes here, exit codes for ms http://msdn.microsoft.com/en-us/library/aa368542(VS.85).aspx UnInstall-ChocolateyPackage "$packageName" "$installerType" "$silentArgs" "$url" -validExitCodes $validExitCodes