private async Task <T> GetResponse <T, M>(T content, M method, Action <T> callback) where T : Content where M : DiyMethod { Exception exception = null; try { BaiduRestResponse response = await this.BaiduClient.RestClient.SendAsync(Activator.CreateInstance <BaiduRestRequest>() .SetFormat(Format.Json) .SetMethod(method)); exception = response.Exception; content.Value = response.Content; } catch (Exception e) { exception = e; } finally { if (exception != null) { content.Exception = exception; content.HasError = true; } } if (!content.HasError) { callback.Invoke(content); } return(content); }
public void SendResponse(BaiduRestResponse response) { if (this.Responsed != null) { this.Responsed(this, new BaiduRestEventArgs() { Client = this.Client, Request = response.Request, Response = response }); } }