Last active
April 28, 2019 23:40
-
-
Save DoubleCouponDay/ba88b685a0c39ece913cba6432f80f8c to your computer and use it in GitHub Desktop.
ASPNET 5 debug server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Diagnostics; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading; | |
| using System.Threading.Tasks; | |
| using Xunit; | |
| using System.Management.Automation; | |
| using System.Windows.Forms; | |
| namespace serversidearchitecture.tests.integration.fast.api | |
| { | |
| public class ApiTestServer : IDisposable | |
| { | |
| const string projectrootpath = @""; | |
| private PowerShell shell; | |
| private IAsyncResult invocation; | |
| public string baselink { get; } = @"http://localhost:8080/"; | |
| public bool wasshutdown { get; private set; } | |
| public ApiTestServer() | |
| { | |
| string iisexpresscommand = @" 'C:\Program Files\IIS Express\iisexpress.exe' '/path:" + projectrootpath + "' '/clr:v4.0' "; | |
| try | |
| { | |
| shell = PowerShell.Create(RunspaceMode.NewRunspace) | |
| .AddScript($"& {iisexpresscommand}"); | |
| invocation = shell.BeginInvoke(); | |
| Thread.Sleep(6000); | |
| } | |
| catch (Exception error) | |
| { | |
| shutdown(); | |
| throw; | |
| } | |
| } | |
| void shutdown() | |
| { | |
| if (wasshutdown == false) | |
| { | |
| var processes = Process.GetProcessesByName("iisexpresstray"); | |
| foreach (Process item in processes) | |
| { | |
| item.Kill(); | |
| } | |
| shell.Dispose(); | |
| wasshutdown = true; | |
| } | |
| } | |
| public void Dispose() | |
| { | |
| shutdown(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment