From 9d46ad474d1322223f0e8d0beafbdc40cf1f7fe2 Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Sat, 23 Sep 2017 15:05:18 +0200
Subject: [PATCH] Split XML classes into separate files, move to XmlWrapper
 subdirectory.

---
 AutoTx/ATXProject.csproj                      |   4 +-
 AutoTx/AutoTx.cs                              |   9 +-
 AutoTx/XmlWrapper/DriveToCheck.cs             |  18 +++
 AutoTx/XmlWrapper/ServiceConfig.cs            |  98 ++++++++++++++
 .../ServiceStatus.cs}                         | 126 ++----------------
 5 files changed, 132 insertions(+), 123 deletions(-)
 create mode 100644 AutoTx/XmlWrapper/DriveToCheck.cs
 create mode 100644 AutoTx/XmlWrapper/ServiceConfig.cs
 rename AutoTx/{XmlConfiguration.cs => XmlWrapper/ServiceStatus.cs} (56%)

diff --git a/AutoTx/ATXProject.csproj b/AutoTx/ATXProject.csproj
index 7e9aedb..d1a9b28 100644
--- a/AutoTx/ATXProject.csproj
+++ b/AutoTx/ATXProject.csproj
@@ -104,7 +104,9 @@
     <Compile Include="SystemChecks.cs">
       <SubType>Component</SubType>
     </Compile>
-    <Compile Include="XmlConfiguration.cs" />
+    <Compile Include="XmlWrapper\DriveToCheck.cs" />
+    <Compile Include="XmlWrapper\ServiceConfig.cs" />
+    <Compile Include="XmlWrapper\ServiceStatus.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="App.config" />
diff --git a/AutoTx/AutoTx.cs b/AutoTx/AutoTx.cs
index e8e4d4e..32baafa 100644
--- a/AutoTx/AutoTx.cs
+++ b/AutoTx/AutoTx.cs
@@ -7,6 +7,7 @@ using System.IO;
 using System.Timers;
 using System.DirectoryServices.AccountManagement;
 using System.Management;
+using AutoTx.XmlWrapper;
 using RoboSharp;
 
 namespace AutoTx
@@ -56,8 +57,8 @@ namespace AutoTx
 
         private TxState _transferState;
 
-        XmlConfiguration _config;
-        XmlStatus _status;
+        private ServiceConfig _config;
+        private ServiceStatus _status;
 
         private static Timer _mainTimer;
 
