48 lines
1.7 KiB
C#
48 lines
1.7 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using System.Text.Json;
|
|
|
|
namespace View_by_Distance.Mirror.Length.Models.Binder;
|
|
|
|
public class AppSettings
|
|
{
|
|
|
|
public string? Company { get; set; }
|
|
public string? Destination { get; set; }
|
|
public int? MaxDegreeOfParallelism { get; set; }
|
|
public string? WorkingDirectoryName { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
|
return result;
|
|
}
|
|
|
|
private static Models.AppSettings Get(AppSettings? appSettings)
|
|
{
|
|
Models.AppSettings result;
|
|
if (appSettings?.Company is null)
|
|
throw new NullReferenceException(nameof(appSettings.Company));
|
|
if (appSettings?.Destination is null || appSettings.Destination.Length != 1)
|
|
throw new NullReferenceException(nameof(appSettings.Destination));
|
|
if (appSettings?.MaxDegreeOfParallelism is null)
|
|
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
|
|
if (appSettings?.WorkingDirectoryName is null)
|
|
throw new NullReferenceException(nameof(appSettings.WorkingDirectoryName));
|
|
result = new(
|
|
appSettings.Company,
|
|
appSettings.Destination.First(),
|
|
appSettings.MaxDegreeOfParallelism.Value,
|
|
appSettings.WorkingDirectoryName
|
|
);
|
|
return result;
|
|
}
|
|
|
|
public static Models.AppSettings Get(IConfigurationRoot configurationRoot)
|
|
{
|
|
Models.AppSettings result;
|
|
AppSettings? appSettings = configurationRoot.Get<AppSettings>();
|
|
result = Get(appSettings);
|
|
return result;
|
|
}
|
|
|
|
} |