From 8f551e77f063983007ebc346036cfe894ff09dab Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Wed, 25 Jul 2018 09:24:02 +0200
Subject: [PATCH] Remember config validation warnings and report to the admin

Fixes #51
---
 ATxCommon/Serializables/ServiceConfig.cs | 9 +++++++--
 ATxService/AutoTx.cs                     | 6 ++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/ATxCommon/Serializables/ServiceConfig.cs b/ATxCommon/Serializables/ServiceConfig.cs
index 5c3a480..ef2899f 100644
--- a/ATxCommon/Serializables/ServiceConfig.cs
+++ b/ATxCommon/Serializables/ServiceConfig.cs
@@ -288,6 +288,9 @@ namespace ATxCommon.Serializables
             }
         }
 
+        [XmlIgnore]
+        public static string ValidatorWarnings { get; set; }
+
 
         #endregion
 
@@ -391,8 +394,10 @@ namespace ATxCommon.Serializables
                     SubOptimal(value.ToString(), name, "value is set very high, please check!");
             }
 
-            void SubOptimal(string value, string name, string msg) {
-                Log.Warn(">>> Sub-optimal setting detected: <{0}> [{1}] {2}", name, value, msg);
+            void SubOptimal(string value, string name, string message) {
+                var msg = $">>> Sub-optimal setting detected: <{name}> [{value}] {message}";
+                ValidatorWarnings += msg + "\n";
+                Log.Warn(msg);
             }
 
             void LogAndThrow(string msg) {
diff --git a/ATxService/AutoTx.cs b/ATxService/AutoTx.cs
index 0397a85..c1752fd 100644
--- a/ATxService/AutoTx.cs
+++ b/ATxService/AutoTx.cs
@@ -415,6 +415,12 @@ namespace ATxService
             }
 
             Log.Debug(msg);
+            
+            // finally check if the validation gave warnings and send them to the admin:
+            var warnings = ServiceConfig.ValidatorWarnings;
+            if (string.IsNullOrWhiteSpace(warnings))
+                return;
+            SendAdminEmail(warnings);
         }
 
         #endregion
-- 
GitLab