2023-10-15 09:51:56 -07:00

111 lines
6.1 KiB
C#

using System.Text.Json;
using System.Text.Json.Serialization;
namespace View_by_Distance.Property.Models;
public class Configuration : Shared.Models.Properties.IPropertyConfiguration
{
protected string _RootDirectory;
public string RootDirectory => _RootDirectory;
public string DateGroup { init; get; }
public string FileNameDirectorySeparator { init; get; }
public bool ForcePropertyLastWriteTimeToCreationTime { init; get; }
public string[] IgnoreExtensions { init; get; }
public string[] IgnoreRulesKeyWords { init; get; }
public int MaxImagesInDirectoryForTopLevelFirstPass { init; get; }
public string? ModelName { init; get; }
public int? NumberOfJitters { init; get; }
public int? NumberOfTimesToUpsample { init; get; }
public int Offset { 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; }
public int ResultAllInOneSubdirectoryLength { init; get; }
public string ResultCollection { init; get; }
public string ResultContent { init; get; }
public string ResultSingleton { init; get; }
public string[] ValidImageFormatExtensions { init; get; }
[JsonConstructor]
public Configuration(string dateGroup,
string fileNameDirectorySeparator,
bool forcePropertyLastWriteTimeToCreationTime,
string[] ignoreExtensions,
string[] ignoreRulesKeyWords,
int maxImagesInDirectoryForTopLevelFirstPass,
string? modelName,
int? numberOfJitters,
int? numberOfTimesToUpsample,
int offset,
string pattern,
string personBirthdayFormat,
bool populatePropertyId,
string? predictorModelName,
bool propertiesChangedForProperty,
string[] propertyContentCollectionFiles,
string resultAllInOne,
int resultAllInOneSubdirectoryLength,
string resultCollection,
string resultContent,
string resultSingleton,
string rootDirectory,
string[] validImageFormatExtensions,
string[] verifyToSeason)
{
DateGroup = dateGroup;
FileNameDirectorySeparator = fileNameDirectorySeparator;
ForcePropertyLastWriteTimeToCreationTime = forcePropertyLastWriteTimeToCreationTime;
IgnoreExtensions = ignoreExtensions;
IgnoreRulesKeyWords = ignoreRulesKeyWords;
MaxImagesInDirectoryForTopLevelFirstPass = maxImagesInDirectoryForTopLevelFirstPass;
ModelName = modelName;
NumberOfJitters = numberOfJitters;
NumberOfTimesToUpsample = numberOfTimesToUpsample;
Offset = offset;
Pattern = pattern;
PersonBirthdayFormat = personBirthdayFormat;
PredictorModelName = predictorModelName;
PopulatePropertyId = populatePropertyId;
PropertiesChangedForProperty = propertiesChangedForProperty;
PropertyContentCollectionFiles = propertyContentCollectionFiles;
ResultAllInOne = resultAllInOne;
ResultAllInOneSubdirectoryLength = resultAllInOneSubdirectoryLength;
ResultCollection = resultCollection;
ResultContent = resultContent;
ResultSingleton = resultSingleton;
_RootDirectory = rootDirectory;
ValidImageFormatExtensions = validImageFormatExtensions;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
public void ChangeRootDirectory(string rootDirectory) =>
_RootDirectory = Path.GetFullPath(rootDirectory);
public static void Verify(Configuration propertyConfiguration, bool requireExist)
{
if (propertyConfiguration is null) throw new NullReferenceException(nameof(propertyConfiguration));
if (propertyConfiguration.IgnoreExtensions is null || propertyConfiguration.IgnoreExtensions.Length == 0) throw new NullReferenceException(nameof(propertyConfiguration.IgnoreExtensions));
if (propertyConfiguration.IgnoreRulesKeyWords is null || propertyConfiguration.IgnoreRulesKeyWords.Length == 0) throw new NullReferenceException(nameof(propertyConfiguration.IgnoreRulesKeyWords));
if (propertyConfiguration.PropertyContentCollectionFiles is null) throw new NullReferenceException(nameof(propertyConfiguration.PropertyContentCollectionFiles));
if (propertyConfiguration.ValidImageFormatExtensions is null || propertyConfiguration.ValidImageFormatExtensions.Length == 0) throw new NullReferenceException(nameof(propertyConfiguration.ValidImageFormatExtensions));
if (propertyConfiguration is null) throw new NullReferenceException(nameof(propertyConfiguration));
if (string.IsNullOrEmpty(propertyConfiguration.DateGroup)) throw new NullReferenceException(nameof(propertyConfiguration.DateGroup));
if (string.IsNullOrEmpty(propertyConfiguration.FileNameDirectorySeparator)) throw new NullReferenceException(nameof(propertyConfiguration.FileNameDirectorySeparator));
if (string.IsNullOrEmpty(propertyConfiguration.Pattern)) throw new NullReferenceException(nameof(propertyConfiguration.Pattern));
if (string.IsNullOrEmpty(propertyConfiguration.RootDirectory) || (requireExist && !Directory.Exists(propertyConfiguration.RootDirectory))) throw new NullReferenceException(nameof(propertyConfiguration.RootDirectory));
if (propertyConfiguration.RootDirectory != Path.GetFullPath(propertyConfiguration.RootDirectory)) throw new Exception();
}
}