Exemple #1
0
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            if (!_disposing)
            {
                Stop();
                _disposing = true;
            }

            WebHost?.Dispose();
            WebHostScope?.Dispose();
            Container?.Dispose();

            if (_logger is IDisposable disposable)
            {
                disposable.Dispose();
            }

            WebHost      = null;
            HostBuilder  = null;
            Container    = null;
            WebHostScope = null;
            _disposed    = true;
            _disposing   = false;
        }
Exemple #2
0
 public static void CleanUp()
 {
     host.Dispose();
     simpleHost.Dispose();
     host       = null;
     simpleHost = null;
 }
Exemple #3
0
 public void AfterScenario()
 {
     if (_webHost != null)
     {
         _webHost.Dispose();
     }
 }
Exemple #4
0
 public void Stop()
 {
     if (WebHost != null)
     {
         WebHost.StopAsync(TimeSpan.FromSeconds(0));
         WebHost.Dispose();
         WebHost = null;
     }
 }
Exemple #5
0
        //Public
        public Task <int> StartWebServer()
        {
            WebServerPort = 7001;
            ErrorMessage  = "";

            return(Task <int> .Factory.StartNew((Func <int>)(() =>
            {
                try
                {
                    if (mWebHost != null && mWebHost.Running)
                    {
                        if (mWebHost.Port == WebServerPort)
                        {
                            return 1;
                        }
                        this.StopWebServer().Wait();
                    }
                    if (this.mWebHost == null)
                    {
                        mWebHost = new WebHost();
                        mWebHost.Port = this.WebServerPort;
                        mWebHost.RootDirectoryPath = this.WebServerDirectoryPath;
                        mWebHost.Start();
                    }
                    this.WebServerRunnning = true;
                    return 0;
                }
                catch (Exception ex)
                {
                    if (mWebHost != null)
                    {
                        mWebHost.Dispose();
                        mWebHost = (WebHost)null;
                    }

                    SanitaLog.e(TAG, "StartWebServer error !", ex);

                    ErrorMessage = ex.ToString();
                    WebServerRunnning = false;
                    return -1;
                }
            })));
        }
Exemple #6
0
        public static void OpenApplicationInBrowser()
        {
            var host = new WebHost();

            //System.Diagnostics.Process.Start(host.Url);

            Console.Write("Press enter to exit:");
            Console.Read();

            host.Dispose();
        }
Exemple #7
0
 public void Dispose()
 {
     lock (_servers)
     {
         foreach (var s in _servers)
         {
             s.Dispose();
         }
     }
     WebHost.Dispose();
     SignalrHost.Dispose();
 }
Exemple #8
0
 public void Dispose()
 {
     try
     {
         ChutzpahTracer.TraceInformation("Tearing down Web Server Host at path {0} and port {1}", RootPath, Port);
         IsRunning = false;
         WebHost.Dispose();
     }
     catch (Exception e)
     {
         ChutzpahTracer.TraceError(e, "Error tearing down Web Server Host at path {0} and port {1}", RootPath, Port);
     }
 }
        protected virtual void Dispose(bool disposing)
        {
            if (_disposedValue)
            {
                return;
            }
            if (disposing)
            {
                WebHost.StopAsync().GetAwaiter().GetResult();
                WebHost.Dispose();
            }

            _disposedValue = true;
        }
Exemple #10
0
            public async Task OnStoppingServiceAsync(OperationContext context)
            {
                if (ProxyService != null)
                {
                    await ProxyService.ShutdownAsync(context).IgnoreFailure();
                }

                if (ContentCacheService != null)
                {
                    await ContentCacheService.ShutdownAsync(context).IgnoreFailure();
                }

                // Not passing cancellation token since it will already be signaled
                await WebHost.StopAsync();

                WebHost.Dispose();
            }
