Files
BeWoPlaner/Service/ServiceImplementations/Enhanced/StatusServiceImp.cs
2026-03-30 13:06:19 +02:00

100 lines
2.1 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("Database", result.DatabaseOk));
//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 bool CheckAiModule()
{
try
{
// #1
var configPath = ConfigReader.GetConfigPath(SpecialConfig.CustomPreSystemPrompt);
if (!File.Exists(configPath))
return false;
return true;
}
catch
{
return false;
}
}
private ServiceStatusDC CheckService(string name, bool ok)
{
return new ServiceStatusDC
{
Name = name,
IsOk = ok,
Message = ok ? "OK" : "Fehler"
};
}
}
}