예제 #1
0
        public override bool Execute(string[] arguments)
        {
            const string url = "http://localhost:8082/";

            BookGenArgumentBase args = new BookGenArgumentBase();

            if (!ArgumentParser.ParseArguments(arguments, args))
            {
                return(false);
            }

            using (var server = HttpServerFactory.CreateServerForPreview(CurrentState.Log, CurrentState.ServerLog, args.Directory))
            {
                server.Start();
                CurrentState.Log.Info("-------------------------------------------------");
                CurrentState.Log.Info("Test server running on: {0}", url);
                CurrentState.Log.Info("Serving from: {0}", args.Directory);

                if (Program.AppSetting.AutoStartWebserver)
                {
                    GeneratorRunner.StartUrl(url);
                }

                Console.WriteLine(GeneratorRunner.ExitString);
                Console.ReadLine();
                server.Stop();
            }
            return(true);
        }
예제 #2
0
        public void ShouldBeAbleToHostAtSameAddressIfPreviousWasDisposed()
        {
            var serverFactory = new HttpServerFactory();

            var uri = new Uri(String.Format("http://localhost:{0}", PortHelper.FindLocalAvailablePortForTesting()));
            IHttpServer server1, server2 = null;
            server1 = serverFactory.Get(uri).WithNewContext(uri.AbsoluteUri);
            try
            {
                server1.Start();
                server1.Dispose();
                server1 = null;

                server2 = serverFactory.Get(uri).WithNewContext(uri.AbsoluteUri);
                Assert.DoesNotThrow(server2.Start);
            }
            finally
            {
                if (server1 != null)
                {
                    server1.Dispose();
                }
                if (server2 != null)
                {
                    server2.Dispose();
                }
            }
        }
예제 #3
0
        public void ShouldBeAbleToHostAtSameAddressIfPreviousWasDisposed()
        {
            var serverFactory = new HttpServerFactory();

            var         uri = new Uri(HostHelper.GenerateAHostUrlForAStubServer());
            IHttpServer server1, server2 = null;

            server1 = serverFactory.Get(uri).WithNewContext();
            try
            {
                server1.Start();
                server1.Dispose();
                server1 = null;

                server2 = serverFactory.Get(uri).WithNewContext();
                Assert.DoesNotThrow(server2.Start);
            }
            finally
            {
                if (server1 != null)
                {
                    server1.Dispose();
                }
                if (server2 != null)
                {
                    server2.Dispose();
                }
            }
        }
        public void SetupMockHttp()
        {
            var serverFactory = new HttpServerFactory();

            _mockApi = serverFactory.Get(new Uri(_mockBaseUrl)).WithNewContext();

            _mockApi.Start();

            _mockApi.Stub(r => r.Get(_testUrl.simpleJson))
            .Return(@"{""name"":""first test""}")
            .AsContentType("application/json")
            .OK();

            // test status code ('Unavailable For Legal Reasons') not available in .NET HttpStatusCode enum
            _mockApi.Stub(r => r.Get(_testUrl.customStatusCode)).WithStatus((HttpStatusCode)451);

            _mockApi.Stub(r => r.Get(_testUrl.rateLimitHit))
            .Return(string.Empty)
            .WithStatus((HttpStatusCode)429);

            Func <string> wait = delegate() { System.Threading.Thread.Sleep(1000); return(string.Empty); };

            _mockApi.Stub(r => r.Get(_testUrl.cancel))
            .Return(wait)
            .OK();

            double unixTimestamp = UnixTimestampUtils.To(new DateTime(1981, 12, 2));

            _mockApi.Stub(r => r.Get(_testUrl.xrateheader))
            .AddHeader("X-Rate-Limit-Interval", "60")
            .AddHeader("X-Rate-Limit-Limit", "100000")
            .AddHeader("X-Rate-Limit-Reset", unixTimestamp.ToString())
            .OK();
        }
