public void Test_1()
        {
            var str = JsonSerializationHelper.SerializeWithType(new MyClass1("Derrick"));
            var obj = JsonSerializationHelper.DeserializeWithType(str) as MyClass1;

            obj.ShouldNotBe(null);
            obj.Name.ShouldBe("Derrick");
        }
예제 #2
0
        public void Test_1()
        {
            var str    = JsonSerializationHelper.SerializeWithType(new MyClass1("John"));
            var result = (MyClass1)JsonSerializationHelper.DeserializeWithType(str);

            result.ShouldNotBeNull();
            result.Name.ShouldBe("John");
        }
        public void Should_Simply_Serialize_And_Deserialize()
        {
            var str    = JsonSerializationHelper.SerializeWithType(new LocalizableString("Foo", "Bar"));
            var result = (LocalizableString)JsonSerializationHelper.DeserializeWithType(str);

            result.ShouldNotBeNull();
            result.Name.ShouldBe("Foo");
            result.SourceName.ShouldBe("Bar");
        }
        public void Test_3()
        {
            Clock.Provider = ClockProviders.Local;

            var myClass = new MyClass2(new DateTime(2016, 04, 13, 08, 58, 10, 526, Clock.Kind));
            var str     = JsonSerializationHelper.SerializeWithType(myClass);
            var result  = (MyClass2)JsonSerializationHelper.DeserializeWithType(str);

            result.Date.ShouldBe(new DateTime(2016, 04, 13, 08, 58, 10, 526, Clock.Kind));
            result.Date.Kind.ShouldBe(Clock.Kind);
        }
        public void Test_2()
        {
            Clock.Provider = ClockProviders.Utc;
            var class2  = JsonSerializationHelper.SerializeWithType(new MyClass2(new DateTime(2017, 4, 11, 11, 11, 11)));
            var dataStr = "Abp.Test.Json.JsonSerializationHelper_Tests+MyClass2, Abp.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null|{\"Date\":\"2017 - 04 - 11T11: 11:11Z\"}";
            var result  = (MyClass2)JsonSerializationHelper.DeserializeWithType(dataStr);

            result.ShouldNotBe(null);
            result.Date.ShouldBe(new DateTime(2017, 4, 11, 11, 11, 11, Clock.Kind));
            result.Date.Kind.ShouldBe(Clock.Kind);
        }
        public override void Set(string key, object value, TimeSpan?slidingExpireTime = null, TimeSpan?absoluteExpireTime = null)
        {
            if (value == null)
            {
                throw new AbpException("Can not insert null values to the cache!");
            }

            //TODO: This is a workaround for serialization problems of entities.
            //TODO: Normally, entities should not be stored in the cache, but currently Abp.Zero packages does it. It will be fixed in the future.
            var type = value.GetType();

            if (EntityHelper.IsEntity(type) && type.Assembly.FullName.Contains("EntityFrameworkDynamicProxies"))
            {
                type = type.BaseType;
            }

            _database.StringSet(
                GetLocalizedKey(key),
                JsonSerializationHelper.SerializeWithType(value, type),
                absoluteExpireTime ?? slidingExpireTime ?? DefaultAbsoluteExpireTime ?? DefaultSlidingExpireTime
                );
        }
 /// <summary>
 ///     Produce a string representation of the supplied object.
 /// </summary>
 /// <param name="value">Instance to serialize.</param>
 /// <returns>
 ///     Returns a string representing the object instance that can be placed into the Redis cache.
 /// </returns>
 /// <seealso cref="Deserialize" />
 public string Serialize(object value)
 {
     return(JsonSerializationHelper.SerializeWithType(value));
 }
 /// <summary>
 ///     Produce a string representation of the supplied object.
 /// </summary>
 /// <param name="value">Instance to serialize.</param>
 /// <param name="type">Type of the object.</param>
 /// <returns>Returns a string representing the object instance that can be placed into the Redis cache.</returns>
 /// <seealso cref="IRedisCacheSerializer.Deserialize" />
 public virtual string Serialize(object value, Type type)
 {
     return(JsonSerializationHelper.SerializeWithType(value, type));
 }
예제 #9
0
        public ContentResult KingeditorUploadImage()
        {
            try
            {
                //Check input
                if (Request.Files.Count <= 0 || Request.Files[0] == null)
                {
                    //throw new UserFriendlyException("没有找到上传的图片");
                    //return Json(new AjaxResponse(new { error = 1, message = "没有找到上传的图片" }));
                    var result = new KingEditorUploadImageResult {
                        error = 1, message = "没有找到上传的图片"
                    };
                    return(Content(JsonSerializationHelper.SerializeWithType(result), "text/html"));
                }

                var file = Request.Files[0];

                if (file.ContentLength > 5242880 * 10) //1MB.
                {
                    //throw new UserFriendlyException("图片大小超出限制(不能超过10M)");
                    //return Json(new AjaxResponse(new { error = 1, message = "图片大小超出限制(不能超过10M)" }));
                    var result = new KingEditorUploadImageResult {
                        error = 1, message = "图片大小超出限制(不能超过10M)"
                    };
                    return(Content(JsonSerializationHelper.SerializeWithType(result), "text/html"));
                }

                //Check file type & format
                var fileImage = Image.FromStream(file.InputStream);
                if (!fileImage.RawFormat.Equals(ImageFormat.Jpeg) &&
                    !fileImage.RawFormat.Equals(ImageFormat.Png) &&
                    !fileImage.RawFormat.Equals(ImageFormat.Gif) &&
                    !fileImage.RawFormat.Equals(ImageFormat.Bmp))
                {
                    //throw new UserFriendlyException("不允许的图片格式(支持格式 Jpeg,Png,Gif,Bmp)");
                    //return Json(new AjaxResponse(new { error = 1, message = "不允许的图片格式(支持格式 Jpeg,Png,Gif,Bmp)" }));
                    var result = new KingEditorUploadImageResult {
                        error = 1, message = "不允许的图片格式(支持格式 Jpeg,Png,Gif,Bmp)"
                    };
                    return(Content(JsonSerializationHelper.SerializeWithType(result), "text/html"));
                }

                //Delete old temp profile pictures
                //AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.UploadImageFolder, "userProfileImage_" + AbpSession.GetUserId());

                //Save new picture
                var fileInfo     = new FileInfo(file.FileName);
                var tempFileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + fileInfo.Extension;
                var tempFilePath = Path.Combine(_appFolders.UploadImageFolder, tempFileName);
                file.SaveAs(tempFilePath);

                using (var bmpImage = new Bitmap(tempFilePath))
                {
                    var result = new KingEditorUploadImageResult {
                        url = $"/Upload/Images/{tempFileName}?width=640"
                    };
                    return(Content(JsonSerializationHelper.SerializeWithType(result), "text/html"));
                }
            }
            catch (UserFriendlyException ex)
            {
                //return Json(new AjaxResponse(new ErrorInfo(ex.Message)));
                var result = new KingEditorUploadImageResult {
                    error = 1, message = ex.Message
                };
                return(Content(JsonSerializationHelper.SerializeWithType(result), "text/html"));
            }
        }