/// <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的配置文件 /// </summary> /// <param name="sqlConfig"></param> /// <param name="configDirectory"></param> /// <param name="encoding"></param> /// <param name="isAllDirectories"></param> /// <param name="fileType"></param> public static void LoadDirectory(this ISqlConfig sqlConfig, DirectoryInfo configDirectory, Encoding encoding, bool isAllDirectories = true, SqlConfigFileExtType fileType = SqlConfigFileExtType.json) { sqlConfig.LoadDirectory(configDirectory.FullName, encoding, isAllDirectories, fileType); }
/// <summary> /// 从目录中获取sql的配置文件 /// </summary> /// <param name="sqlConfig"></param> /// <param name="configDirectoryPath"></param> /// <param name="isAllDirectories"></param> /// <param name="fileType"></param> public static void LoadDirectory(this ISqlConfig sqlConfig, string configDirectoryPath, bool isAllDirectories = true, SqlConfigFileExtType fileType = SqlConfigFileExtType.json) { sqlConfig.LoadDirectory(configDirectoryPath, Encoding.UTF8, isAllDirectories, fileType); }