示例#1
0
        public static async Task RunAsync(IMvcApplication application, int port)
        {
            ServerRoutingTable = new ServerRoutingTable();
            IServiceCollection serviceCollection = new ServiceCollection();

            application.ConfigureServices(serviceCollection);
            application.Configure(ServerRoutingTable);

            ServerRoutingTable
            .LoadControllers(application.GetType().Assembly, serviceCollection)
            .LoadStaticFiles();

            Console.WriteLine(string.Join(Environment.NewLine, ServerRoutingTable.GetAllRouteNames()));

            TcpListener listener = new TcpListener(IPAddress.Parse(LocalhostIpAddress), port);

            listener.Start();
            IsRunning = true;

            Console.WriteLine($"Server started at http://{LocalhostIpAddress}:{port}");

            while (IsRunning)
            {
                Console.WriteLine("Waiting for client...");

                var client = await listener.AcceptSocketAsync();

                ListenAsync(client);
            }
        }
示例#2
0
        public static async Task CreateHostAsync(IMvcApplication application, int post = 80)
        {
            List <Route>       routeTable        = new List <Route>();
            IServiceCollection serviceCollection = new ServiceCollection();

            AutoRegisterStaticFiles(routeTable);

            application.ConfigureServices(serviceCollection);
            application.Configure(routeTable);

            AutoRegisterRoutes(routeTable, application, serviceCollection);

            Console.WriteLine("Registered routes:");
            foreach (var route in routeTable)
            {
                Console.WriteLine($"{route.Method} => {route.Path}");
            }
            Console.WriteLine();
            Console.WriteLine("Requests:");

            IHttpServer server = new HttpServer(routeTable);

            //If we want to auto-start the HomePage or any other page
            //Process.Start(@"C:\Program Files\Mozilla Firefox\firefox.exe", "http://localhost/");
            await server.StartAsync(80);
        }
示例#3
0
        public static async Task CreateHostAsync(IMvcApplication application, int port = 80)
        {
            var routeTable        = new List <Route>();
            var serviceCollection = new ServiceCollection();

            //We pass "application" so we can access the executing assembly ang get all types -> GetTypes().

            application.ConfigureServices(serviceCollection);
            application.Configure(routeTable);

            AutoGenerateStaticFiles(routeTable);
            AutoRegisterRoutes(routeTable, application, serviceCollection);

            //For debugging purposes
            System.Console.WriteLine("All registered routes");
            foreach (var route in routeTable)
            {
                System.Console.WriteLine($"{route.Method} => {route.Path}");
            }

            IHttpServer server = new HttpServer(routeTable);

            //If we don't "await" here, the app will close after receiving the first client. Now, it will keep listening (tcpListener).
            await server.StartAsync(80);
        }
示例#4
0
        public static async Task CreateHostAsync(IMvcApplication application, int port = 80)
        {
            // TODO: {controller}/{action}/{id}
            List <Route>       routeTable        = new List <Route>();
            IServiceCollection serviceCollection = new ServiceCollection();

            application.ConfigureServices(serviceCollection);
            application.Configure(routeTable);

            AutoRegisterStaticFile(routeTable);
            AutoRegisterRoutes(routeTable, application, serviceCollection);

            Console.WriteLine("Registered routes:");
            foreach (var route in routeTable)
            {
                Console.WriteLine($"{route.Method} {route.Path}");
            }

            Console.WriteLine();
            Console.WriteLine("Requests:");
            IHttpServer server = new HttpServer(routeTable);

            // Process.Start(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "http://localhost/");
            await server.StartAsync(port);
        }
