예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MvcServer"/> class.
        /// </summary>
        public MvcServer()
        {
            _current = this;
            Add(this);
            _viewEngines = new ViewEngineCollection();

            // register built in actions
            _actions.Register(_actionProvider);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MvcServer"/> class.
        /// </summary>
        public MvcServer()
        {
            _current = this;
            Add(this);
            _viewEngines = new ViewEngineCollection();

            // register built in actions
            _actions.Register(_actionProvider);
        }
예제 #3
0
        /// <summary>
        /// Process a request.
        /// </summary>
        /// <param name="context">Request information</param>
        /// <returns>What to do next.</returns>
        public ProcessingResult Process(RequestContext context)
        {
            _current = this;
            var controllerContext = new ControllerContext(context);

            foreach (ControllerDirector director in _directors)
            {
                if (!director.CanProcess(controllerContext))
                {
                    continue;
                }

                _logger.Debug("Controller '" + director.Uri + "' is handling the request.");
                Controller controller = null;
                try
                {
                    object result = director.Process(controllerContext, out controller);
                    if (result == null)
                    {
                        continue;
                    }

                    var viewData = result as IViewData;
                    if (viewData != null)
                    {
                        _logger.Trace("Rendering action " + controllerContext.ActionName);
                        RenderView(controllerContext, viewData);
                    }
                    else
                    {
                        var action = result as IActionResult;
                        if (action != null)
                        {
                            ProcessingResult processingResult = _actionProvider.Invoke(context, action);
                            if (processingResult == ProcessingResult.Abort)
                            {
                                return(processingResult);
                            }
                        }
                    }

                    return(ProcessingResult.SendResponse);
                }
                finally
                {
                    // We want to keep the controller during the whole
                    // rendering process. To be able to access the controller from
                    // the view.
                    if (controller != null)
                    {
                        director.Enqueue(controller);
                    }
                }
            }

            return(ProcessingResult.Continue);
        }
예제 #4
0
 public HttpServant()
 {
     this._server = new MvcServer()
     {
         ServerName = String.Format(
             "MetaTweet/{0} ({1}) HttpServant/{2}",
             ThisAssembly.EntireVersion,
             Environment.OSVersion.Platform,
             ThisAssembly.CombinedShortVersionInfo
         ),
     };
 }
예제 #5
0
        /// <summary>
        /// Process a request.
        /// </summary>
        /// <param name="context">Request information</param>
        /// <returns>What to do next.</returns>
        public ProcessingResult Process(RequestContext context)
        {
            _current = this;
            var routingContext = new RoutingContext(context.Request);
            var routeResult    = RoutingService.Route(routingContext);

            if (routeResult == null)
            {
                return(ProcessingResult.Continue);
            }

            var controllerContext = new ControllerContext(context)
            {
                ActionName = routeResult.ActionName, ControllerUri = routeResult.ControllerUri
            };
            var result = _factory.Invoke(routeResult.ControllerType, routeResult.Action, controllerContext);

            var viewData = result as IViewData;

            if (viewData != null)
            {
                _logger.Trace("Rendering action " + controllerContext.ActionName);
                RenderView(controllerContext, viewData);
            }
            else
            {
                var action = result as IActionResult;
                if (action != null)
                {
                    ProcessingResult processingResult = _actionProvider.Invoke(context, action);
                    if (processingResult == ProcessingResult.Abort)
                    {
                        return(processingResult);
                    }
                }
            }

            return(ProcessingResult.SendResponse);
        }
예제 #6
0
        private static void Main(string[] args)
        {
            // Log everything to console.
            LogFactory.Assign(new ConsoleLogFactory(null));

            Assembly thisAssembly = typeof (Program).Assembly;

            // create a MVC web server.
            var server = new MvcServer();
            server.ViewEngines.Add(new NHamlViewEngine());
            server.Add(HttpListener.Create(IPAddress.Any, 8080));
            server.Add(new SimpleRouter("/", "/user/"));

            // Load controllers and embedded views.
            BootStrapper bootStrapper = new BootStrapper(server);
            bootStrapper.LoadEmbeddedViews(thisAssembly);
            bootStrapper.LoadControllers(thisAssembly);

            server.Start(5);

            // run until you press enter.
            Console.ReadLine();
        }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BootStrapper"/> class.
 /// </summary>
 /// <param name="server">The server.</param>
 public BootStrapper(MvcServer server)
 {
     _server = server;
     _server.ViewProvider.Add(_resource);
 }
예제 #8
0
        /// <summary>
        /// Process a request.
        /// </summary>
        /// <param name="context">Request information</param>
        /// <returns>What to do next.</returns>
        public ProcessingResult Process(RequestContext context)
        {
            _current = this;
            var routingContext = new RoutingContext(context.Request);
            var routeResult = RoutingService.Route(routingContext);
            if (routeResult == null)
                return ProcessingResult.Continue;

            var controllerContext = new ControllerContext(context)
                                        {ActionName = routeResult.ActionName, ControllerUri = routeResult.ControllerUri};
            var result = _factory.Invoke(routeResult.ControllerType, routeResult.Action, controllerContext);

            var viewData = result as IViewData;
            if (viewData != null)
            {
                _logger.Trace("Rendering action " + controllerContext.ActionName);
                RenderView(controllerContext, viewData);
            }
            else
            {
                var action = result as IActionResult;
                if (action != null)
                {
                    ProcessingResult processingResult = _actionProvider.Invoke(context, action);
                    if (processingResult == ProcessingResult.Abort)
                        return processingResult;
                }
            }

            return ProcessingResult.SendResponse;

        }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BootStrapper"/> class.
 /// </summary>
 /// <param name="server">The server.</param>
 public BootStrapper(MvcServer server)
 {
     _server = server;
     _server.ViewProvider.Add(_resource);
 }
예제 #10
0
 /// <summary>
 /// Installs the Spark view engine. Settings passed in.
 /// </summary>
 public static void RegisterViewEngine(MvcServer server, ISparkSettings settings)
 {
     server.ViewEngines.Add(CreateViewEngine(settings));
 }
예제 #11
0
 /// <summary>
 /// Installs the Spark view engine. Settings come from config or are defaulted.
 /// </summary>
 public static void RegisterViewEngine(MvcServer server)
 {
     server.ViewEngines.Add(CreateViewEngine());
 }
예제 #12
0
 /// <summary>
 /// Installs the Spark view engine. Container passed in.
 /// </summary>
 public static void RegisterViewEngine(MvcServer server, ISparkServiceContainer container)
 {
     server.ViewEngines.Add(container.GetService<IViewEngine>());
 }
예제 #13
0
        /// <summary>
        /// Process a request.
        /// </summary>
        /// <param name="context">Request information</param>
        /// <returns>What to do next.</returns>
        public ProcessingResult Process(RequestContext context)
        {
            _current = this;
            var controllerContext = new ControllerContext(context);

            foreach (ControllerDirector director in _directors)
            {
                if (!director.CanProcess(controllerContext))
                    continue;

                _logger.Debug("Controller '" + director.Uri + "' is handling the request.");
                Controller controller = null;
                try
                {
                    object result = director.Process(controllerContext, out controller);
                    if (result == null)
                        continue;

                    var viewData = result as IViewData;
                    if (viewData != null)
                    {
                        _logger.Trace("Rendering action " + controllerContext.ActionName);
                        RenderView(controllerContext, viewData);
                    }
                    else
                    {
                        var action = result as IActionResult;
                        if (action != null)
                        {
                            ProcessingResult processingResult = _actionProvider.Invoke(context, action);
                            if (processingResult == ProcessingResult.Abort)
                                return processingResult;
                        }
                    }

                    return ProcessingResult.SendResponse;
                }
                finally
                {
                    // We want to keep the controller during the whole
                    // rendering process. To be able to access the controller from
                    // the view.
                    if (controller != null)
                        director.Enqueue(controller);
                }
            }

            return ProcessingResult.Continue;
        }