67 lines
2.8 KiB
C#
67 lines
2.8 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Phares.Shared;
|
|
using System.Text.Json;
|
|
|
|
namespace View_by_Distance.Date.Group.Models.Binder;
|
|
|
|
public class Configuration
|
|
{
|
|
|
|
#nullable disable
|
|
|
|
public bool? ByCreateDateShortcut { get; set; }
|
|
public bool? ByDay { get; set; }
|
|
public bool? ByHash { get; set; }
|
|
public bool? BySeason { get; set; }
|
|
public bool? ByWeek { get; set; }
|
|
public bool? KeepFullPath { get; set; }
|
|
public Property.Models.Configuration PropertyConfiguration { 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.ByCreateDateShortcut is null) throw new NullReferenceException(nameof(configuration.ByCreateDateShortcut));
|
|
if (configuration.ByDay is null) throw new NullReferenceException(nameof(configuration.ByDay));
|
|
if (configuration.ByHash is null) throw new NullReferenceException(nameof(configuration.ByHash));
|
|
if (configuration.BySeason is null) throw new NullReferenceException(nameof(configuration.BySeason));
|
|
if (configuration.ByWeek is null) throw new NullReferenceException(nameof(configuration.ByWeek));
|
|
if (configuration.KeepFullPath is null) throw new NullReferenceException(nameof(configuration.KeepFullPath));
|
|
result = new(
|
|
configuration.PropertyConfiguration,
|
|
configuration.ByCreateDateShortcut.Value,
|
|
configuration.ByDay.Value,
|
|
configuration.ByHash.Value,
|
|
configuration.BySeason.Value,
|
|
configuration.ByWeek.Value,
|
|
configuration.KeepFullPath.Value);
|
|
return result;
|
|
}
|
|
|
|
public static Models.Configuration Get(IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, Property.Models.Configuration propertyConfiguration)
|
|
{
|
|
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);
|
|
if (configuration is null) throw new NullReferenceException(nameof(configuration));
|
|
return result;
|
|
}
|
|
|
|
} |