From 81596e4561541486399a3431c6692efe98404fcb Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch> Date: Mon, 18 Sep 2017 18:16:10 +0200 Subject: [PATCH] Add GetDirectorySize method and CurrentTransferSize attribute to status. --- AutoTx/AutoTx.cs | 13 +++++++++++++ AutoTx/RoboCommand.cs | 3 ++- AutoTx/XmlConfiguration.cs | 12 ++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/AutoTx/AutoTx.cs b/AutoTx/AutoTx.cs index f4dfd51..eacf7e0 100644 --- a/AutoTx/AutoTx.cs +++ b/AutoTx/AutoTx.cs @@ -601,6 +601,7 @@ namespace AutoTx try { _status.CurrentTransferSrc = queued[0].GetDirectories()[0].FullName; + _status.CurrentTransferSize = GetDirectorySize(_status.CurrentTransferSrc); } catch (Exception ex) { writeLog("Error checking for data to be transferred: " + ex.Message); @@ -651,6 +652,7 @@ namespace AutoTx MoveToGraceLocation(); SendTransferCompletedMail(); _status.CurrentTransferSrc = ""; // cleanup completed, so reset CurrentTransferSrc + _status.CurrentTransferSize = 0; _transferredFiles.Clear(); // empty the list of transferred files } } @@ -928,6 +930,17 @@ namespace AutoTx _lastUserDirCheck = DateTime.Now; } + /// <summary> + /// Recursively sum up size of all files under a given path. + /// </summary> + /// <param name="path"></param> + /// <returns>The total size in bytes.</returns> + public static long GetDirectorySize(string path) { + return new DirectoryInfo(path) + .GetFiles("*", SearchOption.AllDirectories) + .Sum(file => file.Length); + } + #endregion } diff --git a/AutoTx/RoboCommand.cs b/AutoTx/RoboCommand.cs index 4129b3b..4cfa85b 100644 --- a/AutoTx/RoboCommand.cs +++ b/AutoTx/RoboCommand.cs @@ -69,7 +69,8 @@ namespace AutoTx _roboCommand.RetryOptions.RetryCount = 0; _roboCommand.RetryOptions.RetryWaitTime = 2; _roboCommand.Start(); - writeLogDebug("Transfer started"); + writeLogDebug("Transfer started, total size: " + + _status.CurrentTransferSize / MegaBytes + " MB"); } catch (ManagementException ex) { writeLog("Error in StartTransfer(): " + ex.Message); diff --git a/AutoTx/XmlConfiguration.cs b/AutoTx/XmlConfiguration.cs index 3b9c74c..90d0de4 100644 --- a/AutoTx/XmlConfiguration.cs +++ b/AutoTx/XmlConfiguration.cs @@ -128,6 +128,8 @@ namespace AutoTx bool _filecopyFinished; private bool _cleanShutdown; + private long _currentTransferSize; + [XmlElement("LastStatusUpdate", DataType = "dateTime")] public DateTime LastStatusUpdate { get { return _lastStatusUpdate; } @@ -190,6 +192,16 @@ namespace AutoTx } } + public long CurrentTransferSize { + get { return _currentTransferSize; } + set + { + _currentTransferSize = value; + log("CurrentTransferSize was updated (" + value + "), calling Serialize()..."); + Serialize(); + } + } + public XmlStatus() { _currentTransferSrc = ""; _currentTargetTmp = ""; -- GitLab