This commit is contained in:
2022-11-20 23:20:28 -07:00
parent c6aa7e8e3c
commit 3b988ba152
85 changed files with 1355 additions and 980 deletions

View File

@ -20,10 +20,10 @@ public class AppSettings
return result;
}
private static Models.AppSettings Get(AppSettings appSettings)
private static Models.AppSettings Get(AppSettings? appSettings)
{
Models.AppSettings result;
if (appSettings.MaxDegreeOfParallelism is null)
if (appSettings?.MaxDegreeOfParallelism is null)
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
result = new(
appSettings.Company,
@ -36,7 +36,7 @@ public class AppSettings
public static Models.AppSettings Get(IConfigurationRoot configurationRoot)
{
Models.AppSettings result;
AppSettings appSettings = configurationRoot.Get<AppSettings>();
AppSettings? appSettings = configurationRoot.Get<AppSettings>();
result = Get(appSettings);
return result;
}

View File

@ -1,3 +1,5 @@
using Microsoft.Extensions.Configuration;
using Phares.Shared;
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
@ -11,6 +13,7 @@ public class Configuration
[Display(Name = "By Create Date Shortcut"), Required] public bool? ByCreateDateShortcut { get; set; }
[Display(Name = "By Date"), Required] public bool? ByDay { get; set; }
[Display(Name = "By Hash"), Required] public bool? ByHash { get; set; }
[Display(Name = "By None"), Required] public bool? ByNone { get; set; }
[Display(Name = "By Season"), Required] public bool? BySeason { get; set; }
[Display(Name = "By Week"), Required] public bool? ByWeek { get; set; }
[Display(Name = "Ignore Subdirectories for Rename"), Required] public bool? KeepFullPath { get; set; }
@ -24,4 +27,47 @@ public class Configuration
return result;
}
private static Models.Configuration Get(Configuration? configuration)
{
Models.Configuration result;
if (configuration is null)
throw new NullReferenceException(nameof(configuration));
if (configuration.ByCreateDateShortcut is null)
throw new NullReferenceException(nameof(configuration.ByCreateDateShortcut));
if (configuration.ByDay is null)
throw new NullReferenceException(nameof(configuration.ByDay));
if (configuration.ByHash is null)
throw new NullReferenceException(nameof(configuration.ByHash));
if (configuration.ByNone is null)
throw new NullReferenceException(nameof(configuration.ByNone));
if (configuration.BySeason is null)
throw new NullReferenceException(nameof(configuration.BySeason));
if (configuration.ByWeek is null)
throw new NullReferenceException(nameof(configuration.ByWeek));
if (configuration.KeepFullPath is null)
throw new NullReferenceException(nameof(configuration.KeepFullPath));
result = new(configuration.PropertyConfiguration, configuration.ByCreateDateShortcut.Value, configuration.ByDay.Value, configuration.ByHash.Value, configuration.ByNone.Value, configuration.BySeason.Value, configuration.ByWeek.Value, configuration.KeepFullPath.Value);
return result;
}
public static Models.Configuration Get(IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, Property.Models.Configuration propertyConfiguration)
{
Models.Configuration result;
Configuration? configuration;
if (isEnvironment is null)
configuration = configurationRoot.Get<Configuration>();
else
{
string environmentName = IsEnvironment.GetEnvironmentName(isEnvironment);
string section = string.Concat(environmentName, ":", nameof(Configuration));
IConfigurationSection configurationSection = configurationRoot.GetSection(section);
configuration = configurationSection.Get<Configuration>();
}
result = Get(configuration);
if (configuration is null)
throw new NullReferenceException(nameof(configuration));
result.SetAndUpdate(propertyConfiguration, numberOfJitters: null, numberOfTimesToUpsample: null, modelName: null, predictorModelName: null);
return result;
}
}

View File

@ -6,30 +6,27 @@ namespace View_by_Distance.Date.Group.Models;
public class Configuration
{
protected readonly bool? _ByCreateDateShortcut;
protected readonly bool? _ByDay;
protected readonly bool? _ByHash;
protected readonly bool? _BySeason;
protected readonly bool? _ByWeek;
protected readonly bool? _KeepFullPath;
protected Property.Models.Configuration _PropertyConfiguration;
public bool? ByCreateDateShortcut => _ByCreateDateShortcut;
public bool? ByDay => _ByDay;
public bool? ByHash => _ByHash;
public bool? BySeason => _BySeason;
public bool? ByWeek => _ByWeek;
public bool? KeepFullPath => _KeepFullPath;
public Property.Models.Configuration PropertyConfiguration => _PropertyConfiguration;
public bool ByCreateDateShortcut { init; get; }
public bool ByDay { init; get; }
public bool ByHash { init; get; }
public bool ByNone { init; get; }
public bool BySeason { init; get; }
public bool ByWeek { init; get; }
public bool KeepFullPath { init; get; }
[JsonConstructor]
public Configuration(bool? byCreateDateShortcut, bool? byDay, bool? byHash, bool? bySeason, bool? byWeek, bool? keepFullPath, Property.Models.Configuration propertyConfiguration)
public Configuration(Property.Models.Configuration propertyConfiguration, bool byCreateDateShortcut, bool byDay, bool byHash, bool byNone, bool bySeason, bool byWeek, bool keepFullPath)
{
_ByCreateDateShortcut = byCreateDateShortcut;
_ByDay = byDay;
_ByHash = byHash;
_BySeason = bySeason;
_ByWeek = byWeek;
_KeepFullPath = keepFullPath;
ByDay = byDay;
ByHash = byHash;
ByNone = byNone;
ByWeek = byWeek;
BySeason = bySeason;
KeepFullPath = keepFullPath;
ByCreateDateShortcut = byCreateDateShortcut;
_PropertyConfiguration = propertyConfiguration;
}

View File

@ -1,43 +0,0 @@
using Microsoft.Extensions.Configuration;
using Phares.Shared;
using System.Text.Json;
namespace View_by_Distance.Date.Group.Models.Stateless;
public abstract class Configuration
{
public static Models.Configuration Get(IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, string workingDirectory, Property.Models.Configuration propertyConfiguration)
{
Models.Configuration? result;
string environmentName = IsEnvironment.GetEnvironmentName(isEnvironment);
string section = string.Concat(environmentName, ":", nameof(Binder.Configuration));
IConfigurationSection configurationSection = configurationRoot.GetSection(section);
Binder.Configuration configuration = configurationSection.Get<Binder.Configuration>();
string json = JsonSerializer.Serialize(configuration, new JsonSerializerOptions() { WriteIndented = true });
result = JsonSerializer.Deserialize<Models.Configuration>(json);
if (result is null)
throw new Exception(json);
string jsonThis = result.ToString();
result.SetAndUpdate(propertyConfiguration, null, null, null, null);
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;
}
}