From b9448a37df7330f62e7afffa78ebc4f5c6ed9a5d Mon Sep 17 00:00:00 2001 From: Peter Liapin Date: Tue, 23 Jan 2024 18:26:59 +0530 Subject: [PATCH 1/4] First attempt to upgrade to .NET 8.0 --- .azure/azure-pipelines.yml | 4 ++-- .github/workflows/build_and_test.yml | 2 +- .github/workflows/build_test_and_publish.yml | 2 +- .../OnlineSales.Plugin.EmailSync.csproj | 2 +- .../OnlineSales.Plugin.ReverseProxy.csproj | 2 +- .../OnlineSales.Plugin.SendGrid.csproj | 2 +- .../Exceptions/AwsSnsException.cs | 5 ----- .../Exceptions/GetshoutoutException.cs | 5 ----- .../Exceptions/NotifyLkException.cs | 5 ----- .../Exceptions/SMSPluginException.cs | 5 ----- .../Exceptions/SmscException.cs | 5 ----- .../Exceptions/TwilioException.cs | 5 ----- .../Exceptions/UnknownCountryCodeException.cs | 5 ----- .../OnlineSales.Plugin.Sms.csproj | 2 +- .../OnlineSales.Plugin.TestPlugin.csproj | 2 +- .../OnlineSales.Plugin.Vsto.csproj | 2 +- .../Controllers/ActivityLogController.cs | 4 ++-- src/OnlineSales/Controllers/BaseController.cs | 8 ++++---- .../Controllers/UsersController.cs | 4 ++-- src/OnlineSales/Exceptions/EmailException.cs | 5 ----- .../MissingConfigurationException.cs | 5 ----- .../Exceptions/PluginDbContextException.cs | 5 ----- .../PluginDbContextNotFoundException.cs | 5 ----- .../PluginDbContextTooManyException.cs | 5 ----- src/OnlineSales/Exceptions/QueryException.cs | 5 ----- .../Exceptions/SyncEmailLogTaskException.cs | 5 ----- src/OnlineSales/OnlineSales.csproj | 20 +++++++++---------- .../Properties/launchSettings.json | 3 +-- .../Environment/TestAuthenticationHandler.cs | 4 ++-- .../OnlineSales.Tests.csproj | 4 ++-- 30 files changed, 33 insertions(+), 104 deletions(-) diff --git a/.azure/azure-pipelines.yml b/.azure/azure-pipelines.yml index 2e9e1067..ea985097 100644 --- a/.azure/azure-pipelines.yml +++ b/.azure/azure-pipelines.yml @@ -12,9 +12,9 @@ steps: displayName: 'docker compose -f ./docker-compose/docker-compose.tests.yml up -d' - task: UseDotNet@2 - displayName: 'install .net sdk 7.x' + displayName: 'install .net sdk 8.x' inputs: - version: 7.x + version: 8.x installationPath: $(Agent.ToolsDirectory)/dotnet - script: | diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 2921c280..c02e3edf 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -21,7 +21,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x - name: docker compose -f ./docker-compose/docker-compose.tests.yml up -d run: docker compose -f ./docker-compose/docker-compose.tests.yml up -d diff --git a/.github/workflows/build_test_and_publish.yml b/.github/workflows/build_test_and_publish.yml index 32bcb452..d81816e8 100644 --- a/.github/workflows/build_test_and_publish.yml +++ b/.github/workflows/build_test_and_publish.yml @@ -32,7 +32,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x - name: Setup NuGet uses: nuget/setup-nuget@v1 diff --git a/plugins/OnlineSales.Plugin.EmailSync/OnlineSales.Plugin.EmailSync.csproj b/plugins/OnlineSales.Plugin.EmailSync/OnlineSales.Plugin.EmailSync.csproj index 162d8e53..2cf82f89 100644 --- a/plugins/OnlineSales.Plugin.EmailSync/OnlineSales.Plugin.EmailSync.csproj +++ b/plugins/OnlineSales.Plugin.EmailSync/OnlineSales.Plugin.EmailSync.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 true enable enable diff --git a/plugins/OnlineSales.Plugin.ReverseProxy/OnlineSales.Plugin.ReverseProxy.csproj b/plugins/OnlineSales.Plugin.ReverseProxy/OnlineSales.Plugin.ReverseProxy.csproj index 1260ad15..8d6da813 100644 --- a/plugins/OnlineSales.Plugin.ReverseProxy/OnlineSales.Plugin.ReverseProxy.csproj +++ b/plugins/OnlineSales.Plugin.ReverseProxy/OnlineSales.Plugin.ReverseProxy.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 enable true enable diff --git a/plugins/OnlineSales.Plugin.SendGrid/OnlineSales.Plugin.SendGrid.csproj b/plugins/OnlineSales.Plugin.SendGrid/OnlineSales.Plugin.SendGrid.csproj index 92fd4512..b7498cea 100644 --- a/plugins/OnlineSales.Plugin.SendGrid/OnlineSales.Plugin.SendGrid.csproj +++ b/plugins/OnlineSales.Plugin.SendGrid/OnlineSales.Plugin.SendGrid.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 true enable enable diff --git a/plugins/OnlineSales.Plugin.Sms/Exceptions/AwsSnsException.cs b/plugins/OnlineSales.Plugin.Sms/Exceptions/AwsSnsException.cs index 8f325c9c..8b14cf15 100644 --- a/plugins/OnlineSales.Plugin.Sms/Exceptions/AwsSnsException.cs +++ b/plugins/OnlineSales.Plugin.Sms/Exceptions/AwsSnsException.cs @@ -27,10 +27,5 @@ public AwsSnsException(string? message, Exception? innerException) : base(message, innerException) { } - - protected AwsSnsException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } } \ No newline at end of file diff --git a/plugins/OnlineSales.Plugin.Sms/Exceptions/GetshoutoutException.cs b/plugins/OnlineSales.Plugin.Sms/Exceptions/GetshoutoutException.cs index cd722cad..07236ecb 100644 --- a/plugins/OnlineSales.Plugin.Sms/Exceptions/GetshoutoutException.cs +++ b/plugins/OnlineSales.Plugin.Sms/Exceptions/GetshoutoutException.cs @@ -22,9 +22,4 @@ public GetshoutoutException(string? message, Exception? innerException) : base(message, innerException) { } - - protected GetshoutoutException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } \ No newline at end of file diff --git a/plugins/OnlineSales.Plugin.Sms/Exceptions/NotifyLkException.cs b/plugins/OnlineSales.Plugin.Sms/Exceptions/NotifyLkException.cs index 74511bb7..0ffd49d2 100644 --- a/plugins/OnlineSales.Plugin.Sms/Exceptions/NotifyLkException.cs +++ b/plugins/OnlineSales.Plugin.Sms/Exceptions/NotifyLkException.cs @@ -22,10 +22,5 @@ public NotifyLkException(string? message, Exception? innerException) : base(message, innerException) { } - - protected NotifyLkException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } } \ No newline at end of file diff --git a/plugins/OnlineSales.Plugin.Sms/Exceptions/SMSPluginException.cs b/plugins/OnlineSales.Plugin.Sms/Exceptions/SMSPluginException.cs index 721d643b..0e5d2aa5 100644 --- a/plugins/OnlineSales.Plugin.Sms/Exceptions/SMSPluginException.cs +++ b/plugins/OnlineSales.Plugin.Sms/Exceptions/SMSPluginException.cs @@ -27,10 +27,5 @@ public SmsPluginException(string? message, Exception? innerException) : base(message, innerException) { } - - protected SmsPluginException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } } \ No newline at end of file diff --git a/plugins/OnlineSales.Plugin.Sms/Exceptions/SmscException.cs b/plugins/OnlineSales.Plugin.Sms/Exceptions/SmscException.cs index f1038765..76d8865c 100644 --- a/plugins/OnlineSales.Plugin.Sms/Exceptions/SmscException.cs +++ b/plugins/OnlineSales.Plugin.Sms/Exceptions/SmscException.cs @@ -27,10 +27,5 @@ public SmscException(string? message, Exception? innerException) : base(message, innerException) { } - - protected SmscException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } } \ No newline at end of file diff --git a/plugins/OnlineSales.Plugin.Sms/Exceptions/TwilioException.cs b/plugins/OnlineSales.Plugin.Sms/Exceptions/TwilioException.cs index bfef540b..46073d01 100644 --- a/plugins/OnlineSales.Plugin.Sms/Exceptions/TwilioException.cs +++ b/plugins/OnlineSales.Plugin.Sms/Exceptions/TwilioException.cs @@ -22,10 +22,5 @@ public TwilioException(string? message, Exception? innerException) : base(message, innerException) { } - - protected TwilioException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } } \ No newline at end of file diff --git a/plugins/OnlineSales.Plugin.Sms/Exceptions/UnknownCountryCodeException.cs b/plugins/OnlineSales.Plugin.Sms/Exceptions/UnknownCountryCodeException.cs index 1fe8ac17..f818cf58 100644 --- a/plugins/OnlineSales.Plugin.Sms/Exceptions/UnknownCountryCodeException.cs +++ b/plugins/OnlineSales.Plugin.Sms/Exceptions/UnknownCountryCodeException.cs @@ -22,10 +22,5 @@ public UnknownCountryCodeException(string? message, Exception? innerException) : base(message, innerException) { } - - protected UnknownCountryCodeException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } } \ No newline at end of file diff --git a/plugins/OnlineSales.Plugin.Sms/OnlineSales.Plugin.Sms.csproj b/plugins/OnlineSales.Plugin.Sms/OnlineSales.Plugin.Sms.csproj index 796da52d..1f253e54 100644 --- a/plugins/OnlineSales.Plugin.Sms/OnlineSales.Plugin.Sms.csproj +++ b/plugins/OnlineSales.Plugin.Sms/OnlineSales.Plugin.Sms.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 true enable enable diff --git a/plugins/OnlineSales.Plugin.TestPlugin/OnlineSales.Plugin.TestPlugin.csproj b/plugins/OnlineSales.Plugin.TestPlugin/OnlineSales.Plugin.TestPlugin.csproj index 2ab6936c..eef39946 100644 --- a/plugins/OnlineSales.Plugin.TestPlugin/OnlineSales.Plugin.TestPlugin.csproj +++ b/plugins/OnlineSales.Plugin.TestPlugin/OnlineSales.Plugin.TestPlugin.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 true enable enable diff --git a/plugins/OnlineSales.Plugin.Vsto/OnlineSales.Plugin.Vsto.csproj b/plugins/OnlineSales.Plugin.Vsto/OnlineSales.Plugin.Vsto.csproj index a2e1d485..c2e2c051 100644 --- a/plugins/OnlineSales.Plugin.Vsto/OnlineSales.Plugin.Vsto.csproj +++ b/plugins/OnlineSales.Plugin.Vsto/OnlineSales.Plugin.Vsto.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 true enable enable diff --git a/src/OnlineSales/Controllers/ActivityLogController.cs b/src/OnlineSales/Controllers/ActivityLogController.cs index 3dac1195..7f836495 100644 --- a/src/OnlineSales/Controllers/ActivityLogController.cs +++ b/src/OnlineSales/Controllers/ActivityLogController.cs @@ -38,8 +38,8 @@ public virtual async Task>> Get([FromQu var qp = queryProviderFactory.BuildQueryProvider(); var result = await qp.GetResult(); - Response.Headers.Add(ResponseHeaderNames.TotalCount, result.TotalCount.ToString()); - Response.Headers.Add(ResponseHeaderNames.AccessControlExposeHeader, ResponseHeaderNames.TotalCount); + Response.Headers.Append(ResponseHeaderNames.TotalCount, result.TotalCount.ToString()); + Response.Headers.Append(ResponseHeaderNames.AccessControlExposeHeader, ResponseHeaderNames.TotalCount); return Ok(mapper.Map>(result.Records)); } } diff --git a/src/OnlineSales/Controllers/BaseController.cs b/src/OnlineSales/Controllers/BaseController.cs index 6817daf3..88530741 100644 --- a/src/OnlineSales/Controllers/BaseController.cs +++ b/src/OnlineSales/Controllers/BaseController.cs @@ -104,8 +104,8 @@ public virtual async Task>> Get([FromQuery] string? query) var qp = queryProviderFactory.BuildQueryProvider(); var result = await qp.GetResult(); - Response.Headers.Add(ResponseHeaderNames.TotalCount, result.TotalCount.ToString()); - Response.Headers.Add(ResponseHeaderNames.AccessControlExposeHeader, ResponseHeaderNames.TotalCount); + Response.Headers.Append(ResponseHeaderNames.TotalCount, result.TotalCount.ToString()); + Response.Headers.Append(ResponseHeaderNames.AccessControlExposeHeader, ResponseHeaderNames.TotalCount); var res = mapper.Map>(result.Records); RemoveSecondLevelObjects(res); return Ok(res); @@ -120,8 +120,8 @@ public virtual async Task>> Export([FromQuery] string? que var qp = queryProviderFactory.BuildQueryProvider(int.MaxValue); var result = await qp.GetResult(); - Response.Headers.Add(ResponseHeaderNames.TotalCount, result.TotalCount.ToString()); - Response.Headers.Add(ResponseHeaderNames.AccessControlExposeHeader, ResponseHeaderNames.TotalCount); + Response.Headers.Append(ResponseHeaderNames.TotalCount, result.TotalCount.ToString()); + Response.Headers.Append(ResponseHeaderNames.AccessControlExposeHeader, ResponseHeaderNames.TotalCount); var res = mapper.Map>(result.Records); RemoveSecondLevelObjects(res); return Ok(res); diff --git a/src/OnlineSales/Controllers/UsersController.cs b/src/OnlineSales/Controllers/UsersController.cs index ef62a632..98403de6 100644 --- a/src/OnlineSales/Controllers/UsersController.cs +++ b/src/OnlineSales/Controllers/UsersController.cs @@ -38,8 +38,8 @@ public async Task> GetAll() { var allUsers = await userManager.Users.ToListAsync(); var resultsToClient = mapper.Map(allUsers).ToArray(); - Response.Headers.Add(ResponseHeaderNames.TotalCount, resultsToClient.Count().ToString()); - Response.Headers.Add(ResponseHeaderNames.AccessControlExposeHeader, ResponseHeaderNames.TotalCount); + Response.Headers.Append(ResponseHeaderNames.TotalCount, resultsToClient.Count().ToString()); + Response.Headers.Append(ResponseHeaderNames.AccessControlExposeHeader, ResponseHeaderNames.TotalCount); return Ok(resultsToClient); } diff --git a/src/OnlineSales/Exceptions/EmailException.cs b/src/OnlineSales/Exceptions/EmailException.cs index 06c71ede..eecc6f40 100644 --- a/src/OnlineSales/Exceptions/EmailException.cs +++ b/src/OnlineSales/Exceptions/EmailException.cs @@ -22,9 +22,4 @@ public EmailException(string? message, Exception? innerException) : base(message, innerException) { } - - protected EmailException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } \ No newline at end of file diff --git a/src/OnlineSales/Exceptions/MissingConfigurationException.cs b/src/OnlineSales/Exceptions/MissingConfigurationException.cs index 7c78bb45..b10bf4ad 100644 --- a/src/OnlineSales/Exceptions/MissingConfigurationException.cs +++ b/src/OnlineSales/Exceptions/MissingConfigurationException.cs @@ -22,9 +22,4 @@ public MissingConfigurationException(string? message, Exception? innerException) : base(message, innerException) { } - - protected MissingConfigurationException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } \ No newline at end of file diff --git a/src/OnlineSales/Exceptions/PluginDbContextException.cs b/src/OnlineSales/Exceptions/PluginDbContextException.cs index 48f84969..12a877cc 100644 --- a/src/OnlineSales/Exceptions/PluginDbContextException.cs +++ b/src/OnlineSales/Exceptions/PluginDbContextException.cs @@ -25,10 +25,5 @@ public PluginDbContextException(string? message, Type? unregisteredDbContext, Ex UnregisteredDbContext = unregisteredDbContext; } - protected PluginDbContextException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } - public Type? UnregisteredDbContext { get; private set; } } \ No newline at end of file diff --git a/src/OnlineSales/Exceptions/PluginDbContextNotFoundException.cs b/src/OnlineSales/Exceptions/PluginDbContextNotFoundException.cs index d0d4b22b..02d9886b 100644 --- a/src/OnlineSales/Exceptions/PluginDbContextNotFoundException.cs +++ b/src/OnlineSales/Exceptions/PluginDbContextNotFoundException.cs @@ -25,9 +25,4 @@ public PluginDbContextNotFoundException(Type? unregisteredDbContext, Exception? : base(HardcodedMessage, unregisteredDbContext, innerException) { } - - protected PluginDbContextNotFoundException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } \ No newline at end of file diff --git a/src/OnlineSales/Exceptions/PluginDbContextTooManyException.cs b/src/OnlineSales/Exceptions/PluginDbContextTooManyException.cs index a74afbb8..91a348fd 100644 --- a/src/OnlineSales/Exceptions/PluginDbContextTooManyException.cs +++ b/src/OnlineSales/Exceptions/PluginDbContextTooManyException.cs @@ -25,9 +25,4 @@ public PluginDbContextTooManyException(Type? unregisteredDbContext, Exception? i : base(HardcodedMessage, unregisteredDbContext, innerException) { } - - protected PluginDbContextTooManyException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } \ No newline at end of file diff --git a/src/OnlineSales/Exceptions/QueryException.cs b/src/OnlineSales/Exceptions/QueryException.cs index 0e443d26..49b66142 100644 --- a/src/OnlineSales/Exceptions/QueryException.cs +++ b/src/OnlineSales/Exceptions/QueryException.cs @@ -19,11 +19,6 @@ public QueryException(IEnumerable innerExceptions) FailedCommands = innerExceptions.SelectMany(e => e.FailedCommands).ToList(); } - protected QueryException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } - public List> FailedCommands { get; init; } = new List>(); } } \ No newline at end of file diff --git a/src/OnlineSales/Exceptions/SyncEmailLogTaskException.cs b/src/OnlineSales/Exceptions/SyncEmailLogTaskException.cs index 44dbf784..e441ee9a 100644 --- a/src/OnlineSales/Exceptions/SyncEmailLogTaskException.cs +++ b/src/OnlineSales/Exceptions/SyncEmailLogTaskException.cs @@ -22,10 +22,5 @@ public SyncEmailLogTaskException(string? message, Exception? innerException) : base(message, innerException) { } - - protected SyncEmailLogTaskException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } } diff --git a/src/OnlineSales/OnlineSales.csproj b/src/OnlineSales/OnlineSales.csproj index 9cf9d902..0bd19d23 100644 --- a/src/OnlineSales/OnlineSales.csproj +++ b/src/OnlineSales/OnlineSales.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable enable OnlineSales @@ -38,31 +38,31 @@ - - - + + + - + - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + - + - + diff --git a/src/OnlineSales/Properties/launchSettings.json b/src/OnlineSales/Properties/launchSettings.json index 16b1213a..ec664f13 100644 --- a/src/OnlineSales/Properties/launchSettings.json +++ b/src/OnlineSales/Properties/launchSettings.json @@ -12,8 +12,7 @@ "OnlineSales": { "commandName": "Project", "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "http://localhost:45437", + "applicationUrl": "http://localhost:16305", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/tests/OnlineSales.Tests/Environment/TestAuthenticationHandler.cs b/tests/OnlineSales.Tests/Environment/TestAuthenticationHandler.cs index 60b62f9c..c55bdd16 100644 --- a/tests/OnlineSales.Tests/Environment/TestAuthenticationHandler.cs +++ b/tests/OnlineSales.Tests/Environment/TestAuthenticationHandler.cs @@ -14,8 +14,8 @@ public class TestAuthenticationHandler : AuthenticationHandler options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) - : base(options, logger, encoder, clock) + public TestAuthenticationHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder) + : base(options, logger, encoder) { } diff --git a/tests/OnlineSales.Tests/OnlineSales.Tests.csproj b/tests/OnlineSales.Tests/OnlineSales.Tests.csproj index 4002bd25..ab88b928 100644 --- a/tests/OnlineSales.Tests/OnlineSales.Tests.csproj +++ b/tests/OnlineSales.Tests/OnlineSales.Tests.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable enable @@ -25,7 +25,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + From 94f434812437460569ae3ea7047c5b4c199a6188 Mon Sep 17 00:00:00 2001 From: Peter Liapin Date: Tue, 23 Jan 2024 18:45:45 +0530 Subject: [PATCH 2/4] Unused using has been removed --- src/OnlineSales/DataAnnotations/CurrencyCodeAttribute.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OnlineSales/DataAnnotations/CurrencyCodeAttribute.cs b/src/OnlineSales/DataAnnotations/CurrencyCodeAttribute.cs index 4b8a8546..eb9ea3a3 100644 --- a/src/OnlineSales/DataAnnotations/CurrencyCodeAttribute.cs +++ b/src/OnlineSales/DataAnnotations/CurrencyCodeAttribute.cs @@ -5,7 +5,6 @@ using System.ComponentModel.DataAnnotations; using System.Globalization; using System.Text; -using Npgsql.Internal.TypeHandlers.NetworkHandlers; namespace OnlineSales.DataAnnotations; From d48fa3493d51f5c09d30710bc13e7ea77ab65a4d Mon Sep 17 00:00:00 2001 From: Peter Liapin Date: Tue, 23 Jan 2024 22:38:23 +0530 Subject: [PATCH 3/4] Migration to NpgsqlDataSourceBuilder and support for EnableDynamicJson --- .../OnlineSales.Plugin.Sms/Services/SmscService.cs | 2 -- src/OnlineSales/Controllers/AccountsController.cs | 2 -- src/OnlineSales/Data/EsDbContext.cs | 3 --- src/OnlineSales/Data/PgDbContext.cs | 13 +++++++++---- src/OnlineSales/Entities/DealPipeline.cs | 2 +- src/OnlineSales/Helpers/JsonHelper.cs | 4 ---- src/OnlineSales/OnlineSales.csproj | 1 - 7 files changed, 10 insertions(+), 17 deletions(-) diff --git a/plugins/OnlineSales.Plugin.Sms/Services/SmscService.cs b/plugins/OnlineSales.Plugin.Sms/Services/SmscService.cs index f08e248c..0a4a1b16 100644 --- a/plugins/OnlineSales.Plugin.Sms/Services/SmscService.cs +++ b/plugins/OnlineSales.Plugin.Sms/Services/SmscService.cs @@ -2,12 +2,10 @@ // Licensed under the MIT license. See LICENSE file in the samples root for full license information. // -using System.Reflection; using System.Web; using Newtonsoft.Json; using OnlineSales.Plugin.Sms.Configuration; using OnlineSales.Plugin.Sms.Exceptions; -using Serilog; namespace OnlineSales.Plugin.Sms.Services; diff --git a/src/OnlineSales/Controllers/AccountsController.cs b/src/OnlineSales/Controllers/AccountsController.cs index e1482814..dca7b765 100644 --- a/src/OnlineSales/Controllers/AccountsController.cs +++ b/src/OnlineSales/Controllers/AccountsController.cs @@ -5,8 +5,6 @@ using AutoMapper; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Options; -using OnlineSales.Configuration; using OnlineSales.Data; using OnlineSales.DTOs; using OnlineSales.Entities; diff --git a/src/OnlineSales/Data/EsDbContext.cs b/src/OnlineSales/Data/EsDbContext.cs index faca56ab..df39d8e6 100644 --- a/src/OnlineSales/Data/EsDbContext.cs +++ b/src/OnlineSales/Data/EsDbContext.cs @@ -2,9 +2,6 @@ // Licensed under the MIT license. See LICENSE file in the samples root for full license information. // -using System; -using System.Reflection; -using Microsoft.EntityFrameworkCore.Metadata.Internal; using Nest; using OnlineSales.Configuration; using OnlineSales.DataAnnotations; diff --git a/src/OnlineSales/Data/PgDbContext.cs b/src/OnlineSales/Data/PgDbContext.cs index cbb56dc7..43d7a950 100644 --- a/src/OnlineSales/Data/PgDbContext.cs +++ b/src/OnlineSales/Data/PgDbContext.cs @@ -7,8 +7,8 @@ using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; -using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql; using OnlineSales.Configuration; using OnlineSales.DataAnnotations; using OnlineSales.Entities; @@ -208,11 +208,16 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) throw new MissingConfigurationException("Postgres configuration is mandatory."); } + var dataSourceBuilder = new NpgsqlDataSourceBuilder(postgresConfig.ConnectionString); + dataSourceBuilder.EnableDynamicJson(); + var dataSource = dataSourceBuilder + .Build(); + optionsBuilder.UseNpgsql( - postgresConfig.ConnectionString, + dataSource, b => b.MigrationsHistoryTable("_migrations")) - .UseSnakeCaseNamingConvention() - .ReplaceService(); + .UseSnakeCaseNamingConvention() + .ReplaceService(); Console.WriteLine("PgDbContext successfully configured"); } diff --git a/src/OnlineSales/Entities/DealPipeline.cs b/src/OnlineSales/Entities/DealPipeline.cs index b9e23e7a..b0bba40e 100644 --- a/src/OnlineSales/Entities/DealPipeline.cs +++ b/src/OnlineSales/Entities/DealPipeline.cs @@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using Newtonsoft.Json; +using System.Text.Json.Serialization; using OnlineSales.DataAnnotations; namespace OnlineSales.Entities; diff --git a/src/OnlineSales/Helpers/JsonHelper.cs b/src/OnlineSales/Helpers/JsonHelper.cs index 2ac4d298..8ab693f8 100644 --- a/src/OnlineSales/Helpers/JsonHelper.cs +++ b/src/OnlineSales/Helpers/JsonHelper.cs @@ -4,10 +4,6 @@ using System.Text.Json; using System.Text.Json.Serialization; -using System.Text.Json.Serialization.Metadata; -using CsvHelper.TypeConversion; -using Newtonsoft.Json.Converters; -using Newtonsoft.Json.Serialization; using OnlineSales.Configuration; namespace OnlineSales.Helpers; diff --git a/src/OnlineSales/OnlineSales.csproj b/src/OnlineSales/OnlineSales.csproj index 0bd19d23..d0c9d65d 100644 --- a/src/OnlineSales/OnlineSales.csproj +++ b/src/OnlineSales/OnlineSales.csproj @@ -41,7 +41,6 @@ - From 4e8f28aa302f163765c782d6224fc44e057f5c43 Mon Sep 17 00:00:00 2001 From: Peter Liapin Date: Tue, 23 Jan 2024 23:48:12 +0530 Subject: [PATCH 4/4] Fix for singletone object being created multiple times --- .../Data/EmailSyncDbContext.cs | 5 ++-- .../Data/SendgridDbContext.cs | 5 ++-- .../Data/SmsDbContext.cs | 5 ++-- .../Data/TestPluginDbContext.cs | 6 +++-- .../Data/VstoDbContext.cs | 5 ++-- src/OnlineSales/Data/PgDbContext.cs | 27 ++++++++++--------- src/OnlineSales/Data/PluginDbContextBase.cs | 5 ++-- src/OnlineSales/Dockerfile | 4 +-- src/OnlineSales/Program.cs | 21 ++++++++++++++- 9 files changed, 55 insertions(+), 28 deletions(-) diff --git a/plugins/OnlineSales.Plugin.EmailSync/Data/EmailSyncDbContext.cs b/plugins/OnlineSales.Plugin.EmailSync/Data/EmailSyncDbContext.cs index 1aa31e8b..88c622b9 100644 --- a/plugins/OnlineSales.Plugin.EmailSync/Data/EmailSyncDbContext.cs +++ b/plugins/OnlineSales.Plugin.EmailSync/Data/EmailSyncDbContext.cs @@ -7,6 +7,7 @@ using EntityFrameworkCore.EncryptColumn.Util; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; +using Npgsql; using OnlineSales.Data; using OnlineSales.Interfaces; using OnlineSales.Plugin.EmailSync.Entities; @@ -22,8 +23,8 @@ public EmailSyncDbContext() { } - public EmailSyncDbContext(DbContextOptions options, IConfiguration configuration, IHttpContextHelper httpContextHelper) - : base(options, configuration, httpContextHelper) + public EmailSyncDbContext(DbContextOptions options, IConfiguration configuration, IHttpContextHelper httpContextHelper, NpgsqlDataSource dataSource) + : base(options, configuration, httpContextHelper, dataSource) { var key = configuration.GetSection("EmailSync:EncryptionKey").Get(); if (key == null ) diff --git a/plugins/OnlineSales.Plugin.SendGrid/Data/SendgridDbContext.cs b/plugins/OnlineSales.Plugin.SendGrid/Data/SendgridDbContext.cs index ecb511a4..6dd8dacc 100644 --- a/plugins/OnlineSales.Plugin.SendGrid/Data/SendgridDbContext.cs +++ b/plugins/OnlineSales.Plugin.SendGrid/Data/SendgridDbContext.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; +using Npgsql; using OnlineSales.Data; using OnlineSales.Interfaces; using OnlineSales.Plugin.SendGrid.Entities; @@ -17,8 +18,8 @@ public SendgridDbContext() { } - public SendgridDbContext(DbContextOptions options, IConfiguration configuration, IHttpContextHelper httpContextHelper) - : base(options, configuration, httpContextHelper) + public SendgridDbContext(DbContextOptions options, IConfiguration configuration, IHttpContextHelper httpContextHelper, NpgsqlDataSource dataSource) + : base(options, configuration, httpContextHelper, dataSource) { } diff --git a/plugins/OnlineSales.Plugin.Sms/Data/SmsDbContext.cs b/plugins/OnlineSales.Plugin.Sms/Data/SmsDbContext.cs index 93a142ec..1c4cb8c8 100644 --- a/plugins/OnlineSales.Plugin.Sms/Data/SmsDbContext.cs +++ b/plugins/OnlineSales.Plugin.Sms/Data/SmsDbContext.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; +using Npgsql; using OnlineSales.Data; using OnlineSales.Plugin.Sms.Entities; @@ -11,8 +12,8 @@ namespace OnlineSales.Plugin.Sms.Data; public class SmsDbContext : PluginDbContextBase { - public SmsDbContext(DbContextOptions options, IConfiguration configuration, IHttpContextHelper httpContextHelper) - : base(options, configuration, httpContextHelper) + public SmsDbContext(DbContextOptions options, IConfiguration configuration, IHttpContextHelper httpContextHelper, NpgsqlDataSource dataSource) + : base(options, configuration, httpContextHelper, dataSource) { } diff --git a/plugins/OnlineSales.Plugin.TestPlugin/Data/TestPluginDbContext.cs b/plugins/OnlineSales.Plugin.TestPlugin/Data/TestPluginDbContext.cs index d2383219..2fdb8eb5 100644 --- a/plugins/OnlineSales.Plugin.TestPlugin/Data/TestPluginDbContext.cs +++ b/plugins/OnlineSales.Plugin.TestPlugin/Data/TestPluginDbContext.cs @@ -2,10 +2,12 @@ // Licensed under the MIT license. See LICENSE file in the samples root for full license information. // +using System.Data.Common; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.Extensions.Configuration; +using Npgsql; using OnlineSales.Data; using OnlineSales.Interfaces; using OnlineSales.Plugin.TestPlugin.Entities; @@ -23,8 +25,8 @@ public TestPluginDbContext() migrations = new SortedSet(); } - public TestPluginDbContext(DbContextOptions options, IConfiguration configuration, IHttpContextHelper httpContextHelper) - : base(options, configuration, httpContextHelper) + public TestPluginDbContext(DbContextOptions options, IConfiguration configuration, IHttpContextHelper httpContextHelper, NpgsqlDataSource dataSource) + : base(options, configuration, httpContextHelper, dataSource) { migrations = new SortedSet(Database.GetPendingMigrations()); } diff --git a/plugins/OnlineSales.Plugin.Vsto/Data/VstoDbContext.cs b/plugins/OnlineSales.Plugin.Vsto/Data/VstoDbContext.cs index 1ebc5f9c..8db54c2f 100644 --- a/plugins/OnlineSales.Plugin.Vsto/Data/VstoDbContext.cs +++ b/plugins/OnlineSales.Plugin.Vsto/Data/VstoDbContext.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; +using Npgsql; using OnlineSales.Data; using OnlineSales.Plugin.Vsto.Entities; @@ -16,8 +17,8 @@ public VstoDbContext() { } - public VstoDbContext(DbContextOptions options, IConfiguration configuration, IHttpContextHelper httpContextHelper) - : base(options, configuration, httpContextHelper) + public VstoDbContext(DbContextOptions options, IConfiguration configuration, IHttpContextHelper httpContextHelper, NpgsqlDataSource dataSource) + : base(options, configuration, httpContextHelper, dataSource) { } diff --git a/src/OnlineSales/Data/PgDbContext.cs b/src/OnlineSales/Data/PgDbContext.cs index 43d7a950..7b96be91 100644 --- a/src/OnlineSales/Data/PgDbContext.cs +++ b/src/OnlineSales/Data/PgDbContext.cs @@ -23,6 +23,7 @@ public class PgDbContext : IdentityDbContext public readonly IConfiguration Configuration; private readonly IHttpContextHelper? httpContextHelper; + private readonly NpgsqlDataSource dataSource; /// /// Initializes a new instance of the class. @@ -40,6 +41,17 @@ public PgDbContext() .AddUserSecrets(typeof(Program).Assembly) .Build(); + var postgresConfig = Configuration.GetSection("Postgres").Get(); + + if (postgresConfig == null) + { + throw new MissingConfigurationException("Postgres configuration is mandatory."); + } + + var dataSourceBuilder = new NpgsqlDataSourceBuilder(postgresConfig.ConnectionString); + dataSourceBuilder.EnableDynamicJson(); + dataSource = dataSourceBuilder.Build(); + Console.WriteLine("PgDbContext initialized"); } catch (Exception ex) @@ -49,11 +61,12 @@ public PgDbContext() } } - public PgDbContext(DbContextOptions options, IConfiguration configuration, IHttpContextHelper httpContextHelper) + public PgDbContext(DbContextOptions options, IConfiguration configuration, IHttpContextHelper httpContextHelper, NpgsqlDataSource dataSource) : base(options) { Configuration = configuration; this.httpContextHelper = httpContextHelper; + this.dataSource = dataSource; } public bool IsImportRequest { get; set; } @@ -201,18 +214,6 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { Console.WriteLine("Configuring PgDbContext..."); - var postgresConfig = Configuration.GetSection("Postgres").Get(); - - if (postgresConfig == null) - { - throw new MissingConfigurationException("Postgres configuration is mandatory."); - } - - var dataSourceBuilder = new NpgsqlDataSourceBuilder(postgresConfig.ConnectionString); - dataSourceBuilder.EnableDynamicJson(); - var dataSource = dataSourceBuilder - .Build(); - optionsBuilder.UseNpgsql( dataSource, b => b.MigrationsHistoryTable("_migrations")) diff --git a/src/OnlineSales/Data/PluginDbContextBase.cs b/src/OnlineSales/Data/PluginDbContextBase.cs index aa36b48a..bbd8c135 100644 --- a/src/OnlineSales/Data/PluginDbContextBase.cs +++ b/src/OnlineSales/Data/PluginDbContextBase.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; +using Npgsql; using OnlineSales.Interfaces; namespace OnlineSales.Data; @@ -15,8 +16,8 @@ protected PluginDbContextBase() { } - protected PluginDbContextBase(DbContextOptions options, IConfiguration configuration, IHttpContextHelper httpContextHelper) - : base(options, configuration, httpContextHelper) + protected PluginDbContextBase(DbContextOptions options, IConfiguration configuration, IHttpContextHelper httpContextHelper, NpgsqlDataSource dataSource) + : base(options, configuration, httpContextHelper, dataSource) { } diff --git a/src/OnlineSales/Dockerfile b/src/OnlineSales/Dockerfile index 8d65ade7..5eb23b13 100644 --- a/src/OnlineSales/Dockerfile +++ b/src/OnlineSales/Dockerfile @@ -1,10 +1,10 @@ #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. -FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine AS base +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base WORKDIR /app EXPOSE 80 -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src COPY ["src/OnlineSales/OnlineSales.csproj", "src/OnlineSales/"] RUN dotnet restore "src/OnlineSales/OnlineSales.csproj" diff --git a/src/OnlineSales/Program.cs b/src/OnlineSales/Program.cs index 2c1d8317..e32c70e6 100644 --- a/src/OnlineSales/Program.cs +++ b/src/OnlineSales/Program.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.EntityFrameworkCore; using Microsoft.OpenApi.Models; +using Npgsql; using OnlineSales.Configuration; using OnlineSales.Data; using OnlineSales.Formatters.Csv; @@ -46,8 +47,10 @@ public static void Main(string[] args) { builder.Configuration.AddJsonFile(path, false, true); }); - + ConfigureLogs(builder); + + ConfigurePgDataSource(builder); PluginManager.Init(builder.Configuration); builder.Configuration.AddUserSecrets(typeof(Program).Assembly); @@ -156,6 +159,22 @@ public static void Main(string[] args) app.Run(); } + private static void ConfigurePgDataSource(WebApplicationBuilder builder) + { + var postgresConfig = builder.Configuration.GetSection("Postgres").Get(); + + if (postgresConfig == null) + { + throw new MissingConfigurationException("Postgres configuration is mandatory."); + } + + var dataSourceBuilder = new NpgsqlDataSourceBuilder(postgresConfig.ConnectionString); + dataSourceBuilder.EnableDynamicJson(); + var dataSource = dataSourceBuilder.Build(); + + builder.Services.AddSingleton(dataSource); + } + private static void ConfigureImportSizeLimit(WebApplicationBuilder builder) { var maxImportSizeConfig = builder.Configuration.GetValue("ApiSettings:MaxImportSize");