コード例 #1
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestDictionaryType()
        {
            var target = new Hashtable(2);

            target["A"] = "A";
            target["B"] = new TwoLevel()
            {
                Name = 1122, U = "First"
            };
            //GlobalJsonCompileSetting.Config(new JsonCompileSetting() { UseNumberInEnum = true });
            Console.WriteLine("target:" + target.ToString());
            var text = EasyJsonSerializer.Serialize(target);

            Console.WriteLine("target:" + text);
            target = EasyJsonSerializer.Deserialize <Hashtable>(text);
            Console.WriteLine("target:" + target.ToString());
            Console.WriteLine("-----------------------");

            target      = new Hashtable(2);
            target["A"] = "A";
            target["B"] = new TwoLevel()
            {
                Name = 1122, U = "First"
            };
            Console.WriteLine("target:" + target.ToString());
            text = EasyJsonSerializer.Serialize(target);
            Console.WriteLine("target:" + text);
            var target2 = EasyJsonSerializer.Deserialize <System.Collections.Generic.Dictionary <string, string> >(text);

            Console.WriteLine("target:" + target.ToString());
            Console.WriteLine("-----------------------");
        }
コード例 #2
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestWriteType()
        {
            var type = typeof(int);
            var text = EasyJsonSerializer.Serialize <Type>(type);

            type = EasyJsonSerializer.Deserialize <Type>(text);
        }
コード例 #3
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestIntPrimitiveType()
        {
            var reader = ThunderReader.Load("{\n\n}");
            var abc    = EasyJsonSerializer.Deserialize <AccessTokenModel>(reader);
            var test   = EasyJsonSerializer.Serialize(new AccessTokenModel());
            var target = 0;

            Console.WriteLine("target:" + target.ToString());
            var text = EasyJsonSerializer.Serialize(target);

            target = EasyJsonSerializer.Deserialize <int>(text);
            var target2 = EasyJsonSerializer.Deserialize <int[]>("  ");

            Console.WriteLine("target:" + target.ToString());
            Console.WriteLine("-----------------------");

            target = 11;
            Console.WriteLine("target:" + target.ToString());
            text   = EasyJsonSerializer.Serialize(target);
            target = EasyJsonSerializer.Deserialize <int>(text);
            Console.WriteLine("target:" + target.ToString());
            Console.WriteLine("-----------------------");

            target = 192;
            Console.WriteLine("target:" + target.ToString());
            text   = EasyJsonSerializer.Serialize(target);
            target = EasyJsonSerializer.Deserialize <int>(text);
            Console.WriteLine("target:" + target.ToString());
            Console.WriteLine("-----------------------");
        }
コード例 #4
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestDemo6()
        {
            //GlobalJsonCompileSetting.Config(new JsonCompileSetting() { WriteNullStringWhenObjectIsNull = false });

            var target = new TestDemo6()
            {
                Name = "\\\\LTET\"0",
                //Name = "\r",
                //Demo3 = new Serialization.TestDemo3()
                //{
                //    Name = "E",
                //    UId = 1265,
                //    ULong = 56465
                //}
            };

            var text = EasyJsonSerializer.Serialize(target);
            var tet  = EasyJsonSerializer.Serialize(text);

            Console.WriteLine("target:" + EasyJsonSerializer.Serialize(text));
            Console.WriteLine("target:" + Newtonsoft.Json.JsonConvert.SerializeObject(text));
            var t2 = Newtonsoft.Json.JsonConvert.DeserializeObject <string>(EasyJsonSerializer.Serialize(text));
            //var t3 = Newtonsoft.Json.JsonConvert.DeserializeObject<DateTime>("2015-06-23");
            var target2 = EasyJsonSerializer.Deserialize <TestDemo6>(t2);
            var targe3  = Newtonsoft.Json.JsonConvert.DeserializeObject <TestDemo6>(t2);
        }
