/// <summary> /// .ctor /// </summary> /// <param name="dbProperty">数据库属性信息</param> /// <param name="isWrite">是否写连接(默认使用读连接)</param> public BaseDataAccess(DatabaseProperty dbProperty, bool isWrite = false) { EnsureUtil.NotNull(dbProperty, "dbProperty不能为空!"); DatabaseConnection dbConnection = isWrite ? dbProperty.Writer : dbProperty.Reader; _conn = CreateConnection(dbConnection); }
public RedisBaseRepository(IRedisProvider redisProvider, RedisConfig redisConfig) { EnsureUtil.NotNull(redisProvider, "IRedisProvider"); EnsureUtil.NotNull(redisConfig, "RedisConfig"); _redisProvider = redisProvider; _redisConfig = redisConfig; }
public RpcClient(IPAddress hostIPAddress, int port) { EnsureUtil.NotNull(hostIPAddress, "hostIPAddress"); EnsureUtil.Positive(port, "port"); _hostIPAddress = hostIPAddress; _bindPort = port; }
public RedisBaseRepository(IRedisDatabaseProvider databaseProvider, RedisCacheOption redisCacheOption) { EnsureUtil.NotNull(databaseProvider, "IRedisDatabaseProvider"); EnsureUtil.NotNull(redisCacheOption, "RedisCacheOption"); _databaseProvider = databaseProvider; _cacheOption = redisCacheOption; }
/// <summary> /// 获取表达式的成员名字 /// </summary> /// <typeparam name="T">对象类型</typeparam> /// <typeparam name="TProperty">属性</typeparam> /// <param name="express">表达式</param> /// <returns>属性名字</returns> public static string GetMemberName <T, TProperty>(this Expression <Func <T, TProperty> > express) { EnsureUtil.NotNull(express, "express"); var body = express.Body as MemberExpression; EnsureUtil.NotNull(body, "body"); return(body.Member.Name); }
public StackExchangeRedisClient(RedisCacheOption redisCacheOption, IRedisBinarySerializer serializer) { EnsureUtil.NotNull(redisCacheOption, "RedisCacheOptions"); EnsureUtil.NotNull(serializer, "IBinarySerializer"); _redisCacheOption = redisCacheOption; _serializer = serializer; _connectionMultiplexer = ConnectionMultiplexerFactory.GetConnection(_redisCacheOption.ConnectionString); }
public StackExchangeRedisClient(RedisConfig redisConfig, IRedisBinarySerializer serializer) { EnsureUtil.NotNull(redisConfig, "redisConfig"); EnsureUtil.NotNull(serializer, "serializer"); _redisConfig = redisConfig; _serializer = serializer; _database = ConnectionMultiplexerFactory.GetDatabase(_redisConfig); _connectionMultiplexer = ConnectionMultiplexerFactory.GetConnectionMultiplexer(_redisConfig); }
/// <summary> /// 以特定的条件运行组合两个Expression表达式 /// </summary> /// <typeparam name="T">表达式的主实体类型</typeparam> /// <param name="first">第一个Expression表达式</param> /// <param name="second">要组合的Expression表达式</param> /// <param name="merge">组合条件运算方式</param> /// <returns>组合后的表达式</returns> public static Expression <T> Compose <T>(this Expression <T> first, Expression <T> second, Func <Expression, Expression, Expression> merge) { EnsureUtil.NotNull(first, "firstExpression"); EnsureUtil.NotNull(second, "secondExpression"); EnsureUtil.NotNull(merge, "mergeExpression"); Dictionary <ParameterExpression, ParameterExpression> map = first.Parameters.Select((f, i) => new { f, s = second.Parameters[i] }).ToDictionary(p => p.s, p => p.f); Expression secondBody = ParameterRebinder.ReplaceParameters(map, second.Body); return(Expression.Lambda <T>(merge(first.Body, secondBody), first.Parameters)); }
/// <summary> /// 设置绝对缓存 /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="absoluteExpireTime"></param> /// <returns></returns> public async Task SetAbsoluteCacheAsync(string key, object value, DateTimeOffset?absoluteExpireTime = null) { EnsureUtil.NotNull(value, "value can be not null"); if (absoluteExpireTime == null) { await RedisClient.StringSetAsync(key, value); } else { await RedisClient.StringSetAsync(key, value, absoluteExpireTime.Value); } }
/// <summary> /// 设置绝对缓存 /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="absoluteExpireTime">绝对失效时间</param> public void SetAbsoluteCache(string key, object value, DateTimeOffset?absoluteExpireTime = null) { EnsureUtil.NotNull(value, "value can be not null"); if (absoluteExpireTime == null) { RedisClient.StringSet(key, value); } else { RedisClient.StringSet(key, value, absoluteExpireTime.Value); } }
/// <summary> /// 拼接批量插入的SqlQuery /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <exception cref="ArgumentNullException">entityList</exception> /// <param name="entityList">实体列表,不能为Null或者为空列表</param> /// <param name="tableName">表名</param> /// <param name="keyName">主键名字</param> /// <param name="ignoreFields">需要忽略的字段</param> /// <param name="isIdentity">是否自增</param> /// <param name="dbType">数据库类型,默认MSSQLServer</param> /// <returns>批量插入的SqlQuery</returns> public static SqlQuery BuilderInsertManySqlQuery <T>(List <T> entityList, string tableName, string keyName = null, string[] ignoreFields = null, bool isIdentity = true, DatabaseType dbType = DatabaseType.MSSQLServer) where T : new() { EnsureUtil.NotNull(entityList, "entityList"); var entity = entityList.FirstOrDefault(); if (entity == null) { throw new ArgumentNullException("entityList"); } var propertyList = GetInsertPropertyList(entity, ignoreFields); var proNameList = propertyList.Select(m => m.Name); var columns = string.Join(",", proNameList); StringBuilder builder = new StringBuilder(); SqlQuery sqlQuery = new SqlQuery(); for (int i = 0; i < entityList.Count; i++) { var values = string.Join(",", proNameList.Select(p => GetSign(dbType) + i.ToString() + p)); builder.AppendFormat("INSERT INTO {0} ({1}) VALUES ({2});{3};", tableName, columns, values, isIdentity ? GetIdentityKeyScript(keyName, dbType) : string.Empty); sqlQuery.AddObjectParam(entityList[i], i.ToString(), ignoreFields: ignoreFields); } sqlQuery.CommandText = builder.ToString(); return(sqlQuery); }
/// <summary> /// 连接不为空 /// </summary> private void ConnIsNotNull() { EnsureUtil.NotNull(_conn, "conn不能为空!"); }
/// <summary> /// 设置相对缓存 /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="slidingExpireTime"></param> public void SetSlidingCache(string key, object value, TimeSpan?slidingExpireTime = null) { EnsureUtil.NotNull(value, "value can be not null"); RedisClient.StringSet(key, value, slidingExpireTime ?? DefaultSlidingExpireTime); }
/// <summary> /// 以 Expression.OrElse 组合两个Expression表达式 /// </summary> /// <typeparam name="T">表达式的主实体类型</typeparam> /// <param name="first">第一个Expression表达式</param> /// <param name="second">要组合的Expression表达式</param> /// <returns>组合后的表达式</returns> public static Expression <Func <T, bool> > Or <T>(this Expression <Func <T, bool> > first, Expression <Func <T, bool> > second) { EnsureUtil.NotNull(first, "firstExpression"); EnsureUtil.NotNull(second, "secondExpression"); return(first.Compose(second, Expression.OrElse)); }
/// <summary> /// 设置相对缓存 /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="slidingExpireTime"></param> /// <returns></returns> public async Task SetSlidingCacheAsync(string key, object value, TimeSpan?slidingExpireTime = null) { EnsureUtil.NotNull(value, "value can be not null"); await RedisClient.StringSetAsync(key, value, slidingExpireTime ?? DefaultSlidingExpireTime); }
public ConnectionStringSettings(IConfiguration configuration) { EnsureUtil.NotNull(configuration, "数据库连接"); this.ConnectionString = configuration["ConnectionString"]; this.ProviderName = configuration["ProviderName"]; }
/// <summary> /// 声明一个交换机、队列,并绑定对应关系 /// </summary> /// <param name="mqAttribute">消息队列特性信息</param> private void CreateExchangeAndQueue(MQAttribute mqAttribute, bool isConsumer = false) { EnsureUtil.NotNull(mqAttribute, "MQAttribute不能为空"); CreateExchangeAndQueue(mqAttribute.ExchangeName, mqAttribute.QueueName, mqAttribute.RoutingKey, exchangeType: mqAttribute.ExchangeType, durable: mqAttribute.Durable, exclusive: mqAttribute.Exclusive, autoDelete: mqAttribute.AutoDelete, arguments: mqAttribute.Arguments, isConsumer: isConsumer); }
public RabbitMQClient(MQConfig mqConfig) { EnsureUtil.NotNull(mqConfig, "配置信息不能为空"); _mqConfig = mqConfig; }