diff --git a/.github/workflows/buildwindowsimage.yml b/.github/workflows/buildwindowsimage.yml index 5ae6883..64625fd 100644 --- a/.github/workflows/buildwindowsimage.yml +++ b/.github/workflows/buildwindowsimage.yml @@ -15,11 +15,6 @@ jobs: steps: - uses: actions/checkout@v2.3.4 - - name: Install NET 9 - uses: actions/setup-dotnet@v4.0.1 - with: - dotnet-version: '9.0.x' - - name: Get the version id: get_version uses: battila7/get-version-action@v2 diff --git a/.github/workflows/createrelease.yml b/.github/workflows/createrelease.yml index 665ea95..969224b 100644 --- a/.github/workflows/createrelease.yml +++ b/.github/workflows/createrelease.yml @@ -19,11 +19,6 @@ jobs: id: get_version run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} - - name: Install NET 9 - uses: actions/setup-dotnet@v4.0.1 - with: - dotnet-version: '9.0.x' - - name: Restore Nuget Packages run: dotnet restore MobileConfiguration.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }} @@ -51,7 +46,7 @@ jobs: - name: Publish API if: ${{ github.event.release.prerelease == false }} - run: dotnet publish "MobileConfiguration\MobileConfiguration.csproj" --configuration Release --output publishOutput -r linux-x64 --self-contained + run: dotnet publish "MobileConfiguration\MobileConfiguration.csproj" --configuration Release --output publishOutput -r win-x64 --self-contained - name: Build Release Package run: | @@ -71,8 +66,8 @@ jobs: # dotnet nuget push Nugets/TransactionProcessor.Client.${{ steps.get_version.outputs.VERSION }}.nupkg --api-key ${{ secrets.MYGET_APIKEY }} --source https://www.myget.org/F/transactionprocessing/api/v2/package deploystaging: - runs-on: [stagingserver, linux] - needs: buildlinux + runs-on: stagingserver + needs: build environment: staging name: "Deploy to Staging" @@ -81,77 +76,31 @@ jobs: uses: actions/download-artifact@v4.1.8 with: name: mobileconfiguration - path: /tmp/mobileconfiguration # Download to a temporary directory - - - name: Remove existing service (if applicable) + + - name: Remove existing Windows service run: | - SERVICE_NAME="mobileconfiguration" - if systemctl is-active --quiet "$SERVICE_NAME"; then - echo "Stopping existing service..." - sudo systemctl stop "$SERVICE_NAME" - fi - if systemctl is-enabled --quiet "$SERVICE_NAME"; then - echo "Disabling existing service..." - sudo systemctl disable "$SERVICE_NAME" - fi - if [ -f "/etc/systemd/system/${SERVICE_NAME}.service" ]; then - echo "Removing existing service unit file..." - sudo rm "/etc/systemd/system/${SERVICE_NAME}.service" - sudo systemctl daemon-reload - fi - + $serviceName = "Transaction Processing - Mobile Configuration" + # Check if the service exists + if (Get-Service -Name $serviceName -ErrorAction SilentlyContinue) { + Stop-Service -Name $serviceName + sc.exe delete $serviceName + } + - name: Unzip the files run: | - sudo mkdir -p /opt/txnproc/transactionprocessing/mobileconfiguration - sudo unzip -o /tmp/mobileconfiguration/mobileconfiguration.zip -d /opt/txnproc/transactionprocessing/mobileconfiguration - - # IMPORTANT: Add a step to ensure the .NET runtime is installed on the server - # This assumes it's not already there. If your base image already has it, you can skip this. - - name: Install .NET Runtime + Expand-Archive -Path mobileconfiguration.zip -DestinationPath "C:\txnproc\transactionprocessing\mobileconfiguration" -Force + + - name: Install as a Windows service run: | - # Example for Ubuntu. Adjust based on your .NET version (e.g., 8.0, 7.0) - # and if you need the SDK or just the runtime. - # This uses Microsoft's package repository for the latest versions. - wget https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb -O packages-microsoft-prod.deb - sudo dpkg -i packages-microsoft-prod.deb - rm packages-microsoft-prod.deb - sudo apt update - sudo apt install -y aspnetcore-runtime-9.0 - - - name: Install and Start as a Linux service - run: | - SERVICE_NAME="mobileconfiguration" - # The WorkingDirectory is crucial for .NET apps to find appsettings.json and other files - WORKING_DIRECTORY="/opt/txnproc/transactionprocessing/mobileconfiguration" - DLL_NAME="MobileConfiguration.dll" # Your application's DLL - SERVICE_DESCRIPTION="Transaction Processing - Mobile Configuration" - - # Create a systemd service file - echo "[Unit]" | sudo tee /etc/systemd/system/${SERVICE_NAME}.service - echo "Description=${SERVICE_DESCRIPTION}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - echo "After=network.target" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - echo "" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - echo "[Service]" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - # IMPORTANT: Use 'dotnet' to run your DLL - echo "ExecStart=/usr/bin/dotnet ${WORKING_DIRECTORY}/${DLL_NAME}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - echo "WorkingDirectory=${WORKING_DIRECTORY}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - echo "Restart=always" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - echo "User=youruser" # IMPORTANT: Change to a dedicated, less privileged user - echo "Group=yourgroup" # IMPORTANT: Change to a dedicated, less privileged group - echo "Environment=ASPNETCORE_ENVIRONMENT=Production" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service # Example - echo "" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - echo "[Install]" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - echo "WantedBy=multi-user.target" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - - # Reload systemd, enable, and start the service - sudo systemctl daemon-reload - sudo systemctl enable "$SERVICE_NAME" - sudo systemctl start "$SERVICE_NAME" - sudo systemctl status "$SERVICE_NAME" --no-pager # For debugging/verification + $serviceName = "Transaction Processing - Mobile Configuration" + $servicePath = "C:\txnproc\transactionprocessing\mobileconfiguration\MobileConfiguration.exe" + + New-Service -Name $serviceName -BinaryPathName $servicePath -Description $serviceName -DisplayName $serviceName -StartupType Automatic + Start-Service -Name $serviceName deployproduction: - runs-on: [productionserver, linux] - needs: [buildlinux, deploystaging] + runs-on: productionserver + needs: [build, deploystaging] environment: production name: "Deploy to Production" @@ -160,70 +109,24 @@ jobs: uses: actions/download-artifact@v4.1.8 with: name: mobileconfiguration - path: /tmp/mobileconfiguration # Download to a temporary directory - - - name: Remove existing service (if applicable) + + - name: Remove existing Windows service run: | - SERVICE_NAME="mobileconfiguration" - if systemctl is-active --quiet "$SERVICE_NAME"; then - echo "Stopping existing service..." - sudo systemctl stop "$SERVICE_NAME" - fi - if systemctl is-enabled --quiet "$SERVICE_NAME"; then - echo "Disabling existing service..." - sudo systemctl disable "$SERVICE_NAME" - fi - if [ -f "/etc/systemd/system/${SERVICE_NAME}.service" ]; then - echo "Removing existing service unit file..." - sudo rm "/etc/systemd/system/${SERVICE_NAME}.service" - sudo systemctl daemon-reload - fi - + $serviceName = "Transaction Processing - Mobile Configuration" + # Check if the service exists + if (Get-Service -Name $serviceName -ErrorAction SilentlyContinue) { + Stop-Service -Name $serviceName + sc.exe delete $serviceName + } + - name: Unzip the files run: | - sudo mkdir -p /opt/txnproc/transactionprocessing/mobileconfiguration - sudo unzip -o /tmp/mobileconfiguration/mobileconfiguration.zip -d /opt/txnproc/transactionprocessing/mobileconfiguration - - # IMPORTANT: Add a step to ensure the .NET runtime is installed on the server - # This assumes it's not already there. If your base image already has it, you can skip this. - - name: Install .NET Runtime - run: | - # Example for Ubuntu. Adjust based on your .NET version (e.g., 8.0, 7.0) - # and if you need the SDK or just the runtime. - # This uses Microsoft's package repository for the latest versions. - wget https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb -O packages-microsoft-prod.deb - sudo dpkg -i packages-microsoft-prod.deb - rm packages-microsoft-prod.deb - sudo apt update - sudo apt install -y aspnetcore-runtime-9.0 - - - name: Install and Start as a Linux service + Expand-Archive -Path mobileconfiguration.zip -DestinationPath "C:\txnproc\transactionprocessing\mobileconfiguration" -Force + + - name: Install as a Windows service run: | - SERVICE_NAME="mobileconfiguration" - # The WorkingDirectory is crucial for .NET apps to find appsettings.json and other files - WORKING_DIRECTORY="/opt/txnproc/transactionprocessing/mobileconfiguration" - DLL_NAME="MobileConfiguration.dll" # Your application's DLL - SERVICE_DESCRIPTION="Transaction Processing - Mobile Configuration" - - # Create a systemd service file - echo "[Unit]" | sudo tee /etc/systemd/system/${SERVICE_NAME}.service - echo "Description=${SERVICE_DESCRIPTION}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - echo "After=network.target" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - echo "" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - echo "[Service]" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - # IMPORTANT: Use 'dotnet' to run your DLL - echo "ExecStart=/usr/bin/dotnet ${WORKING_DIRECTORY}/${DLL_NAME}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - echo "WorkingDirectory=${WORKING_DIRECTORY}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - echo "Restart=always" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - echo "User=youruser" # IMPORTANT: Change to a dedicated, less privileged user - echo "Group=yourgroup" # IMPORTANT: Change to a dedicated, less privileged group - echo "Environment=ASPNETCORE_ENVIRONMENT=Production" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service # Example - echo "" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - echo "[Install]" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - echo "WantedBy=multi-user.target" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service - - # Reload systemd, enable, and start the service - sudo systemctl daemon-reload - sudo systemctl enable "$SERVICE_NAME" - sudo systemctl start "$SERVICE_NAME" - sudo systemctl status "$SERVICE_NAME" --no-pager # For debugging/verification + $serviceName = "Transaction Processing - Mobile Configuration" + $servicePath = "C:\txnproc\transactionprocessing\mobileconfiguration\MobileConfiguration.exe" + + New-Service -Name $serviceName -BinaryPathName $servicePath -Description $serviceName -DisplayName $serviceName -StartupType Automatic + Start-Service -Name $serviceName diff --git a/.github/workflows/nightlybuild.yml b/.github/workflows/nightlybuild.yml index daf6b70..64ecc38 100644 --- a/.github/workflows/nightlybuild.yml +++ b/.github/workflows/nightlybuild.yml @@ -19,11 +19,6 @@ jobs: - name: Set Up Variables run: echo "action_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_ENV - - name: Install NET 9 - uses: actions/setup-dotnet@v4.0.1 - with: - dotnet-version: '9.0.x' - - name: Restore Nuget Packages run: dotnet restore MobileConfiguration.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }} diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index c1a2ed9..f4cd143 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -16,11 +16,6 @@ jobs: steps: - uses: actions/checkout@v2.3.4 - - name: Install NET 9 - uses: actions/setup-dotnet@v4.0.1 - with: - dotnet-version: '9.0.x' - - name: Restore Nuget Packages run: dotnet restore MobileConfiguration.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }} diff --git a/MobileConfiguration/Database/ConfigurationReaderConnectionStringRepository.cs b/MobileConfiguration/Database/ConfigurationReaderConnectionStringRepository.cs deleted file mode 100644 index 2fd4b15..0000000 --- a/MobileConfiguration/Database/ConfigurationReaderConnectionStringRepository.cs +++ /dev/null @@ -1,49 +0,0 @@ -namespace MobileConfiguration.Database; - -using System.Data.Common; -using System.Diagnostics.CodeAnalysis; -using Microsoft.Data.SqlClient; -using MySqlConnector; -using Shared.General; -using Shared.Repositories; - -[ExcludeFromCodeCoverage] -public class ConfigurationReaderConnectionStringRepository : IConnectionStringConfigurationRepository -{ - #region Methods - - public async Task CreateConnectionString(String externalIdentifier, - String connectionStringIdentifier, - String connectionString, - CancellationToken cancellationToken) - { - throw new NotImplementedException("This is only required to complete the interface"); - } - - public async Task DeleteConnectionStringConfiguration(String externalIdentifier, - String connectionStringIdentifier, - CancellationToken cancellationToken) - { - throw new NotImplementedException("This is only required to complete the interface"); - } - - public async Task GetConnectionString(String externalIdentifier, - String connectionStringIdentifier, - CancellationToken cancellationToken) { - String connectionString = string.Empty; - String databaseName = string.Empty; - - databaseName = $"{connectionStringIdentifier}{externalIdentifier}"; - connectionString = ConfigurationReader.GetConnectionString(connectionStringIdentifier); - - DbConnectionStringBuilder builder = null; - - // Default to SQL Server - builder = new SqlConnectionStringBuilder(connectionString) { InitialCatalog = databaseName }; - - - return builder.ToString(); - } - - #endregion -} \ No newline at end of file diff --git a/MobileConfiguration/Dockerfile b/MobileConfiguration/Dockerfile index 3ecda39..ece3904 100644 --- a/MobileConfiguration/Dockerfile +++ b/MobileConfiguration/Dockerfile @@ -1,7 +1,7 @@ FROM stuartferguson/txnprocbase AS base WORKDIR /app -FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build WORKDIR /src COPY ["MobileConfiguration/NuGet.Config", "MobileConfiguration/"] COPY ["MobileConfiguration/MobileConfiguration.csproj", "MobileConfiguration/"] diff --git a/MobileConfiguration/Dockerfilewindows b/MobileConfiguration/Dockerfilewindows index b8aa24d..6162722 100644 --- a/MobileConfiguration/Dockerfilewindows +++ b/MobileConfiguration/Dockerfilewindows @@ -2,7 +2,7 @@ FROM stuartferguson/txnprocbasewindows AS base USER ContainerAdministrator WORKDIR /app -FROM mcr.microsoft.com/dotnet/sdk:9.0-windowsservercore-ltsc2022 AS build +FROM mcr.microsoft.com/dotnet/sdk:10.0-windowsservercore-ltsc2022 AS build WORKDIR /src COPY ["MobileConfiguration/NuGet.Config", "MobileConfiguration/"] COPY ["MobileConfiguration/MobileConfiguration.csproj", "MobileConfiguration/"] diff --git a/MobileConfiguration/MobileConfiguration.csproj b/MobileConfiguration/MobileConfiguration.csproj index a4335bb..679f6a6 100644 --- a/MobileConfiguration/MobileConfiguration.csproj +++ b/MobileConfiguration/MobileConfiguration.csproj @@ -1,34 +1,82 @@  - net9.0 + net10.0 enable enable 8795d0e9-2509-41b8-b1e1-f28f8468338b - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - + + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + diff --git a/MobileConfiguration/Program.cs b/MobileConfiguration/Program.cs index af4029d..a0b41dc 100644 --- a/MobileConfiguration/Program.cs +++ b/MobileConfiguration/Program.cs @@ -5,16 +5,18 @@ using Microsoft.Extensions.Logging; using MobileConfiguration.Database; using MobileConfiguration.Repository; +using NLog; using NLog.Extensions.Logging; using Shared.EntityFramework; using Shared.Extensions; using Shared.General; using Shared.Logger; +using Shared.Logger.TennantContext; using Shared.Middleware; -using Shared.Repositories; using System.Reflection; -using Shared.Logger.TennantContext; using ILogger = Microsoft.Extensions.Logging.ILogger; +using Logger = NLog.Logger; +using LogLevel = Microsoft.Extensions.Logging.LogLevel; IConfigurationRoot configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json") @@ -52,40 +54,37 @@ } bool logRequests = ConfigurationReaderExtensions.GetValueOrDefault("MiddlewareLogging", "LogRequests", true); bool logResponses = ConfigurationReaderExtensions.GetValueOrDefault("MiddlewareLogging", "LogResponses", true); -LogLevel middlewareLogLevel = ConfigurationReaderExtensions.GetValueOrDefault("MiddlewareLogging", "MiddlewareLogLevel", LogLevel.Warning); +LogLevel middlewareLogLevel = ConfigurationReaderExtensions.GetValueOrDefault("MiddlewareLogging", "MiddlewareLogLevel", LogLevel.Warning); -RequestResponseMiddlewareLoggingConfig config = - new RequestResponseMiddlewareLoggingConfig(middlewareLogLevel, logRequests, logResponses); +RequestResponseMiddlewareLoggingConfig config = new(middlewareLogLevel, logRequests, logResponses); builder.Services.AddSingleton(config); var app = builder.Build(); +String contentRoot = Directory.GetCurrentDirectory(); -String nlogConfigFilename = "nlog.config"; +String nlogConfigPath = Path.Combine(contentRoot, "nlog.config"); app.UseMiddleware(); -if (app.Environment.IsDevelopment()) +app.UseSwagger(); +app.UseSwaggerUI(); + +LogManager.Setup(b => { - var developmentNlogConfigFilename = "nlog.development.config"; - if (File.Exists(Path.Combine(app.Environment.ContentRootPath, developmentNlogConfigFilename))) + b.SetupLogFactory(setup => { - nlogConfigFilename = developmentNlogConfigFilename; - } - - app.UseSwagger(); - app.UseSwaggerUI(); -} - -var loggerFactory = app.Services.GetRequiredService(); - -loggerFactory.ConfigureNLog(Path.Combine(path, nlogConfigFilename)); -loggerFactory.AddNLog(); + setup.AddCallSiteHiddenAssembly(typeof(NlogLogger).Assembly); + setup.AddCallSiteHiddenAssembly(typeof(Shared.Logger.Logger).Assembly); + setup.AddCallSiteHiddenAssembly(typeof(TenantMiddleware).Assembly); + }); + b.LoadConfigurationFromFile(nlogConfigPath); +}); -ILogger logger = loggerFactory.CreateLogger("MobileConfiguration"); +Logger logger = LogManager.LogFactory.GetLogger("MobileConfiguration"); -Logger.Initialise(logger); +Shared.Logger.Logger.Initialise(logger as ILogger); // Configure the HTTP request pipeline. diff --git a/MobileConfiguration/Repository/IConfigurationRepository.cs b/MobileConfiguration/Repository/IConfigurationRepository.cs index 424ce2e..7b07c00 100644 --- a/MobileConfiguration/Repository/IConfigurationRepository.cs +++ b/MobileConfiguration/Repository/IConfigurationRepository.cs @@ -9,9 +9,6 @@ namespace MobileConfiguration.Repository using Newtonsoft.Json; using Shared.EntityFramework; using Shared.Exceptions; - using Shared.General; - using Shared.Repositories; - using ApplicationCentreConfiguration = Database.Entities.ApplicationCentreConfiguration; public interface IConfigurationRepository {