using Microsoft.Extensions.Configuration; using System; using System.Linq; using System.Text.Json; namespace OI.Metrology.Archive.Models.Stateless; public abstract class AppSettings { #nullable enable public static Models.AppSettings Get(IConfigurationRoot configurationRoot) { Models.AppSettings? result; Binder.AppSettings appSettings = configurationRoot.Get(); string json = JsonSerializer.Serialize(appSettings, new JsonSerializerOptions() { WriteIndented = true }); result = JsonSerializer.Deserialize(json); if (result is null) throw new Exception(json); if (string.IsNullOrEmpty(result.Company)) throw new Exception(json); string jsonThis = result.ToString(); 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; } }