Files
juipnet/Services/Hncore.Pass.OSS/UEditor/Config.cs
“wanyongkang” b562aba2b1 忽略dll文件git
2023-07-29 10:19:42 +08:00

80 lines
2.2 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 System;
using System.IO;
using System.Linq;
using Newtonsoft.Json.Linq;
namespace UEditor.Core
{
/// <summary>
/// Config 的摘要说明
/// </summary>
public static class Config
{
public static bool NoCache = true;
private static JObject BuildItems()
{
var configExtension = Path.GetExtension(ConfigFile);
var configFileName = ConfigFile.Substring(0, ConfigFile.Length - configExtension.Length);
var evnConfig = $"{configFileName}.{Config.EnvName}{configExtension}";
if (File.Exists(Path.Combine(WebRootPath, evnConfig)))
{
var json = File.ReadAllText(Path.Combine(WebRootPath, evnConfig));
return JObject.Parse(json);
}
else
{
var configFilePath = Path.Combine(WebRootPath, ConfigFile);
if (!File.Exists(configFilePath))
{
throw new Exception("未找到UEditor配置文件请检查若有问题请参阅文档https://github.com/baiyunchen/UEditor.Core");
}
var json = File.ReadAllText(configFilePath);
return JObject.Parse(json);
}
}
public static JObject Items
{
get
{
if (NoCache || _Items == null)
{
_Items = BuildItems();
}
return _Items;
}
}
public static string EnvName { get; set; }
public static string WebRootPath { get; set; }
// public static string WwwRootPath { get; set; }
public static string ConfigFile { set; get; } = "ueditor.json";
private static JObject _Items;
public static T GetValue<T>(string key)
{
return Items[key].Value<T>();
}
public static String[] GetStringList(string key)
{
return Items[key].Select(x => x.Value<String>()).ToArray();
}
public static String GetString(string key)
{
return GetValue<String>(key);
}
public static int GetInt(string key)
{
return GetValue<int>(key);
}
}
}