示例#5
0
        public static async Task StartAsync(IMvcApplication application)
        {
            IList <Route> routeTable = new List <Route>();

            IServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.Add <ILogger, ConsoleLogger>();

            application.ConfigureServices(serviceCollection);
            application.Configure(routeTable);
            AutoRegisterStaticFilesRoutes(routeTable);
            AutoRegisterActionRoutes(routeTable, application, serviceCollection);

            var logger = serviceCollection.CreateInstance <ILogger>();

            logger.Log("Registered routes:");
            foreach (var route in routeTable)
            {
                logger.Log(route.ToString());
            }

            logger.Log(string.Empty);
            logger.Log("Requests:");
            var httpServer = new HttpServer(80, routeTable, logger);
            await httpServer.StartAsync();
        }
示例#6
0
文件: Host.cs 项目: 00mjk/CSharp-Web
        public static async Task CreateHostAsync(IMvcApplication application, int port = 80)
        {
            List <Route> routeTable = new List <Route>();

            IServiceCollection serviceCollection = new ServiceCollection();

            application.ConfigureServices(serviceCollection);

            application.Configure(routeTable);

            AutoRegisterStaticFile(routeTable);

            AutoRegisterRoutes(routeTable, application, serviceCollection);

            Console.WriteLine("Registered routes:");
            foreach (var route in routeTable)
            {
                Console.WriteLine($"{route.Method} " +
                                  $"{route.Path}");
            }

            Console.WriteLine();

            Console.WriteLine("Requests:");

            IHttpServer server = new HttpServer(routeTable);

            await server.StartAsync(port);
        }
示例#7
0
        public static async Task StartAsync(IMvcApplication application)
        {
            var routeTable = new List <Route>();

            application.ConfigureServices();
            application.Configure(routeTable);
            var httpServer = new HttpServer(80, routeTable);
            await httpServer.StartAsync();
        }
示例#8
0
        public static void Start(IMvcApplication application)
        {
            IServerRoutingTable serverRoutingTable = new ServerRoutingTable();
            IHttpSessionStorage httpSessionStorage = new HttpSessionStorage();
            IServiceProvider    serviceProvider    = new ServiceProvider();

            serviceProvider.Add <ILogger, ConsoleLogger>();

            application.ConfigureServices(serviceProvider);

            AutoRegisterRoutes(application, serverRoutingTable, serviceProvider);
            application.ConfigureServices(serviceProvider);
            application.Configure(serverRoutingTable);

            var server = new Server(8000, serverRoutingTable, httpSessionStorage);

            server.Run();
        }
示例#9
0
        public static async Task RunAsync(IMvcApplication application, int port = 80)
        {
            List <Route> routeTable = new List <Route>();

            application.ConfigureServices();
            application.Configure(routeTable);

            IHttpServer server = new Server(routeTable);
            await server.StartAsync(port);
        }
示例#10
0
        public static void Start(IMvcApplication application)
        {
            IServiceCollection services = InitializeServices();

            application.ConfigureServices(services);
            application.Configure();
            Server    server = new Server(Constants.ServerHostPort, services);
            MvcEngine engine = new MvcEngine(server);

            engine.Run();
        }
示例#11
0
        public static void Start(IMvcApplication application)
        {
            IServerRoutingTable serverRoutingTable = new ServerRoutingTable();

            AutoRegisterRoutes(application, serverRoutingTable);
            application.ConfigureServices();
            application.Configure(serverRoutingTable);
            var server = new Server(8000, serverRoutingTable);

            server.Run();
        }
示例#12
0
        public static async Task CreateHostAsync(IMvcApplication mvcApplication, int port = 80)
        {
            List <Route> routeTable = new List <Route>();

            mvcApplication.ConfigureServices();
            mvcApplication.Configure(routeTable);

            IHttpServer server = new HttpServer(routeTable);

            await server.StartAsync(80);
        }
示例#13
0
        public static async Task CreateHostAsync(IMvcApplication application, int port = 80)
        {
            // TODO: {controller}/{action}/{id}
            List <Route> routeTable = new List <Route>();

            application.ConfigureServices();
            application.Configure(routeTable);

            IHttpServer server = new HttpServer(routeTable);

            // Process.Start(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "http://localhost/");
            await server.StartAsync(port);
        }
