Esempio n. 1
0
 public RequestContext(String url, RouteData routeData, IMvcHandler handler, String verb)
 {
     _url = url;
     _verb = verb;
     _handler = handler;
     _routeData = routeData;
 }
Esempio n. 2
0
        public override RouteData GetRouteData(String url)
        {
            String virtualPath = url;
            if(virtualPath.StartsWith("/"))
            {
                virtualPath = virtualPath.Remove(0,1);
            }
            String queryString = null;
            if (virtualPath.Contains('?'))
            {
                queryString = virtualPath.Substring(virtualPath.IndexOf('?') + 1);
                virtualPath = virtualPath.Substring(0,virtualPath.IndexOf('?'));
            }
            RouteValueDictionary values = _parsedRoute.Match(virtualPath, Defaults);
            if (values == null)
            {
                return null;
            }
            RouteData data = new RouteData(this);

            foreach (KeyValuePair<String, Object> valuePair in values)
            {
                data.Values.Add(valuePair.Key, valuePair.Value);
            }
            if (queryString != null)
            {
                RouteValueDictionary queryStringValues = GetQueryStringValues(queryString);
                foreach (var queryPair in queryStringValues)
                {
                    data.Values.Add(queryPair.Key, queryPair.Value);
                }
            }
            return data;
        }
        private Object[] GetParameterValues(ParameterInfo[] parameters, RouteData routeData)
        {
            Requires.NotNull(parameters, "parameters");
            Requires.NotNull(routeData, "routeData");

            if ((parameters.Length > 0)&&(routeData.Values.Count > 0))
            {
                List<Object> parameterValues = new List<Object>();
                foreach (var parameter in parameters)
                {
                    Object value = routeData.Values.GetValueOrDefault(parameter.Name);
                    if (value != null)
                    {
                        try
                        {
                            value = Convert.ChangeType(value, parameter.ParameterType, Thread.CurrentThread.CurrentCulture);
                        }
                        catch
                        {
                        }
                    }
                    parameterValues.Add(value);
                }
                return parameterValues.ToArray();
            }
            return null;
        }
        public ControllerContext(IController controller, RequestContext requestContext, RouteData routeData)
        {
            Requires.NotNull(controller, "controller");
            Requires.NotNull(requestContext, "requestContext");
            Requires.NotNull(routeData, "routeData");

            _controller = controller;
            _requestContext = requestContext;
            _routeData = routeData;
        }