From 43c621db5c30bc2256f2f997f5eb8213afab0524 Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch> Date: Thu, 15 Feb 2018 01:03:18 +0100 Subject: [PATCH] Add block comments to denote sequence of validation checks. --- ATxCommon/Serializables/ServiceConfig.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ATxCommon/Serializables/ServiceConfig.cs b/ATxCommon/Serializables/ServiceConfig.cs index 6407069..a9affb4 100644 --- a/ATxCommon/Serializables/ServiceConfig.cs +++ b/ATxCommon/Serializables/ServiceConfig.cs @@ -351,6 +351,7 @@ namespace ATxCommon.Serializables throw new ConfigurationErrorsException(msg); } + // check if all required parameters are there and non-empty / non-zero: errmsg += CheckEmpty(c.HostAlias, nameof(c.HostAlias)); errmsg += CheckEmpty(c.SourceDrive, nameof(c.SourceDrive)); errmsg += CheckEmpty(c.IncomingDirectory, nameof(c.IncomingDirectory)); @@ -363,11 +364,14 @@ namespace ATxCommon.Serializables errmsg += CheckMinValue(c.MaxCpuUsage, nameof(c.MaxCpuUsage), 5); errmsg += CheckMinValue(c.MinAvailableMemory, nameof(c.MinAvailableMemory), 256); - // if any of the above detected invalid settings we terminate now as many of the + // if any of the required parameter checks failed we terminate now as many of the // string checks below would fail on empty strings: if (!string.IsNullOrWhiteSpace(errmsg)) LogAndThrow(errmsg); + + ////////// REQUIRED PARAMETERS SETTINGS VALIDATION ////////// + // SourceDrive if (c.SourceDrive.Substring(1) != @":\") errmsg += "SourceDrive must be of form [X:\\]\n!"; @@ -388,16 +392,22 @@ namespace ATxCommon.Serializables if (!Directory.Exists(tmpTransferPath)) errmsg += $"can't find (or reach) temporary transfer dir: {tmpTransferPath}\n"; + + ////////// OPTIONAL PARAMETERS SETTINGS VALIDATION ////////// + // DriveName foreach (var driveToCheck in c.SpaceMonitoring) { errmsg += CheckLocalDrive(driveToCheck.DriveName, nameof(driveToCheck.DriveName)); } - // NON-CRITICAL stuff is simply reported to the logs: + ////////// WEAK CHECKS ON PARAMETERS SETTINGS ////////// + // those checks are non-critical and are simply reported to the logs + if (!c.DestinationDirectory.StartsWith(@"\\")) SubOptimal("DestinationDirectory", c.DestinationDirectory, "is not a UNC path!"); + if (string.IsNullOrWhiteSpace(errmsg)) return; -- GitLab