diff --git a/ATXSerializables/FsUtils.cs b/ATXSerializables/FsUtils.cs index 8dadf4d898fba827a749f48267098a1fdbb19ce9..c21eaa5b81a5ef9788589ce1aabc6c66fd6b3707 100644 --- a/ATXSerializables/FsUtils.cs +++ b/ATXSerializables/FsUtils.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; @@ -40,5 +41,40 @@ namespace ATXCommon } return (baseTime - dirTimestamp).Days; } + + /// <summary> + /// Assemble a dictionary with information about expired directories. + /// </summary> + /// <param name="baseDir">The base directory to scan for subdirectories.</param> + /// <param name="thresh">The number of days used as expiration threshold.</param> + /// <returns>A dictionary having usernames as keys (of those users that actually do have + /// expired directories), where the values are lists of tuples with the DirInfo objects, + /// size and age (in days) of the expired directories.</returns> + public static Dictionary<string, List<Tuple<DirectoryInfo, long, int>>> ExpiredDirs( + DirectoryInfo baseDir,int thresh) { + + var collection = new Dictionary<string, List<Tuple<DirectoryInfo, long, int>>>(); + var now = DateTime.Now; + foreach (var userdir in baseDir.GetDirectories()) { + var expired = new List<Tuple<DirectoryInfo, long, int>>(); + foreach (var subdir in userdir.GetDirectories()) { + var age = DirNameToAge(subdir, now); + if (age < thresh) + continue; + long size = -1; + try { + size = GetDirectorySize(subdir.FullName) / Conv.MegaBytes; + } + catch (Exception ex) { + Log.Error("ERROR getting directory size of [{0}]: {1}", + subdir.FullName, ex.Message); + } + expired.Add(new Tuple<DirectoryInfo, long, int>(subdir, size, age)); + } + if (expired.Count > 0) + collection.Add(userdir.Name, expired); + } + return collection; + } } } diff --git a/AutoTx/AutoTx.cs b/AutoTx/AutoTx.cs index e3ee62ccdddfe03585458e6eaf8d11a8659b0591..ae708e59c3f37be9cfb9e2b3b6c293b917f6c38e 100644 --- a/AutoTx/AutoTx.cs +++ b/AutoTx/AutoTx.cs @@ -961,7 +961,8 @@ namespace AutoTx /// </summary> /// <param name="threshold">The number of days used as expiration threshold.</param> public string GraceLocationSummary(int threshold) { - var expired = ExpiredDirs(threshold); + var doneDir = new DirectoryInfo(Path.Combine(_managedPath, "DONE")); + var expired = FsUtils.ExpiredDirs(doneDir, threshold); var report = ""; foreach (var userdir in expired.Keys) { report += "\n - user '" + userdir + "'\n"; @@ -983,39 +984,6 @@ namespace AutoTx return report; } - /// <summary> - /// Assemble a dictionary with information about expired directories. - /// </summary> - /// <param name="thresh">The number of days used as expiration threshold.</param> - /// <returns>A dictionary having usernames as keys (of those users that actually do have - /// expired directories), where the values are lists of tuples with the DirInfo objects, - /// size and age (in days) of the expired directories.</returns> - private Dictionary<string, List<Tuple<DirectoryInfo, long, int>>> ExpiredDirs(int thresh) { - var collection = new Dictionary<string, List<Tuple<DirectoryInfo, long, int>>>(); - var graceDir = new DirectoryInfo(Path.Combine(_managedPath, "DONE")); - var now = DateTime.Now; - foreach (var userdir in graceDir.GetDirectories()) { - var expired = new List<Tuple<DirectoryInfo, long, int>>(); - foreach (var subdir in userdir.GetDirectories()) { - var age = FsUtils.DirNameToAge(subdir, now); - if (age < thresh) - continue; - long size = -1; - try { - size = FsUtils.GetDirectorySize(subdir.FullName) / MegaBytes; - } - catch (Exception ex) { - Log.Error("ERROR getting directory size of [{0}]: {1}", - subdir.FullName, ex.Message); - } - expired.Add(new Tuple<DirectoryInfo, long, int>(subdir, size, age)); - } - if (expired.Count > 0) - collection.Add(userdir.Name, expired); - } - return collection; - } - #endregion }