Files
BeWoPlaner/Service/ServiceImplementations/Enhanced/StatusServiceImp.cs
2026-04-07 12:01:30 +02:00

110 lines
2.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.Attributes;
using BeWo.Service.Core;
using BeWo.Service.ServiceContracts.Enhanced;
using BS.Shared.DataContracts;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Threading.Tasks;
namespace BeWo.Service.ServiceImplementations.Enhanced
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall,
ConcurrencyMode = ConcurrencyMode.Single)]
public class StatusServiceImp : IStatusService
{
public ServerStatusDC GetStatus()
{
var result = new ServerStatusDC
{
ServerTime = DateTime.Now.ToString("o"),
Version = Assembly.GetExecutingAssembly()
.GetName().Version?.ToString() ?? "unbekannt",
Services = new List<ServiceStatusDC>()
};
// Datenbankverbindung prüfen
result.DatabaseOk = CheckDatabase();
// Einzelne Subsysteme prüfen
//result.Services.Add(CheckService("Mail", CheckMail()));
result.Services.Add(CheckService("AIModule", CheckAiModule()));
return result;
}
private bool CheckDatabase()
{
try
{
// Leichter DB-Ping z.B. eine einfache Abfrage über DAOFactory
DAOFactory.GenericDAO.GetAll<ApplicationUser>();
return true;
}
catch
{
return false;
}
}
private bool CheckMail()
{
try
{
// z.B. SMTP-Verbindung kurz aufbauen und sofort schließen
// Kann auch weggelassen / später ergänzt werden
return true;
}
catch
{
return false;
}
}
private string CheckAiModule()
{
try
{
// #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";
return null;
}
catch
{
return "Fehler";
}
}
private ServiceStatusDC CheckService(string name, string error)
{
var ok = error is null;
return CheckService(name, ok, error);
}
private ServiceStatusDC CheckService(string name, bool ok, string error)
{
return new ServiceStatusDC
{
Name = name,
IsOk = ok,
Message = ok ? "OK" : error
};
}
}
}