Inheritance: HA4IoT.Contracts.Api.ApiContext
        private async Task SendResponseMessage(QueueBasedApiContext context)
        {
            var clientEtag = (string)context.Request["ETag"];

            var brokerProperties = new JObject
            {
                ["CorrelationId"] = context.CorrelationId
            };

            var message = new JObject
            {
                ["ResultCode"] = context.ResultCode.ToString(),
                ["Content"]    = context.Response
            };

            var serverEtag = (string)context.Response["Meta"]["Hash"];

            message["ETag"] = serverEtag;

            if (!string.Equals(clientEtag, serverEtag))
            {
                message["Content"] = context.Response;
            }

            await _outboundQueue.SendAsync(brokerProperties, message);
        }
        private void DistpachMessage(object sender, MessageReceivedEventArgs e)
        {
            var correlationId = (string)e.Body["CorrelationId"];
            var uri           = (string)e.Body["Uri"];
            var request       = (JObject)e.Body["Content"] ?? new JObject();

            var context   = new QueueBasedApiContext(correlationId, uri, request, new JObject());
            var eventArgs = new ApiRequestReceivedEventArgs(context);

            RequestReceived?.Invoke(this, eventArgs);

            if (!eventArgs.IsHandled)
            {
                context.ResultCode = ApiResultCode.UnknownUri;
            }

            SendResponseMessage(context).Wait();
        }
        private async Task SendResponseMessage(QueueBasedApiContext context)
        {
            var clientEtag = (string)context.Request["ETag"];

            var brokerProperties = new JObject
            {
                ["CorrelationId"] = context.CorrelationId
            };

            var message = new JObject
            {
                ["ResultCode"] = context.ResultCode.ToString(),
                ["Content"] = context.Response
        };

            var serverEtag = (string)context.Response["Meta"]["Hash"];
            message["ETag"] = serverEtag;

            if (!string.Equals(clientEtag, serverEtag))
            {
                message["Content"] = context.Response;
            }

            await _outboundQueue.SendAsync(brokerProperties, message);
        }
        private void DistpachMessage(object sender, MessageReceivedEventArgs e)
        {
            var correlationId = (string)e.Body["CorrelationId"];
            var uri = (string)e.Body["Uri"];
            var request = (JObject)e.Body["Content"] ?? new JObject();

            var context = new QueueBasedApiContext(correlationId, uri, request, new JObject());
            var eventArgs = new ApiRequestReceivedEventArgs(context);
            RequestReceived?.Invoke(this, eventArgs);

            if (!eventArgs.IsHandled)
            {
                context.ResultCode = ApiResultCode.UnknownUri;
            }

            SendResponseMessage(context).Wait();
        }