namespace OSS.Tools.DirConfig;
///
/// 列表配置通用存储获取信息
///
public static class ListConfigHelper
{
public static IToolListConfig DefaultDirTool
{
get;
set;
} = new DefaultToolListConfig();
///
/// 配置信息来源提供者
///
public static Func? ToolProvider { get; set; }
///
/// 来源名称格式化
///
public static Func? SourceFormat { get; set; }
///
/// 通过来源名称获取
///
///
///
private static IToolListConfig GetDirConfig(string sourceName)
{
if (SourceFormat != null)
sourceName = SourceFormat.Invoke(sourceName);
return ToolProvider?.Invoke(sourceName) ?? DefaultDirTool;
}
///
/// 添加列表配置项
///
/// 配置关键字
/// 项关键字
///
/// 来源名称
/// 配置信息类型
///
public static Task SetItem(string listKey, string itemKey, TConfig itemValue, string sourceName = "")
{
return GetDirConfig(sourceName).SetItem(listKey, itemKey, itemValue, sourceName);
}
///
/// 获取列表配置
///
/// 配置关键字
/// 来源名称
/// 配置信息类型
///
public static Task>> GetList(string listKey, string sourceName = "")
{
return GetDirConfig(sourceName).GetList(listKey, sourceName);
}
///
/// 获取列表数量
///
/// 配置关键字
/// 来源名称
///
public static Task GetCount(string listKey, string sourceName="")
{
return GetDirConfig(sourceName).GetCount(listKey, sourceName);
}
///
/// 获取列表配置具体项
///
/// 配置关键字
/// 项Key
/// 来源名称
/// 配置信息类型
///
public static Task?> GetItem(string listKey, string itemKey, string sourceName = "")
{
return GetDirConfig(sourceName).GetItem(listKey, itemKey,sourceName);
}
///
/// 移除列表配置项
///
///
///
/// 来源名称
///
public static Task RemoveItem(string listKey, string itemKey, string sourceName = "")
{
return GetDirConfig(sourceName).RemoveItem(listKey, itemKey, sourceName);
}
}