From 4bb26e90663b733e751956d7bbc748db0a1f3615 Mon Sep 17 00:00:00 2001 From: samatrhea Date: Wed, 20 Mar 2024 14:47:57 +0100 Subject: [PATCH] [Add] apsettings [Add] ResourceLoader and ascii-art --- nginx | 34 +++++++++ reqifviewer/Program.cs | 28 ++++--- reqifviewer/Resources/IResourceLoader.cs | 55 ++++++++++++++ reqifviewer/Resources/ResourceLoader.cs | 97 ++++++++++++++++++++++++ reqifviewer/Resources/ascii-art.txt | 11 +++ reqifviewer/_Imports.razor | 1 - reqifviewer/appsettings.json | 39 ++++++++++ reqifviewer/reqifviewer.csproj | 10 ++- 8 files changed, 261 insertions(+), 14 deletions(-) create mode 100644 nginx create mode 100644 reqifviewer/Resources/IResourceLoader.cs create mode 100644 reqifviewer/Resources/ResourceLoader.cs create mode 100644 reqifviewer/Resources/ascii-art.txt create mode 100644 reqifviewer/appsettings.json diff --git a/nginx b/nginx new file mode 100644 index 0000000..fd9007b --- /dev/null +++ b/nginx @@ -0,0 +1,34 @@ +map $http_connection $connection_upgrade { + "~*Upgrade" $http_connection; + default keep-alive; +} + +server { + server_name viewer.reqifsharp.org; + + location / { + proxy_pass http://127.0.0.1:5000; + + # Configuration for WebSockets + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_cache off; + + # WebSockets were implemented after http/1.0 + proxy_http_version 1.1; + + # Configuration for LongPolling or if your KeepAliveInterval is longer than 60 seconds + proxy_read_timeout 100s; + + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # kill cache + add_header Last-Modified $date_gmt; + add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0'; + if_modified_since off; + expires off; + etag off; + } +} \ No newline at end of file diff --git a/reqifviewer/Program.cs b/reqifviewer/Program.cs index 6e6f1b3..c7b6862 100644 --- a/reqifviewer/Program.cs +++ b/reqifviewer/Program.cs @@ -35,13 +35,14 @@ namespace reqifviewer using Radzen; using Serilog; - using Serilog.Events; + using Microsoft.Extensions.Logging; + using ReqifViewer.Resources; /// /// The purpose of the class is to provide the /// main entry point of te application /// - public static class Program + public class Program { /// /// Main entry point of the application @@ -52,21 +53,19 @@ public static class Program /// public static async Task Main(string[] args) { - Log.Logger = new LoggerConfiguration() - .MinimumLevel.Debug() - .MinimumLevel.Override("Microsoft", LogEventLevel.Information) - .Enrich.FromLogContext() - .WriteTo.BrowserConsole() - .CreateLogger(); - var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); - builder.Services.AddLogging(loggingBuilder => - loggingBuilder.AddSerilog(dispose: true)); + builder.Host.UseSerilog((hostingContext, loggerConfiguration) => + { + loggerConfiguration + .ReadFrom.Configuration(hostingContext.Configuration) + .WriteTo.Console(); + }); + builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -78,6 +77,13 @@ public static async Task Main(string[] args) var app = builder.Build(); + var logger = app.Services.GetService>(); + var resourceLoader = app.Services.GetService(); + var logo = resourceLoader.QueryLogo(); + logger.LogInformation("################################################################"); + logger.LogInformation(logo); + logger.LogInformation("################################################################"); + app.UseStaticFiles(); app.UseRouting(); app.MapBlazorHub(); diff --git a/reqifviewer/Resources/IResourceLoader.cs b/reqifviewer/Resources/IResourceLoader.cs new file mode 100644 index 0000000..91c5015 --- /dev/null +++ b/reqifviewer/Resources/IResourceLoader.cs @@ -0,0 +1,55 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright 2021-2024 RHEA System S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------- + +namespace ReqifViewer.Resources +{ + /// + /// Definition of the interface used to load (embedded) resources + /// + public interface IResourceLoader + { + /// + /// Load an embedded resource + /// + /// + /// The path of the embedded resource + /// + /// + /// a string containing the contents of the embedded resource + /// + string LoadEmbeddedResource(string path); + + /// + /// queries the version number from the executing assembly + /// + /// + /// a string representation of the version of the application + /// + string QueryVersion(); + + /// + /// Queries the logo with version info from the embedded resources + /// + /// + /// the logo + /// + string QueryLogo(); + } +} diff --git a/reqifviewer/Resources/ResourceLoader.cs b/reqifviewer/Resources/ResourceLoader.cs new file mode 100644 index 0000000..905ce95 --- /dev/null +++ b/reqifviewer/Resources/ResourceLoader.cs @@ -0,0 +1,97 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright 2021-2024 RHEA System S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------- + +namespace ReqifViewer.Resources +{ + using System.Diagnostics; + using System.IO; + using System.Reflection; + using System.Resources; + + /// + /// Class responsible for loading embedded resources. + /// + public class ResourceLoader : IResourceLoader + { + /// + /// Load an embedded resource + /// + /// + /// The path of the embedded resource + /// + /// + /// a string containing the contents of the embedded resource + /// + public string LoadEmbeddedResource(string path) + { + var assembly = Assembly.GetExecutingAssembly(); + + using var stream = assembly.GetManifestResourceStream(path); + + using var reader = new StreamReader(stream ?? throw new MissingManifestResourceException()); + + return reader.ReadToEnd(); + } + + /// + /// queries the version number from the executing assembly + /// + /// + /// a string representation of the version of the application + /// + public string QueryVersion() + { + var assembly = Assembly.GetExecutingAssembly(); + var infoVersion = assembly.GetCustomAttribute(); + + if (infoVersion != null) + { + var plusIndex = infoVersion.InformationalVersion.IndexOf('+'); + + if (plusIndex != -1) + { + return infoVersion.InformationalVersion.Substring(0, plusIndex); + } + + return infoVersion.InformationalVersion; + } + + var fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); + var fileVersion = fileVersionInfo.FileVersion; + return fileVersion; + } + + /// + /// Queries the logo with version info from the embedded resources + /// + /// + /// the logo + /// + public string QueryLogo() + { + var version = this.QueryVersion(); + + var logo = this.LoadEmbeddedResource("reqifviewer.Resources.ascii-art.txt") + .Replace("reqifviewerVersion", version); + + return logo; + } + } +} diff --git a/reqifviewer/Resources/ascii-art.txt b/reqifviewer/Resources/ascii-art.txt new file mode 100644 index 0000000..f5a797e --- /dev/null +++ b/reqifviewer/Resources/ascii-art.txt @@ -0,0 +1,11 @@ + + + ██████╗ ███████╗ ██████╗ ██╗███████╗███████╗██╗ ██╗ █████╗ ██████╗ ██████╗ + ██╔══██╗██╔════╝██╔═══██╗██║██╔════╝██╔════╝██║ ██║██╔══██╗██╔══██╗██╔══██╗ + ██████╔╝█████╗ ██║ ██║██║█████╗ ███████╗███████║███████║██████╔╝██████╔╝ + ██╔══██╗██╔══╝ ██║▄▄ ██║██║██╔══╝ ╚════██║██╔══██║██╔══██║██╔══██╗██╔═══╝ + ██║ ██║███████╗╚██████╔╝██║██║ ███████║██║ ██║██║ ██║██║ ██║██║ + ═╝ ╚═╝╚══════╝ ╚══▀▀═╝ ╚═╝╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ + + Copyright (c) 2022-2024 RHEA System S.A. + reqifviewer version: reqifviewerVersion diff --git a/reqifviewer/_Imports.razor b/reqifviewer/_Imports.razor index d80bfcd..f52fd67 100644 --- a/reqifviewer/_Imports.razor +++ b/reqifviewer/_Imports.razor @@ -6,7 +6,6 @@ @using Microsoft.AspNetCore.Components.Routing @using Microsoft.AspNetCore.Components.Web @using Microsoft.AspNetCore.Components.Web.Virtualization -@using Microsoft.AspNetCore.Components.WebAssembly.Http @using Microsoft.JSInterop @using reqifviewer @using reqifviewer.Shared diff --git a/reqifviewer/appsettings.json b/reqifviewer/appsettings.json new file mode 100644 index 0000000..62bee75 --- /dev/null +++ b/reqifviewer/appsettings.json @@ -0,0 +1,39 @@ +{ + "Kestrel": { + "Endpoints": { + "MyHttpEndpoint": { + "Url": "http://localhost:5000" + } + } + }, + "Serilog": { + "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ], + "MinimumLevel": { + "Default": "Information", + "Override": { + "Microsoft": "Warning", + "System": "Warning" + } + }, + "WriteTo:Async": { + "Name": "Async", + "Args": { + "configure": [ + { + "Name": "File", + "Args": { + "path": "logs/log-reqifviewer-.txt", + "rollingInterval": "Day", + "rollOnFileSizeLimit": true + } + } + ] + } + }, + "Enrich": [ "FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId" ], + "Properties": { + "Application": "dmap-cdao", + "Environment": "Production" + } + } +} diff --git a/reqifviewer/reqifviewer.csproj b/reqifviewer/reqifviewer.csproj index 70f2c21..837987e 100644 --- a/reqifviewer/reqifviewer.csproj +++ b/reqifviewer/reqifviewer.csproj @@ -20,20 +20,26 @@ + + + + + - - + + +