@@ -8,6 +8,7 @@ using System;
using System.Collections.Generic ;
using System.IO ;
using System.Linq ;
using System.Net ;
using System.Reflection ;
using System.ServiceModel ;
using System.ServiceModel.Web ;
@@ -20,6 +21,24 @@ namespace BeWo.Service.ServiceImplementations.Enhanced
ConcurrencyMode = ConcurrencyMode.Single)]
public class StatusServiceImp : IStatusService
{
private readonly List < WebConfigSetting > RequiredWebConfigs = new List < WebConfigSetting > ( )
{
WebConfigSetting . OllamaUrl ,
WebConfigSetting . Ollama2Url ,
//WebConfigSetting.XRechnungApiUrl,
//WebConfigSetting.StoredFilesFolderPath,
//WebConfigSetting.StoredTenantFilesFolderPath,
//WebConfigSetting.HelloWorldPdfLocation,
//WebConfigSetting.BeWoPlanerServiceRoot,
WebConfigSetting . AiPromptsUrl
} ;
private readonly List < WebSecretConfigSetting > RequiredWebSecretConfigs = new List < WebSecretConfigSetting > ( )
{
WebSecretConfigSetting . Ollama2Key ,
WebSecretConfigSetting . AppStatusApiKey
} ;
public ServerStatusDC GetStatus ( )
{
var result = new ServerStatusDC
@@ -31,30 +50,31 @@ namespace BeWo.Service.ServiceImplementations.Enhanced
} ;
// Datenbankverbindung prüfen
result . DatabaseOk = CheckDatabase ( );
result . DatabaseOk = executeCheck ( "Datenbank" , CheckDatabase) ;
// Einzelne Subsysteme prüfen
// result. Services.Add(CheckService("Mail", CheckMail())) ;
result . Services . Add ( CheckService ( "AIModule" , CheckAiModule ( ) ) ) ;
result . Services . Add ( CheckService ( "Web.config" , CheckWebConfig( ) ) ) ;
result. Services. Add ( executeCheck ( "AIModule" , CheckAiModule ) ) ;
result . Services . Add ( executeCheck ( "Web.config" , CheckWebConfig ) ) ;
result . Services . Add ( executeCheck ( "Web.Secret. config" , CheckWebSecret Config ) ) ;
var allHealthy = result . DatabaseOk . IsOk & & result . Services . All ( x = > x . IsOk ) ;
if ( ! allHealthy )
{
WebOperationContext . Current . OutgoingResponse . StatusCode =
HttpStatusCode . InternalServerError ;
}
return result ;
}
private bool CheckDatabase ( )
private string CheckDatabase ( )
{
t ry
{
// Leichter DB-Ping – z.B. eine einfache Abfrage über DAOFactory
DAOFactory . GenericDAO . GetAll < ApplicationUser > ( ) ;
return true ;
}
catch
{
return false ;
}
// Leichter DB-Ping – z.B. eine einfache Abfrage über DAOFacto ry
DAOFactory . GenericDAO . GetAll < ApplicationUser > ( ) ;
return null ;
}
private bool CheckMail ( )
@@ -73,51 +93,67 @@ namespace BeWo.Service.ServiceImplementations.Enhanced
private string CheckAiModule ( )
{
try
{
// #1
var configPath = ConfigReader . GetConfigPath ( SpecialConfig. CustomPreSystemPrompt) ;
if ( ! File . Exists ( configPath ) )
return "SpecialConfig.CustomPreSystemPrompt wurde nicht korrekt konfiguriert" ;
// #1
var configPath = ConfigReader . GetConfigPath ( SpecialConfig . CustomPreSystemPrompt ) ;
if ( ! File . Exists ( configPath ) )
return " SpecialConfig. CustomPreSystemPrompt wurde nicht korrekt konfiguriert" ;
// #2
if ( string . IsNullOrEmpty ( MergedConfig . GetSecretSetting ( WebSecretConfigSetting . Ollama2Key ) ) )
return "Ollama2Key wurde nicht korrekt konfiguriert" ;
// #2
if ( string . IsNullOrEmpty ( MergedConfig . GetSecretSetting ( WebSecretConfigSetting . Ollama2Key ) ) )
return "Ollama2Key wurde nicht korrekt konfiguriert" ;
return null ;
}
catch
{
return "Fehler" ;
}
if ( checkDatabaseScript ( "Changes_2026-05-22 AiConv ActionType" ) is string error )
return error ;
return null ;
}
private string CheckWebConfig ( )
{
foreach ( var webConfig in RequiredWebConfigs )
{
var url = MergedConfig . GetSetting ( webConfig ) ;
if ( string . IsNullOrWhiteSpace ( url ) )
return $"'{webConfig}' wurde nicht korrekt konfiguriert" ;
}
return null ;
}
private string CheckWebSecretConfig ( )
{
foreach ( var webSecretConfig in RequiredWebSecretConfigs )
{
var key = MergedConfig . GetSecretSetting ( webSecretConfig ) ;
if ( string . IsNullOrWhiteSpace ( key ) )
return $"'{webSecretConfig}' wurde nicht korrekt konfiguriert" ;
}
return null ;
}
private string checkDatabaseScript ( string name )
{
var executed = DAOFactory . ScriptDAO . IsScriptExecuted ( name ) ;
return executed ? null : $"Script '{name}' wurde nicht ausgeführt" ;
}
private ServiceStatusDC executeCheck ( string name , Func < string > validation )
{
string error ;
try
{
// #1
var url = MergedConfig . GetSetting ( WebConfigSetting . AiPromptsUrl ) ;
if ( ! string . IsNullOrWhiteSpace ( url ) )
return "AiPromptsUrl wurde nicht korrekt konfiguriert" ;
return null ;
error = validation ( ) ;
}
catch
catch ( Exception ex )
{
return "Fehler" ;
error = ex . ToString ( ) ;
}
}
private ServiceStatusDC CheckService ( string name , string error )
{
var ok = error is null ;
var ok = string . IsNullOrEmpty ( error ) ;
return CheckService ( name , ok , error ) ;
}
private ServiceStatusDC CheckService ( string name , bool ok , string error )
{
return new ServiceStatusDC
{
Name = name ,