Example #1
0
        private async Task <ChromelyResponse> ExecuteRouteAsync(string requestId, RoutePath routePath, IDictionary <string, string> parameters, object postData, string requestData)
        {
            var route = ServiceRouteProvider.GetActionRoute(_container, routePath);

            if (route == null)
            {
                throw new Exception($"Route for path = {routePath} is null or invalid.");
            }

            ChromelyResponse response;

            if (route.IsAsync)
            {
                response = await route.InvokeAsync(requestId : requestId, routePath : routePath, parameters : parameters, postData : postData, rawJson : requestData);
            }
            else
            {
                response = route.Invoke(requestId: requestId, routePath: routePath, parameters: parameters, postData: postData, rawJson: requestData);
            }

            response.ReadyState = (int)ReadyState.ResponseIsReady;
            response.Status     = (int)System.Net.HttpStatusCode.OK;
            response.StatusText = "OK";

            return(response);
        }
Example #2
0
        public ChromelyResponse Run(ChromelyRequest request)
        {
            if (request.RoutePath == null)
            {
                return(GetBadRequestResponse(request.Id));
            }

            if (string.IsNullOrEmpty(request.RoutePath.Path))
            {
                return(GetBadRequestResponse(request.Id));
            }

            if (request.RoutePath.Path.ToLower().Equals("/info"))
            {
                return(GetInfo(request.Id));
            }

            var route = ServiceRouteProvider.GetActionRoute(_container, request.RoutePath);

            if (route == null)
            {
                throw new Exception($"Route for path = {request.RoutePath} is null or invalid.");
            }

            var parameters = request.Parameters ?? request.RoutePath.Path.GetParameters()?.ToObjectDictionary();
            var postData   = request.PostData;

            return(ExecuteRoute(request.Id, request.RoutePath, parameters, postData, request.RawJson));
        }
Example #3
0
        public ChromelyResponse Run(string requestId, RoutePath routePath, IDictionary <string, string> parameters, object postData, string requestData)
        {
            var response = new ChromelyResponse(requestId);

            if (string.IsNullOrEmpty(routePath.Path))
            {
                response.ReadyState = (int)ReadyState.ResponseIsReady;
                response.Status     = (int)System.Net.HttpStatusCode.BadRequest;
                response.StatusText = "Bad Request";

                return(response);
            }

            if (routePath.Path.ToLower().Equals("/info"))
            {
                response = GetInfo();
                return(response);
            }

            var route = ServiceRouteProvider.GetActionRoute(_container, routePath);

            if (route == null)
            {
                throw new Exception($"Route for path = {routePath} is null or invalid.");
            }

            return(ExecuteRoute(requestId, routePath, parameters, postData, requestData));
        }
Example #4
0
        public ChromelyResponse Run(string method, string path, object parameters, object postData)
        {
            var response  = new ChromelyResponse();
            var routePath = new RoutePath(method, path);

            if (routePath == null || string.IsNullOrWhiteSpace(routePath?.Path))
            {
                response.ReadyState = (int)ReadyState.ResponseIsReady;
                response.Status     = (int)System.Net.HttpStatusCode.BadRequest;
                response.StatusText = "Bad Request";

                return(response);
            }

            if (routePath.Path.ToLower().Equals("/info"))
            {
                response = GetInfo();
                return(response);
            }

            var route = ServiceRouteProvider.GetActionRoute(_container, routePath);

            if (route == null)
            {
                throw new Exception($"Route for path = {routePath.Path} is null or invalid.");
            }

            return(ExcuteRoute(string.Empty, routePath, parameters, postData, string.Empty));
        }
        private ChromelyResponse ExecuteRoute(string requestId, RoutePath routePath, IDictionary <string, string> parameters, object postData, string requestData)
        {
            var route = ServiceRouteProvider.GetActionRoute(_container, routePath);

            if (route == null)
            {
                throw new Exception($"Route for path = {routePath} is null or invalid.");
            }

            var response = route.Invoke(requestId: requestId, routePath: routePath, parameters: parameters, postData: postData, rawJson: requestData);

            response.ReadyState = (int)ReadyState.ResponseIsReady;
            response.Status     = (response.Status == 0) ? (int)HttpStatusCode.OK : response.Status;
            response.StatusText = (string.IsNullOrWhiteSpace(response.StatusText) && (response.Status == (int)HttpStatusCode.OK)) ? "OK" : response.StatusText;

            return(response);
        }
