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

Move static methods to ATXCommon.

parent 80ca771a
Branches
Tags
No related merge requests found
...@@ -40,10 +40,12 @@ ...@@ -40,10 +40,12 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="FsUtils.cs" />
<Compile Include="Serializables\DriveToCheck.cs" /> <Compile Include="Serializables\DriveToCheck.cs" />
<Compile Include="Serializables\ServiceConfig.cs" /> <Compile Include="Serializables\ServiceConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Serializables\ServiceStatus.cs" /> <Compile Include="Serializables\ServiceStatus.cs" />
<Compile Include="TimeUtils.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
......
using System.IO;
using System.Linq;
namespace ATXCommon
{
public static class FsUtils
{
/// <summary>
/// Recursively sum up size of all files under a given path.
/// </summary>
/// <param name="path">Full path of the directory.</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);
}
}
}
using System;
namespace ATXCommon
{
public static class TimeUtils
{
/// <summary>
/// Helper method to create timestamp strings in a consistent fashion.
/// </summary>
/// <returns>A timestamp string of the current time.</returns>
public static string Timestamp() {
return DateTime.Now.ToString("yyyy-MM-dd__HH-mm-ss");
}
}
}
...@@ -10,6 +10,7 @@ using System.DirectoryServices.AccountManagement; ...@@ -10,6 +10,7 @@ using System.DirectoryServices.AccountManagement;
using System.Globalization; using System.Globalization;
using System.Management; using System.Management;
using ATXCommon.Serializables; using ATXCommon.Serializables;
using ATXCommon;
using RoboSharp; using RoboSharp;
namespace AutoTx namespace AutoTx
...@@ -413,14 +414,6 @@ namespace AutoTx ...@@ -413,14 +414,6 @@ namespace AutoTx
} }
} }
/// <summary>
/// Helper method to create timestamp strings in a consistent fashion.
/// </summary>
/// <returns>A timestamp string of the current time.</returns>
private static string CreateTimestamp() {
return DateTime.Now.ToString("yyyy-MM-dd__HH-mm-ss");
}
#endregion #endregion
#region ActiveDirectory, email address, user name, ... #region ActiveDirectory, email address, user name, ...
...@@ -733,7 +726,7 @@ namespace AutoTx ...@@ -733,7 +726,7 @@ namespace AutoTx
var targetDir = Path.Combine( var targetDir = Path.Combine(
_managedPath, _managedPath,
target, target,
CreateTimestamp(), TimeUtils.Timestamp(),
userDir.Name); userDir.Name);
if (MoveAllSubDirs(userDir, targetDir)) if (MoveAllSubDirs(userDir, targetDir))
return; return;
...@@ -758,7 +751,7 @@ namespace AutoTx ...@@ -758,7 +751,7 @@ namespace AutoTx
_managedPath, _managedPath,
"DONE", "DONE",
sourceDirectory.Name, // the username directory sourceDirectory.Name, // the username directory
CreateTimestamp()); TimeUtils.Timestamp());
// writeLogDebug("MoveToGraceLocation: src(" + sourceDirectory.FullName + ") dst(" + dstPath + ")"); // writeLogDebug("MoveToGraceLocation: src(" + sourceDirectory.FullName + ") dst(" + dstPath + ")");
try { try {
...@@ -803,7 +796,7 @@ namespace AutoTx ...@@ -803,7 +796,7 @@ namespace AutoTx
var target = Path.Combine(destPath, subDir.Name); var target = Path.Combine(destPath, subDir.Name);
// make sure NOT to overwrite the subdirectories: // make sure NOT to overwrite the subdirectories:
if (Directory.Exists(target)) if (Directory.Exists(target))
target += "_" + CreateTimestamp(); target += "_" + TimeUtils.Timestamp();
writeLogDebug(" - " + subDir.Name + " > " + target); writeLogDebug(" - " + subDir.Name + " > " + target);
subDir.MoveTo(target); subDir.MoveTo(target);
...@@ -848,7 +841,7 @@ namespace AutoTx ...@@ -848,7 +841,7 @@ namespace AutoTx
if (unique == false) if (unique == false)
return dirPath; return dirPath;
dirPath = dirPath + "_" + CreateTimestamp(); dirPath = dirPath + "_" + TimeUtils.Timestamp();
} }
Directory.CreateDirectory(dirPath); Directory.CreateDirectory(dirPath);
writeLogDebug("Created directory: " + dirPath); writeLogDebug("Created directory: " + dirPath);
...@@ -915,17 +908,6 @@ namespace AutoTx ...@@ -915,17 +908,6 @@ namespace AutoTx
_lastUserDirCheck = DateTime.Now; _lastUserDirCheck = DateTime.Now;
} }
/// <summary>
/// Recursively sum up size of all files under a given path.
/// </summary>
/// <param name="path">Full path of the directory.</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);
}
/// <summary> /// <summary>
/// Generate a report on expired folders in the grace location. /// Generate a report on expired folders in the grace location.
/// ///
...@@ -977,7 +959,7 @@ namespace AutoTx ...@@ -977,7 +959,7 @@ namespace AutoTx
continue; continue;
long size = -1; long size = -1;
try { try {
size = GetDirectorySize(subdir.FullName) / MegaBytes; size = FsUtils.GetDirectorySize(subdir.FullName) / MegaBytes;
} }
catch (Exception ex) { catch (Exception ex) {
writeLog("ERROR getting directory size of " + subdir.FullName + writeLog("ERROR getting directory size of " + subdir.FullName +
......
using System; using System;
using System.IO; using System.IO;
using System.Management; using System.Management;
using ATXCommon;
using RoboSharp; using RoboSharp;
namespace AutoTx namespace AutoTx
...@@ -22,7 +23,7 @@ namespace AutoTx ...@@ -22,7 +23,7 @@ namespace AutoTx
return; return;
_status.CurrentTransferSrc = sourcePath; _status.CurrentTransferSrc = sourcePath;
_status.CurrentTransferSize = GetDirectorySize(sourcePath); _status.CurrentTransferSize = FsUtils.GetDirectorySize(sourcePath);
// the user name is expected to be the last part of the path: // the user name is expected to be the last part of the path:
_status.CurrentTargetTmp = new DirectoryInfo(sourcePath).Name; _status.CurrentTargetTmp = new DirectoryInfo(sourcePath).Name;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment