Skip to content

Commit

Permalink
Upgraded to .NET 8 and updated Nuget packages (#169)
Browse files Browse the repository at this point in the history
* Upgraded to .NET 8 and updated Nuget packages

* Update Dockerfile

---------

Co-authored-by: Ion Dormenco <idormenco@gmail.com>
  • Loading branch information
bogdanbujdea and idormenco authored Jun 3, 2024
1 parent dd85e72 commit 250365f
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 127 deletions.
21 changes: 13 additions & 8 deletions src/ElectionResults.API/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["ElectionResults.API/ElectionResults.API.csproj", "ElectionResults.API/"]
RUN dotnet restore "ElectionResults.API/ElectionResults.API.csproj"
COPY ["ElectionResults.Core/ElectionResults.Core.csproj", "ElectionResults.Core/"]
COPY ["ElectionResults.Importer/ElectionResults.Importer.csproj", "ElectionResults.Importer/"]
RUN dotnet restore "./ElectionResults.API/ElectionResults.API.csproj"
COPY . .
WORKDIR "/src/ElectionResults.API"
RUN dotnet build "ElectionResults.API.csproj" -c Release -o /app/build
RUN dotnet build "./ElectionResults.API.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
RUN dotnet publish "ElectionResults.API.csproj" -c Release -o /app/publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./ElectionResults.API.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
Expand Down
32 changes: 15 additions & 17 deletions src/ElectionResults.API/ElectionResults.API.csproj
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<UserSecretsId>0a7d747b-d86b-44b1-8e0f-69bc4c568730</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.S3" Version="3.5.1.9" />
<PackageReference Include="CSharpFunctionalExtensions" Version="2.11.7" />
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.76" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.8">
<PackageReference Include="AWSSDK.S3" Version="3.7.308.6" />
<PackageReference Include="CSharpFunctionalExtensions" Version="2.42.0" />
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.175" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.8">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ElectionResults.Core\ElectionResults.Core.csproj" />
Expand All @@ -38,4 +36,4 @@
<Folder Include="wwwroot\lib\" />
<Folder Include="wwwroot\upload\" />
</ItemGroup>
</Project>
</Project>
4 changes: 1 addition & 3 deletions src/ElectionResults.API/Import/TurnoutCrawler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ private async Task ProcessStream(Stream csvStream)
var csvContent = await ReadCsvContent(csvStream);
TextReader sr = new StringReader(csvContent);
var csvParser = new CsvReader(sr, CultureInfo.CurrentCulture);
csvParser.Configuration.HeaderValidated = null;
csvParser.Configuration.MissingFieldFound = null;
var turnouts = csvParser.GetRecords<CsvTurnout>().ToList();
using (var dbContext = _serviceProvider.CreateScope().ServiceProvider.GetService<ApplicationDbContext>())
await using (var dbContext = _serviceProvider.CreateScope().ServiceProvider.GetService<ApplicationDbContext>())
{
EntityFrameworkManager.ContextFactory = context => dbContext;
_dbCounties = await dbContext.Counties.ToListAsync();
Expand Down
12 changes: 5 additions & 7 deletions src/ElectionResults.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ public void ConfigureServices(IServiceCollection services)

services
.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Latest)

.AddJsonOptions(options =>
{
options.JsonSerializerOptions.IgnoreNullValues = true;
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(new SnakeCaseNamingPolicy()));
}); ;
});
services.AddLazyCache();
RegisterDependencies(services, Configuration);
services.AddSwaggerGen(c =>
Expand All @@ -63,7 +61,7 @@ public void ConfigureServices(IServiceCollection services)
});
services.AddDbContextPool<ApplicationDbContext>(options =>
{
options.UseMySQL(Configuration["ConnectionStrings:DefaultConnection"]
options.UseMySQL(Configuration["ConnectionStrings:DefaultConnection"]!
);
});

Expand All @@ -81,7 +79,7 @@ public void ConfigureServices(IServiceCollection services)
});
});

if (Configuration["ScheduleTaskEnabled"].ToLower().Equals("true")) //excuse the primitive syntax
if (Configuration["ScheduleTaskEnabled"]!.ToLower().Equals("true")) //excuse the primitive syntax
services.AddHostedService<ScheduledTask>();
}

Expand Down Expand Up @@ -151,7 +149,7 @@ private static void MigrateDatabase(ApplicationDbContext context)
}
catch (Exception e)
{
Console.WriteLine(3);
Console.WriteLine(e);
}
}
}
Expand Down
50 changes: 25 additions & 25 deletions src/ElectionResults.Core/ElectionResults.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSharpFunctionalExtensions" Version="2.11.7" />
<PackageReference Include="CsvHelper" Version="15.0.6" />
<PackageReference Include="Diacritics" Version="2.1.20036.1" />
<PackageReference Include="LazyCache" Version="2.1.1" />
<PackageReference Include="LazyCache.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.8" />
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.21" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="3.0.96" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CSharpFunctionalExtensions" Version="2.42.0" />
<PackageReference Include="CsvHelper" Version="32.0.3" />
<PackageReference Include="Diacritics" Version="3.3.29" />
<PackageReference Include="LazyCache" Version="2.4.0" />
<PackageReference Include="LazyCache.AspNetCore" Version="2.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="MySql.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="8.102.2.5" />
</ItemGroup>

