Dynamic 5 and 14 point copy
AppSettings alignment with other projects _TestContextTestName over _TestContext
This commit is contained in:
@ -26,6 +26,52 @@ public record AppSettings(string AzureDevOpsDestinationDirectory,
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void Verify(AppSettings appSettings)
|
||||
{
|
||||
if (string.IsNullOrEmpty(appSettings.Company))
|
||||
throw new Exception("Company name must have a value!");
|
||||
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
|
||||
throw new Exception("Working directory name must have a value!");
|
||||
}
|
||||
|
||||
public static AppSettings Get(IConfigurationRoot configurationRoot)
|
||||
{
|
||||
AppSettings result;
|
||||
AppSettings? appSettings = configurationRoot.GetSection(nameof(AppSettings)).Get<AppSettings>();
|
||||
#pragma warning restore IL3050, IL2026
|
||||
if (appSettings is null
|
||||
|| appSettings?.Company is null)
|
||||
{
|
||||
List<string> paths = [];
|
||||
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);
|
||||
}
|
||||
throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths.Distinct())}");
|
||||
}
|
||||
result = new(appSettings.AzureDevOpsDestinationDirectory,
|
||||
appSettings.BuildNumber,
|
||||
appSettings.Company,
|
||||
appSettings.EcCharacterizationSi,
|
||||
appSettings.EcMesaFileShareCharacterizationSi,
|
||||
appSettings.GitCommitSeven,
|
||||
appSettings.IsDevelopment,
|
||||
appSettings.IsStaging,
|
||||
appSettings.MockRoot,
|
||||
appSettings.MonAResource,
|
||||
appSettings.MonASite,
|
||||
appSettings.URLs,
|
||||
appSettings.WaferCounterDestinationDirectory,
|
||||
appSettings.WaferCounterTwoFileSecondsWait,
|
||||
appSettings.WorkingDirectoryName);
|
||||
Verify(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
|
@ -1,2 +0,0 @@
|
||||
[*.cs]
|
||||
csharp_preserve_single_line_statements = true
|
@ -1,102 +0,0 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace OI.Metrology.Wafer.Counter.Models.Binder;
|
||||
|
||||
public class AppSettings
|
||||
{
|
||||
|
||||
public string? AzureDevOpsDestinationDirectory { get; set; }
|
||||
public string? BuildNumber { get; set; }
|
||||
public string? Company { get; set; }
|
||||
public string? EcCharacterizationSi { get; set; }
|
||||
public string? EcMesaFileShareCharacterizationSi { get; set; }
|
||||
public string? GitCommitSeven { 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? URLs { get; set; }
|
||||
public string? WaferCounterDestinationDirectory { get; set; }
|
||||
public int? WaferCounterTwoFileSecondsWait { get; set; }
|
||||
public string? WorkingDirectoryName { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, BinderAppSettingsSourceGenerationContext.Default.AppSettings);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void PreVerify(IConfigurationRoot configurationRoot, AppSettings? appSettings)
|
||||
{
|
||||
if (appSettings?.Company is null)
|
||||
{
|
||||
List<string> 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);
|
||||
}
|
||||
throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths.Distinct())}");
|
||||
}
|
||||
}
|
||||
|
||||
private static Models.AppSettings Get(AppSettings? appSettings)
|
||||
{
|
||||
Models.AppSettings result;
|
||||
if (appSettings is null) throw new NullReferenceException(nameof(appSettings));
|
||||
if (appSettings.AzureDevOpsDestinationDirectory is null) throw new NullReferenceException(nameof(AzureDevOpsDestinationDirectory));
|
||||
if (appSettings.BuildNumber is null) throw new NullReferenceException(nameof(BuildNumber));
|
||||
if (appSettings.Company is null) throw new NullReferenceException(nameof(Company));
|
||||
if (appSettings.EcCharacterizationSi is null) throw new NullReferenceException(nameof(EcCharacterizationSi));
|
||||
if (appSettings.EcMesaFileShareCharacterizationSi is null) throw new NullReferenceException(nameof(EcMesaFileShareCharacterizationSi));
|
||||
if (appSettings.GitCommitSeven is null) throw new NullReferenceException(nameof(GitCommitSeven));
|
||||
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.URLs is null) throw new NullReferenceException(nameof(URLs));
|
||||
if (appSettings.WaferCounterDestinationDirectory is null) throw new NullReferenceException(nameof(WaferCounterDestinationDirectory));
|
||||
if (appSettings.WaferCounterTwoFileSecondsWait is null) throw new NullReferenceException(nameof(WaferCounterTwoFileSecondsWait));
|
||||
if (appSettings.WorkingDirectoryName is null) throw new NullReferenceException(nameof(WorkingDirectoryName));
|
||||
result = new(appSettings.AzureDevOpsDestinationDirectory,
|
||||
appSettings.BuildNumber,
|
||||
appSettings.Company,
|
||||
appSettings.EcCharacterizationSi,
|
||||
appSettings.EcMesaFileShareCharacterizationSi,
|
||||
appSettings.GitCommitSeven,
|
||||
appSettings.IsDevelopment.Value,
|
||||
appSettings.IsStaging.Value,
|
||||
appSettings.MockRoot,
|
||||
appSettings.MonAResource,
|
||||
appSettings.MonASite,
|
||||
appSettings.URLs,
|
||||
appSettings.WaferCounterDestinationDirectory,
|
||||
appSettings.WaferCounterTwoFileSecondsWait.Value,
|
||||
appSettings.WorkingDirectoryName);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Models.AppSettings Get(IConfigurationRoot configurationRoot)
|
||||
{
|
||||
Models.AppSettings result;
|
||||
#pragma warning disable IL3050, IL2026
|
||||
AppSettings? appSettings = configurationRoot.Get<AppSettings>();
|
||||
#pragma warning restore IL3050, IL2026
|
||||
PreVerify(configurationRoot, appSettings);
|
||||
result = Get(appSettings);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(AppSettings))]
|
||||
internal partial class BinderAppSettingsSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user