/// <summary> /// Takes the CallStack note from the WCF response and adds it to the current <see cref="IRuntime"/> CallStack /// </summary> /// <param name="result"></param> protected void AppendCallStackFromMessage(IResponseBase result) { if (result.ResponseHeader.CallStack.IsInstance()) { Runtime.CallStack.CallStack.Add(result.ResponseHeader.CallStack); } }
private IResponseBase ZipLocations(IResponseBase result) { Response <StoreLocatorResponse> zipLocations = new Response <StoreLocatorResponse>(); zipLocations = (Response <StoreLocatorResponse>)result; zipLocations.resultset.UrlTarget = TargetUrl; string dayPrefix = DateTime.Now.DayOfWeek.ToString().Substring(0, 3).ToUpper(); GetDayOfWeekNum(dayPrefix); GetZipLocationMsg(zipLocations, dayPrefix); return(result); }
async Task <(bool isSuccess, string body)> ReadAsync(IRequest request, IResponseBase resObj, CancellationToken token) { IRequestEntry nextALS = null; try { if (this.TraceClient != null && this.TraceClient.Current != null) { var als = this.TraceClient.Current; nextALS = als.NewChildRequest(); } var res = await ReadInternalAsync(request, nextALS, resObj, token); if (res.isSuccess) { return(true, res.body); } else { nextALS.Exception = new BusinessException(this.ApiResolveService.Resolve(request.App, request.ApiName).ToString() + resObj.msg, resObj.resCode); } } catch (Exception ex) { if (nextALS != null) { nextALS.Exception = ex; } } finally { if (nextALS != null) { nextALS.EndTime = DateTime.Now; } } return(false, null); }
private IResponseBase GetFailureResponse(Exception e, IResponseBase response) { response.Status = false; response.Message = e.Message; if (e.InnerException != null) { response.Message += Environment.NewLine; response.Message += string.Format("Inner exception: {0}", e.InnerException.Message); } return response; }
async Task <(bool isSuccess, string body, HttpResponseMessage response)> ReadInternalAsync(IRequest request, IRequestEntry nextALS, IResponseBase resObj, CancellationToken token) { var resTask = await this.SendAsync(request, nextALS, token).ContinueWith(p => p); token.ThrowIfCancellationRequested(); if (resTask.IsCanceled) { resObj.resCode = ResponseErrorCode.TaskCancel; resObj.msg = "req rpc task is canceled"; return(false, null, null); } if (resTask.IsFaulted) { resObj.resCode = ResponseErrorCode.TaskFail; resObj.msg = resTask.Exception.GetBaseException().GetBaseException().Message; this.Logger.LogError(0, resTask.Exception, "req rpc api error.{0}", request.ToJson()); return(false, null, null); } var res = await resTask; if (!res.IsSuccessStatusCode) { resObj.resCode = res.StatusCode.ToInt(); resObj.msg = res.ReasonPhrase; return(false, null, null); } token.ThrowIfCancellationRequested(); var readTask = await res.Content.ReadAsStringAsync().ContinueWith(p => p); token.ThrowIfCancellationRequested(); if (readTask.IsFaulted) { resObj.resCode = ResponseErrorCode.ReadRpcContentError; resObj.msg = readTask.Exception.GetBaseException().GetBaseException().Message; return(false, null, null); } if (readTask.IsCanceled) { resObj.resCode = ResponseErrorCode.TaskCancel; resObj.msg = "read prc content task is canceled"; return(false, null, null); } var resultStr = await readTask; return(true, resultStr, res); }
private void SendClientResponse(Socket client, IResponseBase response) { client.Send(Encoding.ASCII.GetBytes(response.GetResponseString())); client.Close(); client.Dispose(); }
public static TimeSpan GetExecutionTimeAsTimeSpan(this IResponseBase self) { return(new TimeSpan(self.ResponseHeader.ExecutionTime)); }