Exemplo n.º 1
0
        void InitWebServer()
        {
            if (WebServer != null)
            {
                WebServer.Dispose();
                WebServer = null;
            }
            var curpath = Path.GetDirectoryName(typeof(PCLocalService).Assembly.Location);

            WebServer = new WebServer(ServerPort);
            WebServer = WebServer
                        .WithModule(new PCWebServerAuth("/api/share", this))
                        .WithWebApi("SSDP", "/clouds", EmbedIOResponseSerializerCallback, module => module.WithController(CreateSSDPServiceController))
                        .WithWebApi("Share", "/api/share", EmbedIOResponseSerializerCallback, module => module.WithController(CreateShareController));
            if (!string.IsNullOrWhiteSpace(ExtraWebPath))
            {
                WebServer = WebServer.WithStaticFolder("/AppsStatic", ExtraWebPath, false);
            }
            var apps = GetAppMgrs();

            foreach (var appmgr in apps)
            {
                var id = appmgr.GetAppId();
                WebServer = appmgr.ConfigWebController(id, $"/api/Apps/{id}", WebServer);
            }
            WebServer.Start();
        }
Exemplo n.º 2
0
 public void StopNetwork()
 {
     nodeDiscovery.StopNetwork();
     WebServer?.Listener?.Stop();
     WebServer?.Dispose();
     WebServer = null;
     CleanKnownNodes();
 }
        public static void StopWebServer()
        {
            //In order to stop the waiting background thread
            try
            {
                serverCts.Cancel();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{nameof(WebApplicationFactory)}.{nameof(WebApplicationFactory.StopWebServer)} - {nameof(serverCts)}: {ex.Message}");
            }

            try
            {
                if (blazorContextBridgeServer != null)
                {
                    blazorContextBridgeServer.Dispose();
                    blazorContextBridgeServer = null;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{nameof(WebApplicationFactory)}.{nameof(WebApplicationFactory.StopWebServer)} - {nameof(blazorContextBridgeServer)}: {ex.Message}");
            }

            server?.Dispose();
            server = null;

            _isStarted = false;
        }
Exemplo n.º 4
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _webServer?.Dispose();
     }
 }
Exemplo n.º 5
0
        public void WebserverCanBeDisposed()
        {
            var cts      = new CancellationTokenSource();
            var instance = new WebServer("http://localhost:" + DefaultPort);
            var task     = instance.RunAsync(cts.Token);

            cts.Cancel();

            try
            {
                //Thread.Sleep(2000);
                task.Wait();
            }
            catch (AggregateException e)
            {
                var baseEx = e.GetBaseException();
                if (baseEx is OperationCanceledException)
                {
                    instance.Dispose();
                    return;
                }

                Assert.Fail($"Must have thrown OperationCanceledException and trhew '{baseEx.GetType().ToString()}' instead.");
            }
            catch (Exception ex)
            {
                Assert.Fail($"Must have thrown AggregateException and threw '{ex.GetType().ToString()}' instead.");
            }
        }
Exemplo n.º 6
0
        private void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            Stop();

            if (_webServer != null)
            {
                _webServer.Dispose();
                _webServer = null;
            }

            if (_cts != null)
            {
                _cts.Dispose();
                _cts = null;
            }

            if (_task != null)
            {
                _task?.Dispose();
                _task = null;
            }
        }
Exemplo n.º 7
0
        private void StartStopHTTP()
        {
            if (!server_status)
            {
                server_status    = true;
                l_webstatus.Text = "Running";
                b_webbutton.Text = "Stop";
                server           = new WebServer();

                /*    server.RegisterModule(
                 *      new StaticFilesModule(
                 *          new Dictionary<string, string> {
                 *           //   { "/", folderPath.Text },
                 *           //   { "/" + iconsDirectory , tmpDirectory + "\\" + iconsDirectory }
                 *             }));*/
                server.RegisterModule(new StaticFilesModule(folderPath.Text));
                server.RegisterModule(new StaticFilesModule(tmpDirectory));

                server.RunAsync();
            }
            else
            {
                server.Dispose();
                l_webstatus.Text = "Stopped";
                b_webbutton.Text = "Start";
                server_status    = false;
            }
        }
Exemplo n.º 8
0
        public void WebserverCanBeDisposed()
        {
            var cts      = new CancellationTokenSource();
            var instance = new WebServer("http://localhost:" + DefaultPort);
            var task     = instance.RunAsync(cts.Token);

            cts.Cancel();

            try
            {
                //Thread.Sleep(2000);
                task.Wait();
            }
            catch (AggregateException e)
            {
                if (e.GetBaseException() is OperationCanceledException)
                {
                    instance.Dispose();
                    return;
                }

                Assert.Fail("Must fail because of an OperationCanceledException");
            }

            Assert.Fail("Must throw an AggregateException");
        }
Exemplo n.º 9
0
        /// <summary>
        /// Clear Webserver resources and set it as not started
        /// </summary>
        private static void ClearWebserverResources()
        {
            try
            {
                if (blazorContextBridgeServer != null)
                {
                    blazorContextBridgeServer.Dispose();
                }
            }
            catch (Exception ex)
            {
            }

            try
            {
                server?.Dispose();
            }
            catch (Exception ex)
            {
            }

            blazorContextBridgeServer = null;
            server     = null;
            _isStarted = false;
        }
Exemplo n.º 10
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         server.Dispose();
     }
 }
Exemplo n.º 11
0
        public void WebserverCanBeDisposed()
        {
            var cts = new CancellationTokenSource();
            var instance = new WebServer("http://localhost:" + DefaultPort);
            var task = instance.RunAsync(cts.Token);

            cts.Cancel();

            try
            {
                //Thread.Sleep(2000);
                task.Wait();
            }
            catch (AggregateException e)
            {
                var baseEx = e.GetBaseException();
                if (baseEx is OperationCanceledException)
                {
                    instance.Dispose();
                    return;
                }

                Assert.Fail($"Must have thrown OperationCanceledException and trhew '{baseEx.GetType().ToString()}' instead.");
            }
            catch (Exception ex)
            {
                Assert.Fail($"Must have thrown AggregateException and threw '{ex.GetType().ToString()}' instead.");
            }
        }
Exemplo n.º 12
0
        public void WebserverCanBeDisposed()
        {
            var cts = new CancellationTokenSource();
            var instance = new WebServer("http://localhost:" + DefaultPort);
            var task = instance.RunAsync(cts.Token);

            cts.Cancel();

            try
            {
                Thread.Sleep(2000);
                task.Wait();
            }
            catch (AggregateException e)
            {
                if (e.GetBaseException() is OperationCanceledException)
                {
                    instance.Dispose();
                    return;
                }

                Assert.Fail("Must fail because of an OperationCanceledException");
            }

            Assert.Fail("Must throw an AggregateException");
        }
Exemplo n.º 13
0
 private static void Stop()
 {
     PlayerWebsocketConnections.CloseAll();
     Thread.Sleep(1000);
     WebServer.Dispose();
     SocketServer.Dispose();
     Game.Engine.Engine.Stop();
 }
 public bool StopServer()
 {
     cancellationTokenSource.Cancel();
     webServerTask.Wait();
     webServerTask.Dispose();
     server.Dispose();
     return(true);
 }
Exemplo n.º 15
0
 void OnDisable()
 {
     Debug.Log("Disposing WebServer...");
     server.Dispose();
     server = null;
     webSocketsHandler.Dispose();
     webSocketsHandler = null;
 }
 public void Dispose()
 {
     if (FWebServer != null)
     {
         FWebServer.Dispose();
         FWebServer = null;
     }
 }
Exemplo n.º 17
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         //WSClient.Instance.Close();
         webServer.Dispose();
     }
 }
Exemplo n.º 18
0
 static void Clear()
 {
     if (_server != null)
     {
         _server.Dispose();
         _resources.Clear();
         _server = null;
     }
 }
Exemplo n.º 19
0
 public void Dispose()
 {
     if (!_disposed)
     {
         _disposed = true;
         _webServer.Stop();
         _webServer.Dispose();
     }
 }
Exemplo n.º 20
0
 public void Dispose()
 {
     logger.Warn("Приложение было закрыто!");
     webServer?.Dispose();
     waitShutdown.Set();
     container.Dispose();
     LogManager.Flush();
     LogManager.Shutdown();
 }
Exemplo n.º 21
0
        private void OnApplicationExit(object sender, EventArgs e)
        {
            //Individual trycatches to make sure everything is off before leaving.
            try
            {
                //Stop the webServer
                cts.Cancel();
                //task.Wait();
                newHTTPServer.Dispose();
            }
            catch { }

            try
            {
                s.Close();
            }
            catch { }
        }
Exemplo n.º 22
0
        private bool disposedValue = false; // To detect redundant calls

        public void Dispose()
        {
            if (!disposedValue)
            {
                if (server != null)
                {
                    server.Dispose();
                }

                disposedValue = true;
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Stops and Disposes of the Web and Web Socket Servers
        /// </summary>
        public static void Stop()
        {
            if (server == null)
            {
                return;
            }

            wss.Dispose();
            server.Dispose();
            server = null;
            wss    = null;
        }
Exemplo n.º 24
0
            public void WithCancellationRequested_ExitsSuccessfully()
            {
                var instance = new WebServer("http://localhost:9696");

                var cts  = new CancellationTokenSource();
                var task = instance.RunAsync(cts.Token);

                cts.Cancel();

                task.Wait();
                instance.Dispose();

                Assert.IsTrue(task.IsCompleted);
            }
Exemplo n.º 25
0
        private void CapFrameXExit(object sender, ExitEventArgs e)
        {
            PresentMonCaptureService.TryKillPresentMon();

            var overlayService = _bootstrapper.Container.Resolve(typeof(IOverlayService), true) as IOverlayService;

            overlayService?.IsOverlayActiveStream.OnNext(false);

            var sensorService = _bootstrapper.Container.Resolve(typeof(ISensorService), true) as ISensorService;

            sensorService?.CloseOpenHardwareMonitor();

            _webServer.Dispose();
        }
Exemplo n.º 26
0
        static void Main(string[] args)
        {
            var server = new WebServer(o => o
                                       .WithUrlPrefix(URL)
                                       .WithMode(HttpListenerMode.EmbedIO))
                         .WithWebApi("/api", m => m.WithController <CpuTempController>())
                         .WithStaticFolder("/", "html", true)
                         .WithModule(new ActionModule("/", HttpVerbs.Any, ctx => ctx.SendDataAsync(new { Message = "Error" })));

            server.RunAsync();

            Console.ReadKey(true);

            server.Dispose();
        }
Exemplo n.º 27
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if (webServer != null)
                    {
                        webServer.Dispose();
                    }
                }
                webServer     = null;
                disposedValue = true;
            }
        }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            using (var server = new WebServer("http://localhost:8082/", RoutingStrategy.Regex))
            {
                server.EnableCors();
                server.RegisterModule(new WebApiModule());
                server.Module <WebApiModule>().RegisterController <PeopleController>();
                server.WithLocalSession();
                var task = server.RunAsync();

                Console.ReadKey(true);
                task.Wait();
                server.Dispose();
            }
        }
Exemplo n.º 29
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                // Dispose managed state (managed objects).
                _webServer?.Dispose();
            }

            _disposed = true;
        }
Exemplo n.º 30
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if (server != null)
                    {
                        server.Dispose();
                    }
                }

                disposedValue = true;
            }
        }
Exemplo n.º 31
0
        private void CapFrameXExit(object sender, ExitEventArgs e)
        {
            PresentMonCaptureService.TryKillPresentMon();

            var sensorService = _bootstrapper.Container.Resolve(typeof(ISensorService), true) as ISensorService;

            sensorService?.CloseOpenHardwareMonitor();

            var rtssService = _bootstrapper.Container.Resolve(typeof(IRTSSService), true) as IRTSSService;

            rtssService.ClearOSD();
            rtssService.CloseHandles();

            _webServer.Dispose();
        }
Exemplo n.º 32
0
        static void Main(string[] args)
        {
            var server = new WebServer(o => o
                                       .WithUrlPrefix(URL)
                                       .WithMode(HttpListenerMode.EmbedIO))
                         .WithLocalSessionManager()
                         .WithModule(new CpuTempWSServer("/ws"))
                         .WithStaticFolder("/", "html", true)
                         .WithModule(new ActionModule("/", HttpVerbs.Any, ctx => ctx.SendDataAsync(new { Message = "Error" })));

            server.RunAsync();

            Console.ReadKey(true);

            server.Dispose();
        }
Exemplo n.º 33
0
        public void WebServerCanBeRestarted()
        {
            var cts = new CancellationTokenSource();
            var instance = new WebServer("http://localhost:" + DefaultPort);
            var task = instance.RunAsync(cts.Token);

            //need to make a request here for it to fail before the cancellation changes, null works, yay
            instance.ProcessRequest(null);

            cts.Cancel();

            try
            {
                //Thread.Sleep(2000);
                task.Wait();
            }
            catch (AggregateException e)
            {
                var baseEx = e.GetBaseException();
                if (baseEx is OperationCanceledException)
                {
                    instance.Dispose();
                    return;
                }
            }
            cts = new CancellationTokenSource();
            instance = new WebServer("http://localhost:" + DefaultPort);
            task = instance.RunAsync(cts.Token);

            cts.Cancel();

            try
            {
                //Thread.Sleep(2000);
                task.Wait();
            }
            catch (AggregateException e)
            {
                var baseEx = e.GetBaseException();
                if (baseEx is OperationCanceledException)
                {
                    instance.Dispose();
                    return;
                }
            }
        }