コード例 #5
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestArrayEnumPrimitiveType()
        {
            //GlobalJsonCompileSetting.Config(new JsonCompileSetting() { UseNumberInEnum = true });
            var target = new[] { ABC.A, ABC.A, ABC.C, ABC.A | ABC.C };

            Console.WriteLine("target:");
            foreach (var i in target)
            {
                Console.WriteLine(i.ToString() + ",");
            }
            var text = EasyJsonSerializer.Serialize(target);

            target = EasyJsonSerializer.Deserialize <ABC[]>(text);
            Console.WriteLine("target:");
            foreach (var i in target)
            {
                Console.WriteLine(i.ToString() + ",");
            }
            Console.WriteLine("-----------------------");

            Console.WriteLine("target:");
            foreach (var i in target)
            {
                Console.WriteLine(i.ToString() + ",");
            }
            text = EasyJsonSerializer.Serialize(target);
            var target2 = EasyJsonSerializer.Deserialize <ICollection <ABC> >(text);

            Console.WriteLine("target:");
            foreach (var i in target2)
            {
                Console.WriteLine(i.ToString() + ",");
            }
            Console.WriteLine("-----------------------");
        }
コード例 #6
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
 public void TestSerializerSpeedTest()
 {
     var timeSpan = TimeSpan.FromHours(2);
     var text     = EasyJsonSerializer.Serialize(timeSpan);
     var spsn     = EasyJsonSerializer.Deserialize <TimeSpan>(text, new JsonDeserializeSetting()
     {
         DateTimeFormat = DateTimeFormat.ChineseStyle
     });
 }
コード例 #7
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestMyString()
        {
            var obj = new
            {
                A = new { B = 1, C = "EFG" }
            };

            var text = EasyJsonSerializer.Serialize(obj);
            var ta   = EasyJsonSerializer.Deserialize <Dictionary <string, string> >(text);
        }
コード例 #8
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestTwoLevel()
        {
            var two = new TwoLevel()
            {
                U = "36}",
            };

            var text = EasyJsonSerializer.Serialize(two);
            var twoc = EasyJsonSerializer.Deserialize <TwoLevelCopy>(text);
        }
コード例 #9
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestTET()
        {
            var command = new MyStringCommand(NewId.GenerateString())
            {
                Version = 2
            };
            var text = EasyJsonSerializer.Serialize(command);

            var cmd1 = EasyJsonSerializer.Deserialize <MyStringCommand>(text);
            var cmd2 = Newtonsoft.Json.JsonConvert.DeserializeObject <MyStringCommand>(text);
        }
コード例 #10
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestException()
        {
            var ex = new Exception("etet", null);
            //var text = Newtonsoft.Json.JsonConvert.SerializeObject(ex);// EasyJsonSerializer.Default.Serialize<Exception>(ex);
            //Never.Serialization.Json.GlobalJsonCompileSetting.Config(new JsonCompileSetting() { WriteNullStringWhenObjectIsNull = true, });

            var text = EasyJsonSerializer.Serialize <Exception>(ex);
            //Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(ex));
            //Console.WriteLine(EasyJsonSerializer.Default.Serialize<Exception>(ex));
            var ex2 = EasyJsonSerializer.Deserialize <Exception>(text);
            // ex2 = Newtonsoft.Json.JsonConvert.DeserializeObject<Exception>(text);// EasyJsonSerializer.Default.Deserialize<Exception>(text);
        }
コード例 #11
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestDemo()
        {
            var demo = new TeseDemo()
            {
                Name  = "Lxl",
                UId   = 365,
                ULong = 54654
            };

            var text  = EasyJsonSerializer.Serialize(demo);
            var list  = ThunderReader.Load(text);
            var demo2 = EasyJsonSerializer.Deserialize <TeseDemo>(text);
        }
コード例 #12
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestArrayArrayIntType()
        {
            var target = new TwoLevel[][]
            {
                new TwoLevel[]
                {
                    new TwoLevel
                    {
                        Name = 234,
                        U    = "E",
                    },
                    new TwoLevel
                    {
                        Name = 54687,
                        U    = "EET"
                    }
                }
            };

            Console.WriteLine("target:");
            foreach (var i in target)
            {
                Console.WriteLine(i.ToString() + ",");
            }
            var text = EasyJsonSerializer.Serialize(target);

            target = EasyJsonSerializer.Deserialize <TwoLevel[][]>(text);
            Console.WriteLine("target:");
            foreach (var i in target)
            {
                Console.WriteLine(i.ToString() + ",");
            }
            Console.WriteLine("-----------------------");

            Console.WriteLine("target:");
            foreach (var i in target)
            {
                Console.WriteLine(i.ToString() + ",");
            }
            text = EasyJsonSerializer.Serialize(target);
            var target2 = EasyJsonSerializer.Deserialize <ICollection <TwoLevel[]> >(text);

            Console.WriteLine("target:");
            foreach (var i in target2)
            {
                Console.WriteLine(i.ToString() + ",");
            }
            Console.WriteLine("-----------------------");
        }
