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 1.4
No related merge requests found
......@@ -40,10 +40,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="FsUtils.cs" />
<Compile Include="Serializables\DriveToCheck.cs" />
<Compile Include="Serializables\ServiceConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Serializables\ServiceStatus.cs" />
<Compile Include="TimeUtils.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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;
using System.Globalization;
using System.Management;
using ATXCommon.Serializables;
using ATXCommon;
using RoboSharp;
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
#region ActiveDirectory, email address, user name, ...
......@@ -733,7 +726,7 @@ namespace AutoTx
var targetDir = Path.Combine(
_managedPath,
target,
CreateTimestamp(),
TimeUtils.Timestamp(),
userDir.Name);
if (MoveAllSubDirs(userDir, targetDir))
return;
......@@ -758,7 +751,7 @@ namespace AutoTx
_managedPath,
"DONE",
sourceDirectory.Name, // the username directory
CreateTimestamp());
TimeUtils.Timestamp());
// writeLogDebug("MoveToGraceLocation: src(" + sourceDirectory.FullName + ") dst(" + dstPath + ")");
try {
......@@ -803,7 +796,7 @@ namespace AutoTx
var target = Path.Combine(destPath, subDir.Name);
// make sure NOT to overwrite the subdirectories:
if (Directory.Exists(target))
target += "_" + CreateTimestamp();
target += "_" + TimeUtils.Timestamp();
writeLogDebug(" - " + subDir.Name + " > " + target);
subDir.MoveTo(target);
......@@ -848,7 +841,7 @@ namespace AutoTx
if (unique == false)
return dirPath;
dirPath = dirPath + "_" + CreateTimestamp();
dirPath = dirPath + "_" + TimeUtils.Timestamp();
}
Directory.CreateDirectory(dirPath);
writeLogDebug("Created directory: " + dirPath);
......@@ -915,17 +908,6 @@ namespace AutoTx
_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>
/// Generate a report on expired folders in the grace location.
///
......@@ -977,7 +959,7 @@ namespace AutoTx
continue;
long size = -1;
try {
size = GetDirectorySize(subdir.FullName) / MegaBytes;
size = FsUtils.GetDirectorySize(subdir.FullName) / MegaBytes;
}
catch (Exception ex) {
writeLog("ERROR getting directory size of " + subdir.FullName +
......
using System;
using System.IO;
using System.Management;
using ATXCommon;
using RoboSharp;
namespace AutoTx
......@@ -22,7 +23,7 @@ namespace AutoTx
return;
_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:
_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