diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html
index c38c545..3380406 100644
--- a/Resources/ChangeLog.html
+++ b/Resources/ChangeLog.html
@@ -1,6 +1,6 @@
WebDoorCreator - Egalware
- Version: 0.9.2404.2317
+ Version: 0.9.2404.2417
Release note:
-
diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt
index e4a6ced..cc045af 100644
--- a/Resources/VersNum.txt
+++ b/Resources/VersNum.txt
@@ -1 +1 @@
-0.9.2404.2317
+0.9.2404.2417
diff --git a/Resources/manifest.xml b/Resources/manifest.xml
index 439962a..e9d2d07 100644
--- a/Resources/manifest.xml
+++ b/Resources/manifest.xml
@@ -1,6 +1,6 @@
-
- 0.9.2404.2317
+ 0.9.2404.2417
http://nexus.steamware.net/repository/SWS/WDC/stable/WDC.UI.zip
http://nexus.steamware.net/repository/SWS/WDC/stable/ChangeLog.html
false
diff --git a/WebDoorCreator.API/Health/Checks.cs b/WebDoorCreator.API/Health/Checks.cs
new file mode 100644
index 0000000..d770f41
--- /dev/null
+++ b/WebDoorCreator.API/Health/Checks.cs
@@ -0,0 +1,95 @@
+using Microsoft.Extensions.Diagnostics.HealthChecks;
+using NLog;
+using System.Net.NetworkInformation;
+using WebDoorCreator.Data;
+
+namespace WebDoorCreator.API.Health
+{
+ public class Checks
+ {
+ #region Public Methods
+
+ public static async Task ConfigCount(IConfiguration _config)
+ {
+ string description = "Try check Config table";
+ var healthCheckData = new Dictionary();
+ using (WDCDataContext localDbCtx = new WDCDataContext(_config))
+ {
+ var dbCount = localDbCtx
+ .DbSetConfig
+ .Count();
+ if (dbCount > 0)
+ {
+ description = $"Check Config table, found {dbCount} records";
+ healthCheckData.Add("Count", dbCount);
+ return HealthCheckResult.Healthy(description, healthCheckData);
+ }
+ }
+
+ await Task.Delay(1);
+ return HealthCheckResult.Unhealthy(description + $" NO RECORD found", null, healthCheckData);
+ }
+
+ public static async Task DoorsCount(IConfiguration _config)
+ {
+ string description = "Try check DOOR table";
+ var healthCheckData = new Dictionary();
+ using (WDCDataContext localDbCtx = new WDCDataContext(_config))
+ {
+ var dbCount = localDbCtx
+ .DbSetDoor
+ .Count();
+ if (dbCount > 0)
+ {
+ description = $"Check DOOR table, found {dbCount} records";
+ healthCheckData.Add("Count", dbCount);
+ return HealthCheckResult.Healthy(description, healthCheckData);
+ }
+ }
+
+ await Task.Delay(1);
+ return HealthCheckResult.Unhealthy(description + $" NO RECORD found", null, healthCheckData);
+ }
+
+ public static async Task OrdersCount(IConfiguration _config)
+ {
+ string description = "Try check ORDER table";
+ var healthCheckData = new Dictionary();
+ using (WDCDataContext localDbCtx = new WDCDataContext(_config))
+ {
+ var dbCount = localDbCtx
+ .DbSetOrders
+ .Count();
+ if (dbCount > 0)
+ {
+ description = $"Check ORDER table, found {dbCount} records";
+ healthCheckData.Add("Count", dbCount);
+ return HealthCheckResult.Healthy(description, healthCheckData);
+ }
+ }
+
+ await Task.Delay(1);
+ return HealthCheckResult.Unhealthy(description + $" NO RECORD found", null, healthCheckData);
+ }
+
+ public static async Task PingCheck(string hostName)
+ {
+ var description = $"Ping to {hostName}";
+ var healthCheckData = new Dictionary();
+ using (var thePing = new Ping())
+ {
+ var pingResult = await thePing.SendPingAsync(hostName);
+ healthCheckData.Add("RoundTripMS", pingResult.RoundtripTime);
+ healthCheckData.Add("ActualIPAddress", pingResult.Address.ToString());
+ if (pingResult.Status == IPStatus.Success)
+ {
+ description += $" - {pingResult.RoundtripTime}ms";
+ return HealthCheckResult.Healthy(description, healthCheckData);
+ }
+ }
+ return HealthCheckResult.Unhealthy(description + $" {hostName}", null, healthCheckData);
+ }
+
+ #endregion Public Methods
+ }
+}
\ No newline at end of file
diff --git a/WebDoorCreator.API/Program.cs b/WebDoorCreator.API/Program.cs
index c9d9fc2..6123b88 100644
--- a/WebDoorCreator.API/Program.cs
+++ b/WebDoorCreator.API/Program.cs
@@ -1,5 +1,8 @@
+using HealthChecks.UI.Client;
+using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.AspNetCore.Localization;
+using Microsoft.Extensions.Diagnostics.HealthChecks;
using StackExchange.Redis;
using StackExchange.Redis.Extensions.Core.Configuration;
using StackExchange.Redis.Extensions.Newtonsoft;
@@ -14,6 +17,7 @@ var builder = WebApplication.CreateBuilder(args);
// configuration setup
ConfigurationManager configuration = builder.Configuration;
+
// Redis
var connStringRedis = configuration.GetConnectionString("Redis");
if (string.IsNullOrEmpty(connStringRedis))
@@ -30,6 +34,58 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
+// APP MAIN setup
+string connectionString = configuration.GetConnectionString("WDC.DB")??"";
+string dbServerAddr = "127.0.0.1";
+if (connectionString != null && connectionString.Contains("Server"))
+{
+ bool trovato = false;
+ var dbTokens = connectionString.Split(";");
+ int numTok = dbTokens.Count();
+ int idx = 0;
+ while (!trovato && idx < numTok)
+ {
+ if (dbTokens[idx].StartsWith("Server="))
+ {
+ // rimuovo la chaive Server...
+ dbServerAddr = dbTokens[idx].Replace("Server=", "");
+ // se ci fosse un nome (tipo \\sqlexpress) rimuovo...
+ if (dbServerAddr.Contains("\\"))
+ {
+ int sIdx = dbServerAddr.IndexOf("\\");
+ dbServerAddr = dbServerAddr.Substring(0, sIdx);
+ }
+ trovato = true;
+ }
+ idx++;
+ }
+}
+
+// healthchecks
+builder.Services.AddHealthChecks()
+ .AddSqlServer(connectionString, healthQuery: "SELECT 1;", name: "SqlServer", failureStatus: HealthStatus.Degraded, tags: new string[] { "DB", "MsSql" })
+ .AddAsyncCheck($"DB PING ({dbServerAddr})", () => WebDoorCreator.API.Health.Checks.PingCheck(dbServerAddr))
+ .AddAsyncCheck($"Redis PING ({redisSrvAddr})", () => WebDoorCreator.API.Health.Checks.PingCheck(redisSrvAddr))
+ // 512 MB max allocated memory
+ .AddProcessAllocatedMemoryHealthCheck(512, "Max Process memory (<512MB)", failureStatus: HealthStatus.Degraded)
+ .AddRedis(connStringRedis, "Redis", failureStatus: HealthStatus.Degraded)
+ .AddAsyncCheck($"Config Table", () => WebDoorCreator.API.Health.Checks.ConfigCount(configuration))
+ .AddAsyncCheck($"Orders Table", () => WebDoorCreator.API.Health.Checks.OrdersCount(configuration))
+ .AddAsyncCheck($"Doors Table", () => WebDoorCreator.API.Health.Checks.DoorsCount(configuration))
+ ;
+
+builder.Services
+ .AddHealthChecksUI(s =>
+ {
+ s.AddHealthCheckEndpoint("GWMS_Services", "health");
+ s.SetEvaluationTimeInSeconds(60);
+ //s.SetEvaluationTimeInSeconds(60);
+ s.SetMinimumSecondsBetweenFailureNotifications(120);
+ s.SetApiMaxActiveRequests(5);
+ s.SetHeaderText("GWMS Health Check Status");
+ })
+ .AddInMemoryStorage();
+
// abilitazione x email management con MailKit
//builder.Services.AddTransient();
builder.Services.AddSingleton();
@@ -94,4 +150,10 @@ app.UseAuthorization();
app.MapControllers();
+app.MapHealthChecks("/health", new HealthCheckOptions
+{
+ Predicate = _ => true,
+ ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
+});
+
app.Run();
diff --git a/WebDoorCreator.API/WebDoorCreator.API.csproj b/WebDoorCreator.API/WebDoorCreator.API.csproj
index bbcf09b..bedb260 100644
--- a/WebDoorCreator.API/WebDoorCreator.API.csproj
+++ b/WebDoorCreator.API/WebDoorCreator.API.csproj
@@ -25,6 +25,16 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/WebDoorCreator.UI/Program.cs b/WebDoorCreator.UI/Program.cs
index 5f17f1c..0c7da81 100644
--- a/WebDoorCreator.UI/Program.cs
+++ b/WebDoorCreator.UI/Program.cs
@@ -27,8 +27,6 @@ var builder = WebApplication.CreateBuilder(args);
// configuration setup
Microsoft.Extensions.Configuration.ConfigurationManager configuration = builder.Configuration;
-// AspNetCore Identity setup
-var connectionString = configuration.GetConnectionString("Identity.DB");
// REDIS setup
string connStringRedis = configuration.GetConnectionString("Redis");
@@ -36,6 +34,8 @@ string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":"))
// avvio oggetto shared x redis...
var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis);
+// AspNetCore Identity setup
+var connectionString = configuration.GetConnectionString("Identity.DB");
string dbServerAddr = "127.0.0.1";
if (connectionString.Contains("Server"))
{
@@ -85,8 +85,6 @@ builder.Services
})
.AddInMemoryStorage();
-
-
// abilitazione x email management con MailKit
builder.Services.AddTransient();
builder.Services.Configure(options =>
diff --git a/WebDoorCreator.UI/WebDoorCreator.UI.csproj b/WebDoorCreator.UI/WebDoorCreator.UI.csproj
index ec2ff54..9b492d4 100644
--- a/WebDoorCreator.UI/WebDoorCreator.UI.csproj
+++ b/WebDoorCreator.UI/WebDoorCreator.UI.csproj
@@ -3,7 +3,7 @@
net6.0
enable
- 0.9.2404.2317
+ 0.9.2404.2417
enable
aspnet-WebDoorCreator.UI-dfe95fed-1398-4144-bd43-8b3a765d6608