示例#14
0
        public static async Task StartASync(IMvcApplication application)
        {
            var routeTable = new List <Route>();

            application.ConfigureServices();
            application.Configure(routeTable);
            AutoRegisterStaticFilesRoutes(routeTable);
            AutoRegisterActionRoutes(routeTable, application);

            var httpServer = new HttpServer(80, routeTable);

            await httpServer.StartAsync();
        }
示例#15
0
        public static async Task CreateHostAsync(IMvcApplication application, int port = 80)
        {
            List <Route> routeTable = new List <Route>();

            AutoRegisterStaticFiles(routeTable);
            AutoRegisterRoutes(routeTable, application);

            application.ConfigureServices();
            application.Configure(routeTable);
            IHttpServer server = new HttpServer(routeTable);

            await server.StartAsync(port);
        }
示例#16
0
        public static void Start(IMvcApplication application)
        {
            IDependencyContainer container = new DependencyContainer();

            application.ConfigureServices(container);

            var controllerRouter = new HttpRouteHandlingContext(new ControllerRouter(container), new ResourceRouter());

            application.Configure();

            Server server = new Server(HostingPort, controllerRouter);

            server.Run();
        }
示例#17
0
        public static void Start(IMvcApplication application)
        {
            IServerRoutingTable serverRoutingTable = new ServerRoutingTable();
            IHttpSessionStorage sessiontorage      = new HttpSessionStorage();

            AutoRegisterRoutes(application, serverRoutingTable);
            application.ConfigureServices();

            application.Configure(serverRoutingTable);

            Server server = new Server(8000, serverRoutingTable, sessiontorage);

            server.Run();
        }
示例#18
0
        public static void Start(IMvcApplication application)
        {
            IDependencyContainer container = new DependencyContainer();

            application.ConfigureServices(container);

            IHttpHandler controllerRouter = new ControllerRouter(container);

            application.Configure();

            var server = new Server(HostingPort, controllerRouter);

            server.Run();
        }
        public static void Start(IMvcApplication application)
        {
            var container = new DependencyContainer();

            application.ConfigureServices(container);

            var handlers = new HttpHandlerContextRouter(new ControllerRouter(container), new ResourceRouter());

            application.Configure();

            var server = new Server(Port, handlers);

            server.Run();
        }
示例#20
0
        public static async Task RunAsync(IMvcApplication application, int port = 80)
        {
            IServiceCollection  serviceCollection = new ServiceCollection();
            ICollection <Route> routeTable        = new HashSet <Route>();

            application.ConfigureServices(serviceCollection);
            application.Configure(routeTable);

            AutoRegisterStaticFile(routeTable);
            AutoRegisterRoutes(routeTable, application, serviceCollection);

            IHttpServer server = new HttpServer(routeTable);
            await server.StartAsync(port);
        }
示例#21
0
        public static async Task CreateHostAsync(IMvcApplication application, int port = 80)
        {
            var routeTable = new List <Route>();
            IServiceCollection serviceCollection = new ServiceCollection();

            application.ConfigureServices(serviceCollection);
            application.Configure(routeTable);

            AutoRegisterStaticFiles(routeTable);
            AutoRegisterRoutes(routeTable, application, serviceCollection);

            var httpServer = new HttpServer(routeTable);

            await httpServer.StartAsync(port);
        }
示例#22
0
        public static void Start(IMvcApplication application)
        {
            IDependencyContainer container = new DependencyContainer();

            application.ConfigureServices(container);

            IHandleable controllerRouter = new ControllerRouter(container);
            IHandleable resourceRouter   = new ResourceRouter();

            application.Configure();

            Server server = new Server(HostingPort, controllerRouter, resourceRouter);

            MvcEngine.Run(server);
        }