コード例 #13
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestMyDict()
        {
            var dict = new MyDict();

            dict["A"] = "A";
            dict["B"] = "B";

            var a = new
            {
                DICT = dict,
            };
            var json = Newtonsoft.Json.JsonConvert.SerializeObject(a);

            json = EasyJsonSerializer.Serialize(a);
            json = Jil.JSON.Serialize(a);
        }
コード例 #14
0
        public void Test0()
        {
            int?[][] vs = new int?[2][];
            vs[0]    = new int?[2];
            vs[0][0] = 0;
            vs[0][1] = 1;
            vs[1]    = new int?[2];
            vs[1][0] = 1;
            vs[1][1] = 1;

            var ser = EasyJsonSerializer.Serialize(vs);

            Console.WriteLine(ser);

            vs = EasyJsonSerializer.Deserialize <int?[][]>(ser);
        }
コード例 #15
0
        public void TestTimeSpan()
        {
            var timeSpan = TimeSpan.FromHours(2);
            var text     = " " + EasyJsonSerializer.Serialize(timeSpan);

            EasyJsonSerializer.Deserialize <TimeSpan>(text, new JsonDeserializeSetting()
            {
                DateTimeFormat = DateTimeFormat.ChineseStyle
            });
            Newtonsoft.Json.JsonConvert.DeserializeObject <TimeSpan>(text);
            Jil.JSON.Deserialize <TimeSpan>(text);

            int times = 10000000;

            Console.WriteLine("begin........");

            using (var t = new Utils.MethodTickCount((x) => { Console.WriteLine(x); }))
            {
                for (var i = 0; i < times; i++)
                {
                    Newtonsoft.Json.JsonConvert.DeserializeObject <TimeSpan>(text);
                }
            }

            using (var t = new Utils.MethodTickCount((x) => { Console.WriteLine(x); }))
            {
                var setting = new JsonDeserializeSetting()
                {
                    DateTimeFormat = DateTimeFormat.ChineseStyle
                };
                for (var i = 0; i < times; i++)
                {
                    EasyJsonSerializer.Deserialize <TimeSpan>(text, setting);
                }
            }

            using (var t = new Utils.MethodTickCount((x) => { Console.WriteLine(x); }))
            {
                for (var i = 0; i < times; i++)
                {
                    Jil.JSON.Deserialize <TimeSpan>(text);
                }
            }

            Console.WriteLine("..........end");
            Console.ReadLine();
        }
コード例 #16
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestGenericDictionaryType()
        {
            var dict = new Dictionary <int, TwoLevel>(2);

            dict[1] = new TwoLevel()
            {
                Name = 1122, U = "First"
            };
            dict[2] = new TwoLevel()
            {
                Name = 3344, U = "Secode"
            };
            var text = EasyJsonSerializer.Serialize(dict);

            Console.WriteLine(text);
            var target2 = EasyJsonSerializer.Deserialize <System.Collections.Generic.Dictionary <int, TwoLevel> >(text);
        }
コード例 #17
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestGuidPrimitiveType()
        {
            var target = Guid.NewGuid();

            Console.WriteLine("target:" + target.ToString());
            var text = EasyJsonSerializer.Serialize(target);

            target = EasyJsonSerializer.Deserialize <Guid>(text);
            Console.WriteLine("target:" + target.ToString());
            Console.WriteLine("-----------------------");

            target = Guid.Empty;
            Console.WriteLine("target:" + target.ToString());
            text   = EasyJsonSerializer.Serialize(target);
            target = EasyJsonSerializer.Deserialize <Guid>(text);
            Console.WriteLine("target:" + target.ToString());
            Console.WriteLine("-----------------------");
        }
コード例 #18
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestMyList()
        {
            //var list = new MyList();
            //list.Add(1);
            //list.Add(2);

            //var a = new
            //{
            //    List = list,
            //};
            //var json = Newtonsoft.Json.JsonConvert.SerializeObject(a);
            //json = EasyJsonSerializer.Default.Serialize(a);
            //json = Jil.JSON.Serialize(a);

            Nullable <int> a = 2;
            //GlobalJsonCompileSetting.Config(new JsonCompileSetting() { WriteQuotationMarkWhenObjectIsNumber = true });

            var txt = EasyJsonSerializer.Serialize(a);
        }
コード例 #19
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestDemo2()
        {
            var demo = new TestDemo2()
            {
                Name  = "Lxl",
                UId   = 365,
                C     = '\ufff2',
                ULong = 54654,
                Demo3 = new TestDemo3()
                {
                    Name  = "Lxl33",
                    UId   = 3665,
                    ULong = 154654,
                }
            };

            var text  = EasyJsonSerializer.Serialize(demo);
            var list  = ThunderReader.Load(text);
            var demo2 = EasyJsonSerializer.Deserialize <TestDemo2>(text);
        }
コード例 #20
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestDemo999()
        {
            var a = new TeseDemo999()
            {
                Array = new TwoLevel[][]
                {
                    new TwoLevel[]
                    {
                        new TwoLevel
                        {
                            Name = 234
                        },
                        new TwoLevel
                        {
                            Name = 234
                        }
                    },
                    null,
                    new TwoLevel[]
                    {
                        new TwoLevel
                        {
                            Name = 234
                        },
                        new TwoLevel
                        {
                            Name = 234
                        }
                    },
                },
            };

            var text = EasyJsonSerializer.Serialize(a);

            Console.WriteLine(text);
            a    = EasyJsonSerializer.Deserialize <TeseDemo999>(text);
            text = EasyJsonSerializer.Serialize(a);
            Console.WriteLine(text);
        }
コード例 #21
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestDemo5()
        {
            var target = new TestDemo5()
            {
                Table = new Hashtable(),
                Name  = "TET",
            };

            target.Table["A"] = "A";
            target.Table["B"] = new TwoLevel()
            {
                Name = 1122, U = "First"
            };
            //GlobalJsonCompileSetting.Config(new JsonCompileSetting() { UseNumberInEnum = true });
            Console.WriteLine("target:" + target.ToString());
            var text = EasyJsonSerializer.Serialize(target);

            Console.WriteLine("target:" + text);
            var target2 = EasyJsonSerializer.Deserialize <TestDemo5>(text);

            Console.WriteLine("target:" + target.ToString());
        }
コード例 #22
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestDemo4()
        {
            var a = new TeseDemo4
            {
                Object = new TwoLevel
                {
                    Name  = 234,
                    U     = "UU",
                    Three = new ThreeLevel()
                    {
                        ABC = "LXL"
                    }
                },
            };

            var text = EasyJsonSerializer.Serialize(Anonymous.NewApiResult(ApiStatus.Success, (TwoLevel)null));

            Console.WriteLine(text);
            var ta = EasyJsonSerializer.Deserialize <ApiResult <TwoLevel> >(text);

            return;
        }
コード例 #23
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestMachineClass()
        {
            /*json序列化配置*/
            //Never.Serialization.Json.GlobalJsonCompileSetting.Config(new Never.Serialization.Json.JsonCompileSetting()
            //{
            //    UseNumberInEnum = false,
            //    WriteNullStringWhenObjectIsNull = true,GlobalJsonCompileSetting
            //    WriteQuotationMarkWhenObjectIsNumber = false,
            //    WriteQuotationMarkWhenObjectIsBoolean = false,
            //    DateTimeFormat = Never.Serialization.Json.DateTimeFormat.ChineseStyle,
            //});

            var target = new MachineClass()
            {
                Machine = Machine.mobile
            };
            var text = EasyJsonSerializer.Serialize(target);

            Console.WriteLine(text);
            //var source = EasyJsonSerializer.Default.Deserialize<MachineClass>(text);

            //text = "{\"Machine\":\"3\"}";
        }
コード例 #24
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestWriteTime()
        {
            var time = DateTime.Now;
            var text = EasyJsonSerializer.Serialize(time, new JsonSerializeSetting()
            {
                DateTimeFormat = DateTimeFormat.MicrosoftStyle
            });
            var time2 = EasyJsonSerializer.Deserialize <DateTime>(text);

            text = EasyJsonSerializer.Serialize(time, new JsonSerializeSetting()
            {
                DateTimeFormat = DateTimeFormat.ChineseStyle
            });
            var time3 = EasyJsonSerializer.Deserialize <DateTime>(text, new JsonDeserializeSetting()
            {
                DateTimeFormat = DateTimeFormat.ChineseStyle
            });

            text = EasyJsonSerializer.Serialize(time, new JsonSerializeSetting()
            {
                DateTimeFormat = DateTimeFormat.ISO8601Style
            });
            var time4 = EasyJsonSerializer.Deserialize <DateTime>(text, new JsonDeserializeSetting()
            {
                DateTimeFormat = DateTimeFormat.ISO8601Style
            });

            text = EasyJsonSerializer.Serialize(time, new JsonSerializeSetting()
            {
                DateTimeFormat = DateTimeFormat.RFC1123Style
            });
            var time5 = EasyJsonSerializer.Deserialize <DateTime>(text, new JsonDeserializeSetting()
            {
                DateTimeFormat = DateTimeFormat.RFC1123Style
            });
        }
コード例 #25
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestEnumType()
        {
            var tet = EasyJsonSerializer.Deserialize <EnumClass>(EasyJsonSerializer.Serialize(new EnumClass()
            {
            }));
            var target = ABC.A | ABC.B;

            //GlobalJsonCompileSetting.Config(new JsonCompileSetting() { UseNumberInEnum = true });
            Console.WriteLine("target:" + target.ToString());
            var text = EasyJsonSerializer.Serialize(target);

            Console.WriteLine("target:" + text);
            target = EasyJsonSerializer.Deserialize <ABC>(text);
            Console.WriteLine("target:" + target.ToString());
            Console.WriteLine("-----------------------");

            target = ABC.C;
            Console.WriteLine("target:" + target.ToString());
            text = EasyJsonSerializer.Serialize(target);
            Console.WriteLine("target:" + text);
            target = EasyJsonSerializer.Deserialize <ABC>("null");
            Console.WriteLine("target:" + target.ToString());
            Console.WriteLine("-----------------------");
        }
コード例 #26
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestWriteObject()
        {
            var a = new TeseDemo1
            {
                C      = '\u0022',
                Empty  = " ",
                Id     = int.MinValue + 1,
                Byte   = 233,
                Short  = -6530,
                Long   = -9676546546L,
                UShort = 6530,
                ULong  = 9676546546L,
                UId    = 6546545,
                Name   = "lxl",
                ABC    = ABC.B,
                DDD    = "}",
                DDD2   = "ddd",
                M      = "dg",
                DDD3   = "ddd",
                DDD4   = "ddd",
                DDD5   = "ddd2",
                DDD6   = "ddd2",
                Guid   = Guid.NewGuid(),
                Amount = -79228162514264337593543950335m,
                Time   = DateTime.Now,
                Object = new TwoLevel
                {
                    Name = 234
                },
                Array = new TwoLevel[][]
                {
                    new TwoLevel[]
                    {
                        new TwoLevel
                        {
                            Name = 234
                        },
                        new TwoLevel
                        {
                            Name = 234
                        }
                    },
                    null,
                    new TwoLevel[]
                    {
                        new TwoLevel
                        {
                            Name = 234
                        },
                        new TwoLevel
                        {
                            Name = 234
                        }
                    },
                },
                Enumables = new[] { new object[] { new { Id = 56456 }, new { EF = "dgd" } } },
                EnumArray = new ABC[]
                {
                    ABC.A,
                    ABC.B,
                    ABC.C
                },
            };

            var text   = EasyJsonSerializer.Serialize(a);
            var aa     = EasyJsonSerializer.Deserialize <TeseDemo1>(text);
            var reader = ThunderReader.Load(text);
            var @obj   = EasyJsonSerializer.Deserialize <TwoLevel[][]>(reader.Parse(reader.Read("Array")));

            return;
        }
コード例 #27
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestArrayIntPrimitiveType()
        {
            var target = new[] { 1M, 2M, 3M };

            Console.WriteLine("target:");
            foreach (var i in target)
            {
                Console.WriteLine(i.ToString() + ",");
            }
            var text = EasyJsonSerializer.Serialize(target);

            target = EasyJsonSerializer.Deserialize <decimal[]>(text);
            Console.WriteLine("target:");
            foreach (var i in target)
            {
                Console.WriteLine(i.ToString() + ",");
            }
            Console.WriteLine("-----------------------");

            Console.WriteLine("target:");
            foreach (var i in target)
            {
                Console.WriteLine(i.ToString() + ",");
            }
            text = EasyJsonSerializer.Serialize(target);
            var target2 = EasyJsonSerializer.Deserialize <List <decimal> >(text);

            Console.WriteLine("target:");
            foreach (var i in target2)
            {
                Console.WriteLine(i.ToString() + ",");
            }
            Console.WriteLine("-----------------------");

            Console.WriteLine("target:");
            foreach (var i in target)
            {
                Console.WriteLine(i.ToString() + ",");
            }

            text = EasyJsonSerializer.Serialize(target);
            var target3 = EasyJsonSerializer.Deserialize <ICollection <decimal> >(text);

            Console.WriteLine("target:");
            foreach (var i in target3)
            {
                Console.WriteLine(i.ToString() + ",");
            }
            Console.WriteLine("-----------------------");

            Console.WriteLine("target:");
            foreach (var i in target)
            {
                Console.WriteLine(i.ToString() + ",");
            }

            text = EasyJsonSerializer.Serialize(target);
            var target4 = EasyJsonSerializer.Deserialize <IList <decimal> >(text);

            Console.WriteLine("target:");
            foreach (var i in target4)
            {
                Console.WriteLine(i.ToString() + ",");
            }
            Console.WriteLine("-----------------------");

            Console.WriteLine("target:");
            foreach (var i in target)
            {
                Console.WriteLine(i.ToString() + ",");
            }

            text = EasyJsonSerializer.Serialize(target);
            var target5 = EasyJsonSerializer.Deserialize <IEnumerable <decimal> >(text);

            Console.WriteLine("target:");
            foreach (var i in target5)
            {
                Console.WriteLine(i.ToString() + ",");
            }
            Console.WriteLine("-----------------------");
        }
コード例 #28
0
            public Task InvokeAsync(HttpContext context, RequestDelegate next)
            {
                if (!context.Request.Path.HasValue)
                {
                    return(next(context));
                }

                if (!context.Request.Method.Equals("post", System.StringComparison.OrdinalIgnoreCase))
                {
                    return(next(context));
                }

                var segments = context.Request.Path.Value.ToLower().Split('/', System.StringSplitOptions.RemoveEmptyEntries);

                if (segments != null && segments.Length == 3 && segments[0] == "api")
                {
                    //拿api地址
                    var host = new HostString(this.proxyRouteDispatcher.GetCurrentUrlHost((context.Request.ContentLength.HasValue ? context.Request.ContentLength.Value : segments[1].GetHashCode()).ToString()));
                    var url  = UriHelper.BuildAbsolute("http", host, context.Request.PathBase, context.Request.Path, context.Request.QueryString, default(FragmentString));

                    var token = this.authenticationService.GetToken(context);
                    IContentEncryptor enctryptor = new TripleDESContentEncryptor(token.CryptToken);
                    var header = this.ConvertHeaders(context, token);
                    //using (var body = this.ConvertContentFromBodyString(context, enctryptor))
                    using (var body = this.ConvertContentFromBodyByteArray(context, enctryptor))
                    {
                        //注册与登陆,由于在这里做identity servie
                        switch (segments[2])
                        {
                        //注册
                        case "Register":
                        //登陆
                        case "Login":
                        {
                            var loginTask    = new HttpRequestDownloader().PostString(new Uri(url), body, header, "application/json", 0);
                            var loginContent = loginTask;
                            var target       = EasyJsonSerializer.Deserialize <Never.Web.WebApi.Controllers.BasicController.ResponseResult <UserIdToken> >(loginContent);
                            if (target != null && target.Code == "0000" && target.Data.UserId > 0)
                            {
                                var token2    = this.authenticationService.SignIn(context, target.Data.UserId).GetAwaiter().GetResult();
                                var appresult = new Never.Web.WebApi.Controllers.BasicController.ResponseResult <AppToken>(target.Code, new AppToken {
                                        @accesstoken = token2.AccessToken
                                    }, target.Message);
                                return(this.ConvertContentToBody(context, EasyJsonSerializer.Serialize(appresult), enctryptor));
                            }

                            var appresult2 = new Never.Web.WebApi.Controllers.BasicController.ResponseResult <AppToken>(target.Code, new AppToken {
                                    @accesstoken = string.Empty
                                }, target.Message);
                            return(this.ConvertContentToBody(context, EasyJsonSerializer.Serialize(appresult2), enctryptor));
                        }

                        //退出
                        case "Logout":
                        {
                            new HttpRequestDownloader().PostString(new Uri(url), body, header, "application/json", 0);
                            this.authenticationService.SignOut(context, token);
                            var appresult = new Never.Web.WebApi.Controllers.BasicController.ResponseResult <AppToken>("0000", new AppToken {
                                    @accesstoken = string.Empty
                                }, string.Empty);
                            return(this.ConvertContentToBody(context, EasyJsonSerializer.Serialize(appresult), enctryptor));
                        }
                        }

                        if (header.ContainsKey("userid"))
                        {
                            url = string.Concat(url, "?userid=", header["userid"]);
                        }

                        var task = new HttpRequestDownloader().Post(new Uri(url), body, header, "application/json", 0);
                        return(this.ConvertContentToBody(context, task, enctryptor));
                        //    var logger = Never.IoC.ContainerContext.Current.ServiceLocator.Resolve<ILoggerBuilder>().Build(typeof(Startup));
                        //    var action = new Action<string>((x) =>
                        //    {
                        //        logger.Warn(url + ":" + x);
                        //    });

                        //    using (var method = new Never.Utils.MethodTickCount(action))
                        //    {
                        //        var task = new HttpRequestDownloader().PostString(new Uri(url), body, header, "application/json");
                        //        var content = task;// task.GetAwaiter().GetResult();
                        //        return context.Response.WriteAsync(this.ConvertResult(content, token));
                        //    }
                    }
                }

                return(next(context));
            }
コード例 #29
0
ファイル: SerializerTest.cs プロジェクト: stonezhu870/never
        public void TestArrayObjectType()
        {
            var target = new TwoLevel[]
            {
                new TwoLevel
                {
                    Name  = 234,
                    Three = new ThreeLevel()
                    {
                    }
                },
                null,
                new TwoLevel
                {
                    Name = 5465
                }
            };

            Console.WriteLine("target:");
            foreach (var i in target)
            {
                if (i == null)
                {
                    continue;
                }

                Console.WriteLine(i.ToString() + ",");
            }
            var text = EasyJsonSerializer.Serialize(target);

            target = EasyJsonSerializer.Deserialize <TwoLevel[]>(text);
            Console.WriteLine("target:");
            foreach (var i in target)
            {
                if (i == null)
                {
                    continue;
                }

                Console.WriteLine(i.ToString() + ",");
            }
            Console.WriteLine("-----------------------");

            Console.WriteLine("target:");
            foreach (var i in target)
            {
                if (i == null)
                {
                    continue;
                }

                Console.WriteLine(i.ToString() + ",");
            }
            text = EasyJsonSerializer.Serialize(target);
            var target2 = EasyJsonSerializer.Deserialize <List <TwoLevel> >(text);

            Console.WriteLine("target:");
            foreach (var i in target2)
            {
                if (i == null)
                {
                    continue;
                }

                Console.WriteLine(i.ToString() + ",");
            }
            Console.WriteLine("-----------------------");
        }