/// <summary>
        /// Take evidence from the given <see cref="HttpContext"/> and
        /// pass it into the action <see cref="IPipeline"/>.
        /// Add the result to the <see cref="HttpContext.Items"/>
        /// collection for downstream components to use.
        /// </summary>
        /// <param name="context">
        /// The current <see cref="HttpContext"/>
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if one of the required arguments is null
        /// </exception>
        public void Process(HttpContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Create the flowData
            var flowData = _pipeline.CreateFlowData();

            context.Response.RegisterForDispose(flowData);
            // Extract the required pieces of evidence from the request
            _evidenceService.AddEvidenceFromRequest(flowData, context.Request);
            // Start processing the data
            flowData.Process();
            // Remove the existing flow data if there is one.
            // This will be from a previous request and the evidence may have
            // changed so we need to update it.
            if (context.Items.ContainsKey(Constants.HTTPCONTEXT_FLOWDATA))
            {
                context.Items.Remove(Constants.HTTPCONTEXT_FLOWDATA);
            }
            // Store the FlowData in the HttpContext
            context.Items.Add(Constants.HTTPCONTEXT_FLOWDATA, flowData);
        }
示例#2
0
 public IActionResult Index()
 {
     using (var flowData = _pipeline.CreateFlowData())
     {
         // Add evidence
         _evidenceService.AddEvidenceFromRequest(flowData, Request);
         // Process
         flowData.Process();
         // Set response headers
         SetHeaderService.SetHeaders(Response.HttpContext, flowData);
         // Send results to view
         return(View(flowData));
     }
 }
        public IActionResult Index()
        {
            var flowData = _pipeline.CreateFlowData();

            // Register the flow data instance for disposal
            // when the response is sent.
            // If we just have a 'using' block then it will
            // be disposed before the view can access the
            // values that it needs.
            HttpContext.Response.RegisterForDispose(flowData);

            // Add evidence
            _evidenceService.AddEvidenceFromRequest(flowData, Request);
            // Process
            flowData.Process();
            // Set response headers
            SetHeaderService.SetHeaders(Response.HttpContext, flowData);

            // Send results to view
            return(View(flowData));
        }