Skip to content

Commit dbcef3d

Browse files
authored
Merge pull request #142 from kijoyin/master
Upgrading to dontnet 6
2 parents 57b7008 + b633b57 commit dbcef3d

File tree

7 files changed

+137
-221
lines changed

7 files changed

+137
-221
lines changed

Engine/Engine.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>
88
<Folder Include="Interfaces\" />
99
</ItemGroup>
1010
<ItemGroup>
11-
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
11+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
1212
</ItemGroup>
1313
</Project>

Tests/Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>

Web/Program.cs

Lines changed: 110 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,118 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore;
1+
using Google.Protobuf.WellKnownTypes;
2+
using Hangfire;
73
using Microsoft.AspNetCore.Builder;
8-
using Microsoft.AspNetCore.Hosting;
9-
using Microsoft.AspNetCore.Http;
10-
using Microsoft.Extensions.DependencyInjection;
11-
using Microsoft.Extensions.Logging;
4+
using Microsoft.AspNetCore.Identity;
125
using Microsoft.Extensions.Configuration;
6+
using Microsoft.Extensions.Hosting;
7+
using QueryTree.Managers;
138
using QueryTree.Models;
9+
using QueryTree.Services;
10+
using QueryTree;
11+
using System;
12+
using System.Configuration;
13+
using Hangfire.SQLite;
14+
using Microsoft.AspNetCore.Http;
15+
using Microsoft.Extensions.DependencyInjection;
1416
using Microsoft.EntityFrameworkCore;
1517

16-
namespace QueryTree
18+
var builder = WebApplication.CreateBuilder(args);
19+
builder.Services.AddSingleton<IConfiguration>(builder.Configuration);
20+
21+
builder.Services.Configure<CustomizationConfiguration>(builder.Configuration.GetSection("Customization"));
22+
builder.Services.Configure<PasswordsConfiguration>(builder.Configuration.GetSection("Passwords"));
23+
24+
switch (builder.Configuration.GetValue<QueryTree.Enums.DataStoreType>("Customization:DataStore"))
1725
{
18-
public class Program
19-
{
20-
public static void Main(string[] args)
21-
{
22-
var host = GetBuilder(args, true)
23-
.Build();
24-
25-
using (var scope = host.Services.CreateScope())
26-
{
27-
var context = scope.ServiceProvider.GetService<ApplicationDbContext>();
28-
context.Database.Migrate();
29-
}
30-
31-
host.Run();
32-
}
33-
34-
public static IWebHost BuildWebHost(string[] args)
35-
{
36-
return GetBuilder(args, false).Build();
37-
}
38-
39-
public static IWebHostBuilder GetBuilder(string[] args, bool runHangfire)
40-
{
41-
var builder = WebHost.CreateDefaultBuilder(args)
42-
.UseStartup<Startup>();
43-
44-
if (runHangfire)
45-
{
46-
builder = builder.UseSetting("RunHangfire", "true");
47-
}
48-
else
49-
{
50-
builder = builder.UseSetting("RunHangfire", "false");
51-
}
52-
53-
return builder.ConfigureAppConfiguration((hostContext, config) =>
26+
case QueryTree.Enums.DataStoreType.MSSqlServer:
27+
builder.Services.AddDbContext<ApplicationDbContext>(options =>
28+
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
29+
builder.Services.AddHangfire(x =>
30+
x.UseSqlServerStorage(builder.Configuration.GetConnectionString("DefaultConnection"))
31+
);
32+
break;
33+
34+
default:
35+
builder.Services.AddDbContext<ApplicationDbContext>(options =>
36+
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));
37+
builder.Services.AddHangfire(x =>
38+
x.UseSQLiteStorage(builder.Configuration.GetConnectionString("DefaultConnection"))
39+
);
40+
break;
41+
}
42+
43+
builder.Services.AddIdentity<ApplicationUser, IdentityRole>()
44+
.AddEntityFrameworkStores<ApplicationDbContext>()
45+
.AddDefaultTokenProviders();
46+
47+
builder.Services.AddAuthentication()
48+
.AddCookie(options =>
5449
{
55-
if (hostContext.HostingEnvironment.IsDevelopment())
56-
{
57-
config.AddJsonFile($"usersettings.json", optional: true);
58-
}
50+
// Cookie settings
51+
options.ExpireTimeSpan = TimeSpan.FromDays(150);
52+
options.LoginPath = "/Account/LogIn";
53+
options.LogoutPath = "/Account/LogOut";
5954
});
60-
}
61-
}
62-
}
55+
56+
builder.Services.Configure<IdentityOptions>(options =>
57+
{
58+
// Password settings
59+
options.Password.RequiredLength = 8;
60+
61+
// Lockout settings
62+
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
63+
options.Lockout.MaxFailedAccessAttempts = 10;
64+
65+
// User settings
66+
options.User.RequireUniqueEmail = true;
67+
});
68+
// Add services to the container.
69+
builder.Services.AddControllersWithViews();
70+
71+
// Add application services.
72+
builder.Services.AddTransient<IEmailSenderService, EmailSenderService>();
73+
builder.Services.AddTransient<IEmailSender, EmailSender>();
74+
builder.Services.AddTransient<IPasswordManager, PasswordManager>(); // Allows controllers to set/get/delete database credentials
75+
builder.Services.AddTransient<IScheduledEmailManager, ScheduledEmailManager>();
76+
builder.Services.AddMemoryCache();
77+
var app = builder.Build();
78+
79+
using (var scope = app.Services.CreateScope())
80+
{
81+
var context = scope.ServiceProvider.GetService<ApplicationDbContext>();
82+
context.Database.Migrate();
83+
}
84+
// Configure the HTTP request pipeline.
85+
if (!app.Environment.IsDevelopment())
86+
{
87+
app.UseExceptionHandler("/Home/Error");
88+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
89+
app.UseHsts();
90+
}
91+
92+
app.UseHttpsRedirection();
93+
app.UseStaticFiles();
94+
95+
app.UseRouting();
96+
app.UseAuthentication();
97+
app.UseAuthorization();
98+
if (builder.Configuration["RunHangfire"] == "true")
99+
{
100+
app.UseHangfireServer();
101+
102+
var dashboardOptions = new DashboardOptions
103+
{
104+
Authorization = new[] { new HangfireAuthorizationFilter() }
105+
};
106+
app.UseHangfireDashboard("/hangfire", dashboardOptions);
107+
}
108+
app.MapControllerRoute(
109+
name: "default",
110+
pattern: "{controller=Home}/{action=Index}/{id?}");
111+
if (!String.IsNullOrWhiteSpace(builder.Configuration.GetValue<string>("Customization:BaseUri")))
112+
{
113+
app.Use((context, next) => {
114+
context.Request.PathBase = new PathString(builder.Configuration.GetValue<string>("Customization:BaseUri"));
115+
return next();
116+
});
117+
}
118+
app.Run();

