frostfs-sdk-csharp/src/FrostFS.SDK.ModelsV2/Client/ClientSettings.cs
Pavel Gross 96eb98b678
Some checks failed
DCO / DCO (pull_request) Failing after 26s
[22] Client: Container session
Signed-off-by: Pavel Gross <p.gross@yando.com>
2024-08-19 10:48:06 +03:00

63 lines
No EOL
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
namespace FrostFS.SDK.ModelsV2;
public class ClientSettings
{
protected static readonly string errorTemplate = "{0} is required parameter";
public string Host { get; set; } = string.Empty;
public virtual void Validate()
{
var errors = CheckFields();
if (errors != null)
ThrowException(errors);
}
protected List<string>? CheckFields()
{
List<string>? errors = null;
if (string.IsNullOrWhiteSpace(Host))
(errors ??= []).Add(string.Format(errorTemplate, nameof(Host)));
return errors;
}
protected static void ThrowException(List<string> errors)
{
StringBuilder messages = new();
foreach (var error in errors)
{
messages.AppendLine(error);
}
throw new ArgumentException(messages.ToString());
}
}
public class SingleOwnerClientSettings : ClientSettings
{
public string Key { get; set; } = string.Empty;
public override void Validate()
{
var errors = CheckFields();
if (errors != null)
ThrowException(errors);
}
protected List<string>? CheckFields()
{
List<string>? errors = base.CheckFields();
if (string.IsNullOrWhiteSpace(Key))
(errors ??= []).Add(string.Format(errorTemplate, nameof(Key)));
return errors;
}
}