Пример #1
0
 private static void Shutdown()
 {
     if (_childProcess != null)
     {
         _childProcess.StandardInput.Write("\n");
         _childProcess.WaitForExit(5000);
     }
     else
     {
         try
         {
             HostableWebCore.Shutdown(true);
         }
         catch (Exception ex)
         {
             Console.Error.WriteLine("Hostable webcore didn't shut down cleanly:");
             Console.Error.WriteLine(ex);
         }
         if (Directory.Exists(_options.TempDirectory))
         {
             for (var i = 0; i < 5; i++)
             {
                 try
                 {
                     Directory.Delete(_options.TempDirectory, true);
                     break;
                 }
                 catch (UnauthorizedAccessException) // just make sure all locks are released, cuz hwc may not shutdown instantly
                 {
                     Thread.Sleep(500);
                 }
             }
         }
     }
 }
Пример #2
0
 private static void Shutdown()
 {
     if (_childProcess != null)
     {
         _childProcess.StandardInput.Write("\n");
         _childProcess.WaitForExit(5000);
     }
     else
     {
         try
         {
             HostableWebCore.Shutdown(true);
             if (_options.UseSSL)
             {
                 var addSslArgs       = $"http delete sslcert ipport=0.0.0.0:{_options.Port}";
                 var processStartInfo = new ProcessStartInfo("netsh", addSslArgs)
                 {
                     UseShellExecute        = false,
                     RedirectStandardError  = true,
                     RedirectStandardOutput = true,
                     RedirectStandardInput  = true,
                     CreateNoWindow         = true,
                     Verb = "runas"
                 };
                 _childProcess = Process.Start(processStartInfo);
                 if (_childProcess == null)
                 {
                     throw new Exception("Can't add ssl cert binding");
                 }
                 _childProcess.BeginOutputReadLine();
                 _childProcess.BeginErrorReadLine();
                 _childProcess.OutputDataReceived += (sender, eventArgs) => Console.WriteLine(eventArgs.Data);
                 _childProcess.ErrorDataReceived  += (sender, eventArgs) => Console.Error.WriteLine(eventArgs.Data);
                 _childProcess.WaitForExit(5000);
             }
         }
         catch (Exception ex)
         {
             Console.Error.WriteLine("Hostable webcore didn't shut down cleanly:");
             Console.Error.WriteLine(ex);
         }
         if (Directory.Exists(_options.TempDirectory))
         {
             for (var i = 0; i < 5; i++)
             {
                 try
                 {
                     Directory.Delete(_options.TempDirectory, true);
                     break;
                 }
                 catch (UnauthorizedAccessException) // just make sure all locks are released, cuz hwc may not shutdown instantly
                 {
                     Thread.Sleep(500);
                 }
             }
         }
     }
 }