From 34a25f488eecee202cbed8d8c2ee64bd60439ab4 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 1 Jul 2021 10:02:37 -0500 Subject: add validator to ensure Address if FTP is Enabled --- src/slskd/Options.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index e32ef522..f8190fc7 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -18,6 +18,7 @@ namespace slskd { using System; + using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Diagnostics; @@ -569,7 +570,7 @@ namespace slskd /// /// FTP options. /// - public class FTPOptions + public class FTPOptions : IValidatableObject { /// /// Gets a value indicating whether the FTP integration is enabled. @@ -662,6 +663,18 @@ namespace slskd [Description("number of times failing FTP uploads will be retried")] [Range(0, 5)] public int RetryAttempts { get; private set; } = 3; + + public IEnumerable Validate(ValidationContext validationContext) + { + var results = new List(); + + if (Enabled && string.IsNullOrWhiteSpace(Address)) + { + results.Add(new ValidationResult($"The Enabled field is true, but no Address has been specified.")); + } + + return results; + } } } } -- cgit v1.2.3