Mike Phares c9dbce3b57 IEnumerable
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
2024-04-28 17:30:55 -07:00

74 lines
2.7 KiB
C#

using Microsoft.Extensions.Configuration;
using System.Text.Json;
namespace View_by_Distance.Duplicate.Search.Models.Binder;
public class AppSettings
{
#nullable disable
public string Company { get; set; }
public bool? IndexOnly { get; set; }
public int? MaxDegreeOfParallelism { get; set; }
public string OutputExtension { get; set; }
public bool? Reverse { 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?.IndexOnly is null)
throw new NullReferenceException(nameof(appSettings.IndexOnly));
if (appSettings?.MaxDegreeOfParallelism is null)
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
if (appSettings?.Reverse is null)
throw new NullReferenceException(nameof(appSettings.Reverse));
result = new(
appSettings.Company,
appSettings.IndexOnly.Value,
appSettings.MaxDegreeOfParallelism.Value,
appSettings.OutputExtension,
appSettings.Reverse.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;
}
}