コード例 #1
0
        /// <summary>
        /// Handles the http request received through Trouter
        /// </summary>
        /// <param name="requestReceived">Http request to be processed</param>
        /// <returns><see cref="HttpResponseMessage"/> to be sent in response of the request</returns>
        private async Task <HttpResponseMessage> ProcessIncomingTrouterRequestAsync(RequestReceived requestReceived)
        {
            try
            {
                m_logger.Information("Incoming callback\r\n " + requestReceived.Body);

                var message = new SerializableHttpRequestMessage();
                message.Method         = requestReceived.HttpMethod;
                message.Uri            = requestReceived.RelativeUri;
                message.LoggingContext = new LoggingContext(Guid.NewGuid());
                message.Content        = requestReceived.Body;
                message.ContentType    = "application/json";
                message.IsIncoming     = true;
                message.Timestamp      = DateTime.UtcNow;

                if (requestReceived.Headers != null)
                {
                    message.RequestHeaders = new List <Tuple <string, string> >();
                    foreach (KeyValuePair <string, string> header in requestReceived.Headers)
                    {
                        if (!string.IsNullOrEmpty(header.Key) && !string.IsNullOrEmpty(header.Value))
                        {
                            message.RequestHeaders.Add(new Tuple <string, string>(header.Key, header.Value));
                        }
                    }
                }

                // Suppress the warning
                await Task.CompletedTask.ConfigureAwait(false);

                // Pass down the response to event channel
                HandleIncomingEvents?.Invoke(this, new EventsChannelArgs(message));
            }
            catch (Exception ex)
            {
                Debug.Assert(false, "unexpected exception: " + ex.ToString());
            }
            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
コード例 #2
0
 public void HandleIncomingHttpRequest(SerializableHttpRequestMessage message)
 {
     HandleIncomingEvents?.Invoke(Instance, new EventsChannelArgs(message));
 }