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

Move validation of status into the ServiceStatus class.

parent 35553e56
No related branches found
No related tags found
No related merge requests found
...@@ -146,7 +146,7 @@ namespace AutoTx ...@@ -146,7 +146,7 @@ namespace AutoTx
private void LoadStatusXml() { private void LoadStatusXml() {
try { try {
writeLogDebug("Trying to load status from " + _statusPath); writeLogDebug("Trying to load status from " + _statusPath);
_status = ServiceStatus.Deserialize(_statusPath); _status = ServiceStatus.Deserialize(_statusPath, _config);
writeLogDebug("Loaded status from " + _statusPath); writeLogDebug("Loaded status from " + _statusPath);
} }
catch (Exception ex) { catch (Exception ex) {
...@@ -170,22 +170,6 @@ namespace AutoTx ...@@ -170,22 +170,6 @@ namespace AutoTx
writeLog("ERROR checking spooling directories (incoming / managed)!"); writeLog("ERROR checking spooling directories (incoming / managed)!");
configInvalid = true; configInvalid = true;
} }
// CurrentTransferSrc
if (_status.CurrentTransferSrc.Length > 0
&& !Directory.Exists(_status.CurrentTransferSrc)) {
writeLog("WARNING: status file contains non-existing source path of an " +
"unfinished transfer: " + _status.CurrentTransferSrc);
_status.CurrentTransferSrc = "";
}
// CurrentTargetTmp
if (_status.CurrentTargetTmp.Length > 0
&& !Directory.Exists(ExpandCurrentTargetTmp())) {
writeLog("WARNING: status file contains non-existing temporary path of an " +
"unfinished transfer: " + _status.CurrentTargetTmp);
_status.CurrentTargetTmp = "";
}
} }
catch (Exception ex) { catch (Exception ex) {
writeLog("Error in CheckConfiguration(): " + ex.Message + " " + ex.StackTrace); writeLog("Error in CheckConfiguration(): " + ex.Message + " " + ex.StackTrace);
...@@ -285,7 +269,11 @@ namespace AutoTx ...@@ -285,7 +269,11 @@ namespace AutoTx
if (!string.IsNullOrEmpty(_config.ValidationWarnings)) { if (!string.IsNullOrEmpty(_config.ValidationWarnings)) {
writeLog("WARNING: some configuration settings might not be optimal:\n" + writeLog("WARNING: some configuration settings might not be optimal:\n" +
_config.ValidationWarnings); _config.ValidationWarnings);
}
if (!string.IsNullOrEmpty(_status.ValidationWarnings)) {
writeLog("WARNING: some status parameters were invalid and have been reset:\n" +
_status.ValidationWarnings);
} }
} }
......
...@@ -7,7 +7,9 @@ namespace AutoTx.XmlWrapper ...@@ -7,7 +7,9 @@ namespace AutoTx.XmlWrapper
[Serializable] [Serializable]
public class ServiceStatus public class ServiceStatus
{ {
[NonSerialized] string _storageFile; // remember where we came from [XmlIgnore] string _storageFile; // remember where we came from
[XmlIgnore] private ServiceConfig _config;
[XmlIgnore] public string ValidationWarnings;
private DateTime _lastStatusUpdate; private DateTime _lastStatusUpdate;
private DateTime _lastStorageNotification; private DateTime _lastStorageNotification;
...@@ -154,8 +156,9 @@ namespace AutoTx.XmlWrapper ...@@ -154,8 +156,9 @@ namespace AutoTx.XmlWrapper
*/ */
} }
public static ServiceStatus Deserialize(string file) { public static ServiceStatus Deserialize(string file, ServiceConfig config) {
ServiceStatus status; ServiceStatus status;
var xs = new XmlSerializer(typeof(ServiceStatus)); var xs = new XmlSerializer(typeof(ServiceStatus));
try { try {
var reader = File.OpenText(file); var reader = File.OpenText(file);
...@@ -166,9 +169,33 @@ namespace AutoTx.XmlWrapper ...@@ -166,9 +169,33 @@ namespace AutoTx.XmlWrapper
// if reading the status XML fails, we return an empty (new) one // if reading the status XML fails, we return an empty (new) one
status = new ServiceStatus(); status = new ServiceStatus();
} }
status._config = config;
ValidateStatus(status);
// now set the storage filename: // now set the storage filename:
status._storageFile = file; status._storageFile = file;
return status; return status;
} }
private static void ValidateStatus(ServiceStatus s) {
// CurrentTransferSrc
if (s.CurrentTransferSrc.Length > 0
&& !Directory.Exists(s.CurrentTransferSrc)) {
s.ValidationWarnings += " - found non-existing source path of an unfinished " +
"transfer: " + s.CurrentTransferSrc + "\n";
s.CurrentTransferSrc = "";
}
// CurrentTargetTmp
var currentTargetTmpPath = Path.Combine(s._config.DestinationDirectory,
s._config.TmpTransferDir,
s.CurrentTargetTmp);
if (s.CurrentTargetTmp.Length > 0
&& !Directory.Exists(currentTargetTmpPath)) {
s.ValidationWarnings += " - found non-existing temporary path of an " +
"unfinished transfer: " + currentTargetTmpPath+ "\n";
s.CurrentTargetTmp = "";
}
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment