コード例 #1
0
ファイル: WebTest.cs プロジェクト: fugaku/scriptsharp
        public bool StopWebServer() {
            bool stopped = false;

            if (_server != null) {
                try {
                    _server.Stop();
                    stopped = true;
                }
                catch {
                }
                _server = null;
            }
            return stopped;
        }
コード例 #2
0
ファイル: WebTest.cs プロジェクト: fugaku/scriptsharp
        public bool StartWebServer(string webRoot, int port) {
            if (_server != null) {
                throw new InvalidOperationException("The server has already been started.");
            }
            if (String.IsNullOrEmpty(webRoot)) {
                throw new ArgumentNullException("webRoot");
            }
            if (Directory.Exists(webRoot) == false) {
                throw new ArgumentException("Invalid directory specified as the web root.", "webRoot");
            }

            bool started = false;
            try {
                WebTestHttpServer server = new WebTestHttpServer(webRoot);
                server.Start(port);

                _server = server;
                started = true;
            }
            catch (Exception e) {
                throw new InvalidOperationException("Failed to start server.", e);
            }

            if (started) {
                UriBuilder uriBuilder = new UriBuilder();
                uriBuilder.Scheme = "http";
                uriBuilder.Host = "localhost";
                uriBuilder.Port = port;

                _rootUri = uriBuilder.Uri;
            }

            return started;
        }