/// <summary> /// Http 异常通知 /// </summary> /// <param name="context">通知上下文</param> /// <returns></returns> public async Task NotifyAsync(NotifyContent context) { var httpContent = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("Title", context.Title), new KeyValuePair <string, string>("Message", context.Message) }; await HttpApiFactory.Create <IHttpNotifyApi>() .SendNotifyAsync(this.opt.Uri, this.opt.Header, httpContent); }
public async Task <AjaxResult <StatisticsDto> > GetOnlineStudyAsync() { try { var userApi = HttpApiFactory.Create <IUserAPI>(); var about = await userApi.GetByIdAsync(new SearchDto() { Role = "1", Code = "钱前" }); return(about); } catch (Exception ex) { throw; } }
public void AddCreateTest() { HttpApiFactory.Add <IMyApi>() .SetLifetime(TimeSpan.FromMilliseconds(100d)); var api1 = HttpApiFactory.Create <IMyApi>(); var api2 = HttpApiFactory.Create <IMyApi>(); Assert.True(IsHttpHandlerEquals(api1, api2)); Assert.False(api1 == api2); Thread.Sleep(TimeSpan.FromMilliseconds(150)); var api3 = HttpApiFactory.Create <IMyApi>(); Assert.False(IsHttpHandlerEquals(api1, api3)); }
/// <summary> /// 请求接口 /// </summary> /// <returns></returns> private static async Task RequestAsync() { // userApi由HttpApiFactory创建,自动接管其生命周期 // 不应该将其做为全局变量缓存起来 var userApi = HttpApiFactory.Create <IUserApi>(); var user = new UserInfo { Account = "laojiu", Password = "******", BirthDay = DateTime.Parse("2018-01-01 12:30:30"), Email = "*****@*****.**", Gender = Gender.Male }; var about = await userApi .GetAboutAsync("webapi/user/about", user, "somevalue"); var user1 = await userApi .GetByIdAsync("id001", CancellationToken.None); var user2 = await userApi .GetByAccountAsync("laojiu", CancellationToken.None); var user3 = await userApi .UpdateWithFormAsync(user, nickName : "老九", age : 18) .Retry(3, i => TimeSpan.FromSeconds(i)) .WhenCatch <HttpStatusFailureException>(); var user4 = await userApi .UpdateWithJsonAsync(user); var user5 = await userApi .UpdateWithXmlAsync(user).HandleAsDefaultWhenException(); var file = new MulitpartFile("file.data"); file.UploadProgressChanged += (s, e) => Console.WriteLine(e); var user6 = await userApi .UpdateWithMulitpartAsync(user, "老九", 18, file); file.Dispose(); }
public void AddCreateTest() { HttpApiFactory.Add <IMyApi>() .SetLifetime(TimeSpan.FromMilliseconds(100d)); var api1 = HttpApiFactory.Create <IMyApi>(); var api2 = HttpApiFactory.Create <IMyApi>(); Assert.True(IsHttpApiConfigEquals(api1, api2)); Assert.False(api1 == api2); Thread.Sleep(TimeSpan.FromMilliseconds(150)); var api3 = HttpApiFactory.Create <IMyApi>(); Assert.False(IsHttpApiConfigEquals(api1, api3)); api3.Dispose(); Assert.True(GetHttpApiConfig(api3).IsDisposed == false); }