- AppSetting bug fix - Updated testes with base test class and editor configuration changes - Created new server and wafer counter tasks json files and pipelines to match
		
			
				
	
	
		
			79 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System.Text.Json;
 | |
| using System.Text.Json.Serialization;
 | |
| 
 | |
| namespace OI.Metrology.Wafer.Counter.Models;
 | |
| 
 | |
| public record AppSettings(string BuildNumber,
 | |
|                           string Company,
 | |
|                           string EcCharacterizationSi,
 | |
|                           string EcMesaFileShareCharacterizationSi,
 | |
|                           string GitCommitSeven,
 | |
|                           bool IsDevelopment,
 | |
|                           bool IsStaging,
 | |
|                           string MockRoot,
 | |
|                           string MonAResource,
 | |
|                           string MonASite,
 | |
|                           string URLs,
 | |
|                           string WaferCounterDestinationDirectory,
 | |
|                           int WaferCounterTwoFileSecondsWait,
 | |
|                           string WorkingDirectoryName)
 | |
| {
 | |
| 
 | |
|     public override string ToString()
 | |
|     {
 | |
|         string result = JsonSerializer.Serialize(this, AppSettingsSourceGenerationContext.Default.AppSettings);
 | |
|         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.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.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)]
 | |
| [JsonSerializable(typeof(AppSettings))]
 | |
| public partial class AppSettingsSourceGenerationContext : JsonSerializerContext
 | |
| {
 | |
| } |