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
64 lines
2.4 KiB
C#
64 lines
2.4 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using System.Text.Json;
|
|
|
|
namespace View_by_Distance.Metadata.Query.Models.Binder;
|
|
|
|
public class AppSettings
|
|
{
|
|
|
|
public string? Company { 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 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?.Company is null)
|
|
throw new NullReferenceException(nameof(appSettings.Company));
|
|
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.MaxDegreeOfParallelism.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;
|
|
}
|
|
|
|
} |