82 lines
2.0 KiB
C#
82 lines
2.0 KiB
C#
using BeWo.Service.Plugins;
|
|
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 BeWoServerPathHelper
|
|
{
|
|
public static string GetUniqueRequestLogFile()
|
|
{
|
|
var folder_path = Path.Combine(getLogRootPath(), "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");
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
#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
|
|
}
|
|
}
|