예제 #5
0
        public override bool Execute(string[] arguments)
        {
            BookGenArgumentBase args = new BookGenArgumentBase();

            if (!ArgumentParser.ParseArguments(arguments, args))
            {
                return(false);
            }

            CurrentState.Log.LogLevel = args.Verbose ? Api.LogLevel.Detail : Api.LogLevel.Info;

            FolderLock.ExitIfFolderIsLocked(args.Directory, CurrentState.Log);

            using (var l = new FolderLock(args.Directory))
            {
                using (var server = HttpServerFactory.CreateServerForServModule(CurrentState.ServerLog, args.Directory))
                {
                    server.Start();
                    Console.WriteLine("Serving: {0}", args.Directory);
                    Console.WriteLine("Server running on http://localhost:8081");
                    Console.WriteLine("Press a key to exit...");
                    Console.ReadLine();
                    server.Stop();
                }
            }

            return(true);
        }
예제 #6
0
        public void InitializeServerBeforeScenario()
        {
            var server     = HttpServerFactory.StartServer();
            var restClient = MyRestClientFactory.CreateRestClient(server);

            ScenarioContext.ScenarioContainer.RegisterInstanceAs(server, dispose: true);
            ScenarioContext.ScenarioContainer.RegisterInstanceAs(restClient, dispose: true);
        }
예제 #7
0
        static void Main(string[] args)
        {
            Logger.Log("Scheduler app started.", LogLevel.Info);
            var server = HttpServerFactory.CreateHost(Convert.ToInt32(_port));

            Logger.Log("Http-host initialized.", LogLevel.Info);

            Logger.Log("Starting http-server...", LogLevel.Info);
            server.Start();
            Logger.Log($"Http-server started. Hosted on: http://localhost:{_port}", LogLevel.Info);

            ConsoleClosure.WaitForExit();
            server.Stop();
        }
예제 #8
0
        public void DoTest()
        {
            if (_configuration == null)
            {
                throw new InvalidOperationException("Configuration is null");
            }

            if (_toc == null)
            {
                throw new InvalidOperationException("Table of contents is null");
            }

            Log.Info("Building test configuration...");
            _configuration.HostName = "http://localhost:8080/";

            var settings = _projectLoader.CreateRuntimeSettings(_configuration, _toc, _configuration.TargetWeb);


            using (var loader = new ShortCodeLoader(Log, settings, Program.AppSetting))
            {
                WebsiteBuilder builder = new WebsiteBuilder(settings, Log, loader, _scriptHandler);
                var            runTime = builder.Run();

                using (var server = HttpServerFactory.CreateServerForTest(ServerLog, Path.Combine(WorkDirectory, _configuration.TargetWeb.OutPutDirectory)))
                {
                    server.Start();
                    Log.Info("-------------------------------------------------");
                    Log.Info("Runtime: {0:0.000} ms", runTime.TotalMilliseconds);
                    Log.Info("Test server running on: http://localhost:8080/");
                    Log.Info("Serving from: {0}", _configuration.TargetWeb.OutPutDirectory);

                    if (Program.AppSetting.AutoStartWebserver)
                    {
                        StartUrl(_configuration.HostName);
                    }

                    Console.WriteLine(ExitString);
                    Console.ReadLine();
                    server.Stop();
                }
            }
        }
예제 #9
0
파일: Program.cs 프로젝트: ikvm/HTTPnet
        public static void Main(string[] args)
        {
            HttpNetTrace.TraceMessagePublished += (s, e) => Console.WriteLine("[" + e.Source + "] [" + e.Level + "] [" + e.Message + "] [" + e.Exception + "]");

            var pipeline = new HttpContextPipeline(new SimpleExceptionHandler());

            pipeline.Add(new RequestBodyHandler());
            pipeline.Add(new TraceHandler());
            pipeline.Add(new WebSocketRequestHandler(ComputeSha1Hash, SessionCreated));
            pipeline.Add(new ResponseBodyLengthHandler());
            pipeline.Add(new ResponseCompressionHandler());
            pipeline.Add(new SimpleHttpRequestHandler());

            var httpServer = new HttpServerFactory().CreateHttpServer();

            httpServer.RequestHandler = pipeline;
            httpServer.StartAsync(HttpServerOptions.Default).GetAwaiter().GetResult();


            Thread.Sleep(Timeout.Infinite);
        }
예제 #10
0
 protected RpcServerBase(int port)
 {
     _factory = new HttpServerFactory();
     _port    = port;
     Router   = new Router();
 }