From cb1d4f67f1409d23962ebb50206b584389a25d28 Mon Sep 17 00:00:00 2001 From: afuersch Date: Fri, 23 Oct 2015 21:03:01 +0200 Subject: [PATCH] #4 Upgrade to ASP.NET 5 Beta 8. --- global.json | 2 +- src/Wuzlstats/AppSettings.cs | 6 +- src/Wuzlstats/Controllers/HomeController.cs | 5 +- src/Wuzlstats/Hubs/ApiHub.cs | 2 +- .../20150810174412_Initial.Designer.cs | 43 ++++++-------- .../Migrations/20150810174412_Initial.cs | 58 +++++++++---------- src/Wuzlstats/Migrations/DbModelSnapshot.cs | 31 +++++----- src/Wuzlstats/Models/Db.cs | 10 ++-- src/Wuzlstats/Startup.cs | 10 +++- src/Wuzlstats/project.json | 31 +++++----- src/Wuzlstats/wwwroot/web.config | 9 +++ 11 files changed, 105 insertions(+), 102 deletions(-) create mode 100644 src/Wuzlstats/wwwroot/web.config diff --git a/global.json b/global.json index 84b0e87..e6dcbe2 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "projects": [ "src", "test" ], "sdk": { - "version": "1.0.0-beta6" + "version": "1.0.0-beta8" } } diff --git a/src/Wuzlstats/AppSettings.cs b/src/Wuzlstats/AppSettings.cs index e2b5be8..5030c1e 100644 --- a/src/Wuzlstats/AppSettings.cs +++ b/src/Wuzlstats/AppSettings.cs @@ -26,8 +26,8 @@ private int Get(IConfiguration configuration, string key, int defaultValue) private string Get(IConfiguration configuration, string key, string defaultValue) { - string value; - return configuration.TryGet(key, out value) ? value : defaultValue; + string value = configuration[key]; + return !string.IsNullOrEmpty(value) ? value : defaultValue; } } -} \ No newline at end of file +} diff --git a/src/Wuzlstats/Controllers/HomeController.cs b/src/Wuzlstats/Controllers/HomeController.cs index d07615f..bb940e1 100644 --- a/src/Wuzlstats/Controllers/HomeController.cs +++ b/src/Wuzlstats/Controllers/HomeController.cs @@ -6,6 +6,7 @@ using Microsoft.AspNet.Mvc; using Wuzlstats.Models; using Wuzlstats.ViewModels.Home; +using Microsoft.Framework.Primitives; namespace Wuzlstats.Controllers { @@ -34,12 +35,12 @@ public IActionResult Index(string league) public async Task Index() { var leagueCookie = Request.Cookies["league"]; - if (leagueCookie == null) + if (StringValues.IsNullOrEmpty(leagueCookie)) { return RedirectToAction("Index", "Leagues"); } - var league = await _db.Leagues.FirstOrDefaultAsync(x => x.Name.ToLower() == leagueCookie.ToLower()); + var league = await _db.Leagues.FirstOrDefaultAsync(x => x.Name.ToLower() == leagueCookie.ToString().ToLower()); if (league == null) { return RedirectToAction("Index", "Leagues"); diff --git a/src/Wuzlstats/Hubs/ApiHub.cs b/src/Wuzlstats/Hubs/ApiHub.cs index 8735bcb..ed1fae6 100644 --- a/src/Wuzlstats/Hubs/ApiHub.cs +++ b/src/Wuzlstats/Hubs/ApiHub.cs @@ -51,4 +51,4 @@ private async Task CheckAndLoadLeague(string league) return leagueEntity; } } -} \ No newline at end of file +} diff --git a/src/Wuzlstats/Migrations/20150810174412_Initial.Designer.cs b/src/Wuzlstats/Migrations/20150810174412_Initial.Designer.cs index 263ea04..2baee47 100644 --- a/src/Wuzlstats/Migrations/20150810174412_Initial.Designer.cs +++ b/src/Wuzlstats/Migrations/20150810174412_Initial.Designer.cs @@ -1,25 +1,16 @@ using System; using Microsoft.Data.Entity; -using Microsoft.Data.Entity.Metadata; -using Microsoft.Data.Entity.Migrations.Infrastructure; using Wuzlstats.Models; +using Microsoft.Data.Entity.Migrations; +using Microsoft.Data.Entity.Infrastructure; namespace Wuzlstats.Migrations { - [ContextType(typeof(Db))] + [DbContext(typeof(Db))] + [Migration("20150810174412_Initial")] partial class Initial { - public override string Id - { - get { return "20150810174412_Initial"; } - } - - public override string ProductVersion - { - get { return "7.0.0-beta6-13815"; } - } - - public override void BuildTargetModel(ModelBuilder builder) + protected override void BuildTargetModel(ModelBuilder builder) { builder .Annotation("ProductVersion", "7.0.0-beta6-13815") @@ -38,7 +29,7 @@ public override void BuildTargetModel(ModelBuilder builder) b.Property("RedScore"); - b.Key("Id"); + b.HasKey("Id"); }); builder.Entity("Wuzlstats.Models.League", b => @@ -50,7 +41,7 @@ public override void BuildTargetModel(ModelBuilder builder) b.Property("TimeoutConfiguration"); - b.Key("Id"); + b.HasKey("Id"); }); builder.Entity("Wuzlstats.Models.Player", b => @@ -64,7 +55,7 @@ public override void BuildTargetModel(ModelBuilder builder) b.Property("Name"); - b.Key("Id"); + b.HasKey("Id"); }); builder.Entity("Wuzlstats.Models.PlayerPosition", b => @@ -78,31 +69,31 @@ public override void BuildTargetModel(ModelBuilder builder) b.Property("Position"); - b.Key("Id"); + b.HasKey("Id"); }); builder.Entity("Wuzlstats.Models.Game", b => { - b.Reference("Wuzlstats.Models.League") - .InverseCollection() + b.HasOne("Wuzlstats.Models.League") + .WithMany() .ForeignKey("LeagueId"); }); builder.Entity("Wuzlstats.Models.Player", b => { - b.Reference("Wuzlstats.Models.League") - .InverseCollection() + b.HasOne("Wuzlstats.Models.League") + .WithMany() .ForeignKey("LeagueId"); }); builder.Entity("Wuzlstats.Models.PlayerPosition", b => { - b.Reference("Wuzlstats.Models.Game") - .InverseCollection() + b.HasOne("Wuzlstats.Models.Game") + .WithMany() .ForeignKey("GameId"); - b.Reference("Wuzlstats.Models.Player") - .InverseCollection() + b.HasOne("Wuzlstats.Models.Player") + .WithMany() .ForeignKey("PlayerId"); }); } diff --git a/src/Wuzlstats/Migrations/20150810174412_Initial.cs b/src/Wuzlstats/Migrations/20150810174412_Initial.cs index 54752c7..9d8b067 100644 --- a/src/Wuzlstats/Migrations/20150810174412_Initial.cs +++ b/src/Wuzlstats/Migrations/20150810174412_Initial.cs @@ -1,22 +1,20 @@ -using System.Collections.Generic; using Microsoft.Data.Entity.Migrations; -using Microsoft.Data.Entity.Migrations.Builders; -using Microsoft.Data.Entity.Migrations.Operations; +using System; namespace Wuzlstats.Migrations { public partial class Initial : Migration { - public override void Up(MigrationBuilder migration) + protected override void Up(MigrationBuilder migration) { migration.CreateTable( name: "League", columns: table => new { - Id = table.Column(type: "int", nullable: false) + Id = table.Column(nullable: false) .Annotation("SqlServer:ValueGenerationStrategy", "IdentityColumn"), - Name = table.Column(type: "nvarchar(max)", nullable: true), - TimeoutConfiguration = table.Column(type: "nvarchar(max)", nullable: true) + Name = table.Column(type: "nvarchar(max)", nullable: true), + TimeoutConfiguration = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { @@ -26,12 +24,12 @@ public override void Up(MigrationBuilder migration) name: "Game", columns: table => new { - Id = table.Column(type: "int", nullable: false) + Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:ValueGenerationStrategy", "IdentityColumn"), - BlueScore = table.Column(type: "int", nullable: false), - Date = table.Column(type: "datetime2", nullable: false), - LeagueId = table.Column(type: "int", nullable: false), - RedScore = table.Column(type: "int", nullable: false) + BlueScore = table.Column(type: "int", nullable: false), + Date = table.Column(type: "datetime2", nullable: false), + LeagueId = table.Column(type: "int", nullable: false), + RedScore = table.Column(type: "int", nullable: false) }, constraints: table => { @@ -39,18 +37,18 @@ public override void Up(MigrationBuilder migration) table.ForeignKey( name: "FK_Game_League_LeagueId", columns: x => x.LeagueId, - referencedTable: "League", - referencedColumn: "Id"); - }); + principalTable: "League", + principalColumns: new[] { "Id" }); + }); migration.CreateTable( name: "Player", columns: table => new { - Id = table.Column(type: "int", nullable: false) + Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:ValueGenerationStrategy", "IdentityColumn"), - Image = table.Column(type: "varbinary(max)", nullable: true), - LeagueId = table.Column(type: "int", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: true) + Image = table.Column(type: "varbinary(max)", nullable: true), + LeagueId = table.Column(type: "int", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { @@ -58,18 +56,18 @@ public override void Up(MigrationBuilder migration) table.ForeignKey( name: "FK_Player_League_LeagueId", columns: x => x.LeagueId, - referencedTable: "League", - referencedColumn: "Id"); + principalTable: "League", + principalColumns: new[] { "Id" }); }); migration.CreateTable( name: "PlayerPosition", columns: table => new { - Id = table.Column(type: "int", nullable: false) + Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:ValueGenerationStrategy", "IdentityColumn"), - GameId = table.Column(type: "int", nullable: false), - PlayerId = table.Column(type: "int", nullable: false), - Position = table.Column(type: "int", nullable: false) + GameId = table.Column(type: "int", nullable: false), + PlayerId = table.Column(type: "int", nullable: false), + Position = table.Column(type: "int", nullable: false) }, constraints: table => { @@ -77,17 +75,17 @@ public override void Up(MigrationBuilder migration) table.ForeignKey( name: "FK_PlayerPosition_Game_GameId", columns: x => x.GameId, - referencedTable: "Game", - referencedColumn: "Id"); + principalTable: "Game", + principalColumns: new[] { "Id" }); table.ForeignKey( name: "FK_PlayerPosition_Player_PlayerId", columns: x => x.PlayerId, - referencedTable: "Player", - referencedColumn: "Id"); + principalTable: "Player", + principalColumns: new[] { "Id" }); }); } - public override void Down(MigrationBuilder migration) + protected override void Down(MigrationBuilder migration) { migration.DropTable("PlayerPosition"); migration.DropTable("Game"); diff --git a/src/Wuzlstats/Migrations/DbModelSnapshot.cs b/src/Wuzlstats/Migrations/DbModelSnapshot.cs index b73d52c..6f135db 100644 --- a/src/Wuzlstats/Migrations/DbModelSnapshot.cs +++ b/src/Wuzlstats/Migrations/DbModelSnapshot.cs @@ -1,15 +1,14 @@ using System; using Microsoft.Data.Entity; -using Microsoft.Data.Entity.Metadata; -using Microsoft.Data.Entity.Migrations.Infrastructure; using Wuzlstats.Models; +using Microsoft.Data.Entity.Infrastructure; namespace Wuzlstats.Migrations { - [ContextType(typeof(Db))] + [DbContext(typeof(Db))] partial class DbModelSnapshot : ModelSnapshot { - public override void BuildModel(ModelBuilder builder) + protected override void BuildModel(ModelBuilder builder) { builder .Annotation("ProductVersion", "7.0.0-beta6-13815") @@ -28,7 +27,7 @@ public override void BuildModel(ModelBuilder builder) b.Property("RedScore"); - b.Key("Id"); + b.HasKey("Id"); }); builder.Entity("Wuzlstats.Models.League", b => @@ -40,7 +39,7 @@ public override void BuildModel(ModelBuilder builder) b.Property("TimeoutConfiguration"); - b.Key("Id"); + b.HasKey("Id"); }); builder.Entity("Wuzlstats.Models.Player", b => @@ -54,7 +53,7 @@ public override void BuildModel(ModelBuilder builder) b.Property("Name"); - b.Key("Id"); + b.HasKey("Id"); }); builder.Entity("Wuzlstats.Models.PlayerPosition", b => @@ -68,31 +67,31 @@ public override void BuildModel(ModelBuilder builder) b.Property("Position"); - b.Key("Id"); + b.HasKey("Id"); }); builder.Entity("Wuzlstats.Models.Game", b => { - b.Reference("Wuzlstats.Models.League") - .InverseCollection() + b.HasOne("Wuzlstats.Models.League") + .WithMany() .ForeignKey("LeagueId"); }); builder.Entity("Wuzlstats.Models.Player", b => { - b.Reference("Wuzlstats.Models.League") - .InverseCollection() + b.HasOne("Wuzlstats.Models.League") + .WithMany() .ForeignKey("LeagueId"); }); builder.Entity("Wuzlstats.Models.PlayerPosition", b => { - b.Reference("Wuzlstats.Models.Game") - .InverseCollection() + b.HasOne("Wuzlstats.Models.Game") + .WithMany() .ForeignKey("GameId"); - b.Reference("Wuzlstats.Models.Player") - .InverseCollection() + b.HasOne("Wuzlstats.Models.Player") + .WithMany() .ForeignKey("PlayerId"); }); } diff --git a/src/Wuzlstats/Models/Db.cs b/src/Wuzlstats/Models/Db.cs index 6581a8b..992524e 100644 --- a/src/Wuzlstats/Models/Db.cs +++ b/src/Wuzlstats/Models/Db.cs @@ -12,12 +12,12 @@ public class Db : DbContext protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity().Reference(x => x.League).InverseCollection(x => x.Games).ForeignKey(x => x.LeagueId); - modelBuilder.Entity().Reference(x => x.League).InverseCollection(x => x.Players).ForeignKey(x => x.LeagueId); - modelBuilder.Entity().Reference(x => x.Player).InverseCollection(x => x.Positions).ForeignKey(x => x.PlayerId); - modelBuilder.Entity().Reference(x => x.Game).InverseCollection(x => x.Positions).ForeignKey(x => x.GameId); + modelBuilder.Entity().HasOne(x => x.League).WithMany(x => x.Games).ForeignKey(x => x.LeagueId); + modelBuilder.Entity().HasOne(x => x.League).WithMany(x => x.Players).ForeignKey(x => x.LeagueId); + modelBuilder.Entity().HasOne(x => x.Player).WithMany(x => x.Positions).ForeignKey(x => x.PlayerId); + modelBuilder.Entity().HasOne(x => x.Game).WithMany(x => x.Positions).ForeignKey(x => x.GameId); base.OnModelCreating(modelBuilder); } } -} \ No newline at end of file +} diff --git a/src/Wuzlstats/Startup.cs b/src/Wuzlstats/Startup.cs index e6c6020..038eb16 100644 --- a/src/Wuzlstats/Startup.cs +++ b/src/Wuzlstats/Startup.cs @@ -4,7 +4,7 @@ using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; -using Microsoft.Framework.Runtime; +using Microsoft.Dnx.Runtime; using Wuzlstats.Models; using Wuzlstats.ViewModels.Hubs; @@ -15,7 +15,8 @@ public class Startup // ReSharper disable once UnusedParameter.Local public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) { - Configuration = new ConfigurationBuilder(appEnv.ApplicationBasePath) + Configuration = new ConfigurationBuilder() + .SetBasePath(appEnv.ApplicationBasePath) .AddJsonFile("config.json") .AddEnvironmentVariables("Wuzlstats.") .Build(); @@ -50,7 +51,10 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF loggerfactory.AddConsole(); - app.UseErrorHandler("/Home/Error"); + app.UseExceptionHandler("/Home/Error"); + + // Add the platform handler to the request pipeline. + app.UseIISPlatformHandler(); app.UseStaticFiles(); diff --git a/src/Wuzlstats/project.json b/src/Wuzlstats/project.json index f38cb9c..a6bac99 100644 --- a/src/Wuzlstats/project.json +++ b/src/Wuzlstats/project.json @@ -1,26 +1,27 @@ -{ +{ "webroot": "wwwroot", "version": "0.0.0-*", "dependencies": { - "Microsoft.AspNet.Diagnostics": "1.0.0-beta6", - "Microsoft.AspNet.Mvc": "6.0.0-beta6", - "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta6", - "Microsoft.AspNet.Server.IIS": "1.0.0-beta6", - "Microsoft.AspNet.Server.WebListener": "1.0.0-beta6", - "Microsoft.AspNet.StaticFiles": "1.0.0-beta6", - "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta6", - "Microsoft.AspNet.SignalR.Server": "3.0.0-beta6", - "Microsoft.Framework.Configuration.Json": "1.0.0-beta6", - "Microsoft.Framework.Logging": "1.0.0-beta6", - "Microsoft.Framework.Logging.Console": "1.0.0-beta6", - "EntityFramework.SqlServer": "7.0.0-beta6", - "EntityFramework.Commands": "7.0.0-beta6", + "Microsoft.AspNet.Diagnostics": "1.0.0-beta8", + "Microsoft.AspNet.Mvc": "6.0.0-beta8", + "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8", + "Microsoft.AspNet.IISPlatformHandler": "1.0.0-beta8", + "Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8", + "Microsoft.AspNet.Server.WebListener": "1.0.0-beta8", + "Microsoft.AspNet.StaticFiles": "1.0.0-beta8", + "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta8", + "Microsoft.AspNet.SignalR.Server": "3.0.0-beta8", + "Microsoft.Framework.Configuration.Json": "1.0.0-beta8", + "Microsoft.Framework.Logging": "1.0.0-beta8", + "Microsoft.Framework.Logging.Console": "1.0.0-beta8", + "EntityFramework.SqlServer": "7.0.0-beta8", + "EntityFramework.Commands": "7.0.0-beta8", "ImageResizer": "3.4.3" }, "commands": { - "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000", + "web": "Microsoft.AspNet.Server.Kestrel", "ef": "EntityFramework.Commands" }, diff --git a/src/Wuzlstats/wwwroot/web.config b/src/Wuzlstats/wwwroot/web.config new file mode 100644 index 0000000..84b3c92 --- /dev/null +++ b/src/Wuzlstats/wwwroot/web.config @@ -0,0 +1,9 @@ + + + + + + + + +