@@ -118,7 +119,7 @@ namespace AutoTx
         /// </summary>
         private void LoadConfigStatusXml() {
             try {
-                _config = XmlConfiguration.Deserialize(_configPath);
+                _config = ServiceConfig.Deserialize(_configPath);
                 writeLogDebug("Loaded config from " + _configPath);
             }
             catch (Exception ex) {
@@ -127,7 +128,7 @@ namespace AutoTx
                 throw new Exception("Error loading config.");
             }
             try {
-                _status = XmlStatus.Deserialize(_statusPath);
+                _status = ServiceStatus.Deserialize(_statusPath);
                 writeLogDebug("Loaded status from " + _statusPath);
             }
             catch (Exception ex) {
diff --git a/AutoTx/XmlWrapper/DriveToCheck.cs b/AutoTx/XmlWrapper/DriveToCheck.cs
new file mode 100644
index 0000000..5455a6c
--- /dev/null
+++ b/AutoTx/XmlWrapper/DriveToCheck.cs
@@ -0,0 +1,18 @@
+using System.Xml.Serialization;
+
+namespace AutoTx.XmlWrapper
+{
+    /// <summary>
+    /// Helper class for the nested SpaceMonitoring sections.
+    /// </summary>
+    public class DriveToCheck
+    {
+        [XmlElement("DriveName")]
+        public string DriveName { get; set; }
+
+        // the value is to be compared to System.IO.DriveInfo.TotalFreeSpace
+        // hence we use the same type (long) to avoid unnecessary casts later:
+        [XmlElement("SpaceThreshold")]
+        public long SpaceThreshold { get; set; }
+    }
+}
\ No newline at end of file
diff --git a/AutoTx/XmlWrapper/ServiceConfig.cs b/AutoTx/XmlWrapper/ServiceConfig.cs
new file mode 100644
index 0000000..6586c3e
--- /dev/null
+++ b/AutoTx/XmlWrapper/ServiceConfig.cs
@@ -0,0 +1,98 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.IO;
+using System.Xml.Serialization;
+
+namespace AutoTx.XmlWrapper
+{
+    /// <summary>
+    /// configuration class based on xml
+    /// </summary>
+    [Serializable]
+    public class ServiceConfig
+    {
+        /// <summary>
+        /// A human friendly name for the host, to be used in emails etc.
+        /// </summary>
+        public string HostAlias { get; set; }
+
+        /// <summary>
+        /// A human friendly name for the target, to be used in emails etc.
+        /// </summary>
+        public string DestinationAlias { get; set; }
+        
+        /// <summary>
+        /// The base drive for the spooling directories (incoming and managed).
+        /// </summary>
+        public string SourceDrive { get; set; }
+
+        /// <summary>
+        /// The name of a directory on SourceDrive that is monitored for new files.
+        /// </summary>
+        public string IncomingDirectory { get; set; }
+
+        /// <summary>
+        /// The name of a marker file to be placed in all **sub**directories
+        /// inside the IncomingDirectory.
+        /// </summary>
+        public string MarkerFile { get; set; }
+
+        /// <summary>
+        /// A directory on SourceDrive to hold the three subdirectories "DONE",
+        /// "PROCESSING" and "UNMATCHED" used during and after transfers.
+        /// </summary>
+        public string ManagedDirectory { get; set; }
+        
+        /// <summary>
+        /// Target path to transfer files to. Usually a UNC location.
+        /// </summary>
+        public string DestinationDirectory { get; set; }
+
+        /// <summary>
+        /// The name of a subdirectory in the DestinationDirectory to be used
+        /// to keep the temporary data of running transfers.
+        /// </summary>
+        public string TmpTransferDir { get; set; }
+        public string SmtpHost { get; set; }
+        public string SmtpUserCredential { get; set; }
+        public string SmtpPasswortCredential { get; set; }
+        public string EmailFrom { get; set; }
+        public string AdminEmailAdress { get; set; }
+        public string EmailPrefix { get; set; }
+
+        public int ServiceTimer { get; set; }
+        public int InterPacketGap { get; set; }
+        public int MaxCpuUsage { get; set; }
+        public int MinAvailableMemory { get; set; }
+        public int SmtpPort { get; set; }
+        public int AdminNotificationDelta { get; set; }
+        public int StorageNotificationDelta { get; set; }
+
+        public bool SendAdminNotification { get; set; }
+        public bool SendTransferNotification { get; set; }
+        public bool Debug { get; set; }
+
+        [XmlArray]
+        [XmlArrayItem(ElementName = "DriveToCheck")]
+        public List<DriveToCheck> SpaceMonitoring { get; set; }
+
+        [XmlArray]
+        [XmlArrayItem(ElementName = "ProcessName")]
+        public List<string> BlacklistedProcesses { get; set; }
+
+        public static void Serialize(string file, ServiceConfig c) {
+            // the config is never meant to be written by us, therefore:
+            throw new SettingsPropertyIsReadOnlyException("The config file should not be written by the service!");
+        }
+
+        public static ServiceConfig Deserialize(string file) {
+            var xs = new XmlSerializer(typeof(ServiceConfig));
+            var reader = File.OpenText(file);
+            var config = (ServiceConfig) xs.Deserialize(reader);
+            reader.Close();
+            return config;
+        }
+
+    }
+}
\ No newline at end of file
diff --git a/AutoTx/XmlConfiguration.cs b/AutoTx/XmlWrapper/ServiceStatus.cs
similarity index 56%
rename from AutoTx/XmlConfiguration.cs
rename to AutoTx/XmlWrapper/ServiceStatus.cs
index 7fce8b0..8ed046c 100644
--- a/AutoTx/XmlConfiguration.cs
+++ b/AutoTx/XmlWrapper/ServiceStatus.cs
@@ -1,120 +1,11 @@
 using System;
-using System.Collections.Generic;
 using System.IO;
 using System.Xml.Serialization;
-using System.Configuration;
 
-namespace AutoTx
+namespace AutoTx.XmlWrapper
 {
-    /// <summary>
-    /// Helper class for the nested SpaceMonitoring sections.
-    /// </summary>
-    public class DriveToCheck
-    {
-        [XmlElement("DriveName")]
-        public string DriveName { get; set; }
-
-        // the value is to be compared to System.IO.DriveInfo.TotalFreeSpace
-        // hence we use the same type (long) to avoid unnecessary casts later:
-        [XmlElement("SpaceThreshold")]
-        public long SpaceThreshold { get; set; }
-    }
-
-
-    /// <summary>
-    /// configuration class based on xml
-    /// </summary>
-    [Serializable]
-    public class XmlConfiguration
-    {
-        /// <summary>
-        /// A human friendly name for the host, to be used in emails etc.
-        /// </summary>
-        public string HostAlias { get; set; }
-
-        /// <summary>
-        /// A human friendly name for the target, to be used in emails etc.
-        /// </summary>
-        public string DestinationAlias { get; set; }
-        
-        /// <summary>
-        /// The base drive for the spooling directories (incoming and managed).
-        /// </summary>
-        public string SourceDrive { get; set; }
-
-        /// <summary>
-        /// The name of a directory on SourceDrive that is monitored for new files.
-        /// </summary>
-        public string IncomingDirectory { get; set; }
-
-        /// <summary>
-        /// The name of a marker file to be placed in all **sub**directories
-        /// inside the IncomingDirectory.
-        /// </summary>
-        public string MarkerFile { get; set; }
-
-        /// <summary>
-        /// A directory on SourceDrive to hold the three subdirectories "DONE",
-        /// "PROCESSING" and "UNMATCHED" used during and after transfers.
-        /// </summary>
-        public string ManagedDirectory { get; set; }
-        
-        /// <summary>
-        /// Target path to transfer files to. Usually a UNC location.
-        /// </summary>
-        public string DestinationDirectory { get; set; }
-
-        /// <summary>
-        /// The name of a subdirectory in the DestinationDirectory to be used
-        /// to keep the temporary data of running transfers.
-        /// </summary>
-        public string TmpTransferDir { get; set; }
-        public string SmtpHost { get; set; }
-        public string SmtpUserCredential { get; set; }
-        public string SmtpPasswortCredential { get; set; }
-        public string EmailFrom { get; set; }
-        public string AdminEmailAdress { get; set; }
-        public string EmailPrefix { get; set; }
-
-        public int ServiceTimer { get; set; }
-        public int InterPacketGap { get; set; }
-        public int MaxCpuUsage { get; set; }
-        public int MinAvailableMemory { get; set; }
-        public int SmtpPort { get; set; }
-        public int AdminNotificationDelta { get; set; }
-        public int StorageNotificationDelta { get; set; }
-
-        public bool SendAdminNotification { get; set; }
-        public bool SendTransferNotification { get; set; }
-        public bool Debug { get; set; }
-
-
-        [XmlArray]
-        [XmlArrayItem(ElementName = "DriveToCheck")]
-        public List<DriveToCheck> SpaceMonitoring { get; set; }
-
-        [XmlArray]
-        [XmlArrayItem(ElementName = "ProcessName")]
-        public List<string> BlacklistedProcesses { get; set; }
-
-        public static void Serialize(string file, XmlConfiguration c) {
-            // the config is never meant to be written by us, therefore:
-            throw new SettingsPropertyIsReadOnlyException("The config file should not be written by the service!");
-        }
-
-        public static XmlConfiguration Deserialize(string file) {
-            var xs = new XmlSerializer(typeof(XmlConfiguration));
-            var reader = File.OpenText(file);
-            var config = (XmlConfiguration) xs.Deserialize(reader);
-            reader.Close();
-            return config;
-        }
-
-    }
-
-
     [Serializable]
-    public class XmlStatus
+    public class ServiceStatus
     {
         [NonSerialized] string _storageFile; // remember where we came from
         
@@ -221,7 +112,7 @@ namespace AutoTx
             }
         }
 
-        public XmlStatus() {
+        public ServiceStatus() {
             _currentTransferSrc = "";
             _currentTargetTmp = "";
             _filecopyFinished = true;
@@ -263,18 +154,17 @@ namespace AutoTx
              */
         }
 
-
-        public static XmlStatus Deserialize(string file) {
-            XmlStatus status;
-            var xs = new XmlSerializer(typeof(XmlStatus));
+        public static ServiceStatus Deserialize(string file) {
+            ServiceStatus status;
+            var xs = new XmlSerializer(typeof(ServiceStatus));
             try {
                 var reader = File.OpenText(file);
-                status = (XmlStatus) xs.Deserialize(reader);
+                status = (ServiceStatus) xs.Deserialize(reader);
                 reader.Close();
             }
             catch (Exception) {
                 // if reading the status XML fails, we return an empty (new) one
-                status = new XmlStatus();
+                status = new ServiceStatus();
             }
             // now set the storage filename:
             status._storageFile = file;
-- 
GitLab