</Project>
</Project>
45 changes: 0 additions & 45 deletions src/ElectionResults.Core/Extensions/AsyncEx.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using MySql.Data.EntityFrameworkCore.Metadata;
using MySql.EntityFrameworkCore.Metadata;

namespace ElectionResults.Core.Migrations
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using MySql.Data.EntityFrameworkCore.Metadata;
using MySql.EntityFrameworkCore.Metadata;

namespace ElectionResults.Core.Migrations
{
Expand Down
14 changes: 5 additions & 9 deletions src/ElectionResults.Core/Scheduler/CsvDownloaderJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ public async Task<LiveElectionInfo> GetCandidatesFromUrl(string url)
return liveElectionInfo;
}

public async Task DownloadFiles()
public Task DownloadFiles()
{
// await DownloadCandidates();
return Task.CompletedTask;
// await DownloadCandidates();
}

private async Task DownloadCandidates()
Expand Down Expand Up @@ -257,13 +258,10 @@ private async Task<Stream> DownloadFile(string url)

private async Task<LiveElectionInfo> ExtractCandidatesFromCsv(Stream csvStream)
{
List<CandidateResult> candidates;
var csvContent = await ReadCsvContent(csvStream);
TextReader sr = new StringReader(csvContent);
var csvParser = new CsvReader(sr, CultureInfo.CurrentCulture);
csvParser.Configuration.HeaderValidated = null;
csvParser.Configuration.MissingFieldFound = null;
candidates = await GetCandidates(csvParser);
var candidates = await GetCandidates(csvParser);
var nullVotes = 0;
var total = 0;
var voted = 0;
Expand Down Expand Up @@ -332,10 +330,8 @@ private async Task ProcessStream(Stream csvStream)
var csvContent = await ReadCsvContent(csvStream);
TextReader sr = new StringReader(csvContent);
var csvParser = new CsvReader(sr, CultureInfo.CurrentCulture);
csvParser.Configuration.HeaderValidated = null;
csvParser.Configuration.MissingFieldFound = null;
var turnouts = csvParser.GetRecords<CsvTurnout>().ToList();
using (var dbContext = _serviceProvider.CreateScope().ServiceProvider.GetService<ApplicationDbContext>())
await using (var dbContext = _serviceProvider.CreateScope().ServiceProvider.GetService<ApplicationDbContext>())
{
EntityFrameworkManager.ContextFactory = context => dbContext;
var localities = await dbContext.Localities.ToListAsync();
Expand Down
11 changes: 7 additions & 4 deletions src/ElectionResults.Core/Scheduler/CsvIndexes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class CsvIndexes
public int CountryNameIndex { get; set; }
public int CandidatesIndex { get; set; }
public int NullVotesIndex2 { get; set; }
public CsvMode CsvMode { get; set; }
private CsvMode CsvMode { get; set; }
public CsvIndexes(CsvMode csvMode)
{
if (csvMode == CsvMode.National || csvMode == CsvMode.Diaspora)
Expand All @@ -29,7 +29,8 @@ public CsvIndexes(CsvMode csvMode)

CsvMode = csvMode;
}
public void SetIndexesForNationalResults()

private void SetIndexesForNationalResults()
{
EligibleVotersIndex = 12;
TotalVotesIndex = 16;
Expand All @@ -40,7 +41,7 @@ public void SetIndexesForNationalResults()
CandidatesIndex = 25;
}

public void SetIndexesForCorrespondenceResults()
private void SetIndexesForCorrespondenceResults()
{
EligibleVotersIndex = 12;
TotalVotesIndex = 13;
Expand All @@ -52,7 +53,7 @@ public void SetIndexesForCorrespondenceResults()
CandidatesIndex = 22;
}

public async Task Map(CsvReader csvParser)
public Task Map(CsvReader csvParser)
{
var index = 0;
while (index < CandidatesIndex)
Expand Down Expand Up @@ -124,6 +125,8 @@ public async Task Map(CsvReader csvParser)
}
index++;
}

return Task.CompletedTask;
}
}
}
7 changes: 1 addition & 6 deletions src/ElectionResults.Core/Scheduler/ResultsCrawler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,10 @@ public async Task<LiveElectionInfo> GetCandidatesFromUrl(string url, CsvIndexes

private async Task<LiveElectionInfo> ExtractCandidatesFromCsv(Stream csvStream, CsvIndexes csvIndexes)
{
List<CandidateResult> candidates;
var csvContent = await ReadCsvContent(csvStream);
TextReader sr = new StringReader(csvContent);
var csvParser = new CsvReader(sr, CultureInfo.CurrentCulture);
csvParser.Configuration.HeaderValidated = null;
csvParser.Configuration.MissingFieldFound = null;
candidates = await GetCandidates(csvParser, csvIndexes);
var candidates = await GetCandidates(csvParser, csvIndexes);
var nullVotes = 0;
var total = 0;
var voted = 0;
Expand Down Expand Up @@ -479,8 +476,6 @@ private async Task<List<PollingSection>> ExtractCandidateResultsFromCsv(Stream c
var csvContent = await ReadCsvContent(csvStream);
TextReader sr = new StringReader(csvContent);
var csvParser = new CsvReader(sr, CultureInfo.CurrentCulture);
csvParser.Configuration.HeaderValidated = null;
csvParser.Configuration.MissingFieldFound = null;
candidates = await GetCandidates(csvParser, csvIndexes);
while (true)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 250365f

Please sign in to comment.