diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/BaseBoostrapper.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/BaseBoostrapper.cs deleted file mode 100644 index 63522f4..0000000 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/BaseBoostrapper.cs +++ /dev/null @@ -1,82 +0,0 @@ -namespace TransactionProcessing.SchedulerService.Jobs -{ - using System.Net.Http; - using Microsoft.Extensions.DependencyInjection; - using Quartz; - - /// - /// - /// - /// - public abstract class BaseBoostrapper : IBootstrapper - { - #region Fields - - /// - /// The job execution context - /// - protected IJobExecutionContext JobExecutionContext; - - /// - /// The service provider - /// - protected ServiceProvider ServiceProvider; - - /// - /// The services - /// - protected IServiceCollection Services; - - #endregion - - #region Methods - - /// - /// Configures the service additional. - /// - /// The job execution context. - public virtual void ConfigureServiceAdditional(IJobExecutionContext jobExecutionContext) - { - // Nothing here - } - - /// - /// Configures the services. - /// - /// The job execution context. - public virtual void ConfigureServices(IJobExecutionContext jobExecutionContext) - { - this.Services = new ServiceCollection(); - this.JobExecutionContext = jobExecutionContext; - - HttpClientHandler httpClientHandler = new HttpClientHandler - { - ServerCertificateCustomValidationCallback = (message, - cert, - chain, - errors) => - { - return true; - } - }; - HttpClient httpClient = new HttpClient(httpClientHandler); - this.Services.AddSingleton(httpClient); - - this.ConfigureServiceAdditional(jobExecutionContext); - - this.ServiceProvider = this.Services.BuildServiceProvider(); - } - - /// - /// Gets the service. - /// - /// - /// - public virtual T GetService() - { - return this.ServiceProvider.GetService(); - } - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Bootstrapper.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Bootstrapper.cs new file mode 100644 index 0000000..687694e --- /dev/null +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Bootstrapper.cs @@ -0,0 +1,84 @@ +namespace TransactionProcessing.SchedulerService.Jobs; + +using System; +using System.Net.Http; +using System.Threading.Tasks; +using System.Threading; +using DataGeneration; +using EstateManagement.Client; +using EstateManagement.DataTransferObjects.Responses; +using Microsoft.Extensions.DependencyInjection; +using Quartz; +using SecurityService.Client; +using SecurityService.DataTransferObjects.Responses; +using TransactionProcessor.Client; + +public static class Bootstrapper{ + + internal static IJobExecutionContext JobExecutionContext; + + internal static ServiceProvider ServiceProvider; + + internal static IServiceCollection Services; + + public static void ConfigureServices(IJobExecutionContext jobExecutionContext){ + Bootstrapper.Services = new ServiceCollection(); + Bootstrapper.JobExecutionContext = jobExecutionContext; + + HttpClientHandler httpClientHandler = new HttpClientHandler{ + ServerCertificateCustomValidationCallback = (message, + cert, + chain, + errors) => { + return true; + } + }; + HttpClient httpClient = new HttpClient(httpClientHandler); + + Bootstrapper.Services.AddSingleton(httpClient); + Bootstrapper.Services.AddSingleton(); + Bootstrapper.Services.AddSingleton(); + Bootstrapper.Services.AddSingleton(); + Bootstrapper.Services.AddSingleton>(container => serviceName => { return jobExecutionContext.MergedJobDataMap.GetString(serviceName); }); + + Bootstrapper.ServiceProvider = Bootstrapper.Services.BuildServiceProvider(); + } + + public static T GetService() + { + return Bootstrapper.ServiceProvider.GetService(); + } +} + +public class BaseJob{ + protected ITransactionDataGenerator CreateTransactionDataGenerator(String clientId, String clientSecret, RunningMode runningMode){ + ISecurityServiceClient securityServiceClient = Bootstrapper.GetService(); + IEstateClient estateClient = Bootstrapper.GetService(); + TransactionProcessorClient transactionProcessorClient = Bootstrapper.GetService(); + Func baseAddressFunc = Bootstrapper.GetService>(); + + ITransactionDataGenerator g = new TransactionDataGenerator(securityServiceClient, + estateClient, + transactionProcessorClient, + baseAddressFunc("EstateManagementApi"), + baseAddressFunc("FileProcessorApi"), + baseAddressFunc("TestHostApi"), + clientId, + clientSecret, + runningMode); + return g; + } + + protected async Task GetToken(String clientId, String clientSecret, CancellationToken cancellationToken) + { + ISecurityServiceClient securityServiceClient = Bootstrapper.GetService(); + TokenResponse token = await securityServiceClient.GetToken(clientId, clientSecret, cancellationToken); + + return token.AccessToken; + } + + protected async Task GetMerchant(String accessToken, Guid estateId, Guid merchantId, CancellationToken cancellationToken){ + IEstateClient estateClient = Bootstrapper.GetService(); + return await estateClient.GetMerchant(accessToken, estateId, merchantId, cancellationToken); + } +} \ No newline at end of file diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateFileUploads/GenerateFileUploadsBootstrapper.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateFileUploads/GenerateFileUploadsBootstrapper.cs deleted file mode 100644 index 2b73b06..0000000 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateFileUploads/GenerateFileUploadsBootstrapper.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace TransactionProcessing.SchedulerService.Jobs -{ - using System; - using EstateManagement.Client; - using Microsoft.Extensions.DependencyInjection; - using Quartz; - using SecurityService.Client; - using TransactionProcessor.Client; - - /// - /// - /// - /// - public class GenerateFileUploadsJobBootstrapper : BaseBoostrapper - { - #region Methods - - /// - /// Configures the service additional. - /// - /// The job execution context. - public override void ConfigureServiceAdditional(IJobExecutionContext jobExecutionContext) - { - this.Services.AddSingleton(); - this.Services.AddSingleton(); - this.Services.AddSingleton(); - - this.Services.AddSingleton>(container => serviceName => { return jobExecutionContext.MergedJobDataMap.GetString(serviceName); }); - } - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateFileUploads/GenerateFileUploadsJob.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateFileUploads/GenerateFileUploadsJob.cs deleted file mode 100644 index d5ede4d..0000000 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateFileUploads/GenerateFileUploadsJob.cs +++ /dev/null @@ -1,100 +0,0 @@ -namespace TransactionProcessing.SchedulerService.Jobs -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Linq; - using System.Net.Http; - using System.Net.Http.Headers; - using System.Threading; - using System.Threading.Tasks; - using DataGeneration; - using EstateManagement.Client; - using EstateManagement.DataTransferObjects.Requests; - using EstateManagement.DataTransferObjects.Responses; - using Quartz; - using Quartz.Impl; - using SecurityService.Client; - using SecurityService.DataTransferObjects.Responses; - using TransactionProcessor.Client; - - /// - /// - /// - /// - [DisallowConcurrentExecution] - public class GenerateFileUploadsJob : IJob - { - #region Fields - - private Func baseAddressFunc; - - private readonly IBootstrapper Bootstrapper; - - private IEstateClient EstateClient; - - private ISecurityServiceClient SecurityServiceClient; - - private ITransactionProcessorClient TransactionProcessorClient; - - #endregion - - #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The bootstrapper resolver. - public GenerateFileUploadsJob(Func bootstrapperResolver) - { - this.Bootstrapper = bootstrapperResolver(nameof(GenerateFileUploadsJob)); - } - - #endregion - - #region Methods - public async Task Execute(IJobExecutionContext context) - { - this.Bootstrapper.ConfigureServices(context); - String clientId = context.MergedJobDataMap.GetString("ClientId"); - String clientSecret = context.MergedJobDataMap.GetString("ClientSecret"); - Guid estateId = context.MergedJobDataMap.GetGuidValueFromString("EstateId"); - Guid merchantId = context.MergedJobDataMap.GetGuidValueFromString("MerchantId"); - - this.SecurityServiceClient = this.Bootstrapper.GetService(); - this.EstateClient = this.Bootstrapper.GetService(); - this.TransactionProcessorClient = this.Bootstrapper.GetService(); - this.baseAddressFunc = this.Bootstrapper.GetService>(); - - ITransactionDataGenerator g = new TransactionDataGenerator(this.SecurityServiceClient, - this.EstateClient, - this.TransactionProcessorClient, - this.baseAddressFunc("FileProcessorApi"), - this.baseAddressFunc("TestHostApi"), - clientId, - clientSecret, - RunningMode.Live); - String accessToken = await this.GetToken(clientId, - clientSecret, - context.CancellationToken); - - MerchantResponse merchant = await this.EstateClient.GetMerchant(accessToken, estateId, merchantId, context.CancellationToken); - - List contracts = await this.EstateClient.GetMerchantContracts(accessToken, merchant.EstateId, merchant.MerchantId, context.CancellationToken); - DateTime fileDate = DateTime.Now; - foreach (ContractResponse contract in contracts){ - // Generate a file and upload - await g.SendUploadFile(fileDate, contract, merchant, context.CancellationToken); - } - } - - private async Task GetToken(String clientId, String clientSecret, CancellationToken cancellationToken) - { - TokenResponse token = await this.SecurityServiceClient.GetToken(clientId, clientSecret, cancellationToken); - - return token.AccessToken; - } - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateFileUploadsJob.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateFileUploadsJob.cs new file mode 100644 index 0000000..1a00257 --- /dev/null +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateFileUploadsJob.cs @@ -0,0 +1,43 @@ +namespace TransactionProcessing.SchedulerService.Jobs +{ + using System; + using System.Collections.Generic; + using System.Threading.Tasks; + using DataGeneration; + using EstateManagement.DataTransferObjects.Responses; + using Quartz; + + [DisallowConcurrentExecution] + public class GenerateFileUploadsJob : BaseJob, IJob + { + #region Methods + public async Task Execute(IJobExecutionContext context) + { + Bootstrapper.ConfigureServices(context); + + String clientId = context.MergedJobDataMap.GetString("ClientId"); + String clientSecret = context.MergedJobDataMap.GetString("ClientSecret"); + Guid estateId = context.MergedJobDataMap.GetGuidValueFromString("EstateId"); + Guid merchantId = context.MergedJobDataMap.GetGuidValueFromString("MerchantId"); + + String accessToken = await this.GetToken(clientId, + clientSecret, + context.CancellationToken); + + ITransactionDataGenerator t = CreateTransactionDataGenerator(clientId, clientSecret, RunningMode.Live); + + MerchantResponse merchant = await this.GetMerchant(accessToken, estateId, merchantId, context.CancellationToken); + + List contracts = await t.GetMerchantContracts(merchant, context.CancellationToken); + DateTime fileDate = DateTime.Now; + foreach (ContractResponse contract in contracts){ + // Generate a file and upload + await t.SendUploadFile(fileDate, contract, merchant, context.CancellationToken); + } + } + + + + #endregion + } +} \ No newline at end of file diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateMerchantStatementJob.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateMerchantStatementJob.cs new file mode 100644 index 0000000..d384bd1 --- /dev/null +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateMerchantStatementJob.cs @@ -0,0 +1,26 @@ +namespace TransactionProcessing.SchedulerService.Jobs; + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using DataGeneration; +using EstateManagement.DataTransferObjects.Responses; +using Quartz; + +public class GenerateMerchantStatementJob : BaseJob, IJob +{ + public async Task Execute(IJobExecutionContext context) + { + Bootstrapper.ConfigureServices(context); + String clientId = context.MergedJobDataMap.GetString("ClientId"); + String clientSecret = context.MergedJobDataMap.GetString("ClientSecret"); + Guid estateId = context.MergedJobDataMap.GetGuidValueFromString("EstateId"); + + ITransactionDataGenerator t = this.CreateTransactionDataGenerator(clientId, clientSecret, RunningMode.Live); + + List merchants = await t.GetMerchants(estateId, context.CancellationToken); + foreach (MerchantResponse merchantResponse in merchants){ + await t.GenerateMerchantStatement(merchantResponse.EstateId, merchantResponse.MerchantId, DateTime.Now, context.CancellationToken); + } + } +} \ No newline at end of file diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateTransactions/GenerateTransactionsBootstrapper.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateTransactions/GenerateTransactionsBootstrapper.cs deleted file mode 100644 index 3a822f4..0000000 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateTransactions/GenerateTransactionsBootstrapper.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace TransactionProcessing.SchedulerService.Jobs.GenerateTransactions -{ - using System; - using EstateManagement.Client; - using Microsoft.Extensions.DependencyInjection; - using Quartz; - using SecurityService.Client; - using TransactionProcessor.Client; - - /// - /// - /// - /// - public class GenerateTransactionsJobBootstrapper : BaseBoostrapper - { - #region Methods - - /// - /// Configures the service additional. - /// - /// The job execution context. - public override void ConfigureServiceAdditional(IJobExecutionContext jobExecutionContext) - { - this.Services.AddSingleton(); - this.Services.AddSingleton(); - this.Services.AddSingleton(); - - this.Services.AddSingleton>(container => serviceName => { return jobExecutionContext.MergedJobDataMap.GetString(serviceName); }); - } - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateTransactions/GenerateTransactionsJob.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateTransactions/GenerateTransactionsJob.cs deleted file mode 100644 index 85564b1..0000000 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateTransactions/GenerateTransactionsJob.cs +++ /dev/null @@ -1,127 +0,0 @@ -namespace TransactionProcessing.SchedulerService.Jobs -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Net.Http; - using System.Text; - using System.Threading; - using System.Threading.Tasks; - using DataGeneration; - using EstateManagement.Client; - using EstateManagement.DataTransferObjects.Requests; - using EstateManagement.DataTransferObjects.Responses; - using Newtonsoft.Json; - using Quartz; - using SecurityService.Client; - using SecurityService.DataTransferObjects.Responses; - using TransactionProcessor.Client; - using TransactionProcessor.DataTransferObjects; - - /// - /// - /// - /// - public class GenerateTransactionsJob : IJob - { - #region Fields - - private Func baseAddressFunc; - - private readonly IBootstrapper Bootstrapper; - - private IEstateClient EstateClient; - - private ISecurityServiceClient SecurityServiceClient; - - private ITransactionProcessorClient TransactionProcessorClient; - - #endregion - - #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The bootstrapper resolver. - public GenerateTransactionsJob(Func bootstrapperResolver) - { - this.Bootstrapper = bootstrapperResolver(nameof(GenerateTransactionsJob)); - } - - #endregion - - #region Methods - - public async Task Execute(IJobExecutionContext context) - { - try - { - this.Bootstrapper.ConfigureServices(context); - - String clientId = context.MergedJobDataMap.GetString("ClientId"); - String clientSecret = context.MergedJobDataMap.GetString("ClientSecret"); - Guid estateId = context.MergedJobDataMap.GetGuidValueFromString("EstateId"); - Guid merchantId = context.MergedJobDataMap.GetGuidValueFromString("MerchantId"); - Boolean requireLogon = context.MergedJobDataMap.GetBooleanValueFromString("requireLogon"); - - this.SecurityServiceClient = this.Bootstrapper.GetService(); - this.TransactionProcessorClient = this.Bootstrapper.GetService(); - this.EstateClient = this.Bootstrapper.GetService(); - this.baseAddressFunc = this.Bootstrapper.GetService>(); - - ITransactionDataGenerator g = new TransactionDataGenerator(this.SecurityServiceClient, - this.EstateClient, - this.TransactionProcessorClient, - this.baseAddressFunc("FileProcessorApi"), - this.baseAddressFunc("TestHostApi"), - clientId, - clientSecret, - RunningMode.Live); - - // get a token - String accessToken = await this.GetToken(clientId, - clientSecret, context.CancellationToken); - - // get the merchant - MerchantResponse merchant = await this.EstateClient.GetMerchant(accessToken, estateId, merchantId, context.CancellationToken); - - Int32 transactionCount = 0; - DateTime transactionDate = DateTime.Now; - - if (requireLogon) - { - // Do a logon transaction for the merchant - await g.PerformMerchantLogon(transactionDate, merchant, context.CancellationToken); - - // Get the merchants contracts - List contracts = await g.GetMerchantContracts(merchant, context.CancellationToken); - - foreach (ContractResponse contract in contracts) - { - // Generate and send some sales - await g.SendSales(transactionDate, merchant, contract, context.CancellationToken); - - // Generate a file and upload - await g.SendUploadFile(transactionDate, contract, merchant, context.CancellationToken); - } - - Console.WriteLine($"Logon sent for Merchant [{merchant.MerchantName}]"); - } - } - catch(Exception e) - { - // TODO: Log the error - } - } - - private async Task GetToken(String clientId, String clientSecret, CancellationToken cancellationToken) - { - TokenResponse token = await this.SecurityServiceClient.GetToken(clientId, clientSecret, cancellationToken); - - return token.AccessToken; - } - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateTransactions/ProductType.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateTransactions/ProductType.cs deleted file mode 100644 index c266703..0000000 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateTransactions/ProductType.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace TransactionProcessing.SchedulerService.Jobs -{ - public enum ProductType - { - /// - /// The not set - /// - NotSet = 0, - - /// - /// The mobile topup - /// - MobileTopup, - - /// - /// The mobile wallet - /// - MobileWallet, - - /// - /// The bill payment - /// - BillPayment, - - /// - /// The voucher - /// - Voucher - } - -} \ No newline at end of file diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateTransactionsJob.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateTransactionsJob.cs new file mode 100644 index 0000000..ccdf052 --- /dev/null +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/GenerateTransactionsJob.cs @@ -0,0 +1,75 @@ +namespace TransactionProcessing.SchedulerService.Jobs +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net.Http; + using System.Text; + using System.Threading; + using System.Threading.Tasks; + using DataGeneration; + using EstateManagement.Client; + using EstateManagement.DataTransferObjects.Requests; + using EstateManagement.DataTransferObjects.Responses; + using Newtonsoft.Json; + using Quartz; + using SecurityService.Client; + using SecurityService.DataTransferObjects.Responses; + using TransactionProcessor.Client; + using TransactionProcessor.DataTransferObjects; + + /// + /// + /// + /// + public class GenerateTransactionsJob : BaseJob, IJob{ + + #region Methods + + public async Task Execute(IJobExecutionContext context){ + try{ + Bootstrapper.ConfigureServices(context); + + String clientId = context.MergedJobDataMap.GetString("ClientId"); + String clientSecret = context.MergedJobDataMap.GetString("ClientSecret"); + Guid estateId = context.MergedJobDataMap.GetGuidValueFromString("EstateId"); + Guid merchantId = context.MergedJobDataMap.GetGuidValueFromString("MerchantId"); + Boolean requireLogon = context.MergedJobDataMap.GetBooleanValueFromString("requireLogon"); + + ITransactionDataGenerator t = CreateTransactionDataGenerator(clientId, clientSecret, RunningMode.Live); + + // get a token + String accessToken = await this.GetToken(clientId, + clientSecret, + context.CancellationToken); + + // get the merchant + MerchantResponse merchant = await this.GetMerchant(accessToken, estateId, merchantId, context.CancellationToken); + + DateTime transactionDate = DateTime.Now; + + if (requireLogon){ + // Do a logon transaction for the merchant + await t.PerformMerchantLogon(transactionDate, merchant, context.CancellationToken); + } + + // Get the merchants contracts + List contracts = await t.GetMerchantContracts(merchant, context.CancellationToken); + + foreach (ContractResponse contract in contracts){ + // Generate and send some sales + await t.SendSales(transactionDate, merchant, contract, context.CancellationToken); + + // Generate a file and upload + await t.SendUploadFile(transactionDate, contract, merchant, context.CancellationToken); + } + + Console.WriteLine($"Logon sent for Merchant [{merchant.MerchantName}]"); + } + catch(Exception e){ + // TODO: Log the error + } + } + #endregion + } +} \ No newline at end of file diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/IBootstrapper.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/IBootstrapper.cs deleted file mode 100644 index a937b49..0000000 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/IBootstrapper.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace TransactionProcessing.SchedulerService.Jobs -{ - using Quartz; - - /// - /// - /// - public interface IBootstrapper - { - #region Methods - - /// - /// Configures the services. - /// - /// The job execution context. - void ConfigureServices(IJobExecutionContext jobExecutionContext); - - /// - /// Gets the service. - /// - /// - /// - T GetService(); - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/ProcessSettlement/ProcessSettlementJob.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/ProcessSettlement/ProcessSettlementJob.cs deleted file mode 100644 index 6048bb4..0000000 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/ProcessSettlement/ProcessSettlementJob.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TransactionProcessing.SchedulerService.Jobs -{ - using System.Threading; - using EstateManagement.Client; - using Quartz; - using SecurityService.Client; - using SecurityService.DataTransferObjects.Responses; - using TransactionProcessing.DataGeneration; - using TransactionProcessor.Client; - - public class ProcessSettlementJob : IJob - { - private Func baseAddressFunc; - - private readonly IBootstrapper Bootstrapper; - - private IEstateClient EstateClient; - - private ISecurityServiceClient SecurityServiceClient; - - private ITransactionProcessorClient TransactionProcessorClient; - - public ProcessSettlementJob(Func bootstrapperResolver) - { - this.Bootstrapper = bootstrapperResolver(nameof(ProcessSettlementJob)); - } - - private async Task GetToken(String clientId, - String clientSecret, - CancellationToken cancellationToken) - { - - - TokenResponse token = await this.SecurityServiceClient.GetToken(clientId, clientSecret, cancellationToken); - - return token.AccessToken; - } - - public async Task Execute(IJobExecutionContext context) - { - this.Bootstrapper.ConfigureServices(context); - String clientId = context.MergedJobDataMap.GetString("ClientId"); - String clientSecret = context.MergedJobDataMap.GetString("ClientSecret"); - Guid estateId = context.MergedJobDataMap.GetGuidValueFromString("EstateId"); - - this.SecurityServiceClient = this.Bootstrapper.GetService(); - this.TransactionProcessorClient = this.Bootstrapper.GetService(); - this.EstateClient = this.Bootstrapper.GetService(); - this.baseAddressFunc = this.Bootstrapper.GetService>(); - - ITransactionDataGenerator g = new TransactionDataGenerator(this.SecurityServiceClient, - this.EstateClient, - this.TransactionProcessorClient, - this.baseAddressFunc("FileProcessorApi"), - this.baseAddressFunc("TestHostApi"), - clientId, - clientSecret, - RunningMode.Live); - - await g.PerformSettlement(DateTime.Now.Date, estateId, context.CancellationToken); - } - } -} diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/ProcessSettlement/ProcessSettlementJobBootstrapper.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/ProcessSettlement/ProcessSettlementJobBootstrapper.cs deleted file mode 100644 index ebef493..0000000 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/ProcessSettlement/ProcessSettlementJobBootstrapper.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace TransactionProcessing.SchedulerService.Jobs -{ - using System; - using EstateManagement.Client; - using Microsoft.Extensions.DependencyInjection; - using Quartz; - using SecurityService.Client; - using TransactionProcessor.Client; - - public class ProcessSettlementJobBootstrapper : BaseBoostrapper - { - #region Methods - - /// - /// Configures the service additional. - /// - /// The job execution context. - public override void ConfigureServiceAdditional(IJobExecutionContext jobExecutionContext) - { - this.Services.AddSingleton(); - this.Services.AddSingleton(); - this.Services.AddSingleton(); - - this.Services.AddSingleton>(container => serviceName => { return jobExecutionContext.MergedJobDataMap.GetString(serviceName); }); - } - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/ProcessSettlementJob.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/ProcessSettlementJob.cs new file mode 100644 index 0000000..8c66b07 --- /dev/null +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/ProcessSettlementJob.cs @@ -0,0 +1,30 @@ +using System; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TransactionProcessing.SchedulerService.Jobs +{ + using System.Threading; + using EstateManagement.Client; + using Quartz; + using SecurityService.Client; + using SecurityService.DataTransferObjects.Responses; + using TransactionProcessing.DataGeneration; + using TransactionProcessor.Client; + + public class ProcessSettlementJob : BaseJob, IJob + { + public async Task Execute(IJobExecutionContext context) + { + Bootstrapper.ConfigureServices(context); + String clientId = context.MergedJobDataMap.GetString("ClientId"); + String clientSecret = context.MergedJobDataMap.GetString("ClientSecret"); + Guid estateId = context.MergedJobDataMap.GetGuidValueFromString("EstateId"); + + ITransactionDataGenerator t = CreateTransactionDataGenerator(clientId, clientSecret, RunningMode.Live); + + await t.PerformSettlement(DateTime.Now.Date, estateId, context.CancellationToken); + } + } +} diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/TransactionProcessing.SchedulerService.Jobs.csproj b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/TransactionProcessing.SchedulerService.Jobs.csproj index 0303e1a..067eb64 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/TransactionProcessing.SchedulerService.Jobs.csproj +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/TransactionProcessing.SchedulerService.Jobs.csproj @@ -9,7 +9,7 @@ - + diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/Startup.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/Startup.cs index 6954644..3e5f2df 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/Startup.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/Startup.cs @@ -21,26 +21,10 @@ namespace TransactionProcessing.SchedulerService /// /// /// - public class Startup - { - #region Fields - - /// - /// The job bootstrappers - /// - private readonly List<(String name, IBootstrapper instance)> JobBootstrappers = new List<(String, IBootstrapper)>(); - - #endregion - + public class Startup{ #region Constructors - /// - /// Initializes a new instance of the class. - /// - /// The web host environment. - public Startup(IWebHostEnvironment webHostEnvironment) - { - //this.Configuration = configuration; + public Startup(IWebHostEnvironment webHostEnvironment){ IConfigurationBuilder builder = new ConfigurationBuilder().SetBasePath(webHostEnvironment.ContentRootPath) .AddJsonFile("/home/txnproc/config/appsettings.json", true, true) .AddJsonFile($"/home/txnproc/config/appsettings.{webHostEnvironment.EnvironmentName}.json", @@ -52,79 +36,49 @@ public Startup(IWebHostEnvironment webHostEnvironment) Startup.Configuration = builder.Build(); Startup.WebHostEnvironment = webHostEnvironment; - var connectionString = Startup.Configuration.GetConnectionString("SchedulerReadModel"); + String connectionString = Startup.Configuration.GetConnectionString("SchedulerReadModel"); Startup.AddOrUpdateConnectionString("SchedulerReadModel", connectionString); } #endregion #region Properties - - /// - /// Gets or sets the configuration. - /// - /// - /// The configuration. - /// - public static IConfigurationRoot Configuration { get; set; } - - /// - /// Gets or sets the web host environment. - /// - /// - /// The web host environment. - /// - public static IWebHostEnvironment WebHostEnvironment { get; set; } + + public static IConfigurationRoot Configuration{ get; set; } + + public static IWebHostEnvironment WebHostEnvironment{ get; set; } #endregion #region Methods - /// - /// Adds the or update connection string. - /// - /// The name. - /// The connection string. public static void AddOrUpdateConnectionString(String name, - String connectionString) - { - try - { + String connectionString){ + try{ Configuration configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConnectionStringSettingsCollection settings = configFile.ConnectionStrings.ConnectionStrings; - if (settings[name] == null) - { + if (settings[name] == null){ settings.Add(new ConnectionStringSettings(name, connectionString)); } - else - { + else{ settings[name].ConnectionString = connectionString; } configFile.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name); } - catch(ConfigurationErrorsException) - { + catch(ConfigurationErrorsException){ Console.WriteLine("Error writing connection string"); } } - /// - /// Configures the specified application. - /// - /// The application. - /// The env. public void Configure(IApplicationBuilder app, - IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { + IWebHostEnvironment env){ + if (env.IsDevelopment()){ app.UseDeveloperExceptionPage(); } - else - { + else{ app.UseExceptionHandler("/Error"); } @@ -137,57 +91,23 @@ public void Configure(IApplicationBuilder app, app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); }); } - /// - /// Configures the services. - /// - /// The services. - public void ConfigureServices(IServiceCollection services) - { - services.AddSingleton>(container => type => - { - (String name, IBootstrapper instance) bootstrapper = - this.JobBootstrappers.SingleOrDefault(b => b.name == $"{type}Bootstrapper"); - return bootstrapper.instance; - }); - + public void ConfigureServices(IServiceCollection services){ services.AddRazorPages(); - this.RegisterJobBootstrappers(); this.RegisterJobs(services); IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler().Result; - - services.AddSilkierQuartz(s => - { - s.VirtualPathRoot = "/quartz"; - s.UseLocalTime = true; - s.DefaultDateFormat = "yyyy-MM-dd"; - s.DefaultTimeFormat = "HH:mm:ss"; - s.Scheduler = scheduler; - }, - a => { a.AccessRequirement = SilkierQuartzAuthenticationOptions.SimpleAccessRequirement.AllowAnonymous; }); - } - - /// - /// Registers the job bootstrappers. - /// - private void RegisterJobBootstrappers() - { - IEnumerable jobs = typeof(IBootstrapper).GetTypeInfo().Assembly.DefinedTypes - .Where(t => typeof(IBootstrapper).GetTypeInfo().IsAssignableFrom(t.AsType()) && t.IsClass && - t.IsAbstract == false).Select(p => p.AsType()); - foreach (Type job in jobs) - { - Object instance = Activator.CreateInstance(job); - this.JobBootstrappers.Add((job.Name, (IBootstrapper)instance)); - } + services.AddSilkierQuartz(s => { + s.VirtualPathRoot = "/quartz"; + s.UseLocalTime = true; + s.DefaultDateFormat = "yyyy-MM-dd"; + s.DefaultTimeFormat = "HH:mm:ss"; + s.Scheduler = scheduler; + }, + a => { a.AccessRequirement = SilkierQuartzAuthenticationOptions.SimpleAccessRequirement.AllowAnonymous; }); } - - /// - /// Registers the jobs. - /// - /// The services. + private void RegisterJobs(IServiceCollection services) { Type type = typeof(IJob);