From f36ad1ae5e27b9f13698cd20292cf9eb8243fd66 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Wed, 24 Aug 2022 12:06:41 -0700 Subject: [PATCH] Add MonIn Send Status --- .vscode/settings.json | 3 +- Archive/Archive.csproj | 3 ++ Archive/Controllers/ExportController.cs | 7 ++- Archive/Models/AppSettings.cs | 69 +++++++++++-------------- Archive/Models/Binder/AppSettings.cs | 52 +++++++++++++------ Archive/Models/Stateless/AppSettings.cs | 44 ---------------- Archive/Program.cs | 2 +- Archive/appsettings.Development.json | 2 + Archive/appsettings.json | 2 + README.md | 8 ++- Tests/Models/AppSettings.cs | 69 +++++++++++-------------- Tests/Models/Binder/AppSettings.cs | 52 +++++++++++++------ Tests/Models/Stateless/AppSettings.cs | 44 ---------------- Tests/Tests.csproj | 5 ++ Tests/UnitTestArchive.cs | 8 +-- Tests/UnitTestExample.cs | 6 +-- Tests/appsettings.Development.json | 1 + Tests/appsettings.json | 1 + Viewer/Controllers/ExportController.cs | 7 ++- Viewer/Models/AppSettings.cs | 69 +++++++++++-------------- Viewer/Models/Binder/AppSettings.cs | 52 +++++++++++++------ Viewer/Models/Stateless/AppSettings.cs | 44 ---------------- Viewer/Program.cs | 2 +- Viewer/Viewer.csproj | 3 ++ Viewer/Views/Shared/_Layout.cshtml | 2 +- Viewer/appsettings.Development.json | 2 + Viewer/appsettings.json | 2 + 27 files changed, 244 insertions(+), 317 deletions(-) delete mode 100644 Archive/Models/Stateless/AppSettings.cs delete mode 100644 Tests/Models/Stateless/AppSettings.cs delete mode 100644 Viewer/Models/Stateless/AppSettings.cs diff --git a/.vscode/settings.json b/.vscode/settings.json index dbf2cfe..11f27b6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,6 @@ "cSpell.enabled": false, "files.exclude": { "**/.git": false - } + }, + "coverage-gutters.coverageBaseDir": "../.vscode/TestResults/*" } \ No newline at end of file diff --git a/Archive/Archive.csproj b/Archive/Archive.csproj index 9025956..f681582 100644 --- a/Archive/Archive.csproj +++ b/Archive/Archive.csproj @@ -29,6 +29,9 @@ + + + diff --git a/Archive/Controllers/ExportController.cs b/Archive/Controllers/ExportController.cs index 844afaa..0234c8e 100644 --- a/Archive/Controllers/ExportController.cs +++ b/Archive/Controllers/ExportController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc; +using Infineon.Monitoring.MonA; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Logging; using OI.Metrology.Archive.Models; @@ -17,11 +18,13 @@ public class ExportController : Controller private readonly ILogger _Logger; private readonly bool _IsTestDatabase; private readonly IMetrologyRepo _Repo; + private readonly AppSettings _AppSettings; public ExportController(AppSettings appSettings, ILogger logger, IMetrologyRepo repo) { _Repo = repo; _Logger = logger; + _AppSettings = appSettings; _IsTestDatabase = appSettings.ConnectionString.Contains("test", StringComparison.InvariantCultureIgnoreCase); } @@ -41,6 +44,8 @@ public class ExportController : Controller StartTime = DateTime.Now.AddMonths(-1), EndTime = DateTime.Now }; + MonIn monIn = MonIn.GetInstance(); + _ = monIn.SendStatus(_AppSettings.MonASite, _AppSettings.MonAResource, "Heartbeat", State.Up); return View(model); } diff --git a/Archive/Models/AppSettings.cs b/Archive/Models/AppSettings.cs index a289f5b..3e90e78 100644 --- a/Archive/Models/AppSettings.cs +++ b/Archive/Models/AppSettings.cs @@ -6,49 +6,38 @@ namespace OI.Metrology.Archive.Models; public class AppSettings { - protected string _ApiLoggingContentTypes; - protected string _ApiLoggingPathPrefixes; - protected string _ApiLogPath; - protected string _AttachmentPath; - protected string _BuildNumber; - protected string _Company; - protected string _ConnectionString; - protected string _GitCommitSeven; - protected string _InboundApiAllowedIPList; - protected string _MonARessource; - protected string _OIExportPath; - protected string _URLs; - protected string _WorkingDirectoryName; - public string ApiLoggingContentTypes => _ApiLoggingContentTypes; - public string ApiLoggingPathPrefixes => _ApiLoggingPathPrefixes; - public string ApiLogPath => _ApiLogPath; - public string AttachmentPath => _AttachmentPath; - public string BuildNumber => _BuildNumber; - public string Company => _Company; - public string ConnectionString => _ConnectionString; - public string GitCommitSeven => _GitCommitSeven; - public string InboundApiAllowedIPList => _InboundApiAllowedIPList; - public string MonARessource => _MonARessource; - public string OIExportPath => _OIExportPath; - public string URLs => _URLs; - public string WorkingDirectoryName => _WorkingDirectoryName; + public string ApiLoggingContentTypes { init; get; } + public string ApiLoggingPathPrefixes { init; get; } + public string ApiLogPath { init; get; } + public string AttachmentPath { init; get; } + public string BuildNumber { init; get; } + public string Company { init; get; } + public string ConnectionString { init; get; } + public string GitCommitSeven { init; get; } + public string InboundApiAllowedIPList { init; get; } + public string MonAResource { init; get; } + public string MonASite { init; get; } + public string OIExportPath { init; get; } + public string URLs { init; get; } + public string WorkingDirectoryName { init; get; } [JsonConstructor] - public AppSettings(string apiLoggingContentTypes, string apiLoggingPathPrefixes, string apiLogPath, string attachmentPath, string buildNumber, string company, string connectionString, string gitCommitSeven, string inboundApiAllowedIPList, string monARessource, string oiExportPath, string urls, string workingDirectoryName) + public AppSettings(string apiLoggingContentTypes, string apiLoggingPathPrefixes, string apiLogPath, string attachmentPath, string buildNumber, string company, string connectionString, string gitCommitSeven, string inboundApiAllowedIPList, string monAResource, string monASite, string oiExportPath, string urls, string workingDirectoryName) { - _ApiLoggingContentTypes = apiLoggingContentTypes; - _ApiLoggingPathPrefixes = apiLoggingPathPrefixes; - _ApiLogPath = apiLogPath; - _AttachmentPath = attachmentPath; - _BuildNumber = buildNumber; - _Company = company; - _ConnectionString = connectionString; - _GitCommitSeven = gitCommitSeven; - _InboundApiAllowedIPList = inboundApiAllowedIPList; - _MonARessource = monARessource; - _OIExportPath = oiExportPath; - _URLs = urls; - _WorkingDirectoryName = workingDirectoryName; + ApiLoggingContentTypes = apiLoggingContentTypes; + ApiLoggingPathPrefixes = apiLoggingPathPrefixes; + ApiLogPath = apiLogPath; + AttachmentPath = attachmentPath; + BuildNumber = buildNumber; + Company = company; + ConnectionString = connectionString; + GitCommitSeven = gitCommitSeven; + InboundApiAllowedIPList = inboundApiAllowedIPList; + MonAResource = monAResource; + MonASite = monASite; + OIExportPath = oiExportPath; + URLs = urls; + WorkingDirectoryName = workingDirectoryName; } public override string ToString() diff --git a/Archive/Models/Binder/AppSettings.cs b/Archive/Models/Binder/AppSettings.cs index 394cad2..72549e3 100644 --- a/Archive/Models/Binder/AppSettings.cs +++ b/Archive/Models/Binder/AppSettings.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Configuration; using System.ComponentModel.DataAnnotations; using System.Text.Json; @@ -6,6 +7,8 @@ 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; } @@ -15,27 +18,13 @@ public class AppSettings [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 Ressource"), Required] public string MonARessource { 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 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; } - public AppSettings() - { - ApiLoggingContentTypes = string.Empty; - ApiLoggingPathPrefixes = string.Empty; - ApiLogPath = string.Empty; - AttachmentPath = string.Empty; - BuildNumber = string.Empty; - Company = string.Empty; - ConnectionString = string.Empty; - GitCommitSeven = string.Empty; - InboundApiAllowedIPList = string.Empty; - MonARessource = string.Empty; - OIExportPath = string.Empty; - URLs = string.Empty; - WorkingDirectoryName = string.Empty; - } +#nullable restore public override string ToString() { @@ -43,4 +32,33 @@ public class AppSettings return result; } + private static Models.AppSettings Get(AppSettings appSettings) + { + Models.AppSettings result; + 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.OIExportPath, + appSettings.URLs, + appSettings.WorkingDirectoryName); + return result; + } + + public static Models.AppSettings Get(IConfigurationRoot configurationRoot) + { + Models.AppSettings result; + AppSettings appSettings = configurationRoot.Get(); + result = Get(appSettings); + return result; + } + } \ No newline at end of file diff --git a/Archive/Models/Stateless/AppSettings.cs b/Archive/Models/Stateless/AppSettings.cs deleted file mode 100644 index 3abfe56..0000000 --- a/Archive/Models/Stateless/AppSettings.cs +++ /dev/null @@ -1,44 +0,0 @@ -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; - } - -} \ No newline at end of file diff --git a/Archive/Program.cs b/Archive/Program.cs index dd698ee..bc46126 100644 --- a/Archive/Program.cs +++ b/Archive/Program.cs @@ -50,7 +50,7 @@ public class Program (string assemblyName, WebApplicationOptions _) = Get(args); WebApplicationBuilder webApplicationBuilder = WebApplication.CreateBuilder(); _ = webApplicationBuilder.Configuration.AddUserSecrets(); - AppSettings appSettings = Models.Stateless.AppSettings.Get(webApplicationBuilder.Configuration); + AppSettings appSettings = Models.Binder.AppSettings.Get(webApplicationBuilder.Configuration); if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName)) throw new Exception("Working directory name must have a value!"); string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assemblyName, appSettings.WorkingDirectoryName); diff --git a/Archive/appsettings.Development.json b/Archive/appsettings.Development.json index 4b03ad8..1a83359 100644 --- a/Archive/appsettings.Development.json +++ b/Archive/appsettings.Development.json @@ -17,6 +17,8 @@ } }, "InboundApiAllowedIPList": "", + "MonAResource": "OI_Metrology_Archive_IFX", + "MonASite": "sjc", "OIExportPath": "\\\\openinsight-db-srv.na.infineon.com\\apps\\Metrology\\Data", "Serilog": { "Using": [ diff --git a/Archive/appsettings.json b/Archive/appsettings.json index 8882280..9c0dcdd 100644 --- a/Archive/appsettings.json +++ b/Archive/appsettings.json @@ -16,7 +16,9 @@ "Microsoft.Hosting.Lifetime": "Information" } }, + "MonAResource": "OI_Metrology_Archive_EC", "InboundApiAllowedIPList": "", + "MonASite": "sjc", "OIExportPath": "\\\\openinsight-db-srv.na.infineon.com\\apps\\Metrology\\Data", "Serilog": { "Using": [ diff --git a/README.md b/README.md index c7a859e..5ed95a0 100644 --- a/README.md +++ b/README.md @@ -26,4 +26,10 @@ Ouellette Jonathan (IFAM IT FI MES) created #315807, 7/25/2022 ## TFS / Azure DevOps - Pipelines * https://tfs.intra.infineon.com/tfs/manufacturingit/Mesa_FI/_build?definitionId=5439&_a=summary -* https://tfs.intra.infineon.com/tfs/manufacturingit/Mesa_FI/_release?_a=releases&view=mine&definitionId=1 \ No newline at end of file +* https://tfs.intra.infineon.com/tfs/manufacturingit/Mesa_FI/_release?_a=releases&view=mine&definitionId=1 + +4c07c49f3b9daa69fecd9d5be64e047d0ad6be1d +343ff2d792149c9eef1216f44dbdb73935cf6041 + +https://oi-metrology-viewer-prod.mes.infineon.com/ +https://oi-metrology-viewer-archive.mes.infineon.com/ \ No newline at end of file diff --git a/Tests/Models/AppSettings.cs b/Tests/Models/AppSettings.cs index 9bf5eeb..053348f 100644 --- a/Tests/Models/AppSettings.cs +++ b/Tests/Models/AppSettings.cs @@ -6,49 +6,38 @@ namespace OI.Metrology.Tests.Models; public class AppSettings { - protected string _ApiLoggingContentTypes; - protected string _ApiLoggingPathPrefixes; - protected string _ApiLogPath; - protected string _AttachmentPath; - protected string _BuildNumber; - protected string _Company; - protected string _ConnectionString; - protected string _GitCommitSeven; - protected string _InboundApiAllowedIPList; - protected string _MonARessource; - protected string _OIExportPath; - protected string _URLs; - protected string _WorkingDirectoryName; - public string ApiLoggingContentTypes => _ApiLoggingContentTypes; - public string ApiLoggingPathPrefixes => _ApiLoggingPathPrefixes; - public string ApiLogPath => _ApiLogPath; - public string AttachmentPath => _AttachmentPath; - public string BuildNumber => _BuildNumber; - public string Company => _Company; - public string ConnectionString => _ConnectionString; - public string GitCommitSeven => _GitCommitSeven; - public string InboundApiAllowedIPList => _InboundApiAllowedIPList; - public string MonARessource => _MonARessource; - public string OIExportPath => _OIExportPath; - public string URLs => _URLs; - public string WorkingDirectoryName => _WorkingDirectoryName; + public string ApiLoggingContentTypes { init; get; } + public string ApiLoggingPathPrefixes { init; get; } + public string ApiLogPath { init; get; } + public string AttachmentPath { init; get; } + public string BuildNumber { init; get; } + public string Company { init; get; } + public string ConnectionString { init; get; } + public string GitCommitSeven { init; get; } + public string InboundApiAllowedIPList { init; get; } + public string MonAResource { init; get; } + public string MonASite { init; get; } + public string OIExportPath { init; get; } + public string URLs { init; get; } + public string WorkingDirectoryName { init; get; } [JsonConstructor] - public AppSettings(string apiLoggingContentTypes, string apiLoggingPathPrefixes, string apiLogPath, string attachmentPath, string buildNumber, string company, string connectionString, string gitCommitSeven, string inboundApiAllowedIPList, string monARessource, string oiExportPath, string urls, string workingDirectoryName) + public AppSettings(string apiLoggingContentTypes, string apiLoggingPathPrefixes, string apiLogPath, string attachmentPath, string buildNumber, string company, string connectionString, string gitCommitSeven, string inboundApiAllowedIPList, string monAResource, string monASite, string oiExportPath, string urls, string workingDirectoryName) { - _ApiLoggingContentTypes = apiLoggingContentTypes; - _ApiLoggingPathPrefixes = apiLoggingPathPrefixes; - _ApiLogPath = apiLogPath; - _AttachmentPath = attachmentPath; - _BuildNumber = buildNumber; - _Company = company; - _ConnectionString = connectionString; - _GitCommitSeven = gitCommitSeven; - _InboundApiAllowedIPList = inboundApiAllowedIPList; - _MonARessource = monARessource; - _OIExportPath = oiExportPath; - _URLs = urls; - _WorkingDirectoryName = workingDirectoryName; + ApiLoggingContentTypes = apiLoggingContentTypes; + ApiLoggingPathPrefixes = apiLoggingPathPrefixes; + ApiLogPath = apiLogPath; + AttachmentPath = attachmentPath; + BuildNumber = buildNumber; + Company = company; + ConnectionString = connectionString; + GitCommitSeven = gitCommitSeven; + InboundApiAllowedIPList = inboundApiAllowedIPList; + MonAResource = monAResource; + MonASite = monASite; + OIExportPath = oiExportPath; + URLs = urls; + WorkingDirectoryName = workingDirectoryName; } public override string ToString() diff --git a/Tests/Models/Binder/AppSettings.cs b/Tests/Models/Binder/AppSettings.cs index a1cce91..246a49a 100644 --- a/Tests/Models/Binder/AppSettings.cs +++ b/Tests/Models/Binder/AppSettings.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Configuration; using System.ComponentModel.DataAnnotations; using System.Text.Json; @@ -6,6 +7,8 @@ namespace OI.Metrology.Tests.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; } @@ -15,27 +18,13 @@ public class AppSettings [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 Ressource"), Required] public string MonARessource { 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 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; } - public AppSettings() - { - ApiLoggingContentTypes = string.Empty; - ApiLoggingPathPrefixes = string.Empty; - ApiLogPath = string.Empty; - AttachmentPath = string.Empty; - BuildNumber = string.Empty; - Company = string.Empty; - ConnectionString = string.Empty; - GitCommitSeven = string.Empty; - InboundApiAllowedIPList = string.Empty; - MonARessource = string.Empty; - OIExportPath = string.Empty; - URLs = string.Empty; - WorkingDirectoryName = string.Empty; - } +#nullable restore public override string ToString() { @@ -43,4 +32,33 @@ public class AppSettings return result; } + private static Models.AppSettings Get(AppSettings appSettings) + { + Models.AppSettings result; + 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.OIExportPath, + appSettings.URLs, + appSettings.WorkingDirectoryName); + return result; + } + + public static Models.AppSettings Get(IConfigurationRoot configurationRoot) + { + Models.AppSettings result; + AppSettings appSettings = configurationRoot.Get(); + result = Get(appSettings); + return result; + } + } \ No newline at end of file diff --git a/Tests/Models/Stateless/AppSettings.cs b/Tests/Models/Stateless/AppSettings.cs deleted file mode 100644 index 3c33475..0000000 --- a/Tests/Models/Stateless/AppSettings.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Microsoft.Extensions.Configuration; -using System; -using System.Linq; -using System.Text.Json; - -namespace OI.Metrology.Tests.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; - } - -} \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 39e1ed3..777ac1f 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -7,6 +7,11 @@ win-x64 net6.0 + + trx + XPlat Code Coverage + ../.vscode/TestResults + true true diff --git a/Tests/UnitTestArchive.cs b/Tests/UnitTestArchive.cs index cd8bfa2..3bf4fd8 100644 --- a/Tests/UnitTestArchive.cs +++ b/Tests/UnitTestArchive.cs @@ -1,8 +1,8 @@ using Microsoft.Extensions.Configuration; +using OI.Metrology.Shared.Models; +using OI.Metrology.Tests.Models; using Serilog; using System.Reflection; -using OI.Metrology.Tests.Models; -using OI.Metrology.Shared.Models; namespace View_by_Distance.Tests; @@ -27,7 +27,7 @@ public class UnitTestArchive .AddEnvironmentVariables() .AddJsonFile("appsettings.Development.json"); configurationRoot = configurationBuilder.Build(); - appSettings = OI.Metrology.Tests.Models.Stateless.AppSettings.Get(configurationRoot); + appSettings = OI.Metrology.Tests.Models.Binder.AppSettings.Get(configurationRoot); workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName); Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory); _ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot); @@ -56,7 +56,7 @@ public class UnitTestArchive Assert.IsFalse(_AppSettings is null); Assert.IsFalse(_WorkingDirectory is null); Assert.IsFalse(_ConfigurationRoot is null); - + } } \ No newline at end of file diff --git a/Tests/UnitTestExample.cs b/Tests/UnitTestExample.cs index 36e8998..c23e218 100644 --- a/Tests/UnitTestExample.cs +++ b/Tests/UnitTestExample.cs @@ -1,8 +1,8 @@ using Microsoft.Extensions.Configuration; +using OI.Metrology.Shared.Models; +using OI.Metrology.Tests.Models; using Serilog; using System.Reflection; -using OI.Metrology.Tests.Models; -using OI.Metrology.Shared.Models; namespace View_by_Distance.Tests; @@ -27,7 +27,7 @@ public class UnitTestExample .AddEnvironmentVariables() .AddJsonFile("appsettings.Development.json"); configurationRoot = configurationBuilder.Build(); - appSettings = OI.Metrology.Tests.Models.Stateless.AppSettings.Get(configurationRoot); + appSettings = OI.Metrology.Tests.Models.Binder.AppSettings.Get(configurationRoot); workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName); Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory); _ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot); diff --git a/Tests/appsettings.Development.json b/Tests/appsettings.Development.json index 4b03ad8..1b69385 100644 --- a/Tests/appsettings.Development.json +++ b/Tests/appsettings.Development.json @@ -17,6 +17,7 @@ } }, "InboundApiAllowedIPList": "", + "MonASite": "sjc", "OIExportPath": "\\\\openinsight-db-srv.na.infineon.com\\apps\\Metrology\\Data", "Serilog": { "Using": [ diff --git a/Tests/appsettings.json b/Tests/appsettings.json index 8882280..301bde9 100644 --- a/Tests/appsettings.json +++ b/Tests/appsettings.json @@ -17,6 +17,7 @@ } }, "InboundApiAllowedIPList": "", + "MonASite": "sjc", "OIExportPath": "\\\\openinsight-db-srv.na.infineon.com\\apps\\Metrology\\Data", "Serilog": { "Using": [ diff --git a/Viewer/Controllers/ExportController.cs b/Viewer/Controllers/ExportController.cs index 8f910cc..d932450 100644 --- a/Viewer/Controllers/ExportController.cs +++ b/Viewer/Controllers/ExportController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc; +using Infineon.Monitoring.MonA; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Logging; using OI.Metrology.Shared.DataModels; @@ -17,11 +18,13 @@ public class ExportController : Controller private readonly ILogger _Logger; private readonly bool _IsTestDatabase; private readonly IMetrologyRepo _Repo; + private readonly AppSettings _AppSettings; public ExportController(AppSettings appSettings, ILogger logger, IMetrologyRepo repo) { _Repo = repo; _Logger = logger; + _AppSettings = appSettings; _IsTestDatabase = appSettings.ConnectionString.Contains("test", StringComparison.InvariantCultureIgnoreCase); } @@ -40,6 +43,8 @@ public class ExportController : Controller StartTime = DateTime.Now.AddMonths(-1), EndTime = DateTime.Now }; + MonIn monIn = MonIn.GetInstance(); + _ = monIn.SendStatus(_AppSettings.MonASite, _AppSettings.MonAResource, "Heartbeat", State.Up); return View(model); } diff --git a/Viewer/Models/AppSettings.cs b/Viewer/Models/AppSettings.cs index 6d4b9e8..75d75c2 100644 --- a/Viewer/Models/AppSettings.cs +++ b/Viewer/Models/AppSettings.cs @@ -6,49 +6,38 @@ namespace OI.Metrology.Viewer.Models; public class AppSettings { - protected string _ApiLoggingContentTypes; - protected string _ApiLoggingPathPrefixes; - protected string _ApiLogPath; - protected string _AttachmentPath; - protected string _BuildNumber; - protected string _Company; - protected string _ConnectionString; - protected string _GitCommitSeven; - protected string _InboundApiAllowedIPList; - protected string _MonARessource; - protected string _OIExportPath; - protected string _URLs; - protected string _WorkingDirectoryName; - public string ApiLoggingContentTypes => _ApiLoggingContentTypes; - public string ApiLoggingPathPrefixes => _ApiLoggingPathPrefixes; - public string ApiLogPath => _ApiLogPath; - public string AttachmentPath => _AttachmentPath; - public string BuildNumber => _BuildNumber; - public string Company => _Company; - public string ConnectionString => _ConnectionString; - public string GitCommitSeven => _GitCommitSeven; - public string InboundApiAllowedIPList => _InboundApiAllowedIPList; - public string MonARessource => _MonARessource; - public string OIExportPath => _OIExportPath; - public string URLs => _URLs; - public string WorkingDirectoryName => _WorkingDirectoryName; + public string ApiLoggingContentTypes { init; get; } + public string ApiLoggingPathPrefixes { init; get; } + public string ApiLogPath { init; get; } + public string AttachmentPath { init; get; } + public string BuildNumber { init; get; } + public string Company { init; get; } + public string ConnectionString { init; get; } + public string GitCommitSeven { init; get; } + public string InboundApiAllowedIPList { init; get; } + public string MonAResource { init; get; } + public string MonASite { init; get; } + public string OIExportPath { init; get; } + public string URLs { init; get; } + public string WorkingDirectoryName { init; get; } [JsonConstructor] - public AppSettings(string apiLoggingContentTypes, string apiLoggingPathPrefixes, string apiLogPath, string attachmentPath, string buildNumber, string company, string connectionString, string gitCommitSeven, string inboundApiAllowedIPList, string monARessource, string oiExportPath, string urls, string workingDirectoryName) + public AppSettings(string apiLoggingContentTypes, string apiLoggingPathPrefixes, string apiLogPath, string attachmentPath, string buildNumber, string company, string connectionString, string gitCommitSeven, string inboundApiAllowedIPList, string monAResource, string monASite, string oiExportPath, string urls, string workingDirectoryName) { - _ApiLoggingContentTypes = apiLoggingContentTypes; - _ApiLoggingPathPrefixes = apiLoggingPathPrefixes; - _ApiLogPath = apiLogPath; - _AttachmentPath = attachmentPath; - _BuildNumber = buildNumber; - _Company = company; - _ConnectionString = connectionString; - _GitCommitSeven = gitCommitSeven; - _InboundApiAllowedIPList = inboundApiAllowedIPList; - _MonARessource = monARessource; - _OIExportPath = oiExportPath; - _URLs = urls; - _WorkingDirectoryName = workingDirectoryName; + ApiLoggingContentTypes = apiLoggingContentTypes; + ApiLoggingPathPrefixes = apiLoggingPathPrefixes; + ApiLogPath = apiLogPath; + AttachmentPath = attachmentPath; + BuildNumber = buildNumber; + Company = company; + ConnectionString = connectionString; + GitCommitSeven = gitCommitSeven; + InboundApiAllowedIPList = inboundApiAllowedIPList; + MonAResource = monAResource; + MonASite = monASite; + OIExportPath = oiExportPath; + URLs = urls; + WorkingDirectoryName = workingDirectoryName; } public override string ToString() diff --git a/Viewer/Models/Binder/AppSettings.cs b/Viewer/Models/Binder/AppSettings.cs index 2d9bf98..8eb6df8 100644 --- a/Viewer/Models/Binder/AppSettings.cs +++ b/Viewer/Models/Binder/AppSettings.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Configuration; using System.ComponentModel.DataAnnotations; using System.Text.Json; @@ -6,6 +7,8 @@ namespace OI.Metrology.Viewer.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; } @@ -15,27 +18,13 @@ public class AppSettings [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 Ressource"), Required] public string MonARessource { 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 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; } - public AppSettings() - { - ApiLoggingContentTypes = string.Empty; - ApiLoggingPathPrefixes = string.Empty; - ApiLogPath = string.Empty; - AttachmentPath = string.Empty; - BuildNumber = string.Empty; - Company = string.Empty; - ConnectionString = string.Empty; - GitCommitSeven = string.Empty; - InboundApiAllowedIPList = string.Empty; - MonARessource = string.Empty; - OIExportPath = string.Empty; - URLs = string.Empty; - WorkingDirectoryName = string.Empty; - } +#nullable restore public override string ToString() { @@ -43,4 +32,33 @@ public class AppSettings return result; } + private static Models.AppSettings Get(AppSettings appSettings) + { + Models.AppSettings result; + 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.OIExportPath, + appSettings.URLs, + appSettings.WorkingDirectoryName); + return result; + } + + public static Models.AppSettings Get(IConfigurationRoot configurationRoot) + { + Models.AppSettings result; + AppSettings appSettings = configurationRoot.Get(); + result = Get(appSettings); + return result; + } + } \ No newline at end of file diff --git a/Viewer/Models/Stateless/AppSettings.cs b/Viewer/Models/Stateless/AppSettings.cs deleted file mode 100644 index 1d88176..0000000 --- a/Viewer/Models/Stateless/AppSettings.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Microsoft.Extensions.Configuration; -using System; -using System.Linq; -using System.Text.Json; - -namespace OI.Metrology.Viewer.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; - } - -} \ No newline at end of file diff --git a/Viewer/Program.cs b/Viewer/Program.cs index d195514..58e78f6 100644 --- a/Viewer/Program.cs +++ b/Viewer/Program.cs @@ -50,7 +50,7 @@ public class Program (string assemblyName, WebApplicationOptions _) = Get(args); WebApplicationBuilder webApplicationBuilder = WebApplication.CreateBuilder(); _ = webApplicationBuilder.Configuration.AddUserSecrets(); - AppSettings appSettings = Models.Stateless.AppSettings.Get(webApplicationBuilder.Configuration); + AppSettings appSettings = Models.Binder.AppSettings.Get(webApplicationBuilder.Configuration); if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName)) throw new Exception("Working directory name must have a value!"); string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assemblyName, appSettings.WorkingDirectoryName); diff --git a/Viewer/Viewer.csproj b/Viewer/Viewer.csproj index 9025956..4c4b784 100644 --- a/Viewer/Viewer.csproj +++ b/Viewer/Viewer.csproj @@ -35,6 +35,9 @@ + + + diff --git a/Viewer/Views/Shared/_Layout.cshtml b/Viewer/Views/Shared/_Layout.cshtml index c499fbc..871f765 100644 --- a/Viewer/Views/Shared/_Layout.cshtml +++ b/Viewer/Views/Shared/_Layout.cshtml @@ -70,7 +70,7 @@
  • @Html.ActionLink("Run Information", "RunInfo", "Pages", new { area = "" }, null)
  • @Html.ActionLink("Run Headers", "RunHeaders", "Pages", new { area = "" }, null)
  • @Html.ActionLink("Export", "Index", "Export", new { area = "" }, null)
  • -
  • Archive
  • +
  • Archive