Filtered => ValidImage GetMappings => if (face.FaceEncoding is null || face.Location is null || face.OutputResolution is null) PreFilter skip done Removed sort Better names break out RootAmazon FilteredOriginalImage DeleteContinueFiles AppSetting PreVerify Settings Tasks
72 lines
2.6 KiB
C#
72 lines
2.6 KiB
C#
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 void PreVerify(IConfigurationRoot configurationRoot, AppSettings? appSettings)
|
|
{
|
|
if (appSettings?.Company is null)
|
|
{
|
|
List<string> paths = [];
|
|
foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers)
|
|
{
|
|
if (configurationProvider is not Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider jsonConfigurationProvider)
|
|
continue;
|
|
if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider)
|
|
continue;
|
|
paths.Add(physicalFileProvider.Root);
|
|
}
|
|
throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths.Distinct())}");
|
|
}
|
|
}
|
|
|
|
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;
|
|
#pragma warning disable IL3050, IL2026
|
|
AppSettings? appSettings = configurationRoot.Get<AppSettings>();
|
|
#pragma warning restore IL3050, IL2026
|
|
PreVerify(configurationRoot, appSettings);
|
|
result = Get(appSettings);
|
|
return result;
|
|
}
|
|
|
|
} |