Exemple #11
0
        public virtual bool Stop(HostControl hostControl)
        {
            Logger.Info("Stopping service");

            if (GameLoopCancellationTokenSource != null)
            {
                GameLoopCancellationTokenSource.Cancel();
            }

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

            CastleContainer.Dispose();

            return(true);
        }
Exemple #12
0
            public async Task OnStoppingServiceAsync(OperationContext context)
            {
                // Not passing cancellation token since it will already be signaled

                // WebHost is null for out-of-proc casaas case.
                if (WebHost != null)
                {
                    await WebHost.StopAsync();
                }

                if (ProxyService != null)
                {
                    await ProxyService.ShutdownAsync(context).IgnoreFailure();
                }

                if (ContentCacheService != null)
                {
                    await ContentCacheService.ShutdownAsync(context).IgnoreFailure();
                }

                WebHost?.Dispose();
            }
Exemple #13
0
 public void Stop()
 {
     StopRequestedByWindows = true;
     WebHost.Dispose();
 }
 public void Dispose()
 {
     WebHost?.Dispose();
     IsDisposed = true;
 }
Exemple #15
0
 private void Application_Exit(object sender, ExitEventArgs e)
 {
     WebHost.Stop();
     WebHost.Dispose();
 }
Exemple #16
0
 protected override void OnFormClosing(FormClosingEventArgs e)
 {
     _host.Dispose();
     base.OnFormClosing(e);
 }
Exemple #17
0
    public IWebHost Build()
    {
        if (_webHostBuilt)
        {
            throw new InvalidOperationException(Resources.WebHostBuilder_SingleInstance);
        }
        _webHostBuilt = true;

        var hostingServices        = BuildCommonServices(out var hostingStartupErrors);
        var applicationServices    = hostingServices.Clone();
        var hostingServiceProvider = GetProviderFromFactory(hostingServices);

        if (!_options.SuppressStatusMessages)
        {
            // Warn about deprecated environment variables
            if (Environment.GetEnvironmentVariable("Hosting:Environment") != null)
            {
                Console.WriteLine("The environment variable 'Hosting:Environment' is obsolete and has been replaced with 'ASPNETCORE_ENVIRONMENT'");
            }

            if (Environment.GetEnvironmentVariable("ASPNET_ENV") != null)
            {
                Console.WriteLine("The environment variable 'ASPNET_ENV' is obsolete and has been replaced with 'ASPNETCORE_ENVIRONMENT'");
            }

            if (Environment.GetEnvironmentVariable("ASPNETCORE_SERVER.URLS") != null)
            {
                Console.WriteLine("The environment variable 'ASPNETCORE_SERVER.URLS' is obsolete and has been replaced with 'ASPNETCORE_URLS'");
            }
        }

        AddApplicationServices(applicationServices, hostingServiceProvider);

        var host = new WebHost(
            applicationServices,
            hostingServiceProvider,
            _options,
            _config,
            hostingStartupErrors);

        try
        {
            host.Initialize();

            // resolve configuration explicitly once to mark it as resolved within the
            // service provider, ensuring it will be properly disposed with the provider
            _ = host.Services.GetService <IConfiguration>();

            var logger = host.Services.GetRequiredService <ILogger <WebHost> >();

            // Warn about duplicate HostingStartupAssemblies
            var assemblyNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            foreach (var assemblyName in _options.GetFinalHostingStartupAssemblies())
            {
                if (!assemblyNames.Add(assemblyName))
                {
                    logger.LogWarning($"The assembly {assemblyName} was specified multiple times. Hosting startup assemblies should only be specified once.");
                }
            }

            return(host);
        }
        catch
        {
            // Dispose the host if there's a failure to initialize, this should dispose
            // services that were constructed until the exception was thrown
            host.Dispose();
            throw;
        }
 public void Dispose()
 {
     Client.Dispose();
     WebHost.Dispose();
 }
 public void Dispose()
 {
     host.Dispose();
 }
 public void TearDown()
 {
     DefaultAppDomainProvider.AppDomain = null;
     host.Dispose();
 }