From d1e07260aed0798abda33cc9cc4053fbc8c7618c Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch> Date: Fri, 19 Jan 2018 14:59:31 +0100 Subject: [PATCH] Report invalid status attributes directly to log. With proper logging in place this is now easily doable, therefore we don't need the "ValidationWarnings" workaround any more. Refers to #3 --- ATXCommon/Serializables/ServiceStatus.cs | 21 +++++++++++++-------- AutoTx/AutoTx.cs | 4 ---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ATXCommon/Serializables/ServiceStatus.cs b/ATXCommon/Serializables/ServiceStatus.cs index 19da781..2d3a07e 100644 --- a/ATXCommon/Serializables/ServiceStatus.cs +++ b/ATXCommon/Serializables/ServiceStatus.cs @@ -13,7 +13,6 @@ namespace ATXCommon.Serializables { [XmlIgnore] private string _storageFile; // remember where we came from [XmlIgnore] private ServiceConfig _config; - [XmlIgnore] public string ValidationWarnings; [XmlIgnore] private static readonly Logger Log = LogManager.GetCurrentClassLogger(); private DateTime _lastStatusUpdate; @@ -221,23 +220,29 @@ namespace ATXCommon.Serializables // CurrentTransferSrc if (s.CurrentTransferSrc.Length > 0 && !Directory.Exists(s.CurrentTransferSrc)) { - s.ValidationWarnings += " - found non-existing source path of an unfinished " + - "transfer: " + s.CurrentTransferSrc + "\n"; + ReportInvalidStatus("CurrentTransferSrc", s.CurrentTransferSrc, + "invalid transfer source path"); s.CurrentTransferSrc = ""; } // CurrentTargetTmp - var currentTargetTmpPath = Path.Combine(s._config.DestinationDirectory, - s._config.TmpTransferDir, - s.CurrentTargetTmp); + var currentTargetTmpPath = s.CurrentTargetTmpFull(); if (s.CurrentTargetTmp.Length > 0 && !Directory.Exists(currentTargetTmpPath)) { - s.ValidationWarnings += " - found non-existing temporary path of an " + - "unfinished transfer: " + currentTargetTmpPath + "\n"; + ReportInvalidStatus("CurrentTargetTmpPath", currentTargetTmpPath, + "invalid temporary path of an unfinished transfer"); s.CurrentTargetTmp = ""; } } + /// <summary> + /// Print a standardized msg about an invalid status attribute to the log. + /// </summary> + private static void ReportInvalidStatus(string attribute, string value, string msg) { + Log.Warn(">>> Invalid status parameter detected, resetting:\n - <{0}> [{1}] {2}.", + attribute, value, msg); + } + /// <summary> /// Generate a human-readable sumary of the current transfer. /// </summary> diff --git a/AutoTx/AutoTx.cs b/AutoTx/AutoTx.cs index 9ec0344..1920273 100644 --- a/AutoTx/AutoTx.cs +++ b/AutoTx/AutoTx.cs @@ -309,10 +309,6 @@ namespace AutoTx SendAdminEmail(warn); } - if (!string.IsNullOrEmpty(_status.ValidationWarnings)) { - Log.Warn("WARNING: some status parameters were invalid and have been reset:\n{0}", - _status.ValidationWarnings); - } Log.Debug(msg); } -- GitLab