Removed Configuration.SetAndUpdate

This commit is contained in:
2023-08-12 10:45:38 -07:00
parent 2f5d309ed1
commit 1c5a2f1d93
57 changed files with 1065 additions and 1542 deletions

View File

@ -0,0 +1,2 @@
[*.cs]
csharp_preserve_single_line_statements = true

View File

@ -1,6 +1,5 @@
using Microsoft.Extensions.Configuration;
using Phares.Shared;
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
namespace View_by_Distance.Property.Models.Binder;
@ -8,28 +7,28 @@ namespace View_by_Distance.Property.Models.Binder;
public class Configuration
{
#nullable disable
[Display(Name = "Date Group"), Required] public string DateGroup { get; set; }
[Display(Name = "File Name Directory Separator"), Required] public string FileNameDirectorySeparator { get; set; }
[Display(Name = "Force Property Last Write Time to Creation Time"), Required] public bool? ForcePropertyLastWriteTimeToCreationTime { get; set; }
[Display(Name = "Ignore Extensions"), Required] public string[] IgnoreExtensions { get; set; }
[Display(Name = "Max Images In Directory For Top Level First Pass"), Required] public int? MaxImagesInDirectoryForTopLevelFirstPass { get; set; }
[Display(Name = "Pattern"), Required] public string Pattern { get; set; }
[Display(Name = "Person Birthday Format"), Required] public string PersonBirthdayFormat { get; set; }
[Display(Name = "Populate Properties FileId"), Required] public bool? PopulatePropertyId { get; set; }
[Display(Name = "Properties Changed For Property"), Required] public bool? PropertiesChangedForProperty { get; set; }
[Display(Name = "Property Content Collection Files"), Required] public string[] PropertyContentCollectionFiles { get; set; }
[Display(Name = "Result All In One"), Required] public string ResultAllInOne { get; set; }
[Display(Name = "Result All In One Max Value"), Required] public int? ResultAllInOneSubdirectoryLength { get; set; }
[Display(Name = "Result Collection"), Required] public string ResultCollection { get; set; }
[Display(Name = "Result Content"), Required] public string ResultContent { get; set; }
[Display(Name = "Result Singleton"), Required] public string ResultSingleton { get; set; }
[Display(Name = "Root Directory"), Required] public string RootDirectory { get; set; }
[Display(Name = "Valid Image Format Extensions"), Required] public string[] ValidImageFormatExtensions { get; set; }
[Display(Name = "Verify to Season"), Required] public string[] VerifyToSeason { get; set; }
#nullable restore
public string? DateGroup { get; set; }
public string? FileNameDirectorySeparator { get; set; }
public bool? ForcePropertyLastWriteTimeToCreationTime { get; set; }
public string[]? IgnoreExtensions { get; set; }
public int? MaxImagesInDirectoryForTopLevelFirstPass { get; set; }
public string? ModelName { init; get; }
public int? NumberOfJitters { init; get; }
public int? NumberOfTimesToUpsample { init; get; }
public string? Pattern { get; set; }
public string? PersonBirthdayFormat { get; set; }
public bool? PopulatePropertyId { get; set; }
public string? PredictorModelName { get; set; }
public bool? PropertiesChangedForProperty { get; set; }
public string[]? PropertyContentCollectionFiles { get; set; }
public string? ResultAllInOne { get; set; }
public int? ResultAllInOneSubdirectoryLength { get; set; }
public string? ResultCollection { get; set; }
public string? ResultContent { get; set; }
public string? ResultSingleton { get; set; }
public string? RootDirectory { get; set; }
public string[]? ValidImageFormatExtensions { get; set; }
public string[]? VerifyToSeason { get; set; }
public override string ToString()
{
@ -40,48 +39,51 @@ public class Configuration
private static Models.Configuration Get(Configuration? configuration)
{
Models.Configuration result;
if (configuration is null)
throw new NullReferenceException(nameof(configuration));
if (configuration.ForcePropertyLastWriteTimeToCreationTime is null)
throw new NullReferenceException(nameof(configuration.ForcePropertyLastWriteTimeToCreationTime));
if (configuration.MaxImagesInDirectoryForTopLevelFirstPass is null)
throw new NullReferenceException(nameof(configuration.MaxImagesInDirectoryForTopLevelFirstPass));
if (configuration.PopulatePropertyId is null)
throw new NullReferenceException(nameof(configuration.PopulatePropertyId));
if (configuration.PropertiesChangedForProperty is null)
throw new NullReferenceException(nameof(configuration.PropertiesChangedForProperty));
if (configuration.ResultAllInOne is null)
throw new NullReferenceException(nameof(configuration.ResultAllInOne));
if (configuration.ResultAllInOneSubdirectoryLength is null)
throw new NullReferenceException(nameof(configuration.ResultAllInOneSubdirectoryLength));
if (configuration.ResultCollection is null)
throw new NullReferenceException(nameof(configuration.ResultCollection));
if (configuration.ResultContent is null)
throw new NullReferenceException(nameof(configuration.ResultContent));
if (configuration.ResultSingleton is null)
throw new NullReferenceException(nameof(configuration.ResultSingleton));
configuration.IgnoreExtensions ??= Array.Empty<string>();
configuration.PropertyContentCollectionFiles ??= Array.Empty<string>();
configuration.ValidImageFormatExtensions ??= Array.Empty<string>();
configuration.VerifyToSeason ??= Array.Empty<string>();
if (configuration is null) throw new NullReferenceException(nameof(configuration));
if (configuration.DateGroup is null) throw new NullReferenceException(nameof(configuration.DateGroup));
if (configuration.FileNameDirectorySeparator is null) throw new NullReferenceException(nameof(configuration.FileNameDirectorySeparator));
if (configuration.ForcePropertyLastWriteTimeToCreationTime is null) throw new NullReferenceException(nameof(configuration.ForcePropertyLastWriteTimeToCreationTime));
// if (configuration.IgnoreExtensions is null) throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
if (configuration.MaxImagesInDirectoryForTopLevelFirstPass is null) throw new NullReferenceException(nameof(configuration.MaxImagesInDirectoryForTopLevelFirstPass));
// if (configuration.ModelName is null) throw new NullReferenceException(nameof(configuration.ModelName));
// if (configuration.NumberOfJitters is null) throw new NullReferenceException(nameof(configuration.NumberOfJitters));
// if (configuration.NumberOfTimesToUpsample is null) throw new NullReferenceException(nameof(configuration.NumberOfTimesToUpsample));
if (configuration.Pattern is null) throw new NullReferenceException(nameof(configuration.Pattern));
if (configuration.PersonBirthdayFormat is null) throw new NullReferenceException(nameof(configuration.PersonBirthdayFormat));
if (configuration.PopulatePropertyId is null) throw new NullReferenceException(nameof(configuration.PopulatePropertyId));
// if (configuration.PredictorModelName is null) throw new NullReferenceException(nameof(configuration.PredictorModelName));
if (configuration.PropertiesChangedForProperty is null) throw new NullReferenceException(nameof(configuration.PropertiesChangedForProperty));
// if (configuration.PropertyContentCollectionFiles is null) throw new NullReferenceException(nameof(configuration.PropertyContentCollectionFiles));
if (configuration.ResultAllInOne is null) throw new NullReferenceException(nameof(configuration.ResultAllInOne));
if (configuration.ResultAllInOneSubdirectoryLength is null) throw new NullReferenceException(nameof(configuration.ResultAllInOneSubdirectoryLength));
if (configuration.ResultCollection is null) throw new NullReferenceException(nameof(configuration.ResultCollection));
if (configuration.ResultContent is null) throw new NullReferenceException(nameof(configuration.ResultContent));
if (configuration.ResultSingleton is null) throw new NullReferenceException(nameof(configuration.ResultSingleton));
if (configuration.RootDirectory is null) throw new NullReferenceException(nameof(configuration.RootDirectory));
// if (configuration.ValidImageFormatExtensions is null) throw new NullReferenceException(nameof(configuration.ValidImageFormatExtensions));
// if (configuration.VerifyToSeason is null) throw new NullReferenceException(nameof(configuration.VerifyToSeason));
result = new(configuration.DateGroup,
configuration.FileNameDirectorySeparator,
configuration.ForcePropertyLastWriteTimeToCreationTime.Value,
configuration.IgnoreExtensions,
configuration.IgnoreExtensions ?? Array.Empty<string>(),
configuration.MaxImagesInDirectoryForTopLevelFirstPass.Value,
configuration.ModelName,
configuration.NumberOfJitters,
configuration.NumberOfTimesToUpsample,
configuration.Pattern,
configuration.PersonBirthdayFormat,
configuration.PopulatePropertyId.Value,
configuration.PredictorModelName,
configuration.PropertiesChangedForProperty.Value,
configuration.PropertyContentCollectionFiles,
configuration.PropertyContentCollectionFiles ?? Array.Empty<string>(),
configuration.ResultAllInOne,
configuration.ResultAllInOneSubdirectoryLength.Value,
configuration.ResultCollection,
configuration.ResultContent,
configuration.ResultSingleton,
configuration.RootDirectory,
configuration.ValidImageFormatExtensions,
configuration.VerifyToSeason);
Path.GetFullPath(configuration.RootDirectory),
configuration.ValidImageFormatExtensions ?? Array.Empty<string>(),
configuration.VerifyToSeason ?? Array.Empty<string>());
return result;
}
@ -98,8 +100,7 @@ public class Configuration
IConfigurationSection configurationSection = configurationRoot.GetSection(section);
configuration = configurationSection.Get<Configuration>();
}
if (configuration is null)
throw new NullReferenceException(nameof(configuration));
if (configuration is null) throw new NullReferenceException(nameof(configuration));
result = Get(configuration);
return result;
}

