99 lines
4.6 KiB
C#
99 lines
4.6 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using System;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Text.Json;
|
|
|
|
namespace OI.Metrology.Archive.Models.Binder;
|
|
|
|
public class AppSettings
|
|
{
|
|
|
|
#nullable disable
|
|
|
|
[Display(Name = "Api Logging Content Types"), Required] public string ApiLoggingContentTypes { get; set; }
|
|
[Display(Name = "Api Logging Path Prefixes"), Required] public string ApiLoggingPathPrefixes { get; set; }
|
|
[Display(Name = "Api Log Path"), Required] public string ApiLogPath { get; set; }
|
|
[Display(Name = "Attachment Path"), Required] public string AttachmentPath { get; set; }
|
|
[Display(Name = "Build Number"), Required] public string BuildNumber { get; set; }
|
|
[Display(Name = "Company"), Required] public string Company { get; set; }
|
|
[Display(Name = "Connection String"), Required] public string ConnectionString { get; set; }
|
|
[Display(Name = "Git Commit Seven"), Required] public string GitCommitSeven { get; set; }
|
|
[Display(Name = "Inbound Api Allowed IP List"), Required] public string InboundApiAllowedIPList { get; set; }
|
|
[Display(Name = "MonA Resource"), Required] public string MonAResource { get; set; }
|
|
[Display(Name = "MonA Site"), Required] public string MonASite { get; set; }
|
|
[Display(Name = "Oi 2 Sql Connection String"), Required] public string Oi2SqlConnectionString { get; set; }
|
|
[Display(Name = "OI Export Path"), Required] public string OIExportPath { get; set; }
|
|
[Display(Name = "URLs"), Required] public string URLs { get; set; }
|
|
[Display(Name = "Working Directory Name"), Required] public string WorkingDirectoryName { get; set; }
|
|
|
|
#nullable restore
|
|
|
|
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.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.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.MonAResource is null)
|
|
throw new NullReferenceException(nameof(MonAResource));
|
|
if (appSettings.MonASite is null)
|
|
throw new NullReferenceException(nameof(MonASite));
|
|
if (appSettings.Oi2SqlConnectionString is null)
|
|
throw new NullReferenceException(nameof(Oi2SqlConnectionString));
|
|
if (appSettings.OIExportPath is null)
|
|
throw new NullReferenceException(nameof(OIExportPath));
|
|
if (appSettings.URLs is null)
|
|
throw new NullReferenceException(nameof(URLs));
|
|
if (appSettings.WorkingDirectoryName is null)
|
|
throw new NullReferenceException(nameof(WorkingDirectoryName));
|
|
result = new(
|
|
appSettings.ApiLoggingContentTypes,
|
|
appSettings.ApiLoggingPathPrefixes,
|
|
appSettings.ApiLogPath,
|
|
appSettings.AttachmentPath,
|
|
appSettings.BuildNumber,
|
|
appSettings.Company,
|
|
appSettings.ConnectionString,
|
|
appSettings.GitCommitSeven,
|
|
appSettings.InboundApiAllowedIPList,
|
|
appSettings.MonAResource,
|
|
appSettings.MonASite,
|
|
appSettings.Oi2SqlConnectionString,
|
|
appSettings.OIExportPath,
|
|
appSettings.URLs,
|
|
appSettings.WorkingDirectoryName);
|
|
return result;
|
|
}
|
|
|
|
public static Models.AppSettings Get(IConfigurationRoot configurationRoot)
|
|
{
|
|
Models.AppSettings result;
|
|
AppSettings appSettings = configurationRoot.Get<AppSettings>();
|
|
result = Get(appSettings);
|
|
return result;
|
|
}
|
|
|
|
} |