private Guid GetCorrelationIdFromRequest(NancyRequest request) { var guidParsed = false; Guid correlationId = Guid.Empty; if (request.Query["CorrelationId"] != null) { guidParsed = Guid.TryParse(request.Query["CorrelationId"].ToString(), out correlationId); } if (!guidParsed && request.Header?.Property("CorrelationId") != null) { guidParsed = Guid.TryParse(request.Header.Property("CorrelationId")?.Value? .FirstOrDefault(x => !string.IsNullOrWhiteSpace($"{x}") && $"{x}" != $"{Guid.Empty}")? .ToString(), out correlationId); } if (guidParsed) { return(correlationId); } return(ReadCorrelationIdFromBody(request.Body)); }
public void SoapRouteRedirect(NancyContext ctx, NancyRequest nancyRequest) { if (ctx.Request.Headers["SOAPAction"].Any()) { var matchingHeaders = ctx.Request.Headers["SOAPAction"]; var headerValue = (matchingHeaders == null) ? "" : (matchingHeaders.FirstOrDefault() ?? ""); if (!string.IsNullOrEmpty(headerValue)) { // Strip the namespace and double quotes from the soap action int nsSplit = headerValue.LastIndexOf('/'); if (nsSplit >= 0) { headerValue = headerValue.Substring(nsSplit + 1); } headerValue = headerValue.Trim("\"".ToCharArray()); // Set the new action if (ctx.Items.ContainsKey(Utils.SoapActionKey)) { ctx.Items.Remove(Utils.SoapActionKey); } ctx.Items.Add(new KeyValuePair <string, object>(Utils.SoapActionKey, headerValue)); } } }
private void ExportPerformances_Btn(object sender, RoutedEventArgs e) { NancyRequest nancyRequest = new NancyRequest(); string response = nancyRequest.ExecuteRequest("Performances", "GET"); FileWriter.Write("Performances", response); DialogBox.Ok("Success", "Performances exported well. \n Check Root folder in main folder."); }
private Guid GetCorrelationIdFromRequest(NancyRequest request) { if (request.Query["CorrelationId"] != null) { return(Guid.Parse(request.Query["CorrelationId"].ToString())); } return(ReadCorrelationIdFromBody(request.Body)); }
public virtual Guid GetCorrelationId(NancyRequest request) { Guid correlationId = GetCorrelationIdFromRequest(request); if (correlationId == Guid.Empty) { if (_configuration.Instance.RequestCorrelationIdIsRequired) { throw new Exception(ErrorCode.CORRELATIONID_REQUIRED.ToString()); } else { correlationId = Guid.NewGuid(); } } return(correlationId); }
protected override void RequestStartup(ILifetimeScope container, IPipelines pipelines, NancyContext context) { // No registrations should be performed in here, however you may // resolve things that are needed during request startup. var _configurationManager = container.Resolve <IConfigurationManager>(); var _correlationId = container.Resolve <ICorrelationId>(); var _pipelineHelper = container.Resolve <IPipelineHelper>(); var _soapAdapter = container.Resolve <ISoapAdapter>(); pipelines.BeforeRequest += (ctx) => { if (ctx.Request.Path.StartsWith(_configurationManager.Instance.ApiPrefix)) { var requestObject = new NancyRequest(ctx.Request.Method, ctx.Request.Url, ctx.Request.Query, Utils.BodyXmlToJObject(ctx.Request.Body)); _correlationId.CurrentValue = _pipelineHelper.GetCorrelationId(requestObject); _pipelineHelper.LogRequest(requestObject); _soapAdapter.SoapRouteRedirect(ctx, requestObject); ctx.Request.Body.Position = 0; } return(null); }; pipelines.AfterRequest += (ctx) => { if (ctx.Request.Path.StartsWith(_configurationManager.Instance.ApiPrefix) && ctx.Response.ContentType.Contains("json")) { _pipelineHelper.LogAndFormatResponse(ctx.Response); } }; pipelines.OnError.AddItemToEndOfPipeline((ctx, ex) => { _pipelineHelper.LogError(ex); var error = _pipelineHelper.BuildErrorResponse(ex.Message); error.StatusCode = HttpStatusCode.BadRequest; return(error); }); base.RequestStartup(container, pipelines, context); }
public virtual void LogRequest(NancyRequest request) { var requestString = JsonSerializer.ToJson(request); _logger.Trace(requestString, correlationId: _correlationId.CurrentValue); }