コード例 #1
0
 public DistributedEvent(object value, string topic, string lable, string objectName)
 {
     this.ObjectName = objectName;
     this.Topic      = topic;
     this._value     = value;
     this.Playload   = JsonSerializerManager.BsonSerialize(value);
     this.Lable      = lable;
 }
コード例 #2
0
 public object GetValue(Type type)
 {
     if (this._value != null)
     {
         return(this._value);
     }
     return(JsonSerializerManager.BsonDeSerialize(this.Playload, type));
 }
コード例 #3
0
 public T GetValue <T>()
 {
     if (this._originalValue != null)
     {
         return(JsonSerializerManager.JsonDeserialize <T>(this._originalValue));
     }
     return(BinarySerializerManager.BinaryDeSerialize <T>(this._originalRawValue));
 }
コード例 #4
0
 public T GetKey <T>()
 {
     if (this._originalKey != null)
     {
         return(JsonSerializerManager.JsonDeserialize <T>(this._originalKey));
     }
     return(BinarySerializerManager.BinaryDeSerialize <T>(this._originalRawKey));
 }
コード例 #5
0
        static void Main(string[] args)
        {
            var testObj = TestObject;

            var newtonsoft = new JsonSerializerManager(new NewtonsoftSerializer());
            var jil        = new JsonSerializerManager(new JilSerializer());

            // Warm up with a throw away serialization.
            //newtonsoft.SerializeToString(testObj);
            //jil.SerializeToString(testObj);

            // 1 million
            int iterations = 1000000;

            // Experiment
            var jilResults        = RunSerializer(jil, iterations, testObj);
            var newtonsoftResults = RunSerializer(newtonsoft, iterations, testObj);

            // Report results
            long jilTotal        = jilResults.Sum();
            long newtonsoftTotal = newtonsoftResults.Sum();

            Debug.WriteLine("Newton: " + newtonsoftTotal);
            Debug.WriteLine("Jil: " + jilTotal);

            // Log results
            var sb = new StringBuilder();

            foreach (var jilResult in jilResults)
            {
                sb.AppendFormat(string.Format("{0},", jilResult));
            }
            File.WriteAllText("jil.txt", sb.ToString());
            sb.Clear();
            foreach (var newtonsoftResult in newtonsoftResults)
            {
                sb.AppendFormat(string.Format("{0},", newtonsoftResult));
            }
            File.WriteAllText("newtonsoft.txt", sb.ToString());
        }
コード例 #6
0
        public bool IsAuthenticate(string token, out IdentityInfo identityInfo)
        {
            identityInfo = null;
            string cacheString;

            if (cacheManager.RawIsSet(_cache_distribute_token_key, out cacheString, token))
            {
                if (this._identityInfoType == null)
                {
                    this._identityInfoType = CreateIdentityInfo().GetType();
                }
                identityInfo = (IdentityInfo)JsonSerializerManager.JsonDeserialize(cacheString, this._identityInfoType);
                string touchValue;
                if (!cacheManager.RawIsSet(_cache_distribute_token_touch_key, out touchValue, token))
                {
                    cacheManager.RawSet(_cache_distribute_token_key, cacheString, _identity_distribute_expire_minutes, token);
                    cacheManager.Set(_cache_distribute_token_touch_key, 1, _identity_distribute_expire_minutes - 5, token);
                }
                return(true);
            }
            return(false);
        }
コード例 #7
0
 public static string ToJsonString(this object obj)
 {
     return(JsonSerializerManager.JsonSerializer <object>(obj));
 }
コード例 #8
0
 public static T FromJsonString <T>(this string jsonData)
 {
     return(JsonSerializerManager.JsonDeserialize <T>(jsonData));
 }
コード例 #9
0
 public static string FormartJsonString(this string jsonData)
 {
     return(JsonSerializerManager.JsonFormat(jsonData));
 }
コード例 #10
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);
        }
コード例 #11
0
 private T Deserialize <T>(byte[] value)
 {
     return(JsonSerializerManager.BsonDeSerialize <T>(value));
 }
コード例 #12
0
 private byte[] Serialize <T>(T value)
 {
     return(JsonSerializerManager.BsonSerialize(value));
 }