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(); }
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; }
protected virtual void Dispose(bool disposing) { if (disposing) { _webServer?.Dispose(); } }
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."); } }
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; } }
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; } }
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"); }
/// <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; }
protected virtual void Dispose(bool disposing) { if (disposing) { server.Dispose(); } }
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"); }
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); }
void OnDisable() { Debug.Log("Disposing WebServer..."); server.Dispose(); server = null; webSocketsHandler.Dispose(); webSocketsHandler = null; }
public void Dispose() { if (FWebServer != null) { FWebServer.Dispose(); FWebServer = null; } }
protected virtual void Dispose(bool disposing) { if (disposing) { //WSClient.Instance.Close(); webServer.Dispose(); } }
static void Clear() { if (_server != null) { _server.Dispose(); _resources.Clear(); _server = null; } }
public void Dispose() { if (!_disposed) { _disposed = true; _webServer.Stop(); _webServer.Dispose(); } }
public void Dispose() { logger.Warn("Приложение было закрыто!"); webServer?.Dispose(); waitShutdown.Set(); container.Dispose(); LogManager.Flush(); LogManager.Shutdown(); }
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 { } }
private bool disposedValue = false; // To detect redundant calls public void Dispose() { if (!disposedValue) { if (server != null) { server.Dispose(); } disposedValue = true; } }
/// <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; }
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); }
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(); }
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(); }
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; } }
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(); } }
protected virtual void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { // Dispose managed state (managed objects). _webServer?.Dispose(); } _disposed = true; }
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; } }
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(); }
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(); }
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; } } }