Adapt samples to .NET Core.

This commit is contained in:
Cesar Blum Silveira 2016-02-08 10:26:44 -08:00
parent f11c5aef23
commit 86af69d2d7
8 changed files with 27 additions and 25 deletions

View File

@ -9,7 +9,12 @@ namespace HelloWorld
{ {
public class Program public class Program
{ {
public static async Task Main(string[] args) public static void Main(string[] args)
{
Run(args).Wait();
}
public static async Task Run(string[] args)
{ {
using (WebListener listener = new WebListener()) using (WebListener listener = new WebListener())
{ {

View File

@ -1,21 +1,19 @@
{ {
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": { "dependencies": {
"Microsoft.Net.Http.Server": "0.1.0-*", "Microsoft.Net.Http.Server": "0.1.0-*",
"Microsoft.Net.WebSockets.Server": "0.1.0-*", "Microsoft.Net.WebSockets.Server": "0.1.0-*"
"Microsoft.NETCore.Platforms": "1.0.1-*"
}, },
"commands": { "commands": {
"sample": "HelloWorld" "sample": "HelloWorld"
}, },
"frameworks": { "frameworks": {
"dnx451": {}, "net451": {},
"netstandardapp1.5": { "netstandardapp1.5": {
"dependencies": { "dependencies": {
"System.Collections": "4.0.11-*", "NETStandard.Library": "1.0.0-*"
"System.Console": "4.0.0-*",
"System.Globalization": "4.0.11-*",
"System.IO": "4.1.0-*",
"System.Threading.Tasks": "4.0.11-*"
}, },
"imports": [ "imports": [
"dnxcore50" "dnxcore50"

View File

@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Features; using Microsoft.AspNetCore.Server.Features;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Net.Http.Server;
namespace HotAddSample namespace HotAddSample
{ {
@ -17,7 +18,7 @@ namespace HotAddSample
{ {
loggerfactory.AddConsole(LogLevel.Information); loggerfactory.AddConsole(LogLevel.Information);
var addresses = app.ServerFeatures.Get<IServerAddressesFeature>().Addresses; var addresses = app.ServerFeatures.Get<WebListener>().UrlPrefixes;
addresses.Add("http://localhost:12346/pathBase/"); addresses.Add("http://localhost:12346/pathBase/");
app.Use(async (context, next) => app.Use(async (context, next) =>
@ -31,7 +32,7 @@ namespace HotAddSample
try try
{ {
addresses.Add(toAdd); addresses.Add(toAdd);
await context.Response.WriteAsync("Added: " + toAdd); await context.Response.WriteAsync("Added: <a href=\"" + toAdd + "\">" + toAdd + "</a>");
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -93,6 +94,7 @@ namespace HotAddSample
var host = new WebHostBuilder() var host = new WebHostBuilder()
.UseDefaultConfiguration(args) .UseDefaultConfiguration(args)
.UseStartup<Startup>() .UseStartup<Startup>()
.UseServer("Microsoft.AspNetCore.Server.WebListener")
.Build(); .Build();
host.Run(); host.Run();

View File

@ -1,4 +0,0 @@
{
"server": "Microsoft.AspNetCore.Server.WebListener",
"server.urls": "http://localhost:12345"
}

View File

@ -2,8 +2,7 @@
"version": "1.0.0-*", "version": "1.0.0-*",
"dependencies": { "dependencies": {
"Microsoft.AspNetCore.Server.WebListener": "0.1.0-*", "Microsoft.AspNetCore.Server.WebListener": "0.1.0-*",
"Microsoft.Extensions.Logging.Console": "1.0.0-*", "Microsoft.Extensions.Logging.Console": "1.0.0-*"
"Microsoft.NETCore.Platforms": "1.0.1-*"
}, },
"compilationOptions": { "compilationOptions": {
"emitEntryPoint": true "emitEntryPoint": true
@ -12,8 +11,11 @@
"web": "HotAddSample" "web": "HotAddSample"
}, },
"frameworks": { "frameworks": {
"dnx451": {}, "net451": {},
"netstandardapp1.5": { "netstandardapp1.5": {
"dependencies": {
"NETStandard.Library": "1.0.0-*"
},
"imports": [ "imports": [
"dnxcore50" "dnxcore50"
] ]

View File

@ -43,6 +43,7 @@ namespace SelfHostServer
var host = new WebHostBuilder() var host = new WebHostBuilder()
.UseDefaultConfiguration(args) .UseDefaultConfiguration(args)
.UseStartup<Startup>() .UseStartup<Startup>()
.UseServer("Microsoft.AspNetCore.Server.WebListener")
.Build(); .Build();
host.Run(); host.Run();

View File

@ -1,4 +0,0 @@
{
"server": "Microsoft.AspNetCore.Server.WebListener",
"server.urls": "http://localhost:8080"
}

View File

@ -1,8 +1,7 @@
{ {
"dependencies": { "dependencies": {
"Microsoft.AspNetCore.Server.WebListener": "0.1.0-*", "Microsoft.AspNetCore.Server.WebListener": "0.1.0-*",
"Microsoft.Extensions.Logging.Console": "1.0.0-*", "Microsoft.Extensions.Logging.Console": "1.0.0-*"
"Microsoft.NETCore.Platforms": "1.0.1-*"
}, },
"compilationOptions": { "compilationOptions": {
"emitEntryPoint": true "emitEntryPoint": true
@ -11,8 +10,11 @@
"web": "SelfHostServer" "web": "SelfHostServer"
}, },
"frameworks": { "frameworks": {
"dnx451": {}, "net451": {},
"netstandardapp1.5": { "netstandardapp1.5": {
"dependencies": {
"NETStandard.Library": "1.0.0-*"
},
"imports": [ "imports": [
"dnxcore50" "dnxcore50"
] ]