2016-01-22 23:21:40 +03:00
|
|
|
using System;
|
2016-01-07 05:08:57 +03:00
|
|
|
using System.Collections.Generic;
|
2017-03-27 20:30:45 +03:00
|
|
|
using System.Threading.Tasks;
|
2016-01-22 23:21:40 +03:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2015-12-12 00:03:43 +03:00
|
|
|
|
|
|
|
// Note that this sample will not run. It is only here to illustrate usage patterns.
|
|
|
|
|
|
|
|
namespace SampleStartups
|
|
|
|
{
|
2016-04-17 10:20:34 +03:00
|
|
|
public class StartupExternallyControlled : StartupBase
|
2015-12-12 00:03:43 +03:00
|
|
|
{
|
2016-01-17 10:11:41 +03:00
|
|
|
private IWebHost _host;
|
2016-01-07 05:08:57 +03:00
|
|
|
private readonly List<string> _urls = new List<string>();
|
2016-05-20 01:05:53 +03:00
|
|
|
|
2015-12-12 00:03:43 +03:00
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
2016-04-17 10:20:34 +03:00
|
|
|
public override void Configure(IApplicationBuilder app)
|
2015-12-12 00:03:43 +03:00
|
|
|
{
|
|
|
|
app.Run(async (context) =>
|
|
|
|
{
|
|
|
|
await context.Response.WriteAsync("Hello World!");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public StartupExternallyControlled()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
{
|
2016-01-17 10:11:41 +03:00
|
|
|
_host = new WebHostBuilder()
|
2016-05-20 01:05:53 +03:00
|
|
|
//.UseKestrel()
|
2017-04-25 17:30:11 +03:00
|
|
|
.UseFakeServer()
|
2016-04-27 01:26:34 +03:00
|
|
|
.UseStartup<StartupExternallyControlled>()
|
|
|
|
.Start(_urls.ToArray());
|
2015-12-12 00:03:43 +03:00
|
|
|
}
|
|
|
|
|
2017-03-27 20:30:45 +03:00
|
|
|
public async Task StopAsync()
|
2015-12-12 00:03:43 +03:00
|
|
|
{
|
2018-05-16 17:26:55 +03:00
|
|
|
using (_host)
|
|
|
|
{
|
|
|
|
await _host.StopAsync(TimeSpan.FromSeconds(5));
|
|
|
|
}
|
2015-12-12 00:03:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public void AddUrl(string url)
|
|
|
|
{
|
2016-01-07 05:08:57 +03:00
|
|
|
_urls.Add(url);
|
2015-12-12 00:03:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|