forked from OmniSharp/omnisharp-roslyn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStopServerMiddleware.cs
More file actions
43 lines (39 loc) · 1.13 KB
/
StopServerMiddleware.cs
File metadata and controls
43 lines (39 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Threading;
using System.Threading.Tasks;
#if NETCOREAPP
using Microsoft.Extensions.Hosting;
#else
using Microsoft.AspNetCore.Hosting;
#endif
using Microsoft.AspNetCore.Http;
namespace OmniSharp.Http.Middleware
{
class StopServerMiddleware
{
#if NETCOREAPP
private readonly IHostApplicationLifetime _lifetime;
public StopServerMiddleware(RequestDelegate next, IHostApplicationLifetime lifetime)
#else
private readonly IApplicationLifetime _lifetime;
public StopServerMiddleware(RequestDelegate next, IApplicationLifetime lifetime)
#endif
{
_lifetime = lifetime;
}
public async Task Invoke(HttpContext httpContext)
{
if (httpContext.Request.Path.HasValue)
{
var endpoint = httpContext.Request.Path.Value;
if (endpoint == OmniSharpEndpoints.StopServer)
{
await Task.Run(() =>
{
Thread.Sleep(200);
_lifetime.StopApplication();
});
}
}
}
}
}