106 lines
6.0 KiB
C#
106 lines
6.0 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Phares.Shared;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Text.Json;
|
|
|
|
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 = "Populate Properties Id"), 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 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 = "Valid Metadata Extensions"), Required] public string[] ValidMetadataExtensions { get; set; }
|
|
[Display(Name = "Verify to Season"), Required] public string[] VerifyToSeason { get; set; }
|
|
[Display(Name = "Write Bitmap Data Bytes"), Required] public bool? WriteBitmapDataBytes { get; set; }
|
|
|
|
#nullable restore
|
|
|
|
public override string ToString()
|
|
{
|
|
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
|
return result;
|
|
}
|
|
|
|
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.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.WriteBitmapDataBytes is null)
|
|
throw new NullReferenceException(nameof(configuration.WriteBitmapDataBytes));
|
|
configuration.IgnoreExtensions ??= Array.Empty<string>();
|
|
configuration.PropertyContentCollectionFiles ??= Array.Empty<string>();
|
|
configuration.ValidImageFormatExtensions ??= Array.Empty<string>();
|
|
configuration.ValidMetadataExtensions ??= Array.Empty<string>();
|
|
configuration.VerifyToSeason ??= Array.Empty<string>();
|
|
result = new(configuration.DateGroup,
|
|
configuration.FileNameDirectorySeparator,
|
|
configuration.ForcePropertyLastWriteTimeToCreationTime.Value,
|
|
configuration.IgnoreExtensions,
|
|
configuration.MaxImagesInDirectoryForTopLevelFirstPass.Value,
|
|
configuration.Pattern,
|
|
configuration.PopulatePropertyId.Value,
|
|
configuration.PropertiesChangedForProperty.Value,
|
|
configuration.PropertyContentCollectionFiles,
|
|
configuration.ResultAllInOne,
|
|
configuration.ResultCollection,
|
|
configuration.ResultContent,
|
|
configuration.ResultSingleton,
|
|
configuration.RootDirectory,
|
|
configuration.ValidImageFormatExtensions,
|
|
configuration.ValidMetadataExtensions,
|
|
configuration.VerifyToSeason,
|
|
configuration.WriteBitmapDataBytes.Value);
|
|
return result;
|
|
}
|
|
|
|
public static Models.Configuration Get(IsEnvironment isEnvironment, IConfigurationRoot configurationRoot)
|
|
{
|
|
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);
|
|
return result;
|
|
}
|
|
|
|
} |