Esempio n. 1
0
        public bool Verify()
        {
            foreach (IWebElement naviLink in _topNavigationLinks)
            {
                String href = naviLink.GetAttribute("href");

                _response = HttpRequestDispatcher.Perform(href);

                if (_response.StatusCode == HttpStatusCode.OK)
                {
                    continue;
                }
                else
                {
                    _erroringLinks.Add(href);
                    continue;
                }
            }

            if (_erroringLinks.Count == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
 public HttpServerContext(ServerConfig config)
 {
     ServerConfig      = config;
     ResourceMapping   = new HttpResourceMapping(this);
     RequestDispatcher = new HttpRequestDispatcher(this);
     tcpConnection     = new TcpConnection(this);
     SessionPool       = new HttpSessionPool(this);
 }
 public HttpRequestContext(HttpRequestDispatcher dispatcher, HttpListenerContext context, string route)
 {
     this.Dispatcher    = dispatcher;
     this.Route         = route;
     this.BaseContext   = context;
     this.RequestBody   = HttpUtility.UrlDecode(context.Request.InputStream.ReadToNull(), Encoding.UTF8);
     this.RemoteAddress = context.Request.RemoteEndPoint.Address.ToString();
     this.UserAgent     = context.Request.UserAgent;
     this.Parameters    = this.ParseParams();
 }
Esempio n. 4
0
        public void InitializeHttpApi()
        {
            _httpServer = new HttpServer();
            HttpRequestDispatcher httpRequestDispatcher = new HttpRequestDispatcher(_httpServer);

            _apiController = httpRequestDispatcher.GetController("api");
            _apiController.Handle(HttpMethod.Get, "read").Using(HandleApiRead);
            _apiController.Handle(HttpMethod.Post, "write").Using(HandleApiWrite);
            _httpServer.StartAsync(80).Wait();
        }
        private void InitializeHttpApi()
        {
            _httpServer = new HttpServer();
            var httpRequestDispatcher = new HttpRequestDispatcher(_httpServer);

            HttpApiController = httpRequestDispatcher.GetController("api");

            var appPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "app");

            httpRequestDispatcher.MapFolder("app", appPath);
        }
        private void InitializeHttpApiEndpoint()
        {
            _httpServer = new HttpServer();

            var httpApiDispatcherEndpoint = new LocalHttpServerApiDispatcherEndpoint(_httpServer);

            ApiController.RegisterEndpoint(httpApiDispatcherEndpoint);

            var httpRequestDispatcher = new HttpRequestDispatcher(_httpServer);

            httpRequestDispatcher.MapFolder("App", StoragePath.WithFilename("App"));
            httpRequestDispatcher.MapFolder("Storage", StoragePath.Root);
        }
Esempio n. 7
0
        static void RunServer()
        {
            var config = ConfigLoadingManager.GetInstance().GetConfig();

            SortedDictionary <string, RouteHandler> routeHandlers = new SortedDictionary <string, RouteHandler>();

            routeHandlers.Add("/article/latest", ArticleHandler.GetInstance());
            routeHandlers.Add("/article", ArticleHandler.GetInstance());
            routeHandlers.Add("/interpreter", InterpreterHandler.GetInstance());

            SortedList <string, RouteHandler> regexRouteHandlers = new SortedList <string, RouteHandler>();

            regexRouteHandlers.Add(@"\/article\/\d+$", ArticleHandler.GetInstance());

            LogManager exceptionLogger = new LogManager(ConfigLoadingManager.GetInstance().GetConfig().ExceptionLogFile);
            LogManager accessLogger    = new LogManager(ConfigLoadingManager.GetInstance().GetConfig().AccessLogFile);

            ExecuteRouteHandler executeRouteHandler = new ExecuteRouteHandler {
                RouteHandlers = routeHandlers, RegexRouteHandlers = regexRouteHandlers, ExceptionLogger = exceptionLogger, AccessLogger = accessLogger
            };

            HttpRequestDispatcher httpDispatcher  = null;
            HttpRequestDispatcher httpsDispatcher = null;

            if (config.HttpListenAddress.IsAvailable())
            {
                httpDispatcher = new HttpRequestDispatcher();
                httpDispatcher.Start(config.HttpListenAddress.IP, config.HttpListenAddress.Port,
                                     config.SessionReadBufferSize, config.SessionNoActionTimeout,
                                     executeRouteHandler.HttpRequestHandler, executeRouteHandler.InternalServerError,
                                     exceptionLogger);
                Console.WriteLine("Http Server - " + Environment.NewLine + config.HttpListenAddress.IP + ":" + config.HttpListenAddress.Port);
            }
            if (config.HttpsListenAddress.IsAvailable())
            {
                httpsDispatcher = new HttpRequestDispatcher();
                httpsDispatcher.Start(config.HttpsListenAddress.IP, config.HttpsListenAddress.Port,
                                      config.SessionReadBufferSize, config.SessionNoActionTimeout,
                                      new X509Certificate2(config.HttpsPfxCertificate, config.HttpsPfxCertificatePassword),
                                      executeRouteHandler.HttpRequestHandler, executeRouteHandler.InternalServerError,
                                      exceptionLogger);
                Console.WriteLine("Https Server - " + Environment.NewLine + config.HttpsListenAddress.IP + ":" + config.HttpsListenAddress.Port);
            }
            if (httpDispatcher == null && httpsDispatcher == null)
            {
                return;
            }

            exceptionLogger.LogAsync("startup successfully");

            bool   stopFlag = false;
            object mut      = new object();

            new Thread(() =>
            {
                const int second = 5;
                Thread.Sleep(second * 1000);
                while (true)
                {
                    Console.Clear();
                    Console.Write("Active Session: " + (httpDispatcher.SessionCount + httpsDispatcher.SessionCount).ToString());
                    lock (mut)
                    {
                        for (int i = 0; i < second; i++)
                        {
                            if (stopFlag)
                            {
                                return;
                            }
                            Console.Write('.');
                            Monitor.Wait(mut, 1000);
                            if (stopFlag)
                            {
                                return;
                            }
                        }
                    }
                }
            }).Start();

            Console.WriteLine("press any key to shut down...");
            Console.ReadKey();

            lock (mut)
            {
                stopFlag = true;
                Monitor.Pulse(mut);
            }

            //stop dispatcher
            if (httpDispatcher != null)
            {
                httpDispatcher.Stop();
            }
            if (httpsDispatcher != null)
            {
                httpsDispatcher.Stop();
            }

            //stop logic
            ArticleHandler.GetInstance().Stop();

            exceptionLogger.LogAsync("stopped");

            //stop logger
            exceptionLogger.Stop();
            accessLogger.Stop();
        }