Web/QueryTree.csproj

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp2.2</TargetFramework>
3+
<TargetFramework>net6.0</TargetFramework>
44
<UserSecretsId>aspnet-QueryTree-46E61BB7-4239-4527-BA0C-1B66D664CC58</UserSecretsId>
55
<Version>0.0.0</Version>
66
<Authors>D4 Software Ltd</Authors>
@@ -20,49 +20,50 @@
2020
<Content Include="Styles\aqb\base.less" />
2121
<Content Include="Styles\aqb\base.min.css" />
2222
</ItemGroup>
23-
2423
<ItemGroup>
2524
<None Update="QueryTree.db" CopyToOutputDirectory="PreserveNewest" />
2625
</ItemGroup>
27-
2826
<ItemGroup>
29-
<PackageReference Include="BuildBundlerMinifier" Version="2.8.391" />
30-
<PackageReference Include="DocumentFormat.OpenXml" Version="2.9.0" />
27+
<PackageReference Include="BuildBundlerMinifier" Version="3.2.449" />
28+
<PackageReference Include="DocumentFormat.OpenXml" Version="2.18.0" />
3129
<PackageReference Include="dotless" Version="1.6.7" />
32-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.2" />
30+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.11" />
31+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.11" />
32+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.11" />
3333
<PackageReference Include="OfficeOpenXml.Core.ExcelPackage" Version="1.0.0" />
3434
<PackageReference Include="Respond" Version="1.4.2" />
35-
<PackageReference Include="System.Data.Common" Version="4.3.0" />
36-
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
35+
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
3736
<PackageReference Include="Hangfire.SQLite" Version="1.4.2" />
38-
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.2.0" />
37+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.1" />
3938
<PackageReference Include="System.Reflection" Version="4.3.0" />
40-
<PackageReference Include="Microsoft.AspNetCore.App" />
4139
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
4240
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.2.0" />
43-
<PackageReference Include="Npgsql" Version="4.0.4" />
44-
<PackageReference Include="MySql.Data" Version="8.0.15" />
45-
<PackageReference Include="Hangfire" Version="1.6.22" />
46-
<PackageReference Include="SSH.NET" Version="2016.1.0" />
41+
<PackageReference Include="Npgsql" Version="6.0.7" />
42+
<PackageReference Include="MySql.Data" Version="8.0.31" />
43+
<PackageReference Include="Hangfire" Version="1.7.31" />
44+
<PackageReference Include="SSH.NET" Version="2020.0.2" />
4745
<PackageReference Include="MailKit" Version="2.1.3" />
48-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.2" />
46+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.11">
47+
<PrivateAssets>all</PrivateAssets>
48+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
49+
</PackageReference>
50+
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.355802">
51+
<PrivateAssets>all</PrivateAssets>
52+
</PackageReference>
53+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.11" />
4954
</ItemGroup>
50-
5155
<ItemGroup>
5256
<ProjectReference Include="..\Engine\Engine.csproj" />
5357
</ItemGroup>
54-
5558
<ItemGroup>
5659
<Folder Include="Scripts\" />
5760
<Folder Include="Scripts\lib\" />
5861
</ItemGroup>
59-
6062
<ItemGroup>
6163
<Content Update="appsettings.json">
6264
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6365
</Content>
6466
</ItemGroup>
6567
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
6668
</Target>
67-
68-
</Project>
69+
</Project>

0 commit comments

Comments
 (0)