示例#1
0
        private DebugEventContractV1 ProcessDebug(ActionContext actionContext)
        {
            // Is the event data being requested
            TestDumpHeader testHeader = Context.Properties.Get <TestDumpHeader>();

            if (testHeader?.Value != TestDumpHeader.Commands.Request)
            {
                return(null);
            }

            IEventDataBuffer eventDataBuffer = Context.Properties.Get <IEventDataBuffer>();

            if (eventDataBuffer == null)
            {
                return(null);
            }

            IList <EventDetailContractV1> eventData = eventDataBuffer.SearchForBaseCv(Context.Cv.Value)
                                                      .Select(x => x.ConvertTo())
                                                      .ToList();

            return(new DebugEventContractV1 {
                EventData = eventData
            });
        }
示例#2
0
        public Task ExecuteResultAsync(ActionContext actionContext)
        {
            actionContext.HttpContext.Response.StatusCode = (int)StatusCode;

            // Requested headers
            Headers.Values.OfType <IHttpHeaderProperty>()
            .Run(x => actionContext.HttpContext.Response.Headers[x.Key] = new StringValues(x.FormatValueForHttp()));

            // Standard headers
            actionContext.HttpContext.Response.Headers[CvHeader.HeaderKey] = new CvHeader(Context.Cv).FormatValueForHttp();

            DebugEventContractV1 debugObject = ProcessDebug(actionContext);

            if (Content != null)
            {
                if (debugObject == null)
                {
                    var objectResult = new ObjectResult(Content);
                    return(objectResult.ExecuteResultAsync(actionContext));
                }

                // Append debug data to response
                if (Content != null && debugObject != null)
                {
                    // Embedded debug data
                    JObject contentObj = JObject.FromObject(Content);
                    JObject debugObj   = JObject.FromObject(debugObject);
                    contentObj.Add("debug", debugObj);

                    // Indicate that the debug data is present
                    var header = new TestDumpHeader(TestDumpHeader.Commands.Reponse);
                    actionContext.HttpContext.Response.Headers[header.Key] = header.FormatValueForHttp();

                    var jsonResult = new JsonResult(contentObj);
                    return(jsonResult.ExecuteResultAsync(actionContext));
                }
            }

            if (debugObject != null)
            {
                var objectResult = new ObjectResult(debugObject);
                return(objectResult.ExecuteResultAsync(actionContext));
            }

            return(Task.FromResult(0));
        }