Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to use aspnet core 2.2 runtime #108

Merged
merged 9 commits into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ environment:
coalesce_version: 2.2.0
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
NET_CORE_VERSION: netcoreapp2.1
NET_CORE_VERSION: netcoreapp2.2
NPM_TOKEN:
secure: dQCkkO4ezshvOI5/8Tml4T0EnIxjHv7nrXFsnq9dStEGBbcQNIWhb+gOBn9lacYs

Expand Down
2 changes: 1 addition & 1 deletion coalesce-ko.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"webProject": {
"projectFile": "./src/Coalesce.Web/Coalesce.Web.csproj",
"framework": "netcoreapp2.1",
"framework": "netcoreapp2.2",
"configuration": "Debug"
},
"dataProject": {
Expand Down
6 changes: 4 additions & 2 deletions coalesce-vue.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"webProject": {
"projectFile": "./src/Coalesce.Web.Vue/Coalesce.Web.Vue.csproj"
"projectFile": "./src/Coalesce.Web.Vue/Coalesce.Web.Vue.csproj",
"framework": "netcoreapp2.2"
},
"dataProject": {
"projectFile": "./src/Coalesce.Domain/Coalesce.Domain.csproj"
"projectFile": "./src/Coalesce.Domain/Coalesce.Domain.csproj",
"framework": "netstandard2.0"
},

"rootGenerator": "Vue"
Expand Down
10 changes: 5 additions & 5 deletions src/Coalesce.Domain/Coalesce.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
Override the used framework by specifying (framework: "tfm") in coalesce.json. -->
<!--
IMPORTANT NOTE REGARDING ENTITYFRAMEWORK MIGRATIONS (Ctrl+f: EFCore, EF Core):
All EF commands need to be ran with - -framework netcoreapp2.1. E.g.:
All EF commands need to be ran with - -framework netcoreapp2.2. E.g.:
dotnet ef database update - -framework netcoreapp2.1
(no space between the dashes; space is there because double dash is illegal in XML comments).
-->
<TargetFrameworks>netstandard2.0;netcoreapp2.1;net471</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netcoreapp2.2;net471</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\IntelliTect.Coalesce\IntelliTect.Coalesce.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="GenFu" Version="1.4.22" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.*" />
</ItemGroup>
</Project>
5 changes: 3 additions & 2 deletions src/Coalesce.Web.Vue/Coalesce.Web.Vue.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Coalesce.Domain\Coalesce.Domain.csproj" />
Expand Down
8 changes: 2 additions & 6 deletions src/Coalesce.Web.Vue/Controllers/EventController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using System.Net.Http;
using Microsoft.AspNetCore.Mvc;

namespace VuePlayground.Controllers
namespace Coalesce.Web.Vue.Controllers
{
public class EventController : Controller
{
Expand Down
22 changes: 16 additions & 6 deletions src/Coalesce.Web.Vue/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.FileProviders;

namespace VuePlayground.Controllers
namespace Coalesce.Web.Vue.Controllers
{
public class HomeController : Controller
{
private readonly IHostingEnvironment hostingEnvironment;

public HomeController(IHostingEnvironment hostingEnvironment)
{
this.hostingEnvironment = hostingEnvironment;
}

public IActionResult Index()
{
return File("~/index.html", "text/html");

IFileProvider provider = new PhysicalFileProvider(hostingEnvironment.WebRootPath);
IFileInfo fileInfo = provider.GetFileInfo("index.html");
var readStream = fileInfo.CreateReadStream();

return File(readStream, "text/html");
}

public IActionResult Error()
Expand Down
3 changes: 1 addition & 2 deletions src/Coalesce.Web.Vue/Controllers/SampleDataController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace VuePlayground.Controllers
namespace Coalesce.Web.Vue.Controllers
{
[Route("api/[controller]")]
public class SampleDataController : Controller
Expand Down
70 changes: 70 additions & 0 deletions src/Coalesce.Web.Vue/DemoMiddleware.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;

namespace Coalesce.Web.Vue
{
public class DemoMiddleware
{
public const string AuthenticationScheme = "DemoMiddleware";

RequestDelegate _next;

public DemoMiddleware(RequestDelegate next)
{
_next = next;
}

public async Task Invoke(HttpContext context)
{
var validRoles = new List<string> { "Admin", "User", "None" };
var wasLoggedIn = context.User.Identity.IsAuthenticated;

var cookie = context.Request.Cookies.FirstOrDefault(c => c.Key == "SecurityTestRole");
if (!cookie.Equals(default(KeyValuePair<string, string>))
&& validRoles.Contains(cookie.Value)
&& context.Request.Host.Value.ToLower().Contains("localhost"))
{
if (cookie.Value != "None")
{
await SignInUser(context, "SecurityTestUser", cookie.Value);
if (!wasLoggedIn) context.Response.Redirect(context.Request.Path);
}
}
else
{
cookie = context.Request.Cookies.FirstOrDefault(c => c.Key == "DemoUserRole");
if (!cookie.Equals(default(KeyValuePair<string, string>))
&& validRoles.Contains(cookie.Value)
&& context.Request.Host.Value.ToLower().Contains("localhost"))
{
await SignInUser(context, "DemoUser", cookie.Value);
}
else
{
await SignInUser(context, "DemoUser", "Admin");
}
}

var isLoggedIn = context.User.Identity.IsAuthenticated;
if (!wasLoggedIn && isLoggedIn) context.Response.Redirect("/");
else await _next(context);
}

private async Task SignInUser(HttpContext context, string name, string role)
{
Claim[] claims;
if (string.IsNullOrEmpty(role)) claims = new[] { new Claim(ClaimTypes.Name, name) };
else claims = new[] {
new Claim(ClaimTypes.Name, name),
new Claim(ClaimTypes.Role, role)
};

var identity = new ClaimsIdentity(claims, "AutoSignIn");
await context.SignInAsync(AuthenticationScheme, new ClaimsPrincipal(identity));
}
}
}
16 changes: 12 additions & 4 deletions src/Coalesce.Web.Vue/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.IO;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using VuePlayground;
using Microsoft.Extensions.Logging;

namespace Coalesce.Web.Vue
{
Expand All @@ -11,8 +12,15 @@ public static void Main(string[] args)
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.ConfigureLogging((context, builder) =>
{
builder.AddConsole();
builder.AddDebug();
})
.UseStartup<Startup>();
}
}
}
}
57 changes: 30 additions & 27 deletions src/Coalesce.Web.Vue/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Security.Claims;
using System.Runtime.InteropServices;
using Coalesce.Domain;
using IntelliTect.Coalesce;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using IntelliTect.Coalesce.DataAnnotations;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
Expand All @@ -25,19 +25,29 @@ public Startup(IConfiguration configuration)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

services.AddCoalesce(builder => builder
.AddContext<AppDbContext>()
.UseDefaultDataSource(typeof(MyDataSource<,>))
.UseDefaultBehaviors(typeof(MyBehaviors<,>))
.UseTimeZone(TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"))
);
services.AddCoalesce(builder =>
{
builder
.AddContext<AppDbContext>()
.UseDefaultDataSource(typeof(MyDataSource<,>))
.UseDefaultBehaviors(typeof(MyBehaviors<,>));

// This breaks on non-windows platforms, see https://github.com/dotnet/corefx/issues/11897
builder.UseTimeZone(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time")
: TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles"));
});

services.AddAuthentication(DemoMiddleware.AuthenticationScheme).AddCookie(DemoMiddleware.AuthenticationScheme);

services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
RoleMapping.Add("Admin", "S-1-5-4"); // Interactive user.
RoleMapping.Add("User", "S-1-1-0"); // Everyone who has logged on
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand All @@ -51,7 +61,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
HotModuleReplacement = true,

// Use a slightly-tweaked version of vue-cli's webpack config to work around a few bugs.
ConfigFile = "webpack.config.aspnetcore-hmr.js",
ConfigFile = "webpack.config.aspnetcore-hmr.js"
});
}
else
Expand All @@ -61,34 +71,27 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)

app.UseStaticFiles();

// *** DEMO ONLY ***
app.UseAuthentication();

// Demo only - logs everyone in as admin.
app.Use(async (context, next) =>
{
Claim[] claims = new[] { new Claim(ClaimTypes.Name, "DemoUser"), new Claim(ClaimTypes.Role, "Admin") };
var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
await context.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity));
await next.Invoke();
});
app.UseMiddleware<DemoMiddleware>();

app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
"default",
"{controller=Home}/{action=Index}/{id?}");
});

app.MapWhen(x => !x.Request.Path.Value.StartsWith("/api"), builder =>
{
builder.UseMvc(routes =>
{
routes.MapSpaFallbackRoute(
name: "spa-fallback",
defaults: new { controller = "Home", action = "Index" });
"spa-fallback",
new {controller = "Home", action = "Index"});
});
});
}
}
}
}
2 changes: 1 addition & 1 deletion src/Coalesce.Web.Vue/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@using VuePlayground
@using Coalesce.Web.Vue
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Microsoft.AspNetCore.SpaServices
Loading