private async Task <IController> GetController(IEnumerable <string> requestParameters, IHttpContext context)
        {
            var current = _controller;

            foreach (var parameter in requestParameters)
            {
                var controllerType = current.GetType();

                LoadRoutes(controllerType, _propertyNameComparer);

                var route = new ControllerRoute(controllerType, parameter, _propertyNameComparer);

                Func <IController, IController> routeFunction;
                if (Routes.TryGetValue(route, out routeFunction))
                {
                    current = routeFunction(current);
                    continue;
                }

                // Try find indexer.
                current = await TryGetIndexerValue(controllerType, context, current, parameter).ConfigureAwait(false);

                if (current != null)
                {
                    continue;
                }

                return(null);
            }

            return(current);
        }
Пример #2
0
    private void SetRouteArguments(IChromelyRequest request)
    {
        ControllerRoute.ValidateRequest(request);
        _propertyNameArgumentMap = new Dictionary <string, RouteArgument>();

        _routeArguments = SetArgumentDefaultValues(out int argumentsCount, out _propertyNameArgumentMap);

        if (argumentsCount == 0)
        {
            return;
        }

        _queryParameterArgs = GetQueryParameterArgs(request.Parameters);

        if (request.PostData is not null)
        {
            ParsePostData(request.PostData);
        }

        // Add query parameters if exist as query arguments but not parsed.
        foreach (var queryArg in _queryParameterArgs)
        {
            if (_propertyNameArgumentMap.ContainsKey(queryArg.Key))
            {
                var argument = _propertyNameArgumentMap[queryArg.Key];
                _routeArguments[argument.Index] = queryArg.Value;
            }
        }
    }
Пример #3
0
        public async Task <IActionResult> RouteAsync()
        {
            try
            {
                KendoGrid <List <ControllerRoutingActions> > controllerRoutingActionsList =
                    await ControllerRoute.GetRouteActionForKendoGridAsync(_provider, Url);

                return(View(controllerRoutingActionsList as IEnumerable <KendoGrid <ControllerRoutingActions> >));
            }
            catch (Exception e)
            {
                return(NotFound(e));
            }
        }
        public async Task <ActionResult <KendoGrid <List <ControllerRoutingActions> > > > GetRouteKendoGridAsync()
        {
            try
            {
                KendoGrid <List <ControllerRoutingActions> > kendoGrid =
                    await ControllerRoute.GetRouteActionForKendoGridAsync(_provider,
                                                                          ControllerContext.ActionDescriptor.ControllerName, Url, this);

                if (null != kendoGrid && kendoGrid.Data.Count > 0)
                {
                    return(kendoGrid);
                }
            }
            catch (Exception e)
            {
                await Task.Run(() => _log4Net.Error(string.Format("{0}, {1}.", e.Message, e.StackTrace), e));
            }

            return(NotFound());
        }
        public async Task <ActionResult <List <ControllerRoutingActions> > > GetRouteAsync()
        {
            try
            {
                List <ControllerRoutingActions> controllerRoutingActionsList =
                    await ControllerRoute.GetRouteActionAsync(_provider,
                                                              ControllerContext.ActionDescriptor.ControllerName, Url, this);

                if (null != controllerRoutingActionsList && controllerRoutingActionsList.Count > 0)
                {
                    return(controllerRoutingActionsList);
                }
            }
            catch (Exception e)
            {
                await Task.Run(() => _log4Net.Error(string.Format("{0}, {1}.", e.Message, e.StackTrace), e));
            }

            return(NotFound());
        }
Пример #6
0
        public async Task <ActionResult <KendoGrid <List <ControllerRoutingActions> > > > GetRouteKendoGridAsync()
        {
            try
            {
                KendoGrid <List <ControllerRoutingActions> > kendoGrid =
                    await ControllerRoute.GetRouteActionForKendoGridAsync(_provider, Url);

                if (null != kendoGrid && kendoGrid.Data.Count > 0)
                {
                    return(kendoGrid);
                }
            }
            catch (Exception e)
            {
                await Task.Run(() =>
                               _log4Net.Error(
                                   $"{Environment.NewLine}{e.GetType()}{Environment.NewLine}{e.InnerException?.GetType()}{Environment.NewLine}{e.Message}{Environment.NewLine}{e.StackTrace}{Environment.NewLine}",
                                   e));

                return(StatusCode(500, e));
            }

            return(NotFound());
        }
Пример #7
0
        public async Task <ActionResult <List <ControllerRoutingActions> > > GetRouteAsync()
        {
            try
            {
                List <ControllerRoutingActions> controllerRoutingActionsList =
                    await ControllerRoute.GetRouteActionAsync(_provider, Url);

                if (null != controllerRoutingActionsList && controllerRoutingActionsList.Count > 0)
                {
                    return(controllerRoutingActionsList);
                }
            }
            catch (Exception e)
            {
                await Task.Run(() =>
                               _log4Net.Error(
                                   $"{Environment.NewLine}{e.GetType()}{Environment.NewLine}{e.InnerException?.GetType()}{Environment.NewLine}{e.Message}{Environment.NewLine}{e.StackTrace}{Environment.NewLine}",
                                   e));

                return(StatusCode(500, e));
            }

            return(NotFound());
        }
Пример #8
0
 private bool Equals(ControllerRoute other)
 {
     return _controllerType == other._controllerType && string.Equals(_propertyName, other._propertyName, StringComparison.InvariantCultureIgnoreCase);
 }
Пример #9
0
        private async Task<IController> GetController(IEnumerable<string> requestParameters, IHttpContext context)
        {
            var current = _controller;
            foreach (var parameter in requestParameters)
            {
                var controllerType = current.GetType();

                LoadRoutes(controllerType);

                var route = new ControllerRoute(controllerType, parameter);

                Func<IController, IController> routeFunction;
                if (Routes.TryGetValue(route, out routeFunction))
                {
                    current = routeFunction(current);
                    continue;
                }

                // Try find indexer.
                Func<IHttpContext, IController, string, Task<IController>> indexerFunction;
                if (IndexerRoutes.TryGetValue(controllerType, out indexerFunction))
                {
                    current = await indexerFunction(context, current, parameter).ConfigureAwait(false);
                    continue;
                }

                return null;
            }

            return current;
        }
 private bool Equals(ControllerRoute other)
 {
     return(other != null &&
            _controllerType == other._controllerType &&
            _propertyNameComparer.Equals(_propertyName, other._propertyName));
 }
Пример #11
0
 /// <inheritdoc />
 public virtual void RegisterRoute(string key, ControllerRoute route)
 {
     RouteMap.Add(key, route);
 }
Пример #12
0
 private bool Equals(ControllerRoute other)
 {
     return(_controllerType == other._controllerType && string.Equals(_propertyName, other._propertyName, StringComparison.InvariantCultureIgnoreCase));
 }
Пример #13
0
 private bool Equals(ControllerRoute other)
 {
     return other != null
         && _controllerType == other._controllerType
         && _propertyNameComparer.Equals(_propertyName, other._propertyName);
 }
Пример #14
0
 private bool Equals(ControllerRoute other)
 {
     return _controllerType == other._controllerType && string.Equals(_propertyName, other._propertyName);
 }
Пример #15
0
 private bool Equals(ControllerRoute other)
 {
     return(_controllerType == other._controllerType && string.Equals(_propertyName, other._propertyName));
 }