コード例 #1
0
        /// <summary>
        /// 生成缓存键
        /// 依据哈希字符串原来
        /// 将参数转换为字节数组,然后做SHA256处理
        /// </summary>
        /// <param name="paramterCollection"></param>
        /// <returns></returns>
        public string GetKey(string functionName, string methodName, string sqlText, DbNetParamterCollection paramterCollection)
        {
            Dictionary <string, object> paramterValues = new Dictionary <string, object>();

            foreach (var item in paramterCollection)
            {
                if (item.CacheKeyType == CacheKeyType.Bind)
                {
                    paramterValues.Add(item.Name, item.Value);
                }
            }
            //二进制序列化成字节数组
            BinaryFormatter binaryFormatter = new BinaryFormatter();

            byte[] data = null;
            using (MemoryStream mstream = new MemoryStream())
            {
                binaryFormatter.Serialize(mstream, paramterValues);
                data = mstream.ToArray();
            }
            //哈希处理
            SHA256 sha = new SHA256CryptoServiceProvider();

            data = sha.ComputeHash(data);
            data = Encoding.UTF8.GetBytes(string.Format(functionName, methodName, sqlText)).Concat(data).ToArray();
            data = sha.ComputeHash(data);
            StringBuilder sb = new StringBuilder();

            foreach (var b in data)
            {
                sb.Append(b.ToString(X_TWO));
            }
            return(sb.ToString());
        }
コード例 #2
0
ファイル: DbNetCommand.cs プロジェクト: zmxGeorge/DbNet
 public DbNetCommand(string _sqlText, string _connectionString, DbNetParamterCollection _paramters, string _commandType, DbNetIsolationLevel _isolationLevel)
 {
     SqlText          = _sqlText;
     ConnectionString = _connectionString;
     Paramters        = _paramters;
     CommandType      = _commandType;
     IsolationLevel   = _isolationLevel;
 }
コード例 #3
0
 public string RouteDbConnection(string routeName, string moduleName, string methodName, DbNetParamterCollection paramters, out IDbNetProvider dbProvider)
 {
     if (string.IsNullOrEmpty(_connectionString))
     {
         throw new Exception("默认数据库连接字符串未设置");
     }
     dbProvider = _dbProvider;
     return(_connectionString);
 }