Re-write
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Phares.Shared;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json;
|
||||
|
||||
@ -6,6 +8,8 @@ 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; }
|
||||
@ -21,23 +25,7 @@ public class Configuration
|
||||
[Display(Name = "Verify to Season"), Required] public string[] VerifyToSeason { get; set; }
|
||||
[Display(Name = "Write Bitmap Data Bytes"), Required] public bool? WriteBitmapDataBytes { get; set; }
|
||||
|
||||
public Configuration()
|
||||
{
|
||||
DateGroup = string.Empty;
|
||||
FileNameDirectorySeparator = string.Empty;
|
||||
ForcePropertyLastWriteTimeToCreationTime = null;
|
||||
IgnoreExtensions = Array.Empty<string>();
|
||||
MaxImagesInDirectoryForTopLevelFirstPass = null;
|
||||
Pattern = string.Empty;
|
||||
PopulatePropertyId = null;
|
||||
PropertiesChangedForProperty = null;
|
||||
PropertyContentCollectionFiles = Array.Empty<string>();
|
||||
RootDirectory = string.Empty;
|
||||
ValidImageFormatExtensions = Array.Empty<string>();
|
||||
ValidMetadataExtensions = Array.Empty<string>();
|
||||
VerifyToSeason = Array.Empty<string>();
|
||||
WriteBitmapDataBytes = null;
|
||||
}
|
||||
#nullable restore
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
@ -45,4 +33,61 @@ public class Configuration
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Models.Configuration Get(Configuration configuration)
|
||||
{
|
||||
Models.Configuration result;
|
||||
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.WriteBitmapDataBytes is null)
|
||||
throw new NullReferenceException(nameof(configuration.WriteBitmapDataBytes));
|
||||
if (configuration.IgnoreExtensions is null)
|
||||
configuration.IgnoreExtensions = Array.Empty<string>();
|
||||
if (configuration.PropertyContentCollectionFiles is null)
|
||||
configuration.PropertyContentCollectionFiles = Array.Empty<string>();
|
||||
if (configuration.ValidImageFormatExtensions is null)
|
||||
configuration.ValidImageFormatExtensions = Array.Empty<string>();
|
||||
if (configuration.ValidMetadataExtensions is null)
|
||||
configuration.ValidMetadataExtensions = Array.Empty<string>();
|
||||
if (configuration.VerifyToSeason is null)
|
||||
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.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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user