AppSettings and Configuration changes,
major changes to E_Distance and minor for D_Face
This commit is contained in:
@ -30,8 +30,6 @@ public class DateGroup
|
||||
if (console is null)
|
||||
{ }
|
||||
_AppSettings = appSettings;
|
||||
if (appSettings.MaxDegreeOfParallelism is null)
|
||||
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
|
||||
_IsEnvironment = isEnvironment;
|
||||
_Exceptions = new List<string>();
|
||||
_Log = Serilog.Log.ForContext<DateGroup>();
|
||||
@ -58,11 +56,11 @@ public class DateGroup
|
||||
string[] dbFiles = Directory.GetFiles(propertyConfiguration.RootDirectory, "*.db", SearchOption.AllDirectories);
|
||||
foreach (string dbFile in dbFiles)
|
||||
File.Delete(dbFile);
|
||||
if (true || appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
if (true || appSettings.MaxDegreeOfParallelism < 2)
|
||||
ticks = LogDelta(ticks, nameof(File.Delete));
|
||||
for (int i = 1; i < 10; i++)
|
||||
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||
if (true || appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
if (true || appSettings.MaxDegreeOfParallelism < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.IPath.DeleteEmptyDirectories));
|
||||
List<Container> containers = Property.Models.Stateless.A_Property.Get(propertyConfiguration, propertyLogic);
|
||||
if (configuration.ByCreateDateShortcut.HasValue && configuration.ByCreateDateShortcut.Value)
|
||||
@ -72,7 +70,7 @@ public class DateGroup
|
||||
List<string> topDirectories = new();
|
||||
List<Property.Models.DirectoryInfo> directoryInfoCollection = new();
|
||||
propertyLogic.ParallelWork(ticks, containers, firstPass: true);
|
||||
if (appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||
ticks = LogDelta(ticks, nameof(PropertyLogic.ParallelWork));
|
||||
if (propertyLogic.ExceptionsDirectories.Any())
|
||||
throw new Exception();
|
||||
@ -80,7 +78,7 @@ public class DateGroup
|
||||
{
|
||||
if (Property.Models.Stateless.A_Property.Any(containers))
|
||||
propertyLogic.ParallelWork(ticks, containers, firstPass: false);
|
||||
if (appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||
ticks = LogDelta(ticks, nameof(PropertyLogic.ParallelWork));
|
||||
if (propertyLogic.ExceptionsDirectories.Any())
|
||||
throw new Exception();
|
||||
@ -331,11 +329,9 @@ public class DateGroup
|
||||
private PropertyLogic GetPropertyLogic(bool reverse, Model? model, PredictorModel? predictorModel)
|
||||
{
|
||||
PropertyLogic result;
|
||||
if (_AppSettings.MaxDegreeOfParallelism is null)
|
||||
throw new NullReferenceException(nameof(_AppSettings.MaxDegreeOfParallelism));
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||
result = new(_AppSettings.MaxDegreeOfParallelism.Value, _Configuration.PropertyConfiguration, reverse, model, predictorModel);
|
||||
result = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, reverse, model, predictorModel);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -6,24 +6,16 @@ namespace View_by_Distance.Date.Group.Models;
|
||||
public class AppSettings
|
||||
{
|
||||
|
||||
protected string _Company;
|
||||
protected string _WorkingDirectoryName;
|
||||
protected int? _MaxDegreeOfParallelism;
|
||||
public string Company => _Company;
|
||||
public string WorkingDirectoryName => _WorkingDirectoryName;
|
||||
public int? MaxDegreeOfParallelism => _MaxDegreeOfParallelism;
|
||||
|
||||
// public AppSettings()
|
||||
// {
|
||||
|
||||
// }
|
||||
public string Company { init; get; }
|
||||
public int MaxDegreeOfParallelism { init; get; }
|
||||
public string WorkingDirectoryName { init; get; }
|
||||
|
||||
[JsonConstructor]
|
||||
public AppSettings(string company, string workingDirectoryName, int? maxDegreeOfParallelism)
|
||||
public AppSettings(string company, int maxDegreeOfParallelism, string workingDirectoryName)
|
||||
{
|
||||
_Company = company;
|
||||
_WorkingDirectoryName = workingDirectoryName;
|
||||
_MaxDegreeOfParallelism = maxDegreeOfParallelism;
|
||||
Company = company;
|
||||
MaxDegreeOfParallelism = maxDegreeOfParallelism;
|
||||
WorkingDirectoryName = workingDirectoryName;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace View_by_Distance.Date.Group.Models.Binder;
|
||||
@ -6,16 +6,13 @@ namespace View_by_Distance.Date.Group.Models.Binder;
|
||||
public class AppSettings
|
||||
{
|
||||
|
||||
[Display(Name = "Company"), Required] public string Company { get; set; }
|
||||
[Display(Name = "Working Directory Name"), Required] public string WorkingDirectoryName { get; set; }
|
||||
[Display(Name = "Max Degree Of Parallelism"), Required] public int? MaxDegreeOfParallelism { get; set; }
|
||||
#nullable disable
|
||||
|
||||
public AppSettings()
|
||||
{
|
||||
Company = string.Empty;
|
||||
WorkingDirectoryName = string.Empty;
|
||||
MaxDegreeOfParallelism = -1;
|
||||
}
|
||||
public string Company { get; set; }
|
||||
public int? MaxDegreeOfParallelism { get; set; }
|
||||
public string WorkingDirectoryName { get; set; }
|
||||
|
||||
#nullable restore
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
@ -23,4 +20,25 @@ public class AppSettings
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Models.AppSettings Get(AppSettings appSettings)
|
||||
{
|
||||
Models.AppSettings result;
|
||||
if (appSettings.MaxDegreeOfParallelism is null)
|
||||
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
|
||||
result = new(
|
||||
appSettings.Company,
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace View_by_Distance.Date.Group.Models.Stateless;
|
||||
|
||||
public abstract class AppSettings
|
||||
{
|
||||
|
||||
public static Models.AppSettings Get(IConfigurationRoot configurationRoot)
|
||||
{
|
||||
Models.AppSettings? result;
|
||||
Binder.AppSettings appSettings = configurationRoot.Get<Binder.AppSettings>();
|
||||
string json = JsonSerializer.Serialize(appSettings, new JsonSerializerOptions() { WriteIndented = true });
|
||||
result = JsonSerializer.Deserialize<Models.AppSettings>(json);
|
||||
if (result is null)
|
||||
throw new Exception(json);
|
||||
if (string.IsNullOrEmpty(result.Company))
|
||||
throw new Exception(json);
|
||||
string jsonThis = result.ToString();
|
||||
if (jsonThis != json)
|
||||
{
|
||||
int? check = null;
|
||||
int min = new int[] { json.Length, jsonThis.Length }.Min();
|
||||
for (int i = 0; i < min; i++)
|
||||
{
|
||||
if (json[i] == jsonThis[i])
|
||||
continue;
|
||||
check = i;
|
||||
break;
|
||||
}
|
||||
if (check is null)
|
||||
throw new Exception();
|
||||
string a = json[..check.Value].Split(',')[^1];
|
||||
string b = json[check.Value..].Split(',')[0];
|
||||
throw new Exception($"{a}{b}");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -21,10 +21,8 @@ public class Program
|
||||
.AddEnvironmentVariables()
|
||||
.AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true);
|
||||
IConfigurationRoot configurationRoot = configurationBuilder.Build();
|
||||
AppSettings appSettings = Models.Stateless.AppSettings.Get(configurationRoot);
|
||||
if (appSettings.MaxDegreeOfParallelism is null)
|
||||
throw new Exception("MaxDegreeOfParallelism must be set!");
|
||||
if (appSettings.MaxDegreeOfParallelism.Value > Environment.ProcessorCount)
|
||||
AppSettings appSettings = Models.Binder.AppSettings.Get(configurationRoot);
|
||||
if (appSettings.MaxDegreeOfParallelism > Environment.ProcessorCount)
|
||||
throw new Exception("MaxDegreeOfParallelism must be =< Environment.ProcessorCount!");
|
||||
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
|
||||
throw new Exception("Working directory name must have a value!");
|
||||
|
Reference in New Issue
Block a user