Move-By-Id
This commit is contained in:
52
Move-By-Id/Models/Binder/AppSettings.cs
Normal file
52
Move-By-Id/Models/Binder/AppSettings.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace View_by_Distance.Move.By.Id.Models.Binder;
|
||||
|
||||
public class AppSettings
|
||||
{
|
||||
|
||||
#nullable disable
|
||||
|
||||
public string Company { get; set; }
|
||||
public string MoveTo { get; set; }
|
||||
public string ComparePathsFile { get; set; }
|
||||
public int? MaxDegreeOfParallelism { get; set; }
|
||||
public int? MaxMinutesDelta { get; set; }
|
||||
public string WorkingDirectoryName { get; set; }
|
||||
|
||||
#nullable restore
|
||||
|
||||
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?.MaxDegreeOfParallelism is null)
|
||||
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
|
||||
if (appSettings?.MaxMinutesDelta is null)
|
||||
throw new NullReferenceException(nameof(appSettings.MaxMinutesDelta));
|
||||
result = new(
|
||||
appSettings.Company,
|
||||
appSettings.MoveTo,
|
||||
appSettings.ComparePathsFile,
|
||||
appSettings.MaxDegreeOfParallelism.Value,
|
||||
appSettings.MaxMinutesDelta.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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user