54 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Microsoft.Extensions.Configuration;
 | |
| using Phares.Shared;
 | |
| using System.Text.Json;
 | |
| 
 | |
| namespace View_by_Distance.Metadata.Query.Models.Binder;
 | |
| 
 | |
| public class Configuration
 | |
| {
 | |
| 
 | |
| #nullable disable
 | |
| 
 | |
|     public string[] IgnoreExtensions { get; set; }
 | |
|     public Property.Models.Configuration PropertyConfiguration { get; set; }
 | |
|     public string PersonBirthdayFormat { 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.IgnoreExtensions is null) throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
 | |
|         if (configuration.PersonBirthdayFormat is null) throw new NullReferenceException(nameof(configuration.PersonBirthdayFormat));
 | |
|         result = new(
 | |
|             configuration.IgnoreExtensions,
 | |
|             configuration.PersonBirthdayFormat,
 | |
|             configuration.PropertyConfiguration);
 | |
|         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);
 | |
|         return result;
 | |
|     }
 | |
| 
 | |
| } |