コード例 #1
0
        /// <summary>
        /// Handles an HTTP request by extracting the Cloud Event from it and passing it to the
        /// original Cloud Event Function. The request fails if it does not contain a Cloud Event.
        /// </summary>
        /// <param name="context">The HTTP context containing the request and response.</param>
        /// <returns>A task representing the asynchronous operation.</returns>
        public async Task HandleAsync(HttpContext context)
        {
            CloudEvent cloudEvent;

            try
            {
                cloudEvent = await CloudEventConverter.ConvertRequest(context.Request);
            }
            catch (CloudEventConverter.ConversionException e)
            {
                context.Response.StatusCode = 400;
                _logger.LogError(e.Message);
                return;
            }
            await _function.HandleAsync(cloudEvent, context.RequestAborted);
        }
        /// <summary>
        /// Handles an HTTP request by extracting the CloudEvent from it, deserializing the data, and passing
        /// both the event and the data to the original CloudEvent Function.
        /// The request fails if it does not contain a CloudEvent.
        /// </summary>
        /// <param name="context">The HTTP context containing the request and response.</param>
        /// <returns>A task representing the asynchronous operation.</returns>
        public async Task HandleAsync(HttpContext context)
        {
            CloudEvent cloudEvent;
            TData      data;

            try
            {
                cloudEvent = await CloudEventAdapter.ConvertRequestAsync(context.Request, _formatter);

                data = (TData)cloudEvent.Data;
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                context.Response.StatusCode = 400;
                return;
            }

            await _function.HandleAsync(cloudEvent, data, context.RequestAborted);
        }