using System.Text.Json; using System.Text.Json.Serialization; namespace OI.Metrology.Server.Models.Binder; public class AppSettings { public string? ApiExportPath { get; set; } public string? ApiLoggingContentTypes { get; set; } public string? ApiLoggingPathPrefixes { get; set; } public string? ApiLogPath { get; set; } public string? ApiUrl { get; set; } public string? AttachmentPath { get; set; } public string? BuildNumber { get; set; } public string? Company { get; set; } public string? ConnectionString { get; set; } public string? GitCommitSeven { get; set; } public string? InboundApiAllowedIPList { get; set; } public string? IqsColumns { get; set; } public string? IqsFile { get; set; } public string? IqsKey { get; set; } public string? IqsRed { get; set; } public string? IqsYellow { get; set; } public bool? IsDevelopment { get; set; } public bool? IsStaging { get; set; } public string? MockRoot { get; set; } public string? MonAResource { get; set; } public string? MonASite { get; set; } public string? OpenInsightApplicationProgrammingInterface { get; set; } public Dictionary? TableToPath { get; set; } public string? URLs { get; set; } public string? WaferCounterDestinationDirectory { get; set; } public string? WaferCounterRootDirectory { get; set; } public string? WorkingDirectoryName { get; set; } public override string ToString() { string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true }); return result; } private static Models.AppSettings Get(AppSettings? appSettings) { Models.AppSettings result; if (appSettings is null) throw new NullReferenceException(nameof(appSettings)); if (appSettings.ApiExportPath is null) throw new NullReferenceException(nameof(ApiExportPath)); if (appSettings.ApiLoggingContentTypes is null) throw new NullReferenceException(nameof(ApiLoggingContentTypes)); if (appSettings.ApiLoggingPathPrefixes is null) throw new NullReferenceException(nameof(ApiLoggingPathPrefixes)); if (appSettings.ApiLogPath is null) throw new NullReferenceException(nameof(ApiLogPath)); if (appSettings.ApiUrl is null) throw new NullReferenceException(nameof(ApiUrl)); if (appSettings.AttachmentPath is null) throw new NullReferenceException(nameof(AttachmentPath)); if (appSettings.BuildNumber is null) throw new NullReferenceException(nameof(BuildNumber)); if (appSettings.Company is null) throw new NullReferenceException(nameof(Company)); if (appSettings.ConnectionString is null) throw new NullReferenceException(nameof(ConnectionString)); if (appSettings.GitCommitSeven is null) throw new NullReferenceException(nameof(GitCommitSeven)); if (appSettings.InboundApiAllowedIPList is null) throw new NullReferenceException(nameof(InboundApiAllowedIPList)); if (appSettings.IqsColumns is null) throw new NullReferenceException(nameof(IqsColumns)); if (appSettings.IqsFile is null) throw new NullReferenceException(nameof(IqsFile)); if (appSettings.IqsKey is null) throw new NullReferenceException(nameof(IqsKey)); if (appSettings.IqsRed is null) throw new NullReferenceException(nameof(IqsRed)); if (appSettings.IqsYellow is null) throw new NullReferenceException(nameof(IqsYellow)); if (appSettings.IsDevelopment is null) throw new NullReferenceException(nameof(IsDevelopment)); if (appSettings.IsStaging is null) throw new NullReferenceException(nameof(IsStaging)); if (appSettings.MockRoot is null) throw new NullReferenceException(nameof(MockRoot)); if (appSettings.MonAResource is null) throw new NullReferenceException(nameof(MonAResource)); if (appSettings.MonASite is null) throw new NullReferenceException(nameof(MonASite)); if (appSettings.OpenInsightApplicationProgrammingInterface is null) throw new NullReferenceException(nameof(OpenInsightApplicationProgrammingInterface)); if (appSettings.URLs is null) throw new NullReferenceException(nameof(URLs)); if (appSettings.TableToPath is null) throw new NullReferenceException(nameof(TableToPath)); if (appSettings.WaferCounterDestinationDirectory is null) throw new NullReferenceException(nameof(WaferCounterDestinationDirectory)); if (appSettings.WaferCounterRootDirectory is null) throw new NullReferenceException(nameof(WaferCounterRootDirectory)); if (appSettings.WorkingDirectoryName is null) throw new NullReferenceException(nameof(WorkingDirectoryName)); result = new( appSettings.ApiExportPath, appSettings.ApiLoggingContentTypes, appSettings.ApiLoggingPathPrefixes, appSettings.ApiLogPath, appSettings.ApiUrl, appSettings.AttachmentPath, appSettings.BuildNumber, appSettings.Company, appSettings.ConnectionString, appSettings.GitCommitSeven, appSettings.InboundApiAllowedIPList, appSettings.IqsColumns, appSettings.IqsFile, appSettings.IqsKey, appSettings.IqsRed, appSettings.IqsYellow, appSettings.IsDevelopment.Value, appSettings.IsStaging.Value, appSettings.MockRoot, appSettings.MonAResource, appSettings.MonASite, appSettings.OpenInsightApplicationProgrammingInterface, appSettings.TableToPath, appSettings.URLs, appSettings.WaferCounterDestinationDirectory, appSettings.WaferCounterRootDirectory, appSettings.WorkingDirectoryName); return result; } public static Models.AppSettings Get(IConfigurationRoot configurationRoot) { Models.AppSettings result; #pragma warning disable IL3050, IL2026 AppSettings? appSettings = configurationRoot.Get(); #pragma warning restore IL3050, IL2026 if (appSettings?.ApiExportPath is null) { List paths = new(); foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers) { if (configurationProvider is not Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider jsonConfigurationProvider) continue; if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider) continue; paths.Add(physicalFileProvider.Root); if (!physicalFileProvider.Root.Contains("UserSecrets")) continue; throw new NotSupportedException(physicalFileProvider.Root); } throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths)}"); } result = Get(appSettings); return result; } } [JsonSourceGenerationOptions(WriteIndented = true)] [JsonSerializable(typeof(AppSettings))] internal partial class BinderAppSettingsSourceGenerationContext : JsonSerializerContext { }