Example #6
0
        private ChromelyResponse ExcuteRoute(string requestId, RoutePath routePath, object parameters, object postData, string requestData)
        {
            var route = ServiceRouteProvider.GetActionRoute(_container, routePath);

            if (route == null)
            {
                throw new Exception($"Route for path = {routePath} is null or invalid.");
            }

            var response = route.Invoke(requestId: requestId, routePath: routePath, parameters: parameters?.ToObjectDictionary(), postData: postData, rawJson: requestData);

            response.ReadyState = (int)ReadyState.ResponseIsReady;
            response.Status     = (int)System.Net.HttpStatusCode.OK;
            response.StatusText = "OK";

            return(response);
        }
Example #7
0
        public ChromelyResponse Run(string requestId, RoutePath routePath, IDictionary <string, string> parameters, object postData, string requestData)
        {
            if (string.IsNullOrEmpty(routePath.Path))
            {
                return(GetBadRequestResponse(requestId));
            }

            if (routePath.Path.ToLower().Equals("/info"))
            {
                return(GetInfo(requestId));
            }

            var route = ServiceRouteProvider.GetActionRoute(_container, routePath);

            if (route == null)
            {
                throw new Exception($"Route for path = {routePath} is null or invalid.");
            }

            return(ExecuteRoute(requestId, routePath, parameters, postData, requestData));
        }
Example #8
0
        public ChromelyResponse Run(ChromelyRequest request)
        {
            var response = new ChromelyResponse(request.Id);

            if (request.RoutePath == null)
            {
                response.ReadyState = (int)ReadyState.ResponseIsReady;
                response.Status     = (int)System.Net.HttpStatusCode.BadRequest;
                response.StatusText = "Bad Request";

                return(response);
            }

            if (string.IsNullOrEmpty(request.RoutePath.Path))
            {
                response.ReadyState = (int)ReadyState.ResponseIsReady;
                response.Status     = (int)System.Net.HttpStatusCode.BadRequest;
                response.StatusText = "Bad Request";

                return(response);
            }

            if (request.RoutePath.Path.ToLower().Equals("/info"))
            {
                response = GetInfo();
                return(response);
            }

            var route = ServiceRouteProvider.GetActionRoute(_container, request.RoutePath);

            if (route == null)
            {
                throw new Exception($"Route for path = {request.RoutePath} is null or invalid.");
            }

            var parameters = request.Parameters ?? request.RoutePath.Path.GetParameters()?.ToObjectDictionary();
            var postData   = request.PostData;

            return(ExcuteRoute(request.Id, request.RoutePath, parameters, postData, request.RawJson));
        }
Example #9
0
        public async Task <ChromelyResponse> RunAsync(string method, string path, IDictionary <string, string> parameters, object postData)
        {
            var routePath = new RoutePath(method, path);

            if (routePath == null || string.IsNullOrWhiteSpace(routePath?.Path))
            {
                return(GetBadRequestResponse(null));
            }

            if (routePath.Path.ToLower().Equals("/info"))
            {
                return(GetInfo(string.Empty));
            }

            var route = ServiceRouteProvider.GetActionRoute(_container, routePath);

            if (route == null)
            {
                throw new Exception($"Route for path = {routePath.Path} is null or invalid.");
            }

            return(await ExecuteRouteAsync(string.Empty, routePath, parameters, postData, string.Empty));
        }