Beispiel #1
0
        private async Task OnReceiveRequestAsync(Guid id, ReceiveRequest request)
        {
            // request is done, we can handle it
            if (_requestHandler != null)
            {
                var response = await _requestHandler.ProcessRequestAsync(request, null, context : _handlerContext).ConfigureAwait(false);

                if (response != null)
                {
                    await _sendOperations.SendResponseAsync(id, response).ConfigureAwait(false);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Serializes the body of this <see cref="ReceiveRequest"/> as JSON.
        /// </summary>
        /// <typeparam name="T">The type to attempt to deserialize the contents of this <see cref="ReceiveRequest"/>'s body into.</typeparam>
        /// <param name="request">The current instance of <see cref="ReceiveRequest"/>.</param>
        /// <returns>On success, an object of type T populated with data serialized from the <see cref="ReceiveRequest"/> body.
        /// Otherwise a default instance of type T.
        /// </returns>
        public static async Task <T> ReadBodyAsJsonAsync <T>(this ReceiveRequest request)
        {
            // The first stream attached to a ReceiveRequest is always the ReceiveRequest body.
            // Any additional streams must be defined within the body or they will not be
            // attached properly when processing activities.
            var contentStream = request.Streams.FirstOrDefault();

            /* If the response had no body we have to return a compatible
             * but empty object to avoid throwing exceptions upstream anytime
             * an empty response is received.
             */
            if (contentStream == null)
            {
                return(default);
        /// <summary>
        /// Reads the body of this <see cref="ReceiveRequest"/> as a string.
        /// </summary>
        /// <param name="request">The current instance of <see cref="ReceiveRequest"/>.</param>
        /// <returns>On success, a string populated with data read from the <see cref="ReceiveRequest"/> body.
        /// Otherwise null.
        /// </returns>
        public static string ReadBodyAsString(this ReceiveRequest request)
        {
            try
            {
                var contentStream = request.Streams.FirstOrDefault();

                if (contentStream == null)
                {
                    return(string.Empty);
                }

                using (var reader = new StreamReader(contentStream.Stream, Encoding.UTF8))
                {
                    return(reader.ReadToEnd());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #4
0
 /// <summary>
 /// Serializes the body of this <see cref="ReceiveRequest"/> as JSON.
 /// </summary>
 /// <typeparam name="T">The type to attempt to deserialize the contents of this <see cref="ReceiveRequest"/>'s body into.</typeparam>
 /// <param name="request">The current instance of <see cref="ReceiveRequest"/>.</param>
 /// <returns>On success, an object of type T populated with data serialized from the <see cref="ReceiveRequest"/> body.
 /// Otherwise a default instance of type T.
 /// </returns>
 public static T ReadBodyAsJson <T>(this ReceiveRequest request)
 {
     return(request.ReadBodyAsJsonAsync <T>().GetAwaiter().GetResult());
 }
Beispiel #5
0
 /// <summary>
 /// The method that must be implemented in order to handle incoming requests.
 /// </summary>
 /// <param name="request">A <see cref="ReceiveRequest"/> for this handler to process.</param>
 /// <param name="logger">Logger.</param>
 /// <param name="context">Optional context to process the request within.</param>
 /// <param name="cancellationToken">Cancellation token.</param>
 /// <returns>A <see cref="Task"/> that will produce a <see cref="StreamingResponse"/> on successful completion.</returns>
 public abstract Task <StreamingResponse> ProcessRequestAsync(ReceiveRequest request, ILogger <RequestHandler> logger, object context = null, CancellationToken cancellationToken = default(CancellationToken));