44 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Microsoft.Extensions.Configuration;
 | |
| using Phares.Shared;
 | |
| using System.Text.Json;
 | |
| 
 | |
| namespace View_by_Distance.Not.Copy.Copy.Models.Stateless;
 | |
| 
 | |
| public abstract class Configuration
 | |
| {
 | |
| 
 | |
|     public static Models.Configuration Get(IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, string workingDirectory, Property.Models.Configuration propertyConfiguration)
 | |
|     {
 | |
|         Models.Configuration? result;
 | |
|         string environmentName = IsEnvironment.GetEnvironmentName(isEnvironment);
 | |
|         string section = string.Concat(environmentName, ":", nameof(Binder.Configuration));
 | |
|         IConfigurationSection configurationSection = configurationRoot.GetSection(section);
 | |
|         Binder.Configuration configuration = configurationSection.Get<Binder.Configuration>();
 | |
|         string json = JsonSerializer.Serialize(configuration, new JsonSerializerOptions() { WriteIndented = true });
 | |
|         result = JsonSerializer.Deserialize<Models.Configuration>(json);
 | |
|         if (result is null)
 | |
|             throw new Exception(json);
 | |
|         string jsonThis = result.ToString();
 | |
|         result.Set(propertyConfiguration);
 | |
|         result.Update();
 | |
|         if (jsonThis != json)
 | |
|         {
 | |
|             int? check = null;
 | |
|             int min = new int[] { json.Length, jsonThis.Length }.Min();
 | |
|             for (int i = 0; i < min; i++)
 | |
|             {
 | |
|                 if (json[i] == jsonThis[i])
 | |
|                     continue;
 | |
|                 check = i;
 | |
|                 break;
 | |
|             }
 | |
|             if (check is null)
 | |
|                 throw new Exception();
 | |
|             string a = json[..check.Value].Split(',')[^1];
 | |
|             string b = json[check.Value..].Split(',')[0];
 | |
|             throw new Exception($"{a}{b}");
 | |
|         }
 | |
|         return result;
 | |
|     }
 | |
| 
 | |
| } |