using System.Text.Json; using System.Text.Json.Serialization; namespace View_by_Distance.Property.Models; public class Configuration { protected readonly string _DateGroup; protected readonly string _FileNameDirectorySeparator; protected readonly bool? _ForcePropertyLastWriteTimeToCreationTime; protected readonly string[] _IgnoreExtensions; protected readonly int? _MaxImagesInDirectoryForTopLevelFirstPass; protected readonly string _Pattern; protected readonly bool? _PopulatePropertyId; protected readonly bool? _PropertiesChangedForProperty; protected readonly string[] _PropertyContentCollectionFiles; protected string _RootDirectory; protected readonly string[] _ValidImageFormatExtensions; protected readonly string[] _ValidMetadataExtensions; protected readonly string[] _VerifyToSeason; protected readonly bool? _WriteBitmapDataBytes; public string DateGroup => _DateGroup; public string FileNameDirectorySeparator => _FileNameDirectorySeparator; public bool? ForcePropertyLastWriteTimeToCreationTime => _ForcePropertyLastWriteTimeToCreationTime; public string[] IgnoreExtensions => _IgnoreExtensions; public int? MaxImagesInDirectoryForTopLevelFirstPass => _MaxImagesInDirectoryForTopLevelFirstPass; public string Pattern => _Pattern; public bool? PopulatePropertyId => _PopulatePropertyId; public bool? PropertiesChangedForProperty => _PropertiesChangedForProperty; public string[] PropertyContentCollectionFiles => _PropertyContentCollectionFiles; public string RootDirectory => _RootDirectory; public string[] ValidImageFormatExtensions => _ValidImageFormatExtensions; public string[] ValidMetadataExtensions => _ValidMetadataExtensions; public string[] VerifyToSeason => _VerifyToSeason; public bool? WriteBitmapDataBytes => _WriteBitmapDataBytes; [JsonConstructor] public Configuration(string dateGroup, string fileNameDirectorySeparator, bool? forcePropertyLastWriteTimeToCreationTime, string[] ignoreExtensions, int? maxImagesInDirectoryForTopLevelFirstPass, string pattern, bool? populatePropertyId, bool? propertiesChangedForProperty, string[] propertyContentCollectionFiles, string rootDirectory, string[] validImageFormatExtensions, string[] validMetadataExtensions, string[] verifyToSeason, bool? writeBitmapDataBytes) { _DateGroup = dateGroup; _FileNameDirectorySeparator = fileNameDirectorySeparator; _ForcePropertyLastWriteTimeToCreationTime = forcePropertyLastWriteTimeToCreationTime; _IgnoreExtensions = ignoreExtensions; _MaxImagesInDirectoryForTopLevelFirstPass = maxImagesInDirectoryForTopLevelFirstPass; _Pattern = pattern; _PopulatePropertyId = populatePropertyId; _PropertiesChangedForProperty = propertiesChangedForProperty; _PropertyContentCollectionFiles = propertyContentCollectionFiles; _RootDirectory = rootDirectory; _ValidImageFormatExtensions = validImageFormatExtensions; _ValidMetadataExtensions = validMetadataExtensions; _VerifyToSeason = verifyToSeason; _WriteBitmapDataBytes = writeBitmapDataBytes; } public override string ToString() { string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true }); return result; } public void Update() => _RootDirectory = Path.GetFullPath(_RootDirectory); public static void Verify(Configuration? propertyConfiguration) { if (propertyConfiguration is null) throw new NullReferenceException(nameof(propertyConfiguration)); if (propertyConfiguration.ForcePropertyLastWriteTimeToCreationTime is null) throw new NullReferenceException(nameof(propertyConfiguration.ForcePropertyLastWriteTimeToCreationTime)); if (propertyConfiguration.IgnoreExtensions is null || !propertyConfiguration.IgnoreExtensions.Any()) throw new NullReferenceException(nameof(propertyConfiguration.IgnoreExtensions)); if (propertyConfiguration.PopulatePropertyId is null) throw new NullReferenceException(nameof(propertyConfiguration.PopulatePropertyId)); if (propertyConfiguration.PropertiesChangedForProperty is null) throw new NullReferenceException(nameof(propertyConfiguration.PropertiesChangedForProperty)); if (propertyConfiguration.PropertyContentCollectionFiles is null) throw new NullReferenceException(nameof(propertyConfiguration.PropertyContentCollectionFiles)); if (propertyConfiguration.ValidImageFormatExtensions is null || !propertyConfiguration.ValidImageFormatExtensions.Any()) throw new NullReferenceException(nameof(propertyConfiguration.ValidImageFormatExtensions)); if (propertyConfiguration.ValidMetadataExtensions is null || !propertyConfiguration.ValidMetadataExtensions.Any()) throw new NullReferenceException(nameof(propertyConfiguration.ValidMetadataExtensions)); if (propertyConfiguration.VerifyToSeason is null || !propertyConfiguration.VerifyToSeason.Any()) throw new NullReferenceException(nameof(propertyConfiguration.VerifyToSeason)); if (propertyConfiguration.WriteBitmapDataBytes is null) throw new NullReferenceException(nameof(propertyConfiguration.WriteBitmapDataBytes)); if (Path.GetPathRoot(propertyConfiguration.RootDirectory) == propertyConfiguration.RootDirectory) throw new NullReferenceException(nameof(propertyConfiguration.RootDirectory)); 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) || !Directory.Exists(propertyConfiguration.RootDirectory)) throw new NullReferenceException(nameof(propertyConfiguration.RootDirectory)); } public void ChangeRootDirectory(string rootDirectory) => _RootDirectory = rootDirectory; }