public Payloader <T> Get <T>(Uri url) { var payloader = new Payloader <T>(); Get(url, (req, res) => { OnPayload(payloader, res); }); return(payloader); }
public Payloader <T> Delete <T>(Uri url) { var payloader = new Payloader <T>(); Delete(url, (req, res) => { OnPayload(payloader, res); }); return(payloader); }
public Payloader <T> Put <T>(Uri url, object field) { var payloader = new Payloader <T>(); Put(url, field, (req, res) => { OnPayload(payloader, res); }); return(payloader); }
public Payloader <T> Send <T>(HttpMethod method, string uri, object data = null) { var payloader = new Payloader <T>(); Send(method, uri, data, (output) => { OnPayload(payloader, output.response); }); return(payloader); }
public void Call <T>(Payloader <T> payloader, ParsingType type, object[] arguments) where T : class { try { var code = (PayloadCode)arguments[0]; switch (code) { case PayloadCode.Error: { var error = arguments[1].ToString(); payloader.OnError(error); } break; case PayloadCode.Success: { var data = default(T); switch (type) { case ParsingType.Json: data = JsonConvert.DeserializeObject <T>(arguments[1].ToString()); break; case ParsingType.Protocol: data = (T)connection.Protocol.ConvertTo(typeof(T), arguments[1]); break; default: data = (T)arguments[1]; break; } //var data = isLocal ? (T)arguments[1] : (T)connection.Protocol.ConvertTo(typeof(T), arguments[1]); payloader.OnSuccess(data); payloader.OnComplete(data); } break; default: { payloader.OnFail(code); payloader.OnComplete(null); } break; } } catch (Exception ex) { HTTPManager.Logger.Error("BaseSignalR", "GetRealArguments: " + ex); } }
private void OnPayload <T>(Payloader <T> payloader, HttpResponseMessage response) { try { if (response == null) { payloader.OnError("OnPayload HTTPResponse null"); return; } var result = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { var obj = JsonConvert.DeserializeObject <Payload <T> >(result); if (obj.data != null) { //성공 payloader.OnSuccess(obj.data); } else { //실패 payloader.OnFail(obj.code); } payloader.OnComplete(obj.data); } else { //에러 payloader.OnError(result); } } catch (Exception ex) { payloader.OnError(ex.Message); } }