From b55ef5c24f84f5d24890ef03e9839fee012566e6 Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Mon, 18 Sep 2017 18:27:44 +0200
Subject: [PATCH] Make LimitReason part of the status.

---
 AutoTx/AutoTx.cs           | 12 ++++++------
 AutoTx/SystemChecks.cs     |  1 -
 AutoTx/XmlConfiguration.cs | 10 ++++++++++
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/AutoTx/AutoTx.cs b/AutoTx/AutoTx.cs
index eacf7e0..1ce2303 100644
--- a/AutoTx/AutoTx.cs
+++ b/AutoTx/AutoTx.cs
@@ -419,8 +419,8 @@ namespace AutoTx
             // all parameters within valid ranges, so set the state to "Running":
             if (string.IsNullOrEmpty(limitReason)) {
                 _serviceSuspended = false;
-                if (!string.IsNullOrEmpty(_lastLimitReason)) {
-                    _lastLimitReason = ""; // reset to force a message on next service suspend
+                if (!string.IsNullOrEmpty(_status.LimitReason)) {
+                    _status.LimitReason = ""; // reset to force a message on next service suspend
                     writeLog("Service resuming operation (all parameters in valid ranges).");
                 }
                 return;
@@ -429,8 +429,8 @@ namespace AutoTx
             // set state to "Running" if no-one is logged on:
             if (NoUserIsLoggedOn()) {
                 _serviceSuspended = false;
-                if (!string.IsNullOrEmpty(_lastLimitReason)) {
-                    _lastLimitReason = ""; // reset to force a message on next service suspend
+                if (!string.IsNullOrEmpty(_status.LimitReason)) {
+                    _status.LimitReason = ""; // reset to force a message on next service suspend
                     writeLog("Service resuming operation (no user logged on).");
                 }
                 return;
@@ -438,10 +438,10 @@ namespace AutoTx
 
             // by reaching this point we know the service should be suspended:
             _serviceSuspended = true;
-            if (limitReason == _lastLimitReason)
+            if (limitReason == _status.LimitReason)
                 return;
             writeLog("Service suspended due to limitiations [" + limitReason + "].");
-            _lastLimitReason = limitReason;
+            _status.LimitReason = limitReason;
         }
 
         /// <summary>
diff --git a/AutoTx/SystemChecks.cs b/AutoTx/SystemChecks.cs
index 4e7cad2..0dca881 100644
--- a/AutoTx/SystemChecks.cs
+++ b/AutoTx/SystemChecks.cs
@@ -9,7 +9,6 @@ namespace AutoTx
     {
         #region global variables
 
-        private string _lastLimitReason; // TODO: this should be part of _status!
         private bool _serviceSuspended; // TODO: this should be part of _status!
 
         #endregion
diff --git a/AutoTx/XmlConfiguration.cs b/AutoTx/XmlConfiguration.cs
index 90d0de4..c327c73 100644
--- a/AutoTx/XmlConfiguration.cs
+++ b/AutoTx/XmlConfiguration.cs
@@ -122,6 +122,7 @@ namespace AutoTx
         private DateTime _lastStorageNotification;
         private DateTime _lastAdminNotification;
 
+        private string _limitReason;
         string _currentTransferSrc;
         string _currentTargetTmp;
 
@@ -154,6 +155,15 @@ namespace AutoTx
             }
         }
 
+        public string LimitReason {
+            get { return _limitReason; }
+            set {
+                _limitReason = value;
+                log("LimitReason was updated (" + value + "), calling Serialize()...");
+                Serialize();
+            }
+        }
+        
         public string CurrentTransferSrc {
             get { return _currentTransferSrc; }
             set {
-- 
GitLab