Ejemplo n.º 1
0
 private void ExposeStatus(object sender, ApiRequestReceivedEventArgs e)
 {
 }
Ejemplo n.º 2
0
        private void HandleApiConfigurationRequest(object sender, ApiRequestReceivedEventArgs e)
        {
            var areas = new JObject();
            foreach (var area in _areas.GetAll())
            {
                areas[area.Id.Value] = ExportAreaConfiguration(area);
            }

            e.Context.Response["Areas"] = areas;
        }
        private void DispatchWebSocketMessage(object sender, WebSocketMessageReceivedEventArgs e)
        {
            var requestMessage = JObject.Parse(((WebSocketTextMessage)e.Message).Text);

            var correlationId = (string)requestMessage["CorrelationId"];
            var uri = (string)requestMessage["Uri"];
            var request = (JObject)requestMessage["Content"] ?? new JObject();

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

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

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

            e.WebSocketClientSession.SendAsync(responseMessage.ToString()).Wait();
        }
 private void HandleApiStatusRequest(object sender, ApiRequestReceivedEventArgs e)
 {
     lock (_syncRoot)
     {
         e.Context.Response["Notifications"] = JArray.FromObject(_notifications);
     }
 }
        private void DispatchHttpRequest(HttpContext httpContext)
        {
            var apiContext = CreateApiContext(httpContext);
            if (apiContext == null)
            {
                httpContext.Response.StatusCode = HttpStatusCode.BadRequest;
                return;
            }

            var eventArgs = new ApiRequestReceivedEventArgs(apiContext);
            RequestReceived?.Invoke(this, eventArgs);

            if (!eventArgs.IsHandled)
            {
                httpContext.Response.StatusCode = HttpStatusCode.BadRequest;
                return;
            }

            if (eventArgs.Context.Response == null)
            {
                eventArgs.Context.Response = new JObject();
            }

            httpContext.Response.StatusCode = ConvertResultCode(eventArgs.Context.ResultCode);

            if (apiContext.UseHash)
            {
                var serverHash = GenerateHash(apiContext.Response.ToString());
                eventArgs.Context.Response["$Hash"] = serverHash;

                var serverHashWithQuotes = "\"" + serverHash + "\"";

                string clientHash;
                if (httpContext.Request.Headers.TryGetValue(HttpHeaderNames.IfNoneMatch, out clientHash))
                {
                    if (clientHash.Equals(serverHashWithQuotes))
                    {
                        httpContext.Response.StatusCode = HttpStatusCode.NotModified;
                        return;
                    }
                }

                httpContext.Response.Headers[HttpHeaderNames.ETag] = serverHashWithQuotes;
            }

            httpContext.Response.Body = new JsonBody(eventArgs.Context.Response);
        }
Ejemplo n.º 6
0
        private void RouteRequest(object sender, ApiRequestReceivedEventArgs e)
        {
            var uri = e.Context.Uri.Trim();

            Action<IApiContext> handler;
            if (_routes.TryGetValue(uri, out handler))
            {
                e.IsHandled = true;
                HandleRequest(e.Context, handler);

                return;
            }

            e.Context.ResultCode = ApiResultCode.UnknownUri;
        }
Ejemplo n.º 7
0
        private void HandleStatusRequest(IApiContext apiContext)
        {
            apiContext.UseHash = true;

            var eventArgs = new ApiRequestReceivedEventArgs(apiContext);
            StatusRequested?.Invoke(this, eventArgs);
            StatusRequestCompleted?.Invoke(this, eventArgs);
        }
Ejemplo n.º 8
0
 private void HandleConfigurationRequest(IApiContext apiContext)
 {
     var eventArgs = new ApiRequestReceivedEventArgs(apiContext);
     ConfigurationRequested?.Invoke(this, eventArgs);
     ConfigurationRequestCompleted?.Invoke(this, eventArgs);
 }
        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();
        }