View File

@ -6,16 +6,8 @@ namespace View_by_Distance.Property.Models;
public class Configuration : Shared.Models.Properties.IPropertyConfiguration
{
protected string? _ModelName;
protected int? _NumberOfJitters;
protected int? _NumberOfTimesToUpsample;
protected string? _PredictorModelName;
protected string _RootDirectory;
public string? ModelName => _ModelName;
public int? NumberOfJitters => _NumberOfJitters;
public int? NumberOfTimesToUpsample => _NumberOfTimesToUpsample;
public string? PredictorModelName => _PredictorModelName;
public string RootDirectory => _RootDirectory;
public string DateGroup { init; get; }
@ -23,9 +15,13 @@ public class Configuration : Shared.Models.Properties.IPropertyConfiguration
public bool ForcePropertyLastWriteTimeToCreationTime { init; get; }
public string[] IgnoreExtensions { init; get; }
public int MaxImagesInDirectoryForTopLevelFirstPass { init; get; }
public string? ModelName { init; get; }
public int? NumberOfJitters { init; get; }
public int? NumberOfTimesToUpsample { init; get; }
public string Pattern { init; get; }
public string PersonBirthdayFormat { init; get; }
public bool PopulatePropertyId { init; get; }
public string? PredictorModelName { init; get; }
public bool PropertiesChangedForProperty { init; get; }
public string[] PropertyContentCollectionFiles { init; get; }
public string ResultAllInOne { init; get; }
@ -41,9 +37,13 @@ public class Configuration : Shared.Models.Properties.IPropertyConfiguration
bool forcePropertyLastWriteTimeToCreationTime,
string[] ignoreExtensions,
int maxImagesInDirectoryForTopLevelFirstPass,
string? modelName,
int? numberOfJitters,
int? numberOfTimesToUpsample,
string pattern,
string personBirthdayFormat,
bool populatePropertyId,
string? predictorModelName,
bool propertiesChangedForProperty,
string[] propertyContentCollectionFiles,
string resultAllInOne,
@ -60,8 +60,12 @@ public class Configuration : Shared.Models.Properties.IPropertyConfiguration
ForcePropertyLastWriteTimeToCreationTime = forcePropertyLastWriteTimeToCreationTime;
IgnoreExtensions = ignoreExtensions;
MaxImagesInDirectoryForTopLevelFirstPass = maxImagesInDirectoryForTopLevelFirstPass;
ModelName = modelName;
NumberOfJitters = numberOfJitters;
NumberOfTimesToUpsample = numberOfTimesToUpsample;
Pattern = pattern;
PersonBirthdayFormat = personBirthdayFormat;
PredictorModelName = predictorModelName;
PopulatePropertyId = populatePropertyId;
PropertiesChangedForProperty = propertiesChangedForProperty;
PropertyContentCollectionFiles = propertyContentCollectionFiles;
@ -80,18 +84,8 @@ public class Configuration : Shared.Models.Properties.IPropertyConfiguration
return result;
}
public void ChangeRootDirectory(string rootDirectory) => _RootDirectory = rootDirectory;
public void Update(int? numberOfJitters, int? numberOfTimesToUpsample, string? modelName, string? predictorModelName)
{
_NumberOfJitters = numberOfJitters;
_NumberOfTimesToUpsample = numberOfTimesToUpsample;
_ModelName = modelName;
_PredictorModelName = predictorModelName;
_RootDirectory = Path.GetFullPath(_RootDirectory);
}
public void Update() => Update(numberOfJitters: null, numberOfTimesToUpsample: null, modelName: null, predictorModelName: null);
public void ChangeRootDirectory(string rootDirectory) =>
_RootDirectory = Path.GetFullPath(rootDirectory);
public static void Verify(Configuration propertyConfiguration, bool requireExist)
{