Skip to content
Snippets Groups Projects
Commit 9d46ad47 authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Split XML classes into separate files, move to XmlWrapper subdirectory.

parent 2e41ddcb
No related branches found
No related tags found
No related merge requests found
......@@ -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" />
......
......@@ -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) {
......
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
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
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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment