79 lines
1.8 KiB
C#
79 lines
1.8 KiB
C#
using BS.Shared.Exceptions;
|
|
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 ConfigReader
|
|
{
|
|
public static List<string> GetIPAddressList(IPAddressList iPAddressList)
|
|
{
|
|
if(iPAddressList == IPAddressList.None)
|
|
throw new ArgumentException(nameof(iPAddressList));
|
|
|
|
var lSubPath = getIPAddressListName(iPAddressList);
|
|
|
|
var lConfigPath = getConfigPath(lSubPath);
|
|
|
|
var lines = File.ReadAllLines(lConfigPath);
|
|
|
|
return lines.ToList();
|
|
}
|
|
|
|
public static string GetConfigPath(SpecialConfig specialConfig)
|
|
{
|
|
if (specialConfig == SpecialConfig.None)
|
|
throw new ArgumentException(nameof(specialConfig));
|
|
|
|
var lSubPath = getSpecialConfigName(specialConfig);
|
|
|
|
var lConfigPath = getConfigPath(lSubPath);
|
|
|
|
return lConfigPath;
|
|
}
|
|
|
|
private static string getConfigPath(string subpath)
|
|
{
|
|
var root = AppDomain.CurrentDomain.BaseDirectory;
|
|
|
|
var path = Path.Combine(root, "Config", subpath);
|
|
|
|
return path;
|
|
}
|
|
|
|
private static string getSpecialConfigName(SpecialConfig config)
|
|
{
|
|
switch (config)
|
|
{
|
|
case SpecialConfig.None:
|
|
break;
|
|
case SpecialConfig.CustomFunctionPreSystemPrompt:
|
|
return Path.Combine("ai", "systemPrompts", "customFunctionPreSystemPrompt.txt");
|
|
case SpecialConfig.CustomPreSystemPrompt:
|
|
return Path.Combine("ai", "systemPrompts", "customPreSystemPrompt.txt");
|
|
default:
|
|
break;
|
|
}
|
|
|
|
throw BeWoNotImplementedException.CreateFromEnum(config);
|
|
}
|
|
|
|
private static string getIPAddressListName(IPAddressList list)
|
|
{
|
|
switch (list)
|
|
{
|
|
case IPAddressList.None:
|
|
break;
|
|
case IPAddressList.AdminApi:
|
|
return "allowed_ips_admin_api.txt";
|
|
}
|
|
|
|
throw BeWoNotImplementedException.CreateFromEnum(list);
|
|
}
|
|
}
|
|
}
|