示例#23
0
        public static void Start(IMvcApplication application)
        {
            var dependencyContainer = new ServiceCollection();

            application.ConfigureServices(dependencyContainer);

            var serverRoutingTable = new ServerRoutingTable();

            AutoRegisterRoutes(serverRoutingTable, application, dependencyContainer);

            application.Configure();

            var server = new Server(80, serverRoutingTable);

            server.Run();
        }
示例#24
0
        public static void Start(IMvcApplication application)
        {
            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;

            ServiceCollection dependencyContainer = new ServiceCollection();

            application.ConfigureServices(dependencyContainer);

            ServerRoutingTable serverRoutingTable = new ServerRoutingTable();

            AutoRegisterRoutes(serverRoutingTable, application, dependencyContainer);

            Server server = new Server(8230, serverRoutingTable);

            server.Run();
        }
示例#25
0
        public static void Start(IMvcApplication application)
        {
            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;

            IServiceCollection serviceCollection = new ServiceCollection();

            application.ConfigureServices(serviceCollection);

            var serverRoutingTable = new ServerRoutingTable();

            AutoRegisterRoutes(application, serverRoutingTable, serviceCollection);

            application.Configure();

            new Server(80, serverRoutingTable).Run();
        }
示例#26
0
        public static async Task StartAsync(IMvcApplication application)
        {
            var routeTable = new List <HttpRoute>();

            IServiceCollection serviceCollection = new ServiceCollection();

            application.ConfigureServices(serviceCollection);

            application.Configure(routeTable);

            GenerateRouteTable(routeTable, serviceCollection);

            HttpServer httpServer = new HttpServer(80, routeTable);

            await httpServer.StartAsync();
        }
示例#27
0
        public static void Run(IMvcApplication startUp)
        {
            IServerRoutingTable serverRoutingTable = new ServerRoutingTable();
            IHttpSessionStorage httpSessionStorage = new HttpSessionStorage();

            DependencyContainer.IServiceProvider serviceProvider = new DependencyContainer.ServiceProvider();

            startUp.ConfigureServices(serviceProvider);

            AutoRegisterRoutes(startUp, serverRoutingTable, serviceProvider);

            startUp.Configure(serverRoutingTable);

            var server = new Server(8000, serverRoutingTable, httpSessionStorage);

            server.Run();
        }
示例#28
0
        public static void Start(IMvcApplication application)
        {
            IDependencyContainer container = new DependencyContainer();

            application.ConfigureServices(container);
            IControllerRouter controllerRouter = new ControllerRouter(container);
            IResourceRouter   resourceRouter   = container.CreateInstance <IResourceRouter>();
            IRouter           router           = new Router(controllerRouter, resourceRouter);

            MvcContext.Get.AssemblyName = Assembly
                                          .GetEntryAssembly()
                                          .GetName()
                                          .Name;
            Server server = new Server(HostingPort, router);

            server.Run();
        }
示例#29
0
        public static void Start(IMvcApplication application)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var dependecyContainer = new ServiceCollection();

            application.ConfigureServices(dependecyContainer);

            ServerRoutingTable table = new ServerRoutingTable();

            AutoRegisterRoutes(table, application, dependecyContainer);

            application.Configure();

            Server server = new Server(8000, table);

            server.Run();
        }
示例#30
0
        public static void Start(IMvcApplication application)
        {
            IServerRoutingTable serverRoutingTable = new ServerRoutingTable();
            IHttpSessionStorage httpSessionStorage = new HttpSessionStorage();
            IServiceProvider    serviceProvider    = new ServiceProvider();
            RouteSettings       routeSettings      = new RouteSettings {
                UnauthorizedRedirectRoute = GlobalConstants.RedirectPath
            };

            serviceProvider.Add <ILogger, ConsoleLogger>();

            application.ConfigureServices(serviceProvider);
            application.Configure(serverRoutingTable, routeSettings);
            AutoRegisterRoutes(application, serverRoutingTable, serviceProvider, routeSettings);
            Server server = new Server(8000, serverRoutingTable, httpSessionStorage);

            server.Run();
        }