diff --git a/AutoTx/AutoTx.cs b/AutoTx/AutoTx.cs index a9c01230a05b6ccef02688cbc4e609af0358b671..4a5b80bb07d4d0480ad500553ae17864914fac60 100644 --- a/AutoTx/AutoTx.cs +++ b/AutoTx/AutoTx.cs @@ -146,7 +146,7 @@ namespace AutoTx private void LoadStatusXml() { try { writeLogDebug("Trying to load status from " + _statusPath); - _status = ServiceStatus.Deserialize(_statusPath); + _status = ServiceStatus.Deserialize(_statusPath, _config); writeLogDebug("Loaded status from " + _statusPath); } catch (Exception ex) { @@ -170,22 +170,6 @@ namespace AutoTx writeLog("ERROR checking spooling directories (incoming / managed)!"); 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) { writeLog("Error in CheckConfiguration(): " + ex.Message + " " + ex.StackTrace); @@ -285,7 +269,11 @@ namespace AutoTx if (!string.IsNullOrEmpty(_config.ValidationWarnings)) { 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); } } diff --git a/AutoTx/XmlWrapper/ServiceStatus.cs b/AutoTx/XmlWrapper/ServiceStatus.cs index 4cd705aac87759e05f8629b6ee5a8c8ba3b7ac3a..de48e5cadc806b93cc11444389b3dd620b645ec2 100644 --- a/AutoTx/XmlWrapper/ServiceStatus.cs +++ b/AutoTx/XmlWrapper/ServiceStatus.cs @@ -7,7 +7,9 @@ namespace AutoTx.XmlWrapper [Serializable] 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 _lastStorageNotification; @@ -154,8 +156,9 @@ namespace AutoTx.XmlWrapper */ } - public static ServiceStatus Deserialize(string file) { + public static ServiceStatus Deserialize(string file, ServiceConfig config) { ServiceStatus status; + var xs = new XmlSerializer(typeof(ServiceStatus)); try { var reader = File.OpenText(file); @@ -166,9 +169,33 @@ namespace AutoTx.XmlWrapper // if reading the status XML fails, we return an empty (new) one status = new ServiceStatus(); } + status._config = config; + ValidateStatus(status); // now set the storage filename: status._storageFile = file; 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 = ""; + } + + } } }