private void OnPayload <T>(Payloader <T> payloader, HTTPResponse res) { try { if (res == null) { payloader.OnError("OnPayload HTTPResponse null"); return; } if (res.IsSuccess) { var payload = JsonConvert.DeserializeObject <Payload <T> >(res.DataAsText); if (payload.code == PayloadCode.Success) { //성공 payloader.OnSuccess(payload.data); } else { //실패 payloader.OnFail(payload.code); } payloader.OnComplete(payload.data); } else { //에러 payloader.OnError(res.DataAsText); } } catch (Exception ex) { payloader.OnError(ex.Message); } }
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); } }
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); } }