From 3a1b6b1ba78f0f5269718786d4375219df0c3ea1 Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Wed, 20 Dec 2017 00:40:38 +0100
Subject: [PATCH] Move generation of config and status summaries into their
 respective classes.

---
 AutoTx/AutoTx.cs                   | 73 ++++++++----------------------
 AutoTx/XmlWrapper/ServiceConfig.cs | 36 +++++++++++++++
 AutoTx/XmlWrapper/ServiceStatus.cs | 14 ++++++
 3 files changed, 68 insertions(+), 55 deletions(-)

diff --git a/AutoTx/AutoTx.cs b/AutoTx/AutoTx.cs
index 45ed6c0..03a2e4c 100644
--- a/AutoTx/AutoTx.cs
+++ b/AutoTx/AutoTx.cs
@@ -190,68 +190,31 @@ namespace AutoTx
         /// Write a summary of loaded config + status to the log.
         /// </summary>
         private void StartupSummary() {
-            writeLogDebug("------ RoboSharp ------");
+            var msg = "\n\n------ RoboSharp ------\n";
             var roboDll = System.Reflection.Assembly.GetAssembly(typeof(RoboCommand)).Location;
             if (roboDll != null) {
                 var versionInfo = FileVersionInfo.GetVersionInfo(roboDll);
-                writeLogDebug(" > DLL file: " + roboDll);
-                writeLogDebug(" > DLL description: " + versionInfo.Comments);
-                writeLogDebug(" > DLL version: " + versionInfo.FileVersion);
-            }
-            writeLogDebug("");
-
-            writeLogDebug("------ Loaded status flags ------");
-            writeLogDebug("CurrentTransferSrc: " + _status.CurrentTransferSrc);
-            writeLogDebug("CurrentTargetTmp: " + _status.CurrentTargetTmp);
-            writeLogDebug("TransferInProgress: " + _status.TransferInProgress);
-            writeLogDebug("LastStorageNotification: " +
-                          _status.LastStorageNotification.ToString("yyyy-MM-dd HH:mm:ss"));
-            writeLogDebug("LastAdminNotification: " +
-                          _status.LastAdminNotification.ToString("yyyy-MM-dd HH:mm:ss"));
-            writeLogDebug("");
-
-            writeLogDebug("------ Loaded configuration settings ------");
-            writeLogDebug("HostAlias: " + _config.HostAlias);
-            writeLogDebug("SourceDrive: " + _config.SourceDrive);
-            writeLogDebug("IncomingDirectory: " + _config.IncomingDirectory);
-            writeLogDebug("MarkerFile: " + _config.MarkerFile);
-            writeLogDebug("ManagedDirectory: " + _config.ManagedDirectory);
-            writeLogDebug("GracePeriod: " + _config.GracePeriod);
-            writeLogDebug("DestinationDirectory: " + _config.DestinationDirectory);
-            writeLogDebug("TmpTransferDir: " + _config.TmpTransferDir);
-            writeLogDebug("EnforceInheritedACLs: " + _config.EnforceInheritedACLs);
-            writeLogDebug("ServiceTimer: " + _config.ServiceTimer);
-            writeLogDebug("InterPacketGap: " + _config.InterPacketGap);
-            writeLogDebug("MaxCpuUsage: " + _config.MaxCpuUsage);
-            writeLogDebug("MinAvailableMemory: " + _config.MinAvailableMemory);
-            foreach (var processName in _config.BlacklistedProcesses) {
-                writeLogDebug("BlacklistedProcess: " + processName);
+                msg += " > DLL file: " + roboDll + "\n" +
+                       " > DLL description: " + versionInfo.Comments + "\n" +
+                       " > DLL version: " + versionInfo.FileVersion + "\n";
             }
-            foreach (var driveToCheck in _config.SpaceMonitoring) {
-                writeLogDebug("Drive to check free space: " + driveToCheck.DriveName +
-                              " (threshold: " + driveToCheck.SpaceThreshold + ")");
-            }
-            writeLogDebug("StorageNotificationDelta: " + _config.StorageNotificationDelta);
-            writeLogDebug("AdminNotificationDelta: " + _config.AdminNotificationDelta);
-            if (string.IsNullOrEmpty(_config.SmtpHost)) {
-                writeLogDebug("SmtpHost: ====== Not configured, disabling notification emails! ======");
-            } else {
-                writeLogDebug("SmtpHost: " + _config.SmtpHost);
-                writeLogDebug("EmailFrom: " + _config.EmailFrom);
-                writeLogDebug("AdminEmailAdress: " + _config.AdminEmailAdress);
-                writeLogDebug("AdminDebugEmailAdress: " + _config.AdminDebugEmailAdress);
-            }
-            writeLogDebug("");
+            writeLogDebug(msg);
 
-            // finally some current information:
-            writeLogDebug("------ Current system parameters ------");
-            writeLogDebug("Hostname: " + Environment.MachineName);
-            writeLogDebug("Free system memory: " + GetFreeMemory() + " MB");
+
+            msg = "\n\n------ Loaded status flags ------\n" + _status.Summary() +
+                  "\n------ Loaded configuration settings ------\n" + _config.Summary();
+            writeLogDebug(msg);
+
+
+            msg = "\n\n------ Current system parameters ------\n" +
+                  "Hostname: " + Environment.MachineName + "\n" +
+                  "Free system memory: " + GetFreeMemory() + " MB" + "\n";
             foreach (var driveToCheck in _config.SpaceMonitoring) {
-                writeLogDebug("Free space on drive '" + driveToCheck.DriveName + "': " +
-                              GetFreeDriveSpace(driveToCheck.DriveName));
+                msg += "Free space on drive '" + driveToCheck.DriveName + "': " +
+                       GetFreeDriveSpace(driveToCheck.DriveName) + "\n";
             }
-            writeLogDebug("");
+            writeLogDebug(msg);
+
 
             writeLogDebug("------ Grace location status ------");
             try {
diff --git a/AutoTx/XmlWrapper/ServiceConfig.cs b/AutoTx/XmlWrapper/ServiceConfig.cs
index 384bd52..dd70309 100644
--- a/AutoTx/XmlWrapper/ServiceConfig.cs
+++ b/AutoTx/XmlWrapper/ServiceConfig.cs
@@ -181,5 +181,41 @@ namespace AutoTx.XmlWrapper
                 c.ValidationWarnings += " - <DestinationDirectory> is not a UNC path!\n";
         }
 
+        public string Summary() {
+            var msg =
+                "HostAlias: " + HostAlias + "\n" +
+                "SourceDrive: " + SourceDrive + "\n" +
+                "IncomingDirectory: " + IncomingDirectory + "\n" +
+                "MarkerFile: " + MarkerFile + "\n" +
+                "ManagedDirectory: " + ManagedDirectory + "\n" +
+                "GracePeriod: " + GracePeriod + "\n" +
+                "DestinationDirectory: " + DestinationDirectory + "\n" +
+                "TmpTransferDir: " + TmpTransferDir + "\n" +
+                "EnforceInheritedACLs: " + EnforceInheritedACLs + "\n" +
+                "ServiceTimer: " + ServiceTimer + "\n" +
+                "InterPacketGap: " + InterPacketGap + "\n" +
+                "MaxCpuUsage: " + MaxCpuUsage + "\n" +
+                "MinAvailableMemory: " + MinAvailableMemory + "\n";
+            foreach (var processName in BlacklistedProcesses) {
+                msg += "BlacklistedProcess: " + processName + "\n";
+            }
+            foreach (var driveToCheck in SpaceMonitoring) {
+                msg += "Drive to check free space: " + driveToCheck.DriveName +
+                       " (threshold: " + driveToCheck.SpaceThreshold + ")" + "\n";
+            }
+            if (string.IsNullOrEmpty(SmtpHost)) {
+                msg += "SmtpHost: ====== Not configured, disabling email! ======" + "\n";
+            } else {
+                msg +=
+                    "SmtpHost: " + SmtpHost + "\n" +
+                    "EmailFrom: " + EmailFrom + "\n" +
+                    "AdminEmailAdress: " + AdminEmailAdress + "\n" +
+                    "AdminDebugEmailAdress: " + AdminDebugEmailAdress + "\n" +
+                    "StorageNotificationDelta: " + StorageNotificationDelta + "\n" +
+                    "AdminNotificationDelta: " + AdminNotificationDelta + "\n";
+
+            }
+            return msg;
+        }
     }
 }
\ No newline at end of file
diff --git a/AutoTx/XmlWrapper/ServiceStatus.cs b/AutoTx/XmlWrapper/ServiceStatus.cs
index de48e5c..25f4ed8 100644
--- a/AutoTx/XmlWrapper/ServiceStatus.cs
+++ b/AutoTx/XmlWrapper/ServiceStatus.cs
@@ -197,5 +197,19 @@ namespace AutoTx.XmlWrapper
             }
 
         }
+
+        public string Summary() {
+            return
+                "CurrentTransferSrc: " + CurrentTransferSrc + "\n" +
+                "CurrentTargetTmp: " + CurrentTargetTmp + "\n" +
+                "TransferInProgress: " + TransferInProgress + "\n" +
+                "CurrentTransferSize: " + CurrentTransferSize + "\n" +
+                "LastStatusUpdate: " +
+                LastStatusUpdate.ToString("yyyy-MM-dd HH:mm:ss") + "\n" +
+                "LastStorageNotification: " +
+                LastStorageNotification.ToString("yyyy-MM-dd HH:mm:ss") + "\n" +
+                "LastAdminNotification: " +
+                LastAdminNotification.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
+        }
     }
 }
-- 
GitLab