diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-05-20 22:01:42 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-05-20 22:01:42 -0500 |
| commit | 347a369779cb51f6f514ea8c8c865268865d6b81 (patch) | |
| tree | b6a6941a7860e0ca506e72f0c696bf8ebb75cd1b /src | |
| parent | cbb6e9400496a18eb362c0bf1bf92cf43986cae3 (diff) | |
| download | slskd-347a369779cb51f6f514ea8c8c865268865d6b81.tar.gz | |
more warnings
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Common/Validation/CompositeValidationResult.cs | 24 | ||||
| -rw-r--r-- | src/slskd/Common/Validation/FileExistsAttribute.cs | 22 | ||||
| -rw-r--r-- | src/slskd/Common/Validation/ValidateAttribute.cs | 22 | ||||
| -rw-r--r-- | src/slskd/Common/Validation/ValidationExtensions.cs | 35 | ||||
| -rw-r--r-- | src/slskd/Program.cs | 2 |
5 files changed, 88 insertions, 17 deletions
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 file="CompositeValidationResult.cs" company="slskd Team"> +// 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/. +// </copyright> + +namespace slskd.Validation +{ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; + /// <summary> + /// The composite result of a recursive validation. + /// </summary> 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 file="FileExistsAttribute.cs" company="slskd Team"> +// 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/. +// </copyright> + +namespace slskd.Validation { using System.ComponentModel.DataAnnotations; using System.IO; + /// <summary> + /// Validates that the file at the specified path exists. + /// </summary> 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 file="ValidateAttribute.cs" company="slskd Team"> +// 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/. +// </copyright> + +namespace slskd.Validation { using System.Collections.Generic; using System.ComponentModel.DataAnnotations; + /// <summary> + /// Indicates that attributed properties should be recursively validated. + /// </summary> 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 file="ValidationExtensions.cs" company="slskd Team"> +// 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/. +// </copyright> + +namespace slskd.Validation { using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; + /// <summary> + /// Extension methods for types involved with validaiton. + /// </summary> 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<string> 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; } |
