Files
BeWoPlaner/Service/Core/PathHelper.cs
2025-12-02 15:40:12 +01:00

71 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeWo.Service.Core
{
public static class PathHelper
{
/// <summary>
/// Holt den Ordner, wo sich die systemInstructions befinden
/// </summary>
public static string GetAiSystemInstructionPath()
=> Path.Combine(getRoot(), "AI", "systemInstructions");
public static string GetOrCreateUniqueRequestLogFile()
{
var folder_path = Path.Combine(getExecutionRoot(), "logs", "ai", "requests");
Directory.CreateDirectory(folder_path);
var file_name = getUniqueFileName(folder_path, $"{DateTime.Now:yyyy.MM.dd HH_mm_ss}", 20);
if (file_name == null)
return null;
return Path.Combine(folder_path, file_name + ".log");
}
/// <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;
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;
}
}
}