2022-07-24 12:35:00 -07:00

103 lines
6.5 KiB
C#

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 Exception($"{nameof(propertyConfiguration)} must be set!");
if (propertyConfiguration.ForcePropertyLastWriteTimeToCreationTime is null)
throw new Exception($"{nameof(propertyConfiguration.ForcePropertyLastWriteTimeToCreationTime)} must be set!");
if (propertyConfiguration.IgnoreExtensions is null || !propertyConfiguration.IgnoreExtensions.Any())
throw new Exception($"{nameof(propertyConfiguration.IgnoreExtensions)} must be set!");
if (propertyConfiguration.PopulatePropertyId is null)
throw new Exception($"{nameof(propertyConfiguration.PopulatePropertyId)} must be set!");
if (propertyConfiguration.PropertiesChangedForProperty is null)
throw new Exception($"{nameof(propertyConfiguration.PropertiesChangedForProperty)} must be set!");
if (propertyConfiguration.PropertyContentCollectionFiles is null)
throw new Exception($"{nameof(propertyConfiguration.PropertyContentCollectionFiles)} must be set!");
if (propertyConfiguration.ValidImageFormatExtensions is null || !propertyConfiguration.ValidImageFormatExtensions.Any())
throw new Exception($"{nameof(propertyConfiguration.ValidImageFormatExtensions)} must be set!");
if (propertyConfiguration.ValidMetadataExtensions is null || !propertyConfiguration.ValidMetadataExtensions.Any())
throw new Exception($"{nameof(propertyConfiguration.ValidMetadataExtensions)} must be set!");
if (propertyConfiguration.VerifyToSeason is null || !propertyConfiguration.VerifyToSeason.Any())
throw new Exception($"{nameof(propertyConfiguration.VerifyToSeason)} must be set!");
if (propertyConfiguration.WriteBitmapDataBytes is null)
throw new Exception($"{nameof(propertyConfiguration.WriteBitmapDataBytes)} must be set!");
if (Path.GetPathRoot(propertyConfiguration.RootDirectory) == propertyConfiguration.RootDirectory)
throw new Exception($"{nameof(propertyConfiguration.RootDirectory)} should have at least one level!");
if (propertyConfiguration is null)
throw new Exception($"{nameof(propertyConfiguration)} must be set!");
if (string.IsNullOrEmpty(propertyConfiguration.DateGroup))
throw new Exception($"{nameof(propertyConfiguration.DateGroup)} must have a value!");
if (string.IsNullOrEmpty(propertyConfiguration.FileNameDirectorySeparator))
throw new Exception($"{nameof(propertyConfiguration.FileNameDirectorySeparator)} must have a value!");
if (string.IsNullOrEmpty(propertyConfiguration.Pattern))
throw new Exception($"{nameof(propertyConfiguration.Pattern)} must have a value!");
if (string.IsNullOrEmpty(propertyConfiguration.RootDirectory) || !Directory.Exists(propertyConfiguration.RootDirectory))
throw new Exception($"{nameof(propertyConfiguration.RootDirectory)} must have a value and exits!");
}
public void ChangeRootDirectory(string rootDirectory) => _RootDirectory = rootDirectory;
}