Skip to content

Commit

Permalink
[Add] apsettings
Browse files Browse the repository at this point in the history
[Add] ResourceLoader and ascii-art
  • Loading branch information
samatrhea committed Mar 20, 2024
1 parent 29fadcc commit 4bb26e9
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 14 deletions.
34 changes: 34 additions & 0 deletions nginx
Original file line number Diff line number Diff line change
@@ -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;
}
}
28 changes: 17 additions & 11 deletions reqifviewer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ namespace reqifviewer
using Radzen;

using Serilog;
using Serilog.Events;
using Microsoft.Extensions.Logging;
using ReqifViewer.Resources;

/// <summary>
/// The purpose of the <see cref="Program"/> class is to provide the
/// main entry point of te application
/// </summary>
public static class Program
public class Program

Check warning on line 45 in reqifviewer/Program.cs

View workflow job for this annotation

GitHub Actions / Build

Add a 'protected' constructor or the 'static' keyword to the class declaration. (https://rules.sonarsource.com/csharp/RSPEC-1118)
{
/// <summary>
/// Main entry point of the application
Expand All @@ -52,21 +53,19 @@ public static class Program
/// </returns>
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<IResourceLoader, ResourceLoader>();
builder.Services.AddScoped<DialogService>();
builder.Services.AddScoped<NotificationService>();
builder.Services.AddScoped<TooltipService>();
Expand All @@ -78,6 +77,13 @@ public static async Task Main(string[] args)

var app = builder.Build();

var logger = app.Services.GetService<ILogger<Program>>();
var resourceLoader = app.Services.GetService<IResourceLoader>();
var logo = resourceLoader.QueryLogo();
logger.LogInformation("################################################################");
logger.LogInformation(logo);
logger.LogInformation("################################################################");

app.UseStaticFiles();
app.UseRouting();
app.MapBlazorHub();
Expand Down
55 changes: 55 additions & 0 deletions reqifviewer/Resources/IResourceLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="IResourceLoader.cs" company="RHEA System S.A.">
//
// 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.
//
// </copyright>
// -------------------------------------------------------------------------------------------------

namespace ReqifViewer.Resources
{
/// <summary>
/// Definition of the interface used to load (embedded) resources
/// </summary>
public interface IResourceLoader
{
/// <summary>
/// Load an embedded resource
/// </summary>
/// <param name="path">
/// The path of the embedded resource
/// </param>
/// <returns>
/// a string containing the contents of the embedded resource
/// </returns>
string LoadEmbeddedResource(string path);

/// <summary>
/// queries the version number from the executing assembly
/// </summary>
/// <returns>
/// a string representation of the version of the application
/// </returns>
string QueryVersion();

/// <summary>
/// Queries the logo with version info from the embedded resources
/// </summary>
/// <returns>
/// the logo
/// </returns>
string QueryLogo();
}
}
97 changes: 97 additions & 0 deletions reqifviewer/Resources/ResourceLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="ResourceLoader.cs" company="RHEA System S.A.">
//
// 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.
//
// </copyright>
// -------------------------------------------------------------------------------------------------

namespace ReqifViewer.Resources
{
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;

/// <summary>
/// Class responsible for loading embedded resources.
/// </summary>
public class ResourceLoader : IResourceLoader
{
/// <summary>
/// Load an embedded resource
/// </summary>
/// <param name="path">
/// The path of the embedded resource
/// </param>
/// <returns>
/// a string containing the contents of the embedded resource
/// </returns>
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();
}

/// <summary>
/// queries the version number from the executing assembly
/// </summary>
/// <returns>
/// a string representation of the version of the application
/// </returns>
public string QueryVersion()
{
var assembly = Assembly.GetExecutingAssembly();
var infoVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();

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;
}

/// <summary>
/// Queries the logo with version info from the embedded resources
/// </summary>
/// <returns>
/// the logo
/// </returns>
public string QueryLogo()
{
var version = this.QueryVersion();

var logo = this.LoadEmbeddedResource("reqifviewer.Resources.ascii-art.txt")
.Replace("reqifviewerVersion", version);

return logo;
}
}
}
11 changes: 11 additions & 0 deletions reqifviewer/Resources/ascii-art.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


██████╗ ███████╗ ██████╗ ██╗███████╗███████╗██╗ ██╗ █████╗ ██████╗ ██████╗
██╔══██╗██╔════╝██╔═══██╗██║██╔════╝██╔════╝██║ ██║██╔══██╗██╔══██╗██╔══██╗
██████╔╝█████╗ ██║ ██║██║█████╗ ███████╗███████║███████║██████╔╝██████╔╝
██╔══██╗██╔══╝ ██║▄▄ ██║██║██╔══╝ ╚════██║██╔══██║██╔══██║██╔══██╗██╔═══╝
██║ ██║███████╗╚██████╔╝██║██║ ███████║██║ ██║██║ ██║██║ ██║██║
═╝ ╚═╝╚══════╝ ╚══▀▀═╝ ╚═╝╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝

Copyright (c) 2022-2024 RHEA System S.A.
reqifviewer version: reqifviewerVersion
1 change: 0 additions & 1 deletion reqifviewer/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions reqifviewer/appsettings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
10 changes: 8 additions & 2 deletions reqifviewer/reqifviewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,26 @@

<ItemGroup>
<None Remove="Dockerfile" />
<None Remove="Resources\ascii-art.txt" />
</ItemGroup>

<ItemGroup>
<Content Include="Dockerfile" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\ascii-art.txt" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Blazor-Analytics" Version="3.12.0" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Radzen.Blazor" Version="4.13.6" />
<PackageReference Include="BlazorStrap.V5" Version="5.1.102.51723" />
<PackageReference Include="ReqIFSharp.Extensions" Version="2.0.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.BrowserConsole" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 4bb26e9

Please sign in to comment.