コード例 #1
0
ファイル: Router.cs プロジェクト: can-acar/mvc
        public void Match(string url)
        {
            Meta = new RouteMeta
            {
                Route = _route
            };
            Match ignoreRoute = Regex.Match(url, "(.*/)?favicon.ico(/.*)?");

            if (!ignoreRoute.Success)
            {
                foreach (var route in RouterCollection)
                {
                    Regex expression = new Regex(route.GetFormat());


                    if (expression.IsMatch(url))
                    {
                        Meta        = ToDefault(route.GetDefault());
                        Meta.Route  = route;
                        Meta.Router = this;

                        var Matches = expression.Match(url);

                        if (Matches.Success)
                        {
                            foreach (string key in expression.GetGroupNames())
                            {
                                int isInt;
                                if (Int32.TryParse(key, out isInt) == false)
                                {
                                    if (Matches.Groups[key].ToString() != "")
                                    {
                                        Meta[key] = Matches.Groups[key].ToString();
                                    }
                                }
                            }
                        }

                        break;
                    }
                }
            }
        }
コード例 #2
0
ファイル: ControllerFactory.cs プロジェクト: can-acar/mvc
        public IController CreateController(HttpContext context, RouteMeta meta)
        {
            string ControllerNmae = meta.Controller;


            if (meta.Controller == null)
            {
                return(null);
            }

            Type controllerType = GetController(ControllerNmae);  // GetController(meta.Controller);


            IController result = (IController)Activator.CreateInstance(controllerType);

            result.Context = context;
            result.Request = context.Request;

            return(result);
        }
コード例 #3
0
ファイル: Controller.cs プロジェクト: can-acar/mvc
        //public void Execute(HttpContext context, RouteMeta routeData)
        //{
        //    String actionName = routeData.Action;
        //    MethodInfo action = FindAction(actionName);

        //    if (actionName == null || action == null)
        //        return null;

        //    actionName = action.Name;

        //    InvokeAction(action);


        //    string html = "";

        //    foreach (KeyValuePair<string, object> listOfparams in this.ViewData)
        //    {
        //        html += "Params" + listOfparams.Key + "----" + "value" + listOfparams.Value;
        //    }
        //    Render(context,actionName);
        //    return html.ToString() ?? "";
        //}


        public void Execute(HttpContext context, RouteMeta routeData)
        {
            String     actionName = routeData.Action;
            MethodInfo action     = FindAction(actionName);

            //if (actionName == null || action == null)
            //    return null;

            actionName = action.Name;

            InvokeAction(action);


            string html = "";

            foreach (KeyValuePair <string, object> listOfparams in this.ViewData)
            {
                html += "Params" + listOfparams.Key + "----" + "value" + listOfparams.Value;
            }
            Render(context, actionName);

            //return html.ToString() ?? "";
        }
コード例 #4
0
        public IRouteMeta Match(string url)
        {
            RouteMeta result = new RouteMeta
            {
                Router = this,
                Route  = this.Route
            };

            foreach (var route in RouterCollection)
            {
                Regex expression = new Regex(route.GetFormat());

                Match match = expression.Match(url);

                if (!match.Success)
                {
                    return(null);
                }



                foreach (var key in _toDefault.Keys)
                {
                    result[key] = _toDefault[key];
                }

                foreach (var part in _parts)
                {
                    //var group = match.Groups[part.Name];
                }

                /*if (expression.IsMatch(url))
                 * {
                 * // Meta.Route =(IRoute) route;
                 * // Meta.Rule =(string) route.Rule;
                 *
                 *  Meta = ToDefault(route.GetDefault());
                 *
                 *  var Matches = expression.Match(url);
                 *
                 *  if (Matches != null)
                 *  {
                 *      foreach (string key in expression.GetGroupNames())
                 *      {
                 *          int isInt;
                 *          if (Int32.TryParse(key, out isInt) == false)
                 *          {
                 *              if (Matches.Groups[key].ToString() != "")
                 *              {
                 *                  Meta[key] = Matches.Groups[key].ToString();
                 *              }
                 *          }
                 *      }
                 *
                 *  }
                 *
                 *  break;
                 * }*/
            }
            return(result);
        }