diff --git a/AutoTx/ATXProject.csproj b/AutoTx/ATXProject.csproj index 7e9aedb97a7acdcd103a39f8bc7f888ce20643c5..d1a9b28dae662258f60a5a7e8a3aea6c2770b653 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 e8e4d4e34cfadfffeec091ea0bccbec482ff791c..32baafa669eaa78de6a71e2e15ed6da615340a15 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 0000000000000000000000000000000000000000..5455a6c69cfdc093ff1e0d59675e7e6a586d4f4e --- /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 0000000000000000000000000000000000000000..6586c3e44e20a3419369717376c537deb3024eb0 --- /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 7fce8b0146cde799fce96d0240ab1a17bdab1676..8ed046c1ab7602e67f7ecf54749e4c954793e0ef 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;