From 347a369779cb51f6f514ea8c8c865268865d6b81 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 20 May 2021 22:01:42 -0500 Subject: more warnings --- .../Common/Validation/CompositeValidationResult.cs | 24 +++++++++++++-- src/slskd/Common/Validation/FileExistsAttribute.cs | 22 +++++++++++++- src/slskd/Common/Validation/ValidateAttribute.cs | 22 +++++++++++++- .../Common/Validation/ValidationExtensions.cs | 35 ++++++++++++++-------- src/slskd/Program.cs | 2 +- 5 files changed, 88 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/slskd/Common/Validation/CompositeValidationResult.cs b/src/slskd/Common/Validation/CompositeValidationResult.cs index f8cd8bc7..5484ae64 100644 --- a/src/slskd/Common/Validation/CompositeValidationResult.cs +++ b/src/slskd/Common/Validation/CompositeValidationResult.cs @@ -1,8 +1,28 @@ -namespace slskd.Validation -{ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Validation +{ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; + /// + /// The composite result of a recursive validation. + /// public class CompositeValidationResult : ValidationResult { public CompositeValidationResult(string errorMessage) diff --git a/src/slskd/Common/Validation/FileExistsAttribute.cs b/src/slskd/Common/Validation/FileExistsAttribute.cs index 8493b783..c1b3fd15 100644 --- a/src/slskd/Common/Validation/FileExistsAttribute.cs +++ b/src/slskd/Common/Validation/FileExistsAttribute.cs @@ -1,8 +1,28 @@ -namespace slskd.Validation +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Validation { using System.ComponentModel.DataAnnotations; using System.IO; + /// + /// Validates that the file at the specified path exists. + /// public class FileExistsAttribute : ValidationAttribute { protected override ValidationResult IsValid(object value, ValidationContext validationContext) diff --git a/src/slskd/Common/Validation/ValidateAttribute.cs b/src/slskd/Common/Validation/ValidateAttribute.cs index b9daab28..72ef25e1 100644 --- a/src/slskd/Common/Validation/ValidateAttribute.cs +++ b/src/slskd/Common/Validation/ValidateAttribute.cs @@ -1,8 +1,28 @@ -namespace slskd.Validation +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Validation { using System.Collections.Generic; using System.ComponentModel.DataAnnotations; + /// + /// Indicates that attributed properties should be recursively validated. + /// public class ValidateAttribute : ValidationAttribute { protected override ValidationResult IsValid(object value, ValidationContext validationContext) diff --git a/src/slskd/Common/Validation/ValidationExtensions.cs b/src/slskd/Common/Validation/ValidationExtensions.cs index 0d8ec83f..fd1da598 100644 --- a/src/slskd/Common/Validation/ValidationExtensions.cs +++ b/src/slskd/Common/Validation/ValidationExtensions.cs @@ -1,22 +1,33 @@ -namespace slskd.Validation +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Validation { using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; + /// + /// Extension methods for types involved with validaiton. + /// public static class ValidationExtensions { - public static string GetResultView(this ValidationResult result, string message) - { - var view = result.GetResultView(0).ToList(); - - if (view.Count > 0 && !string.IsNullOrEmpty(message)) - { - view[0] = message; - } - - return string.Join("\n", view); - } + public static string GetResultView(this CompositeValidationResult result) + => string.Join("\n", result.GetResultView(0)); private static IEnumerable GetResultView(this ValidationResult result, int depth = 0) { diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index f7d3fd66..fca32fcd 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -196,7 +196,7 @@ namespace slskd if (!Options.TryValidate(out var result)) { - Console.WriteLine(result.GetResultView("Invalid configuration:")); + Console.WriteLine(result.GetResultView()); return; } -- cgit v1.2.3