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

Use global variables for incoming and managed paths.

This avoids building them over and over again with Path.Combine() which
is not necessary as they are static anyway and won't change after the
configuration has been parsed and verified.

References issue #7.
parent ab2cdfba
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,8 @@ namespace AutoTx
// ending with "Dir" are DirectoryInfo objects
private string _configPath;
private string _statusPath;
private string _incomingPath;
private string _managedPath;
private List<string> _transferredFiles = new List<string>();
private int _txProgress;
......@@ -142,14 +144,18 @@ namespace AutoTx
@" and a backslash, e.g. 'D:\'!");
configInvalid = true;
}
// IncomingDirectory
if (_config.IncomingDirectory.StartsWith(@"\")) {
writeLog("ERROR: IncomingDirectory must not start with a backslash!");
configInvalid = true;
}
_incomingPath = Path.Combine(_config.SourceDrive, _config.IncomingDirectory);
// ManagedDirectory
if (_config.ManagedDirectory.StartsWith(@"\")) {
writeLog("ERROR: ManagedDirectory must not start with a backslash!");
configInvalid = true;
}
_managedPath = Path.Combine(_config.SourceDrive, _config.ManagedDirectory);
if (_config.ServiceTimer < 1000) {
writeLog("ERROR: ServiceTimer must not be smaller than 1000 ms!");
configInvalid = true;
......@@ -535,8 +541,7 @@ namespace AutoTx
return;
// select next directory from "processing" for transfer:
var processingDir = Path.Combine(_config.SourceDrive,
_config.ManagedDirectory, "PROCESSING");
var processingDir = Path.Combine(_managedPath, "PROCESSING");
var queued = new DirectoryInfo(processingDir).GetDirectories();
if (queued.Length == 0)
return;
......@@ -555,9 +560,8 @@ namespace AutoTx
/// Check the incoming directories for files, move them to the processing location.
/// </summary>
private void CheckIncomingDirectories() {
var incomingPath = Path.Combine(_config.SourceDrive, _config.IncomingDirectory);
// iterate over all user-subdirectories:
foreach (var userDir in new DirectoryInfo(incomingPath).GetDirectories()) {
foreach (var userDir in new DirectoryInfo(_incomingPath).GetDirectories()) {
if (IncomingDirIsEmpty(userDir))
continue;
......@@ -704,8 +708,8 @@ namespace AutoTx
// now everything that is supposed to be transferred is in a folder,
// for example: D:\ATX\PROCESSING\2017-04-02__12-34-56\user00
var targetDir = Path.Combine(_config.SourceDrive,
_config.ManagedDirectory,
var targetDir = Path.Combine(
_managedPath,
target,
CreateTimestamp(),
userDir.Name);
......@@ -728,8 +732,8 @@ namespace AutoTx
string errMsg;
// CurrentTransferSrc is e.g. D:\ATX\PROCESSING\2017-04-02__12-34-56\user00
var sourceDirectory = new DirectoryInfo(_status.CurrentTransferSrc);
var dstPath = Path.Combine(_config.SourceDrive,
_config.ManagedDirectory,
var dstPath = Path.Combine(
_managedPath,
"DONE",
sourceDirectory.Name, // the username directory
CreateTimestamp());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment