public void Get() { RuntimeServPools.TryAddSingleton <IJsonHelper, DefaultJsonHelper>(); var value = "http://www.baidu.com/asasad/dsdfgf/ssasa?x=1".AsRequestable() .AppendQueryString(new { wd = "sql", rsv_spt = 1, rsv_iqid = "0x822dd2a900206e39", issp = 1, rsv_bp = 1, rsv_idx = 2, ie = "utf8" }) .JsonCast(new Dictionary <string, string>()) .JsonCatch((s, e) => { return(new Dictionary <string, string>()); }) .WebCatch(e => { return(new Dictionary <string, string>()); }) .Get(); }
public void GetJson() { RuntimeServPools.TryAddSingleton <IJsonHelper, DefaultJsonHelper>(); var entry = new { data = new { type = string.Empty, token = string.Empty }, status = true, code = 0, message = string.Empty, timestamp = DateTime.Now }; var token = "http://localhost:56324/login".AsRequestable() .AppendQueryString("?account=ljl&password=liujialin&debug=true") .JsonCast(entry, NamingType.CamelCase) .WebCatch(e => entry) .DataVerify(x => x == entry) .ResendCount(1) .Get(); //var values = "http://localhost:56324/api/values".AsRequestable() // .AppendHeader("Authorization", token.data.type + " " + token.data.token) // .ByJson<List<string>>() // .Get(); }
public void Initialize() { #if NET461 var adapter = new CodeArts.Db.SqlServerAdapter(); #else var adapter = new CodeArts.Db.EntityFramework.SqlServerLinqAdapter(); #endif LinqConnectionManager.RegisterAdapter(adapter); RuntimeServPools.TryAddSingleton <IMapper, CastingMapper>(); if (isCompleted) { return; } var connectionString = string.Format(@"Server={0};Database={1};User ID={2};Password={3}", SqlServerConsts.Domain, SqlServerConsts.Database, SqlServerConsts.User, SqlServerConsts.Password); using (var connection = TransactionConnections.GetConnection(connectionString, adapter) ?? DispatchConnections.Instance.GetConnection(connectionString, adapter)) { try { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandType = System.Data.CommandType.Text; var files = Directory.GetFiles("../../../Sql", "*.sql"); foreach (var file in files.Where(x => x.Contains("mssql"))) { string text = File.ReadAllText(file, Encoding.UTF8); command.CommandText = text; command.ExecuteNonQuery(); } } isCompleted = true; } finally { connection.Close(); } } }
public void CopyTo() { var copyTo = new CopyToExpression(); //? 为类型“CopyTest”指定代理。 copyTo.Use((profile, type) => { if (type == typeof(CopyToTest)) { return(source => { var copy = (CopyTest)source; return new CopyTest { Id = copy.Id, Name = copy.Name }; }); } return(profile.Create <CopyTest>(type)); }); RuntimeServPools.TryAddSingleton <ICopyToExpression>(() => copyTo); var value = new CopyToTest { Id = 1000, Name = "test", Date = DateTime.Now }; var value2 = new CopyTo2Test { Id = 1000, Name = "test", Date = DateTime.Now }; for (int i = 0; i < 100000; i++) { var copy1 = Mapper.Copy(value); value.Name = "test1"; var copy2 = Mapper.Copy <CopyTest>(value); var copy3 = Mapper.Copy <CopyTest>(value2); value.Name = "test5"; } }
public async Task GetJsonAsync() { RuntimeServPools.TryAddSingleton <IJsonHelper, DefaultJsonHelper>(); var entry = new { data = new { type = string.Empty, token = string.Empty }, status = true, code = 0, message = string.Empty, timestamp = DateTime.Now }; var token = await "http://localhost:56324/login".AsRequestable() .AppendQueryString("?account=ljl&password=liujialin&debug=true") .TryThen((requestable, e) => { requestable.AppendQueryString("debug=false"); //对请求的参数或Headers进行调整。如:令牌认证。 requestable.AppendHeader("Authorization", "{token}"); }) .If(e => true) // 当认真过期时,才会执行上一个TryThen。 .And(e => true) .ThenAsync((requestable, e) => { return(Task.Delay(1000)); }) .If(e => true) .TryIf(e => e.Status == WebExceptionStatus.Timeout) .Or(e => true) .RetryCount(2) // 设置重试次数 .RetryInterval(500) //重试间隔时长。 .WebCatch(e => { }) .WebCatch(e => { }) .Finally(() => { }) .JsonCast(entry, NamingType.CamelCase) .WebCatch(e => entry) .Finally(() => { }) .GetAsync(); //var values = "http://localhost:56324/api/values".AsRequestable() // .AppendHeader("Authorization", token.data.type + " " + token.data.token) // .ByJson<List<string>>() // .Get(); }
//[TestMethod] public async Task PostForm() { RuntimeServPools.TryAddSingleton <IJsonHelper, DefaultJsonHelper>(); var value = await "http://localhost:49683/weatherforecast".AsRequestable() .Json(new { Date = DateTime.Now, TemperatureC = 1, Summary = 50 }) .JsonCast <ServResult>() .DataVerify(r => r.Success) .ResendCount(2) .ResendInterval((e, i) => i * i * 500) .PostAsync(); }
//[TestMethod] public void PostJson() { RuntimeServPools.TryAddSingleton <IJsonHelper, DefaultJsonHelper>(); //var token = "http://localhost:56324/login".AsRequestable() // .ToQueryString("?account=ljl&password=liujialin&debug=true") // .Json(new // { // data = new { type = string.Empty, token = string.Empty }, // status = true, // code = 0, // message = string.Empty, // timestamp = DateTime.Now // }, NamingType.CamelCase) // .Catch(e => // { // return new // { // data = new { type = string.Empty, token = string.Empty }, // status = true, // code = 0, // message = string.Empty, // timestamp = DateTime.Now // }; // }) // .Get(); //var json = new //{ // page = 1, // size = 10, // shopId = 1000000000000, // lsh = string.Empty, // gmfmc = "优易票", // kpr = "何远利", // startTime = DateTime.Now //}; //var value = "http://localhost:56324/api/values/invoice".AsRequestable() // .Header("Authorization", token.data.type + " " + token.data.token) // .Json(json) // .ByJson(json) // .Post(); }
public void MapDisposeTest() { var mapTo = RuntimeServPools.Singleton <IMapToExpression, MapToExpression>(); //? 为类型“CopyTest”指定代理。 mapTo.Run <CopyToTest, MapToTest>(source => { return(new MapToTest { Id = source.Id, Name = source.Name, Date = source.Date }); }); RuntimeServPools.TryAddSingleton(() => mapTo); var t1 = new T1 { A = 100, B = "10000" }; var value = new CopyToTest { Id = 1000, Name = "test", Date = DateTime.Now }; var t2 = Mapper.Map <T2>(t1); using (var map = new MapToExpression()) { var t3 = map.Map <T2>(t1); var map1 = map.Map <MapToTest>(value); var map2 = Mapper.Map <MapToTest>(value); } var map3 = Mapper.Map <MapToTest>(value); }
public void Test() { var key = KeyGen.Create(6720191477021941760); var key2 = KeyGen.Create(6680757690605506560); RuntimeServPools.TryAddSingleton <IKeyGenFactory>(new SnowflakeFactory(5, 12)); var id = KeyGen.New(); var list = new List <Key>(); for (int i = 0; i < 100000; i++) { list.Add(KeyGen.New()); } var results = list.Distinct().ToList(); Assert.IsTrue(list.Count == results.Count); }
/// <summary> /// 构造函数。 /// </summary> public CastingMapper() { castToExpression = RuntimeServPools.Singleton <ICastToExpression, CastToExpression>(); copyToExpression = RuntimeServPools.Singleton <ICopyToExpression, CopyToExpression>(); mapToExpression = RuntimeServPools.Singleton <IMapToExpression, MapToExpression>(); }
public void MapTo() { //RuntimeServicePools.TryAdd<IProfileConfiguration, ProfileConfiguration>(); var mapTo = RuntimeServPools.Singleton <IMapToExpression, MapToExpression>(); //? 为类型“CopyTest”指定代理。 mapTo.Run <CopyToTest, MapToTest>(source => { return(new MapToTest { Id = source.Id, Name = source.Name, Date = source.Date }); }); RuntimeServPools.TryAddSingleton(() => mapTo); var t1 = new T1 { A = 100, B = "10000" }; var dic = new Dictionary <string, object> { ["sex"] = 1, ["roleenum"] = 32 }; var user = Mapper.Map <User>(dic); var user2 = new User2 { Role = 32 }; var user3 = Mapper.Map <User>(user2); var user4 = Mapper.Map <User2>(user3); var t2 = Mapper.Map <T2>(t1); var value = new CopyToTest { Id = 1000, Name = "test", Date = DateTime.Now }; for (int i = 0; i < 100000; i++) { //mapTo.MapTo<CopyTest>(value); var map1 = Mapper.Map <CopyTest>(value); value.Name = "test1"; var map2 = Mapper.Map <MapToTest>(value); var map3 = Mapper.Map <IEnumerable <KeyValuePair <string, object> > >(value); var map4 = Mapper.Map <ICollection <KeyValuePair <string, object> > >(value); var map5 = Mapper.Map <IDictionary <string, object> >(value); var map6 = Mapper.Map <Dictionary <string, object> >(value); value.Name = "test5"; } }