/// <summary> /// 添加或者合并Tables /// </summary> /// <param name="sqlConfig"></param> /// <param name="sqlTables"></param> public static void AddOrCombine(this ISqlConfig sqlConfig, IEnumerable <IConfigTableInfo> sqlTables) { foreach (var l in sqlTables) { sqlConfig.AddOrCombine(l); } }
/// <summary> /// Sql数据库访问 /// </summary> /// <param name="sqlConfig">数据库配置</param> /// <param name="userContext">用户上下文</param> public MsSqlQuery(ISqlConfig sqlConfig, IUserContext userContext) { AppendWhere = " where 1=1 "; _sqlConfig = sqlConfig; _userContext = userContext; _log = Log.Log.GetLog("SqlTraceLog"); }
/// <summary> /// ef工作单元 /// </summary> /// <param name="sqlConfig">sql配置</param> public ReadEfUnitOfWork(ISqlConfig sqlConfig) { _log = Log.Log.GetLog("EfTraceLog"); TraceId = DateTimeExtensions.GetUnixTimestamp().ToString() + "___" + base.GetHashCode(); //_log.Warn("R工作单元创建" + this.TraceId); //NLog.LogManager.GetLogger("Debug").Error("R工作单元创建" + this.TraceId); _sqlConfig = sqlConfig; }
/// <summary> /// 添加sql /// </summary> /// <param name="sqlConfig"></param> /// <param name="tableName"></param> /// <param name="sqlInfos"></param> public static void AddSqls(this ISqlConfig sqlConfig, string tableName, IEnumerable <KeyValuePair <string, IConfigSqlInfo> > sqlInfos) { foreach (var pair in sqlInfos) { sqlConfig.Add(tableName, pair.Key, pair.Value); } }
/// <summary> /// Установить новые настройки подключения /// </summary> /// <param name="value"></param> public void SetConfig(ISqlConfig value) { config = value; if (IsConnected()) { Connect(); } }
/// <summary> /// ef工作单元 /// </summary> /// <param name="sqlConfig">sql配置</param> public WriteEfUnitOfWork(ISqlConfig sqlConfig) { _log = Log.Log.GetLog("EfTraceLog"); //TraceId = DateTimeExtensions.GetUnixTimestamp().ToString(); //_log.Warn("W工作单元创建" + this.TraceId); TraceId = Uuid.Next(); //NLog.LogManager.GetLogger("Debug").Error("W工作单元创建" + this.TraceId); _sqlConfig = sqlConfig; }
/// <summary> /// Sql数据库访问 /// </summary> /// <param name="sqlConfig">数据库配置</param> /// <param name="userContext">用户上下文</param> public SqlQuery(ISqlConfig sqlConfig, IUserContext userContext) { AppendWhere = " where 1=1 "; _sqlConfig = sqlConfig; _userContext = userContext; _log = Log.Log.GetLog("SqlTraceLog"); //this.CreateDbConnection(); //this.Open(); }
public SQLRepository(ISqlConfig config) { _config = config; _client = new CosmosClient(config.EndPointUri, config.PrimaryKey); _database = _client.CreateDatabaseIfNotExistsAsync(_config.DataBase).Result.Database; _container = _database.CreateContainerIfNotExistsAsync(_config.Container, _config.PartitionKey).Result.Container; }
/// <summary> /// 加载sql的配置文件 /// </summary> /// <param name="sqlConfig"></param> /// <param name="configFilePath"></param> /// <param name="encoding"></param> public static void LoadFile(this ISqlConfig sqlConfig, string configFilePath, Encoding encoding) { var config = CommonExtensions.JsonToObjectNeedDefaultValue <JsonConfigTableInfo>(File.ReadAllText(configFilePath, encoding)); if (string.IsNullOrEmpty(config.Name)) { config.Name = Path.GetFileNameWithoutExtension(configFilePath); } sqlConfig.AddOrCombine(config); }
public DBConfigTable(ISqlConfig config, string tableName, DbContext db) { config.CheckNull(nameof(config)); tableName.CheckStringIsNullOrEmpty(nameof(tableName)); db.CheckNull(nameof(db)); _config = config; DB = db; TableName = tableName; }
/// <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> /// 获取Table的配置信息 /// </summary> /// <param name="sqlConfig"></param> /// <param name="tableName"></param> /// <param name="sqlName"></param> /// <param name="sqlInfo"></param> /// <returns></returns> public static bool TryGetSqlInfo(this ISqlConfig sqlConfig, string tableName, string sqlName, out IConfigSqlInfo sqlInfo) { sqlInfo = null; IConfigTableInfo table; if (sqlConfig.TableSqlInfos.TryGetValue(tableName, out table)) { if (table.Sqls.TryGetValue(sqlName, out sqlInfo)) { return(true); } } return(false); }
/// <summary> /// 获取sql的配置信息 /// </summary> /// <param name="sqlConfig"></param> /// <param name="tableName"></param> /// <param name="sqlName"></param> /// <returns></returns> public static IConfigSqlInfo GetSqlInfo(this ISqlConfig sqlConfig, string tableName, string sqlName) { IConfigTableInfo table; if (sqlConfig.TableSqlInfos.TryGetValue(tableName, out table)) { IConfigSqlInfo sqlInfo = null; if (table.Sqls.TryGetValue(sqlName, out sqlInfo)) { return(sqlInfo); } else { throw new ArgumentException($"The key [{sqlName}] does not exist in the {nameof(IConfigSqlInfo)} collection.", nameof(sqlName)); } } else { throw new ArgumentException($"The key [{tableName}] does not exist in the {nameof(IConfigTableInfo)} collection.", nameof(tableName)); } }
public SqlConfigManagerBase(ISqlConfigExecutorCreator sqlConfigExecutorCreator, IEFQueryCache efcache, ISqlParamConverter sqlParamConverter, ISqlPolicyManager policyExecutorMgr, IObjectReflector objReflec, IEFCoreExtendUtility util) { sqlConfigExecutorCreator.CheckNull(nameof(sqlConfigExecutorCreator)); efcache.CheckNull(nameof(efcache)); sqlParamConverter.CheckNull(nameof(sqlParamConverter)); policyExecutorMgr.CheckNull(nameof(policyExecutorMgr)); objReflec.CheckNull(nameof(objReflec)); util.CheckNull(nameof(util)); _sqlParamConverter = sqlParamConverter; _efcache = efcache; _sqlConfigExecutorCreator = sqlConfigExecutorCreator; _policyMgr = policyExecutorMgr; _objReflec = objReflec; _util = util; _config = new SqlConfig(OnModified); _init = new InitAction(DoInit); //添加默认的策略 AddDefaultPolicies(); }
public SqlDatabase(ISqlConfig sqlConfig) { Configure(sqlConfig); }
public static void Configure(ISqlConfig sqlConfig) { SqlDatabase = new SqlDatabase(sqlConfig.DatabaseProvider, sqlConfig.ConnectionString); }
public static IServiceCollection AddSqlService <T>(this IServiceCollection services, ISqlConfig config, bool moreThanOne = false) where T : IDbConnection, new() { var scopedConfig = new SqlConfig <T> { ConnectionString = config.ConnectionString, Timeout = config.Timeout }; if (moreThanOne) { return(services .AddTransient <ISqlService <T>, SqlService <T> >() .AddSingleton <ISqlConfig <T> >(scopedConfig)); } return(services .AddTransient <ISqlService, SqlService <T> >() .AddSingleton <ISqlConfig <T> >(scopedConfig)); }
public SqlUserProfileRepository(ISqlConfig config) { _config = config; }
public SqlService(ISqlConfig <T> config) { _config = config; }
/// <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); }
public void Configure(ISqlConfig sqlConfig) { Configure(sqlConfig.DatabaseProvider, sqlConfig.ConnectionString); }
/// <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="userContext">用户上下文</param> public SqlQuery(ISqlConfig sqlConfig, IUserContext userContext) { AppendWhere = " where 1=1 "; _sqlConfig = sqlConfig; _userContext = userContext; }
/// <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); }
public ConnectionArgs(ISqlConfig config, StatusDataBase status) { Config = config; Status = status; }
/// <summary> /// 添加sql /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="sqlConfig"></param> /// <param name="sqlInfos"></param> public static void AddSqls <TEntity>(this ISqlConfig sqlConfig, IEnumerable <KeyValuePair <string, IConfigSqlInfo> > sqlInfos) { sqlConfig.AddSqls(EFHelper.Services.EFCoreExUtility.GetTableName(typeof(TEntity), true), sqlInfos); }
static ISqlRepository <T> NewSqlRepository <T>(ISqlConfig <T> config) { return(new SqlRepository <T>(config)); }
/// <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); }