Migrate to .NET Core 3.1.

This commit is contained in:
2020-05-21 05:01:35 +01:00
parent e3ebd41291
commit 880f66df1a
12 changed files with 67 additions and 79 deletions

View File

@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Marechai.Database</RootNamespace> <RootNamespace>Marechai.Database</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="2.2.4" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.1.4" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" /> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.2.5" /> <FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" /> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />

View File

@@ -21,9 +21,9 @@ namespace Marechai.Areas.Admin.Controllers
public class CompanyLogosController : Controller public class CompanyLogosController : Controller
{ {
readonly MarechaiContext _context; readonly MarechaiContext _context;
readonly IHostingEnvironment hostingEnvironment; readonly IWebHostEnvironment hostingEnvironment;
public CompanyLogosController(MarechaiContext context, IHostingEnvironment env) public CompanyLogosController(MarechaiContext context, IWebHostEnvironment env)
{ {
_context = context; _context = context;
hostingEnvironment = env; hostingEnvironment = env;
@@ -144,7 +144,8 @@ namespace Marechai.Areas.Admin.Controllers
}) })
{ {
if(!Directory.Exists(Path.Combine(hostingEnvironment.WebRootPath, "assets/logos", format))) if(!Directory.Exists(Path.Combine(hostingEnvironment.WebRootPath, "assets/logos", format)))
Directory.CreateDirectory(Path.Combine(hostingEnvironment.WebRootPath, "assets/logos", format)); Directory.CreateDirectory(Path.Combine(hostingEnvironment.WebRootPath, "assets/logos",
format));
SKEncodedImageFormat skFormat; SKEncodedImageFormat skFormat;
@@ -280,8 +281,7 @@ namespace Marechai.Areas.Admin.Controllers
float scale = canvasMin / svgMax; float scale = canvasMin / svgMax;
var matrix = SKMatrix.MakeScale(scale, scale); var matrix = SKMatrix.MakeScale(scale, scale);
var bitmap = var bitmap = new SKBitmap((int)(svgSize.Width * scale), (int)(svgSize.Height * scale));
new SKBitmap((int)(svgSize.Width * scale), (int)(svgSize.Height * scale));
var canvas = new SKCanvas(bitmap); var canvas = new SKCanvas(bitmap);
canvas.DrawPicture(svg.Picture, ref matrix); canvas.DrawPicture(svg.Picture, ref matrix);

View File

@@ -20,10 +20,10 @@ namespace Marechai.Areas.Admin.Controllers
public class MachinePhotosController : Controller public class MachinePhotosController : Controller
{ {
readonly MarechaiContext _context; readonly MarechaiContext _context;
readonly IHostingEnvironment hostingEnvironment; readonly IWebHostEnvironment hostingEnvironment;
readonly UserManager<ApplicationUser> userManager; readonly UserManager<ApplicationUser> userManager;
public MachinePhotosController(MarechaiContext context, IHostingEnvironment hostingEnvironment, public MachinePhotosController(MarechaiContext context, IWebHostEnvironment hostingEnvironment,
UserManager<ApplicationUser> userManager) UserManager<ApplicationUser> userManager)
{ {
_context = context; _context = context;
@@ -56,29 +56,19 @@ namespace Marechai.Areas.Admin.Controllers
MachinePhotoDetailsViewModel machinePhoto = MachinePhotoDetailsViewModel machinePhoto =
await _context.MachinePhotos.Select(m => new MachinePhotoDetailsViewModel await _context.MachinePhotos.Select(m => new MachinePhotoDetailsViewModel
{ {
Id = m.Id, CameraManufacturer = m.CameraManufacturer, Id = m.Id, CameraManufacturer = m.CameraManufacturer, CameraModel = m.CameraModel,
CameraModel = m.CameraModel, ColorSpace = m.ColorSpace, Comments = m.Comments, Contrast = m.Contrast,
ColorSpace = m.ColorSpace, Comments = m.Comments, CreationDate = m.CreationDate, DigitalZoomRatio = m.DigitalZoomRatio, ExifVersion = m.ExifVersion,
Contrast = m.Contrast, Exposure = m.Exposure, ExposureProgram = m.ExposureProgram, Flash = m.Flash, Focal = m.Focal,
CreationDate = m.CreationDate, DigitalZoomRatio = m.DigitalZoomRatio, FocalLength = m.FocalLength, FocalLengthEquivalent = m.FocalLengthEquivalent,
ExifVersion = m.ExifVersion, HorizontalResolution = m.HorizontalResolution, IsoRating = m.IsoRating, Lens = m.Lens,
Exposure = m.Exposure, ExposureProgram = m.ExposureProgram, LightSource = m.LightSource, MeteringMode = m.MeteringMode, ResolutionUnit = m.ResolutionUnit,
Flash = m.Flash, Focal = m.Focal, Orientation = m.Orientation, Saturation = m.Saturation, SceneCaptureType = m.SceneCaptureType,
FocalLength = m.FocalLength, FocalLengthEquivalent = m.FocalLengthEquivalent, SensingMethod = m.SensingMethod, Sharpness = m.Sharpness, SoftwareUsed = m.SoftwareUsed,
HorizontalResolution = m.HorizontalResolution, IsoRating = m.IsoRating,
Lens = m.Lens,
LightSource = m.LightSource, MeteringMode = m.MeteringMode,
ResolutionUnit = m.ResolutionUnit,
Orientation = m.Orientation, Saturation = m.Saturation,
SceneCaptureType = m.SceneCaptureType,
SensingMethod = m.SensingMethod, Sharpness = m.Sharpness,
SoftwareUsed = m.SoftwareUsed,
SubjectDistanceRange = m.SubjectDistanceRange, UploadDate = m.UploadDate, SubjectDistanceRange = m.SubjectDistanceRange, UploadDate = m.UploadDate,
VerticalResolution = m.VerticalResolution, WhiteBalance = m.WhiteBalance, VerticalResolution = m.VerticalResolution, WhiteBalance = m.WhiteBalance, License = m.License.Name,
License = m.License.Name, UploadUser = m.User.UserName, Machine = $"{m.Machine.Company.Name} {m.Machine.Name}",
UploadUser = m.User.UserName, MachineId = m.Machine.Id, Source = m.Source
Machine = $"{m.Machine.Company.Name} {m.Machine.Name}",
MachineId = m.Machine.Id, Source = m.Source
}).FirstOrDefaultAsync(m => m.Id == id); }).FirstOrDefaultAsync(m => m.Id == id);
if(machinePhoto == null) if(machinePhoto == null)
@@ -233,10 +223,9 @@ namespace Marechai.Areas.Admin.Controllers
await _context.MachinePhotos.Include(m => m.Machine).Include(m => m.Machine.Company). await _context.MachinePhotos.Include(m => m.Machine).Include(m => m.Machine.Company).
Include(m => m.User).Select(p => new MachinePhotoViewModel Include(m => m.User).Select(p => new MachinePhotoViewModel
{ {
Id = p.Id, Author = p.Author, Id = p.Id, Author = p.Author, License = p.License.Name,
License = p.License.Name,
Machine = $"{p.Machine.Company.Name} {p.Machine.Name}", UploadDate = p.UploadDate, Machine = $"{p.Machine.Company.Name} {p.Machine.Name}", UploadDate = p.UploadDate,
UploadUser = p.User.UserName, LicenseId = p.License.Id UploadUser = p.User.UserName, LicenseId = p.License.Id
}).OrderBy(p => p.Machine).ThenBy(p => p.UploadUser).ThenBy(p => p.UploadDate). }).OrderBy(p => p.Machine).ThenBy(p => p.UploadUser).ThenBy(p => p.UploadDate).
FirstOrDefaultAsync(m => m.Id == id); FirstOrDefaultAsync(m => m.Id == id);

View File

@@ -41,9 +41,9 @@ namespace Marechai.Areas.Admin.Models
public string Company; public string Company;
[DisplayFormat(DataFormatString = "{0:d}"), DataType(DataType.Date)] [DisplayFormat(DataFormatString = "{0:d}"), DataType(DataType.Date)]
public DateTime? Introduced; public DateTime? Introduced;
[DisplayName("Model code")]
public string ModelCode;
public string Name; public string Name;
[DisplayName("Model code")]
public string ModelCode { get; set; }
[NotMapped] [NotMapped]
public string IntroducedView => Introduced?.ToShortDateString() ?? "Unknown"; public string IntroducedView => Introduced?.ToShortDateString() ?? "Unknown";

View File

@@ -35,7 +35,7 @@ namespace Marechai.Areas.Admin.Models
public class GpusByMachineViewModel : BaseViewModel<long> public class GpusByMachineViewModel : BaseViewModel<long>
{ {
[DisplayName("GPU")] [DisplayName("GPU")]
public string Gpu; public string Gpu { get; set; }
public string Machine; public string Machine { get; set; }
} }
} }

View File

@@ -40,9 +40,9 @@ namespace Marechai.Controllers
public class CompanyController : Controller public class CompanyController : Controller
{ {
readonly MarechaiContext _context; readonly MarechaiContext _context;
readonly IHostingEnvironment hostingEnvironment; readonly IWebHostEnvironment hostingEnvironment;
public CompanyController(IHostingEnvironment env, MarechaiContext context) public CompanyController(IWebHostEnvironment env, MarechaiContext context)
{ {
hostingEnvironment = env; hostingEnvironment = env;
_context = context; _context = context;
@@ -70,9 +70,8 @@ namespace Marechai.Controllers
return View(_context.Companies.Include(c => c.Logos).Where(c => c.Name.StartsWith(id)).OrderBy(c => c.Name). return View(_context.Companies.Include(c => c.Logos).Where(c => c.Name.StartsWith(id)).OrderBy(c => c.Name).
Select(c => new CompanyViewModel Select(c => new CompanyViewModel
{ {
Id = c.Id, Id = c.Id, LastLogo = c.Logos.OrderByDescending(l => l.Year).FirstOrDefault().Guid,
LastLogo = c.Logos.OrderByDescending(l => l.Year).FirstOrDefault().Guid, Name = c.Name
Name = c.Name
}).ToList()); }).ToList());
} }
@@ -101,9 +100,8 @@ namespace Marechai.Controllers
return View(_context.Companies.Include(c => c.Logos).Where(c => c.CountryId == id).OrderBy(c => c.Name). return View(_context.Companies.Include(c => c.Logos).Where(c => c.CountryId == id).OrderBy(c => c.Name).
Select(c => new CompanyViewModel Select(c => new CompanyViewModel
{ {
Id = c.Id, Id = c.Id, LastLogo = c.Logos.OrderByDescending(l => l.Year).FirstOrDefault().Guid,
LastLogo = c.Logos.OrderByDescending(l => l.Year).FirstOrDefault().Guid, Name = c.Name
Name = c.Name
}).ToList()); }).ToList());
} }

View File

@@ -39,9 +39,9 @@ namespace Marechai.Controllers
public class ComputerController : Controller public class ComputerController : Controller
{ {
readonly MarechaiContext _context; readonly MarechaiContext _context;
readonly IHostingEnvironment hostingEnvironment; readonly IWebHostEnvironment hostingEnvironment;
public ComputerController(IHostingEnvironment env, MarechaiContext context) public ComputerController(IWebHostEnvironment env, MarechaiContext context)
{ {
hostingEnvironment = env; hostingEnvironment = env;
_context = context; _context = context;
@@ -52,13 +52,11 @@ namespace Marechai.Controllers
ViewBag.ItemCount = _context.Machines.Count(m => m.Type == MachineType.Computer); ViewBag.ItemCount = _context.Machines.Count(m => m.Type == MachineType.Computer);
ViewBag.MinYear = _context. ViewBag.MinYear = _context.
Machines.Where(t => t.Type == MachineType.Computer && Machines.Where(t => t.Type == MachineType.Computer && t.Introduced.HasValue &&
t.Introduced.HasValue &&
t.Introduced.Value.Year > 1000).Min(t => t.Introduced.Value.Year); t.Introduced.Value.Year > 1000).Min(t => t.Introduced.Value.Year);
ViewBag.MaxYear = _context. ViewBag.MaxYear = _context.
Machines.Where(t => t.Type == MachineType.Computer && Machines.Where(t => t.Type == MachineType.Computer && t.Introduced.HasValue &&
t.Introduced.HasValue &&
t.Introduced.Value.Year > 1000).Max(t => t.Introduced.Value.Year); t.Introduced.Value.Year > 1000).Max(t => t.Introduced.Value.Year);
return View(); return View();
@@ -95,8 +93,7 @@ namespace Marechai.Controllers
{ {
ViewBag.Year = id; ViewBag.Year = id;
return View(_context.Machines.Where(t => t.Type == MachineType.Computer && return View(_context.Machines.Where(t => t.Type == MachineType.Computer && t.Introduced.HasValue &&
t.Introduced.HasValue &&
t.Introduced.Value.Year == id).ToArray()); t.Introduced.Value.Year == id).ToArray());
} }
} }

View File

@@ -39,9 +39,9 @@ namespace Marechai.Controllers
public class ConsoleController : Controller public class ConsoleController : Controller
{ {
readonly MarechaiContext _context; readonly MarechaiContext _context;
readonly IHostingEnvironment hostingEnvironment; readonly IWebHostEnvironment hostingEnvironment;
public ConsoleController(IHostingEnvironment env, MarechaiContext context) public ConsoleController(IWebHostEnvironment env, MarechaiContext context)
{ {
hostingEnvironment = env; hostingEnvironment = env;
_context = context; _context = context;
@@ -52,13 +52,11 @@ namespace Marechai.Controllers
ViewBag.ItemCount = _context.Machines.Count(m => m.Type == MachineType.Console); ViewBag.ItemCount = _context.Machines.Count(m => m.Type == MachineType.Console);
ViewBag.MinYear = _context. ViewBag.MinYear = _context.
Machines.Where(t => t.Type == MachineType.Console && Machines.Where(t => t.Type == MachineType.Console && t.Introduced.HasValue &&
t.Introduced.HasValue &&
t.Introduced.Value.Year > 1000).Min(t => t.Introduced.Value.Year); t.Introduced.Value.Year > 1000).Min(t => t.Introduced.Value.Year);
ViewBag.MaxYear = _context. ViewBag.MaxYear = _context.
Machines.Where(t => t.Type == MachineType.Console && Machines.Where(t => t.Type == MachineType.Console && t.Introduced.HasValue &&
t.Introduced.HasValue &&
t.Introduced.Value.Year > 1000).Max(t => t.Introduced.Value.Year); t.Introduced.Value.Year > 1000).Max(t => t.Introduced.Value.Year);
return View(); return View();
@@ -95,8 +93,7 @@ namespace Marechai.Controllers
{ {
ViewBag.Year = id; ViewBag.Year = id;
return View(_context.Machines.Where(t => t.Type == MachineType.Console && return View(_context.Machines.Where(t => t.Type == MachineType.Console && t.Introduced.HasValue &&
t.Introduced.HasValue &&
t.Introduced.Value.Year == id).ToArray()); t.Introduced.Value.Year == id).ToArray());
} }
} }

View File

@@ -42,9 +42,9 @@ namespace Marechai.Controllers
public class HomeController : Controller public class HomeController : Controller
{ {
readonly MarechaiContext _context; readonly MarechaiContext _context;
readonly IHostingEnvironment hostingEnvironment; readonly IWebHostEnvironment hostingEnvironment;
public HomeController(IHostingEnvironment env, MarechaiContext context) public HomeController(IWebHostEnvironment env, MarechaiContext context)
{ {
hostingEnvironment = env; hostingEnvironment = env;
_context = context; _context = context;
@@ -56,7 +56,7 @@ namespace Marechai.Controllers
List<NewsModel> news = new List<NewsModel>(); List<NewsModel> news = new List<NewsModel>();
foreach(News @new in _context.News.OrderByDescending(t => t.Date).Take(10)) foreach(News @new in _context.News.OrderByDescending(t => t.Date).Take(10).ToList())
{ {
Machine machine = _context.Machines.Find(@new.AddedId); Machine machine = _context.Machines.Find(@new.AddedId);

View File

@@ -38,9 +38,9 @@ namespace Marechai.Controllers
public class MachineController : Controller public class MachineController : Controller
{ {
readonly MarechaiContext _context; readonly MarechaiContext _context;
readonly IHostingEnvironment hostingEnvironment; readonly IWebHostEnvironment hostingEnvironment;
public MachineController(IHostingEnvironment env, MarechaiContext context) public MachineController(IWebHostEnvironment env, MarechaiContext context)
{ {
hostingEnvironment = env; hostingEnvironment = env;
_context = context; _context = context;

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<Version>3.0.99.895</Version> <Version>3.0.99.905</Version>
<Company>Canary Islands Computer Museum</Company> <Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright> <Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product> <Product>Canary Islands Computer Museum Website</Product>
@@ -18,8 +18,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia.Skia.Linux.Natives" Version="1.68.0.2" /> <PackageReference Include="Avalonia.Skia.Linux.Natives" Version="1.68.0.2" />
<PackageReference Include="Markdig" Version="0.17.0" /> <PackageReference Include="Markdig" Version="0.17.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="2.2.4" /> <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.4" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" /> <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.1.4" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
<PackageReference Include="MSBump" Version="2.3.2" PrivateAssets="All" /> <PackageReference Include="MSBump" Version="2.3.2" PrivateAssets="All" />
<PackageReference Include="MySql.Data" Version="8.0.16" /> <PackageReference Include="MySql.Data" Version="8.0.16" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0006" /> <PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0006" />

View File

@@ -35,6 +35,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Marechai namespace Marechai
{ {
@@ -54,30 +55,34 @@ namespace Marechai
options.CheckConsentNeeded = context => true; options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None; options.MinimumSameSitePolicy = SameSiteMode.None;
}); });
services.AddControllersWithViews();
services.AddRazorPages();
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http: //go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings. #warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http: //go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
services.AddDbContext<MarechaiContext>(options => options. services.AddDbContext<MarechaiContext>(options => options.
UseLazyLoadingProxies(). UseLazyLoadingProxies().
UseMySql("server=localhost;port=3306;user=marechai;password=marechaipass;database=marechai;TreatTinyAsBoolean=false")); UseMySql("server=localhost;port=3306;user=marechai;password=marechaipass;database=marechai;TreatTinyAsBoolean=false"));
services.AddMvc();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env) public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{ {
if(env.IsDevelopment()) if(env.IsDevelopment())
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
else else
app.UseExceptionHandler("/Home/Error"); app.UseExceptionHandler("/Home/Error");
app.UseRouting();
app.UseStaticFiles(); app.UseStaticFiles();
app.UseAuthentication(); app.UseAuthentication();
app.UseCookiePolicy(); app.UseCookiePolicy();
app.UseMvc(routes => app.UseEndpoints(endpoints =>
{ {
routes.MapRoute("areas", "{area:exists}/{controller=Home}/{action=Index}/{id?}"). endpoints.MapControllerRoute("areas", "{area:exists}/{controller=Home}/{action=Index}/{id?}");
MapRoute("default", "{controller=Home}/{action=Index}/{id?}"); endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
}); });
} }
} }