Пример #1
0
 public T GetValue <T>()
 {
     if (this._originalValue != null)
     {
         return(JsonSerializerManager.JsonDeserialize <T>(this._originalValue));
     }
     return(BinarySerializerManager.BinaryDeSerialize <T>(this._originalRawValue));
 }
Пример #2
0
 public T GetKey <T>()
 {
     if (this._originalKey != null)
     {
         return(JsonSerializerManager.JsonDeserialize <T>(this._originalKey));
     }
     return(BinarySerializerManager.BinaryDeSerialize <T>(this._originalRawKey));
 }
Пример #3
0
        private static InkeyResult <string> GetRedisResult(string actionType, string sType, string vType, string cacheResult, FormatObjcet formart, List <string> pValueList)
        {
            InkeyResult <string> result = new InkeyResult <string>();
            bool sJsonType    = sType == "JSON";
            var  cacheManager = new RedisManager(new CacheManagerActionCacheKeyFormat());
            var  flag         = false;

            switch (actionType)
            {
            case "View":
                flag = cacheManager.Exists(formart.Key, pValueList.ToArray());
                if (!flag)
                {
                    result.Code = InkeyErrorCodes.CommonBusinessFailure;
                    result.Desc = "未设置缓存值";
                    return(result);
                }
                if (sJsonType)
                {
                    result.Data = cacheManager.GetOriginalValue(formart.Key, pValueList.ToArray());
                }
                else
                {
                    if (string.IsNullOrEmpty(vType))
                    {
                        result.Code = InkeyErrorCodes.CommonBusinessFailure;
                        result.Desc = "值类型未设置";
                        return(result);
                    }
                    Type type = Type.GetType(vType);
                    if (type == null)
                    {
                        result.Code = InkeyErrorCodes.CommonBusinessFailure;
                        result.Desc = "值类型未定义,类型:" + vType;
                        return(result);
                    }
                    byte[] oValue = cacheManager.RawGetOriginalValue(formart.Key, pValueList.ToArray());
                    object value  = BinarySerializerManager.BinaryDeSerialize(oValue);
                    result.Data = value.ToJsonString();
                }
                break;

            case "Update":
                flag = cacheManager.Exists(formart.Key, pValueList.ToArray());
                if (!flag)
                {
                    result.Code = InkeyErrorCodes.CommonBusinessFailure;
                    result.Desc = "未设置缓存值";
                    return(result);
                }
                if (sJsonType)
                {
                    flag = cacheManager.OriginalValueAdd(formart.Key, cacheResult, pValueList.ToArray());
                    if (!flag)
                    {
                        result.Code = InkeyErrorCodes.CommonBusinessFailure;
                        result.Desc = "更新失败";
                        return(result);
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(vType))
                    {
                        result.Code = InkeyErrorCodes.CommonBusinessFailure;
                        result.Desc = "值类型未设置";
                        return(result);
                    }
                    Type type = Type.GetType(vType);
                    if (type == null)
                    {
                        result.Code = InkeyErrorCodes.CommonBusinessFailure;
                        result.Desc = "值类型未定义,类型:" + vType;
                        return(result);
                    }
                    var oValue = JsonSerializerManager.JsonDeserialize(cacheResult, type);
                    if (oValue == null)
                    {
                        result.Code = InkeyErrorCodes.CommonBusinessFailure;
                        result.Desc = "json格式错误,类型:" + vType;
                        return(result);
                    }
                    else
                    {
                        var value = BinarySerializerManager.BinarySerialize(oValue);
                        flag = cacheManager.RawOriginalValueAdd(formart.Key, value, pValueList.ToArray());
                        if (!flag)
                        {
                            result.Code = InkeyErrorCodes.CommonBusinessFailure;
                            result.Desc = "更新失败";
                            return(result);
                        }
                    }
                }
                result.Code = InkeyErrorCodes.CommonBusinessFailure;    //前端需要弹出提示,所有设置这个值
                result.Desc = "更新成功";
                break;

            case "Delete":
                flag = cacheManager.Remove(formart.Key, pValueList.ToArray());
                if (!flag)
                {
                    result.Code = InkeyErrorCodes.CommonBusinessFailure;
                    result.Desc = "缓存移除失败";
                    return(result);
                }
                break;
            }
            return(result);
        }