Exemplo n.º 1
0
            /// <summary>
            /// Detect and register all available controller in the system
            /// </summary>
            /// <param name="context">CodeContext, passed from IronPython automatically</param>
            public static void register_all(CodeContext context)
            {
                // Get all Controller in the current scope
                var items = MvcApplication.Host.DefaultScope.ScriptScope.GetItems();

                var pythonController = DynamicHelpers.GetPythonTypeFromType(typeof(AspNetMvcAPI.Controller));

                foreach (var item in items)
                {
                    // Check type and get controller
                    if (item.Value is PythonType)
                    {
                        var pt       = (PythonType)item.Value;
                        var baseType = pt.__getattribute__(context, "__base__");

                        // If is controlelr
                        if (baseType == pythonController)
                        {
                            // Add to controller list
                            __controllers.Add(item.Key.Replace("Controller", ""), pt);
                        }
                    }
                }

                // Register routes
                var routes = System.Web.Routing.RouteTable.Routes;

                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");


                routes.MapRoute(
                    name: "Default",
                    url: "{controller}/{action}/{id}",
                    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                    );

                IControllerFactory factory = new CustomControllerFactory();

                ControllerBuilder.Current.SetControllerFactory(factory);
            }
            /// <summary>
            /// Detect and register all available controller in the system
            /// </summary>
            /// <param name="context">CodeContext, passed from IronPython automatically</param>
            public static void register_all(CodeContext context)
            {
                // Get all Controller in the current scope
                var items = MvcApplication.Host.DefaultScope.ScriptScope.GetItems();

                var pythonController = DynamicHelpers.GetPythonTypeFromType(typeof(AspNetMvcAPI.Controller));

                foreach (var item in items)
                {
                    // Check type and get controller
                    if (item.Value is PythonType)
                    {
                        var pt = (PythonType)item.Value;
                        var baseType = pt.__getattribute__(context, "__base__");

                        // If is controlelr
                        if (baseType == pythonController)
                        {
                            // Add to controller list
                            __controllers.Add(item.Key.Replace("Controller", ""), pt);
                        }
                    }
                }

                // Register routes
                var routes = System.Web.Routing.RouteTable.Routes;
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

                routes.MapRoute(
                    name: "Default",
                    url: "{controller}/{action}/{id}",
                    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                );

                IControllerFactory factory = new CustomControllerFactory();
                ControllerBuilder.Current.SetControllerFactory(factory);
            }