Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Quartz;
using SecurityService.Client;
using SecurityService.DataTransferObjects.Responses;
using Shared.Logger;
using TransactionProcessor.Client;
using TransactionProcessor.DataTransferObjects;

Expand All @@ -27,7 +28,6 @@ public class GenerateTransactionsJob : BaseJob, IJob{
#region Methods

public async Task Execute(IJobExecutionContext context){
try{
Bootstrapper.ConfigureServices(context);

String clientId = context.MergedJobDataMap.GetString("ClientId");
Expand All @@ -36,14 +36,17 @@ public async Task Execute(IJobExecutionContext context){
Guid merchantId = context.MergedJobDataMap.GetGuidValueFromString("MerchantId");
Boolean requireLogon = context.MergedJobDataMap.GetBooleanValueFromString("requireLogon");

Logger.LogInformation($"Running Job {context.JobDetail.Description}");
Logger.LogInformation($"Client Id: [{clientId}]");
Logger.LogInformation($"Client Secret: [{clientSecret}]");
Logger.LogInformation($"Estate Id: [{estateId}]");
Logger.LogInformation($"Merchant Id: [{merchantId}]");
Logger.LogInformation($"Require Logon: [{requireLogon}]");

ITransactionDataGenerator t = CreateTransactionDataGenerator(clientId, clientSecret, RunningMode.Live);

await Jobs.GenerateTransactions(t, estateId, merchantId, requireLogon, context.CancellationToken);
}
catch(Exception e){
// TODO: Log the error
}
}
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using MessagingService.DataTransferObjects;
using Microsoft.Data.SqlClient;
using Newtonsoft.Json;
using Quartz;
using Shared.Logger;

public static class Jobs{
public static async Task GenerateMerchantStatements(ITransactionDataGenerator t, Guid estateId, CancellationToken cancellationToken){
Expand All @@ -27,7 +29,7 @@ public static async Task GenerateMerchantStatements(ITransactionDataGenerator t,

public static async Task GenerateFileUploads(ITransactionDataGenerator t, Guid estateId, Guid merchantId, CancellationToken cancellationToken)
{
MerchantResponse merchant = await t.GetMerchant( estateId, merchantId, cancellationToken);
MerchantResponse merchant = await t.GetMerchant(estateId, merchantId, cancellationToken);

List<ContractResponse> contracts = await t.GetMerchantContracts(merchant, cancellationToken);
DateTime fileDate = DateTime.Now;
Expand All @@ -38,10 +40,17 @@ public static async Task GenerateFileUploads(ITransactionDataGenerator t, Guid e
}
}

public static async Task GenerateTransactions(ITransactionDataGenerator t, Guid estateId, Guid merchantId, Boolean requireLogon, CancellationToken cancellationToken)
{
public static async Task GenerateTransactions(ITransactionDataGenerator t, Guid estateId, Guid merchantId, Boolean requireLogon, CancellationToken cancellationToken){
MerchantResponse merchant = null;
// get the merchant
MerchantResponse merchant = await t.GetMerchant(estateId, merchantId, cancellationToken);
try
{
merchant = await t.GetMerchant(estateId, merchantId, cancellationToken);
}
catch(Exception e){
Logger.LogWarning($"Error getting merchant record [{merchantId}]");
throw new JobExecutionException(new Exception($"Error getting merchant record [{merchantId}]"), false);
}

DateTime transactionDate = DateTime.Now;

Expand Down Expand Up @@ -122,6 +131,7 @@ public static SendEmailRequest BuildSupportEmail(DateTime dateTime,
htmlBuilder.AppendLine("<style>");
htmlBuilder.AppendLine("table, th, td { border: 1px solid black; }");
htmlBuilder.AppendLine("</style>");
htmlBuilder.AppendLine("</style>");
htmlBuilder.AppendLine("</head>");

htmlBuilder.AppendLine("<body>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="MessagingService.Client" Version="2023.3.1" />

<PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.1" />

<PackageReference Include="Shared" Version="1.5.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Quartz" Version="3.5.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace TransactionProcessing.SchedulerService
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
Expand All @@ -13,10 +14,15 @@ namespace TransactionProcessing.SchedulerService
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using Quartz;
using Quartz.Impl;
using Shared.Logger;
using SilkierQuartz;
using ConfigurationManager = System.Configuration.ConfigurationManager;
using ILogger = Microsoft.Extensions.Logging.ILogger;
using SetupBuilderExtensions = NLog.SetupBuilderExtensions;

/// <summary>
///
Expand Down Expand Up @@ -74,14 +80,26 @@ public static void AddOrUpdateConnectionString(String name,
}

public void Configure(IApplicationBuilder app,
IWebHostEnvironment env){
IWebHostEnvironment env, ILoggerFactory loggerFactory)
{

String nlogConfigFilename = "nlog.config";

if (env.IsDevelopment()){
app.UseDeveloperExceptionPage();
}
else{
app.UseExceptionHandler("/Error");
}


loggerFactory.ConfigureNLog(Path.Combine(env.ContentRootPath, nlogConfigFilename));
loggerFactory.AddNLog();

ILogger logger = loggerFactory.CreateLogger("EstateManagement");

Logger.Initialise(logger);

app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReference Include="Quartz.Serialization.Json" Version="3.6.2" />
<PackageReference Include="Shared" Version="1.5.1" />
<PackageReference Include="SilkierQuartz" Version="5.0.356" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.1.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="7.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="asyncFile" xsi:type="AsyncWrapper">
<target name="logfile" xsi:type="File"
fileName="/home/txnproc/trace/estatemanagement.log"
layout="${date:format=dd/MM/yyyy HH\:mm\:ss.ffff} | ${level} | ${callsite:className=true} | ${message} | ${exception:format=type,method:maxInnerExceptionLevel=5:innerFormat=shortType,message,method:InnerExceptionSeparator= | }"
archiveFileName="/home/txnproc/trace/estatemanagement.{#####}.log"
archiveAboveSize="104857600"
archiveNumbering="Sequence"
concurrentWrites="true"
maxArchiveFiles="2"/>
<target name="healthlogfile" xsi:type="File"
fileName="/home/txnproc/trace/estatemanagement_health.log"
layout="${date:format=dd/MM/yyyy HH\:mm\:ss.ffff} | ${level} | ${callsite:className=true} | ${message} | ${exception:format=type,method:maxInnerExceptionLevel=5:innerFormat=shortType,message,method:InnerExceptionSeparator= | }"
archiveFileName="/home/txnproc/trace/estatemanagement_health.{#####}.log"
archiveAboveSize="104857600"
archiveNumbering="Sequence"
concurrentWrites="true"
maxArchiveFiles="2"/>
</target>
</targets>

<rules>
<logger name="Microsoft.*" minlevel="Debug" writeTo="" final="true" />
<logger name="*" minlevel="Debug" writeTo="logfile">
<filters defaultAction="Log">
<when condition="contains('${message}', 'HEALTH_CHECK')" action="Ignore"></when>
</filters>
</logger>
<logger name="*" minlevel="Debug" writeTo="healthlogfile">
<filters defaultAction="Ignore">
<when condition="contains('${message}', 'HEALTH_CHECK')" action="Log"></when>
</filters>
</logger>
</rules>
</nlog>
8 changes: 6 additions & 2 deletions TransactionProcessor.DataGenerator/DataGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ static async Task Main(string[] args){
clientSecret,
RunningMode.Live);

g.TraceGenerated += arguments => {
Console.WriteLine($"{arguments.TraceLevel}|{arguments.Message}");
};

await Program.GenerateTransactions(g, estateId, cancellationToken);
//await Program.GenerateStatements(g, estateId, cancellationToken);

Expand All @@ -97,8 +101,8 @@ private static async Task GenerateStatements(ITransactionDataGenerator g, Guid e

private static async Task GenerateTransactions(ITransactionDataGenerator g, Guid estateId, CancellationToken cancellationToken){
// Set the date range
DateTime startDate = new DateTime(2023, 6, 6); //27/7
DateTime endDate = new DateTime(2023, 6, 7); // This is the date of the last generated transaction
DateTime startDate = new DateTime(2023, 6, 8); //27/7
DateTime endDate = new DateTime(2023, 6, 8); // This is the date of the last generated transaction

List<DateTime> dateRange = g.GenerateDateRange(startDate, endDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,26 @@ public interface ITransactionDataGenerator{
Task<MerchantResponse> GetMerchant(Guid estateId, Guid merchantId, CancellationToken cancellationToken);
Task GenerateMerchantStatement(Guid estateId, Guid merchantId, DateTime statementDateTime, CancellationToken cancellationToken);

event TraceHandler TraceGenerated;

#endregion
}

public delegate void TraceHandler(TraceEventArgs traceArguments);

public class TraceEventArgs : EventArgs
{
public enum Level{
Trace,
Warning,
Error
}

#region Properties

public String Message { get; set; }

public Level TraceLevel { get; set; }

#endregion
}
Loading