Files
BeWoPlaner/Service/Core/BeWoServerPathHelper.cs

87 lines
2.1 KiB
C#
Raw Normal View History

2025-12-02 16:40:27 +01:00
using BeWo.Service.Plugins;
2026-03-09 13:51:33 +01:00
using BeWo.Service.Security;
2025-12-02 16:40:27 +01:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeWo.Service.Core
{
2026-01-16 13:33:59 +01:00
public static class BeWoServerPathHelper
{
2026-03-09 13:51:33 +01:00
public static string GetUniqueRequestLogFile(out string id)
2025-12-02 15:40:12 +01:00
{
2026-03-09 13:51:33 +01:00
id = null;
2025-12-02 16:40:27 +01:00
var folder_path = Path.Combine(getLogRootPath(), "ai", "requests");
2025-12-02 15:40:12 +01:00
Directory.CreateDirectory(folder_path);
2026-03-10 11:30:36 +01:00
var file_name = getUniqueFileName(folder_path, $"{DateTime.Now:yyyy.MM.dd-HH_mm_ss}", 20);
2025-12-02 15:40:12 +01:00
if (file_name == null)
return null;
2026-03-10 11:30:36 +01:00
id = SecurityUtils.CreateRandomString(10, true, true);
2026-03-09 13:51:33 +01:00
2026-03-10 11:30:36 +01:00
return Path.Combine(folder_path, $"{file_name}-{id}.log");
2025-12-02 15:40:12 +01:00
}
2025-12-02 16:40:27 +01:00
public static string GetServiceLogFile()
=> Path.Combine(getLogRootPath(), "service.log.txt");
public static string GetApiServiceTestFile()
=> Path.Combine(getLogRootPath(), "apiservice.test.txt");
public static string GetAiServiceLogFile()
=> Path.Combine(getLogRootPath(), "aiservice.log.txt");
private static string getLogRootPath()
{
var log_root = Path.Combine(getExecutionRoot(), "logs", "LogFiles");
Directory.CreateDirectory(log_root);
return log_root;
}
2025-12-02 15:40:12 +01:00
private static string getUniqueFileName(string folderPath, string fileName, int retries)
{
var path = Path.Combine(folderPath, fileName);
if (!File.Exists(path))
return fileName;
var name = 2;
while(retries-- > 0)
{
var new_fileName = fileName + $" ({name})";
var new_path = Path.Combine(folderPath, new_fileName);
if (!File.Exists(new_path))
return new_fileName;
name++;
}
return null;
}
2025-12-02 16:40:27 +01:00
#region Most basics
/// <summary>
/// Holt den Server Root Path
/// Normalerweise: C:/BeWoPlaner
/// </summary>
private static string getRoot()
=> MergedConfig.GetSetting(WebConfigSetting.BeWoPlanerServiceRoot);
/// <summary>
/// Holt den Service Root Path
/// Normalerweise: C:/BeWoPlaner/service/Host
/// </summary>
private static string getExecutionRoot()
=> AppDomain.CurrentDomain.BaseDirectory;
#endregion
}
}