/// <summary> /// 从目录中获取sql的配置文件 /// </summary> /// <param name="sqlConfig"></param> /// <param name="configDirectoryPath"></param> /// <param name="encoding"></param> /// <param name="isAllDirectories"></param> /// <param name="fileType"></param> public static void LoadDirectory(this ISqlConfig sqlConfig, string configDirectoryPath, Encoding encoding, bool isAllDirectories = true, SqlConfigFileExtType fileType = SqlConfigFileExtType.json) { bool bLoad = false; string[] files; if (isAllDirectories) { files = Directory.GetFiles(configDirectoryPath, "*", SearchOption.AllDirectories); } else { files = Directory.GetFiles(configDirectoryPath); } if (files != null && files.Length > 0) { if (fileType == SqlConfigFileExtType.all) { foreach (var f in files) { sqlConfig.LoadFile(f, encoding); } bLoad = true; } else { var fileExts = new List <string>(); if ((fileType & SqlConfigFileExtType.json) == SqlConfigFileExtType.json) { fileExts.Add(EFHelper.Services.EFCoreExUtility.GetEnumDescription(SqlConfigFileExtType.json)); } if ((fileType & SqlConfigFileExtType.txt) == SqlConfigFileExtType.txt) { fileExts.Add(EFHelper.Services.EFCoreExUtility.GetEnumDescription(SqlConfigFileExtType.txt)); } var finfos = files.Select(l => new FileInfo(l)).Where(l => fileExts.Contains(l.Extension.ToLower())).ToList(); if (finfos != null && finfos.Count > 0) { foreach (var f in finfos) { sqlConfig.LoadFile(f, encoding); } bLoad = true; } } } if (!bLoad) { throw new ArgumentException($"The directory [{configDirectoryPath}] does not exist SQL configuration file.", nameof(configDirectoryPath)); } }
/// <summary> /// 加载sql的配置文件(Encoding默认为Encoding.UTF8) /// </summary> /// <param name="sqlConfig"></param> /// <param name="configFilePath"></param> public static void LoadFile(this ISqlConfig sqlConfig, string configFilePath) { sqlConfig.LoadFile(configFilePath, Encoding.UTF8); }
/// <summary> /// 加载sql的配置文件 /// </summary> /// <param name="sqlConfig"></param> /// <param name="configFile"></param> /// <param name="encoding"></param> public static void LoadFile(this ISqlConfig sqlConfig, FileInfo configFile, Encoding encoding) { sqlConfig.LoadFile(configFile.FullName, encoding); }
/// <summary> /// 加载sql的配置文件(Encoding默认为Encoding.UTF8) /// </summary> /// <param name="sqlConfig"></param> /// <param name="configFile"></param> public static void LoadFile(this ISqlConfig sqlConfig, FileInfo configFile) { sqlConfig.LoadFile(configFile, Encoding.UTF8); }