AppSettings and Configuration changes,
major changes to E_Distance and minor for D_Face
This commit is contained in:
@ -34,8 +34,6 @@ public class Compare
|
||||
string renameTo;
|
||||
string[] segments;
|
||||
_AppSettings = appSettings;
|
||||
if (appSettings.MaxDegreeOfParallelism is null)
|
||||
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
|
||||
_RenameFindReplace = new();
|
||||
_RenameBFindReplace = new();
|
||||
_RenameCFindReplace = new();
|
||||
@ -106,7 +104,7 @@ public class Compare
|
||||
_RenameCFindReplace.Add(new(renameFrom, renameTo));
|
||||
}
|
||||
groupCollection = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
|
||||
if (appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
||||
_Log.Information($"{nameof(Property.Models.Stateless.Container.GetGroupCollection)} has finished");
|
||||
_Configuration = configuration;
|
||||
@ -118,7 +116,7 @@ public class Compare
|
||||
topDirectories.Clear();
|
||||
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||
groupCollection = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
|
||||
if (appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
||||
}
|
||||
_Log.Information($"{nameof(PossiblyRename)} has finished");
|
||||
@ -127,7 +125,7 @@ public class Compare
|
||||
topDirectories.Clear();
|
||||
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||
groupCollection = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
|
||||
if (appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
||||
}
|
||||
_Log.Information($"{nameof(PossiblyRenameB)} has finished");
|
||||
@ -136,7 +134,7 @@ public class Compare
|
||||
topDirectories.Clear();
|
||||
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||
groupCollection = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
|
||||
if (appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
||||
}
|
||||
_Log.Information($"{nameof(PossiblyRenameC)} has finished");
|
||||
@ -145,7 +143,7 @@ public class Compare
|
||||
topDirectories.Clear();
|
||||
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||
groupCollection = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
|
||||
if (appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
||||
}
|
||||
_Log.Information($"{nameof(PossiblyCorrect)} has finished");
|
||||
@ -158,7 +156,7 @@ public class Compare
|
||||
topDirectories.Clear();
|
||||
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||
groupCollection = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
|
||||
if (appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
||||
}
|
||||
if (_IsEnvironment.Development && propertyConfiguration.PopulatePropertyId.Value && !propertyLogic.KeyValuePairs.Any())
|
||||
@ -389,11 +387,9 @@ public class Compare
|
||||
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);
|
||||
string fromPrepareForOld = "34720-637858334555170379.tsv";
|
||||
string fromPrepareForOldFile = Path.Combine(_Configuration.PropertyConfiguration.RootDirectory, fromPrepareForOld);
|
||||
if (File.Exists(fromPrepareForOldFile))
|
||||
@ -433,8 +429,6 @@ public class Compare
|
||||
{
|
||||
if (_Log is null)
|
||||
throw new NullReferenceException(nameof(_Log));
|
||||
if (_AppSettings.MaxDegreeOfParallelism is null)
|
||||
throw new NullReferenceException(nameof(_AppSettings.MaxDegreeOfParallelism));
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "{}");
|
||||
@ -461,7 +455,7 @@ public class Compare
|
||||
throw new Exception("Invalid directory should end with {}!");
|
||||
diffRootDirectory = Property.Models.Stateless.A_Property.GetDiffRootDirectory(_Configuration.DiffPropertyDirectory);
|
||||
}
|
||||
PropertyCompare.Models.PropertyCompareLogic propertyCompareLogic = new(_AppSettings.MaxDegreeOfParallelism.Value, _Configuration.PropertyConfiguration, _SpellingFindReplace, diffRootDirectory);
|
||||
PropertyCompare.Models.PropertyCompareLogic propertyCompareLogic = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, _SpellingFindReplace, diffRootDirectory);
|
||||
if (string.IsNullOrEmpty(_Configuration.DiffPropertyDirectory) || !Directory.Exists(_Configuration.DiffPropertyDirectory))
|
||||
diffPropertyCompareCollection = Array.Empty<PropertyCompare.Models.PropertyCompare>();
|
||||
else
|
||||
@ -509,14 +503,12 @@ public class Compare
|
||||
|
||||
private void ChangeExtensionFromDeleteToJson(string aPropertySingletonDirectory)
|
||||
{
|
||||
if (_AppSettings.MaxDegreeOfParallelism is null)
|
||||
throw new NullReferenceException(nameof(_AppSettings.MaxDegreeOfParallelism));
|
||||
string searchPattern = "*.delete";
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
List<string> topDirectories = new();
|
||||
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)> groupCollection;
|
||||
groupCollection = Property.Models.Stateless.Container.GetGroupCollection(aPropertySingletonDirectory, searchPattern, topDirectories);
|
||||
if (_AppSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
if (_AppSettings.MaxDegreeOfParallelism < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
||||
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles, int r) in groupCollection)
|
||||
{
|
||||
|
@ -6,24 +6,16 @@ namespace View_by_Distance.Compare.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.Compare.Models.Binder;
|
||||
@ -6,16 +6,13 @@ namespace View_by_Distance.Compare.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.Compare.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