Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #4
0
 public HttpServant()
 {
     this._server = new MvcServer()
     {
         ServerName = String.Format(
             "MetaTweet/{0} ({1}) HttpServant/{2}",
             ThisAssembly.EntireVersion,
             Environment.OSVersion.Platform,
             ThisAssembly.CombinedShortVersionInfo
         ),
     };
 }
Beispiel #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);
        }
Beispiel #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();
        }
Beispiel #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);
 }
Beispiel #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;

        }
Beispiel #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);
 }
 /// <summary>
 /// Installs the Spark view engine. Settings passed in.
 /// </summary>
 public static void RegisterViewEngine(MvcServer server, ISparkSettings settings)
 {
     server.ViewEngines.Add(CreateViewEngine(settings));
 }
 /// <summary>
 /// Installs the Spark view engine. Settings come from config or are defaulted.
 /// </summary>
 public static void RegisterViewEngine(MvcServer server)
 {
     server.ViewEngines.Add(CreateViewEngine());
 }
 /// <summary>
 /// Installs the Spark view engine. Container passed in.
 /// </summary>
 public static void RegisterViewEngine(MvcServer server, ISparkServiceContainer container)
 {
     server.ViewEngines.Add(container.GetService<IViewEngine>());
 }
Beispiel #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;
        }