diff --git a/TransactionProcessor.Aggregates/EstateAggregate.cs b/TransactionProcessor.Aggregates/EstateAggregate.cs index bb9adfea..b65414a1 100644 --- a/TransactionProcessor.Aggregates/EstateAggregate.cs +++ b/TransactionProcessor.Aggregates/EstateAggregate.cs @@ -128,7 +128,6 @@ public static void PlayEvent(this EstateAggregate aggregate, EstateDomainEvents. } public static void PlayEvent(this EstateAggregate aggregate, EstateDomainEvents.OperatorRemovedFromEstateEvent domainEvent){ - KeyValuePair @operator = aggregate.Operators.Single(o => o.Key == domainEvent.OperatorId); aggregate.Operators[domainEvent.OperatorId].IsDeleted = true; } diff --git a/TransactionProcessor.BusinessLogic/Services/SettlementDomainService.cs b/TransactionProcessor.BusinessLogic/Services/SettlementDomainService.cs index 392d1544..3723c86e 100644 --- a/TransactionProcessor.BusinessLogic/Services/SettlementDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/SettlementDomainService.cs @@ -46,7 +46,6 @@ public async Task> ProcessSettlement(SettlementCommands.ProcessSett return await PolicyFactory.ExecuteWithPolicyAsync(async () => { Guid settlementAggregateId = Helpers.CalculateSettlementAggregateId(command.SettlementDate, command.MerchantId, command.EstateId); - List<(Guid transactionId, Guid merchantId, CalculatedFee calculatedFee)> feesToBeSettled = new(); Result getSettlementResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(settlementAggregateId, ct), settlementAggregateId, cancellationToken, false); if (getSettlementResult.IsFailed) @@ -73,7 +72,7 @@ public async Task> ProcessSettlement(SettlementCommands.ProcessSett settlementSaveResult = await this.AggregateService.Save(settlementAggregate, cancellationToken); } - feesToBeSettled = settlementAggregate.GetFeesToBeSettled(); + List<(Guid transactionId, Guid merchantId, CalculatedFee calculatedFee)> feesToBeSettled = settlementAggregate.GetFeesToBeSettled(); if (feesToBeSettled.Any()) { // Record the process call @@ -189,7 +188,7 @@ public async Task AddSettledFeeToSettlement(SettlementCommands.AddSettle return ResultHelpers.CreateFailure(getMerchantResult); MerchantAggregate merchant = getMerchantResult.Data; - Result stateResult = Result.Failure(); + Result stateResult; if (merchant.SettlementSchedule == SettlementSchedule.Immediate) { stateResult = settlementAggregate.ImmediatelyMarkFeeAsSettled(command.MerchantId, command.TransactionId, command.FeeId); } diff --git a/TransactionProcessor.BusinessLogic/Services/TransactionValidationService.cs b/TransactionProcessor.BusinessLogic/Services/TransactionValidationService.cs index 2336d956..4360b394 100644 --- a/TransactionProcessor.BusinessLogic/Services/TransactionValidationService.cs +++ b/TransactionProcessor.BusinessLogic/Services/TransactionValidationService.cs @@ -74,7 +74,7 @@ public async Task> ValidateLogonTransaction( if (estateValidationResult.IsFailed) return CreateFailedResult(estateValidationResult.Data.validationResult); // Validate Merchant - var merchantValidationResult = await ValidateMerchant(estateId, estateValidationResult.Data.additionalData.EstateName, merchantId, cancellationToken); + var merchantValidationResult = await ValidateMerchant(estateValidationResult.Data.additionalData.EstateName, merchantId, cancellationToken); if (merchantValidationResult.IsFailed) return CreateFailedResult(merchantValidationResult.Data.validationResult); ; Models.Merchant.Merchant merchant = merchantValidationResult.Data.additionalData.GetMerchant(); @@ -99,7 +99,7 @@ public async Task> ValidateReconciliationTra EstateAggregate estate = estateValidationResult.Data.additionalData; // Validate Merchant - Result> merchantValidationResult = await ValidateMerchant(estateId, estate.EstateName, merchantId, cancellationToken); + Result> merchantValidationResult = await ValidateMerchant(estate.EstateName, merchantId, cancellationToken); if (merchantValidationResult.IsFailed) return CreateFailedResult(merchantValidationResult.Data.validationResult); ; var merchant = merchantValidationResult.Data.additionalData.GetMerchant(); @@ -134,7 +134,7 @@ public async Task> ValidateSaleTransaction(G if (estateOperatorValidationResult.IsFailed) return estateOperatorValidationResult; // Validate Merchant - Result> merchantValidationResult = await ValidateMerchant(estateId, estate.EstateName, merchantId, cancellationToken); + Result> merchantValidationResult = await ValidateMerchant(estate.EstateName, merchantId, cancellationToken); if (merchantValidationResult.IsFailed) return CreateFailedResult(merchantValidationResult.Data.validationResult); ; Models.Merchant.Merchant merchant = merchantValidationResult.Data.additionalData.GetMerchant(); @@ -148,7 +148,7 @@ public async Task> ValidateSaleTransaction(G if (merchantOperatorValidationResult.IsFailed) return merchantOperatorValidationResult; // Validate Contract and Product - Result contractProductValidationResult = await ValidateContractAndProduct(merchant, contractId, productId, cancellationToken); + Result contractProductValidationResult = ValidateContractAndProduct(merchant, contractId, productId); if (contractProductValidationResult.IsFailed) return contractProductValidationResult; // Validate Transaction Amount @@ -191,7 +191,7 @@ private Result ValidateEstateOperator(EstateAggrega return result; } - private async Task>> ValidateMerchant(Guid estateId, String estateName, Guid merchantId, CancellationToken cancellationToken) + private async Task>> ValidateMerchant(String estateName, Guid merchantId, CancellationToken cancellationToken) { Result getMerchantResult = await this.AggregateService.Get(merchantId, cancellationToken); if (getMerchantResult.IsFailed) @@ -257,7 +257,7 @@ private Result ValidateMerchantOperator(Models.Merc return result; } - private async Task> ValidateContractAndProduct(Models.Merchant.Merchant merchant, Guid contractId, Guid productId, CancellationToken cancellationToken) + private Result ValidateContractAndProduct(Models.Merchant.Merchant merchant, Guid contractId, Guid productId) { if (contractId == Guid.Empty) { diff --git a/TransactionProcessor.Client/TransactionProcessorClient.cs b/TransactionProcessor.Client/TransactionProcessorClient.cs index c4e8aed0..29f9b918 100644 --- a/TransactionProcessor.Client/TransactionProcessorClient.cs +++ b/TransactionProcessor.Client/TransactionProcessorClient.cs @@ -82,8 +82,6 @@ public async Task> GetEstate(String accessToken, public async Task CreateEstate(String accessToken, CreateEstateRequest createEstateRequest, CancellationToken cancellationToken) { - CreateEstateResponse response = null; - String requestUri = this.BuildRequestUrl("/api/estates/"); try { @@ -116,8 +114,6 @@ public async Task CreateEstate(String accessToken, public async Task>> GetEstates(String accessToken, Guid estateId, CancellationToken cancellationToken) { - List response = null; - String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/all"); try { @@ -143,8 +139,6 @@ public async Task>> GetEstates(String accessToken, throw exception; } - - return response; } public async Task CreateFloatForContractProduct(String accessToken, @@ -282,8 +276,6 @@ public async Task> GetVoucherByCode(String accessToke Guid estateId, String voucherCode, CancellationToken cancellationToken) { - GetVoucherResponse response = null; - String requestUri = this.BuildRequestUrl($"/api/vouchers?estateId={estateId}&voucherCode={voucherCode}"); try { @@ -316,8 +308,6 @@ public async Task> GetVoucherByTransactionId(String a Guid estateId, Guid transactionId, CancellationToken cancellationToken) { - GetVoucherResponse response = null; - String requestUri = this.BuildRequestUrl($"/api/vouchers?estateId={estateId}&transactionId={transactionId}"); try { @@ -453,8 +443,6 @@ public async Task RecordFloatCreditPurchase(String accessToken, public async Task> RedeemVoucher(String accessToken, RedeemVoucherRequest redeemVoucherRequest, CancellationToken cancellationToken) { - RedeemVoucherResponse response = null; - String requestUri = this.BuildRequestUrl($"/api/vouchers"); try { @@ -849,8 +837,6 @@ public async Task CreateContract(String accessToken, Guid estateId, CreateContractRequest createContractRequest, CancellationToken cancellationToken) { - CreateContractResponse response = null; - String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/contracts/"); try { @@ -884,8 +870,6 @@ public async Task CreateOperator(String accessToken, Guid estateId, CreateOperatorRequest createOperatorRequest, CancellationToken cancellationToken) { - CreateOperatorResponse response = null; - String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/operators"); try { @@ -953,8 +937,6 @@ public async Task CreateMerchant(String accessToken, Guid estateId, CreateMerchantRequest createMerchantRequest, CancellationToken cancellationToken) { - CreateMerchantResponse response = null; - String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/merchants"); try { @@ -1086,8 +1068,6 @@ public async Task> GetContract(String accessToken, Guid estateId, Guid contractId, CancellationToken cancellationToken) { - ContractResponse response = null; - String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/contracts/{contractId}"); try { @@ -1114,15 +1094,11 @@ public async Task> GetContract(String accessToken, throw exception; } - - return response; } public async Task>> GetContracts(String accessToken, Guid estateId, CancellationToken cancellationToken) { - List response = null; - String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/contracts"); try { @@ -1148,16 +1124,12 @@ public async Task>> GetContracts(String accessToke throw exception; } - - return response; } public async Task> GetMerchant(String accessToken, Guid estateId, Guid merchantId, CancellationToken cancellationToken) { - MerchantResponse response = null; - String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/merchants/{merchantId}"); try { @@ -1183,16 +1155,12 @@ public async Task> GetMerchant(String accessToken, throw exception; } - - return response; } public async Task>> GetMerchantContracts(String accessToken, Guid estateId, Guid merchantId, CancellationToken cancellationToken) { - List response = null; - String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/merchants/{merchantId}/contracts"); try { @@ -1218,15 +1186,11 @@ public async Task>> GetMerchantContracts(String ac throw exception; } - - return response; } public async Task>> GetMerchants(String accessToken, Guid estateId, CancellationToken cancellationToken) { - List response = null; - String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/merchants"); try { @@ -1252,8 +1216,6 @@ public async Task>> GetMerchants(String accessToke throw exception; } - - return response; } public async Task> GetSettlement(String accessToken, @@ -1261,8 +1223,6 @@ public async Task>> GetMerchants(String accessToke Guid? merchantId, Guid settlementId, CancellationToken cancellationToken) { - DataTransferObjects.Responses.Settlement.SettlementResponse response = null; - String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/settlements/{settlementId}?merchantId={merchantId}"); try { @@ -1288,8 +1248,6 @@ public async Task>> GetMerchants(String accessToke throw exception; } - - return response; } public async Task>> GetSettlements(String accessToken, @@ -1298,8 +1256,6 @@ public async Task>> GetMerchants(String accessToke String startDate, String endDate, CancellationToken cancellationToken) { - List response = null; - String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/settlements?merchantId={merchantId}&start_date={startDate}&end_date={endDate}"); try { @@ -1325,8 +1281,6 @@ public async Task>> GetMerchants(String accessToke throw exception; } - - return response; } public async Task>> GetTransactionFeesForProduct(String accessToken, @@ -1335,8 +1289,6 @@ public async Task>> GetTransactionFee Guid contractId, Guid productId, CancellationToken cancellationToken) { - List response = null; - String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/merchants/{merchantId}/contracts/{contractId}/products/{productId}/transactionFees"); try { @@ -1363,8 +1315,6 @@ public async Task>> GetTransactionFee throw exception; } - - return response; } public async Task MakeMerchantDeposit(String accessToken, @@ -1406,8 +1356,6 @@ public async Task MakeMerchantWithdrawal(String accessToken, Guid merchantId, MakeMerchantWithdrawalRequest makeMerchantWithdrawalRequest, CancellationToken cancellationToken) { - MakeMerchantWithdrawalResponse response = null; - String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/merchants/{merchantId}/withdrawals"); try { @@ -1442,8 +1390,6 @@ public async Task SetMerchantSettlementSchedule(String accessToken, Guid merchantId, SetSettlementScheduleRequest setSettlementScheduleRequest, CancellationToken cancellationToken) { - MakeMerchantDepositResponse response = null; - String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/merchants/{merchantId}"); try { @@ -1651,8 +1597,6 @@ public async Task> GetOperator(String accessToken, Guid estateId, Guid operatorId, CancellationToken cancellationToken) { - OperatorResponse response = null; - String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/operators/{operatorId}"); try { @@ -1678,15 +1622,11 @@ public async Task> GetOperator(String accessToken, throw exception; } - - return response; } public async Task>> GetOperators(String accessToken, Guid estateId, CancellationToken cancellationToken) { - List response = null; - String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/operators"); try { @@ -1712,7 +1652,5 @@ public async Task>> GetOperators(String accessToke throw exception; } - - return response; } } \ No newline at end of file diff --git a/TransactionProcessor.DataTransferObjects/MetadataContants.cs b/TransactionProcessor.DataTransferObjects/MetadataContants.cs index 3e9e1b20..26d397d1 100644 --- a/TransactionProcessor.DataTransferObjects/MetadataContants.cs +++ b/TransactionProcessor.DataTransferObjects/MetadataContants.cs @@ -7,7 +7,7 @@ /// /// [ExcludeFromCodeCoverage] - public class MetadataContants + public static class MetadataContants { #region Others diff --git a/TransactionProcessor.ProjectionEngine/Dispatchers/MerchantBalanceStateDispatcher.cs b/TransactionProcessor.ProjectionEngine/Dispatchers/MerchantBalanceStateDispatcher.cs index cb4d88b9..b12fb445 100644 --- a/TransactionProcessor.ProjectionEngine/Dispatchers/MerchantBalanceStateDispatcher.cs +++ b/TransactionProcessor.ProjectionEngine/Dispatchers/MerchantBalanceStateDispatcher.cs @@ -22,11 +22,11 @@ public async Task Dispatch(MerchantBalanceState state, MerchantBalanceChangedEntry entry = @event switch { MerchantDomainEvents.MerchantCreatedEvent e => this.CreateOpeningBalanceEntry(e), - MerchantDomainEvents.ManualDepositMadeEvent e => this.CreateManualDepositBalanceEntry(state, e), - MerchantDomainEvents.AutomaticDepositMadeEvent e => this.CreateAutomaticDepositBalanceEntry(state, e), - MerchantDomainEvents.WithdrawalMadeEvent e => this.CreateWithdrawalBalanceEntry(state, e), - TransactionDomainEvents.TransactionHasBeenCompletedEvent e => this.CreateTransactionBalanceEntry(state, e), - TransactionDomainEvents.SettledMerchantFeeAddedToTransactionEvent e => this.CreateTransactionFeeBalanceEntry(state, e), + MerchantDomainEvents.ManualDepositMadeEvent e => this.CreateManualDepositBalanceEntry(e), + MerchantDomainEvents.AutomaticDepositMadeEvent e => this.CreateAutomaticDepositBalanceEntry(e), + MerchantDomainEvents.WithdrawalMadeEvent e => this.CreateWithdrawalBalanceEntry(e), + TransactionDomainEvents.TransactionHasBeenCompletedEvent e => this.CreateTransactionBalanceEntry(e), + TransactionDomainEvents.SettledMerchantFeeAddedToTransactionEvent e => this.CreateTransactionFeeBalanceEntry(e), _ => null }; @@ -38,8 +38,7 @@ public async Task Dispatch(MerchantBalanceState state, return await this.TransactionProcessorReadRepository.AddMerchantBalanceChangedEntry(entry, cancellationToken); } - private MerchantBalanceChangedEntry CreateTransactionFeeBalanceEntry(MerchantBalanceState state, - TransactionDomainEvents.SettledMerchantFeeAddedToTransactionEvent @event) => + private MerchantBalanceChangedEntry CreateTransactionFeeBalanceEntry(TransactionDomainEvents.SettledMerchantFeeAddedToTransactionEvent @event) => new MerchantBalanceChangedEntry { MerchantId = @event.MerchantId, EstateId = @event.EstateId, @@ -51,8 +50,7 @@ private MerchantBalanceChangedEntry CreateTransactionFeeBalanceEntry(MerchantBal DebitOrCredit = "C" }; - private MerchantBalanceChangedEntry CreateWithdrawalBalanceEntry(MerchantBalanceState state, - MerchantDomainEvents.WithdrawalMadeEvent @event) => + private MerchantBalanceChangedEntry CreateWithdrawalBalanceEntry(MerchantDomainEvents.WithdrawalMadeEvent @event) => new MerchantBalanceChangedEntry { MerchantId = @event.MerchantId, EstateId = @event.EstateId, @@ -64,7 +62,7 @@ private MerchantBalanceChangedEntry CreateWithdrawalBalanceEntry(MerchantBalance DebitOrCredit = "D" }; - private MerchantBalanceChangedEntry CreateTransactionBalanceEntry(MerchantBalanceState state, TransactionDomainEvents.TransactionHasBeenCompletedEvent @event) { + private MerchantBalanceChangedEntry CreateTransactionBalanceEntry(TransactionDomainEvents.TransactionHasBeenCompletedEvent @event) { if (@event.IsAuthorised == false) return null; @@ -90,8 +88,7 @@ private MerchantBalanceChangedEntry CreateTransactionBalanceEntry(MerchantBalanc }; } - private MerchantBalanceChangedEntry CreateManualDepositBalanceEntry(MerchantBalanceState state, - MerchantDomainEvents.ManualDepositMadeEvent @event) => + private MerchantBalanceChangedEntry CreateManualDepositBalanceEntry(MerchantDomainEvents.ManualDepositMadeEvent @event) => new MerchantBalanceChangedEntry { MerchantId = @event.MerchantId, EstateId = @event.EstateId, @@ -103,8 +100,7 @@ private MerchantBalanceChangedEntry CreateManualDepositBalanceEntry(MerchantBala DebitOrCredit = "C" }; - private MerchantBalanceChangedEntry CreateAutomaticDepositBalanceEntry(MerchantBalanceState state, - MerchantDomainEvents.AutomaticDepositMadeEvent @event) => + private MerchantBalanceChangedEntry CreateAutomaticDepositBalanceEntry(MerchantDomainEvents.AutomaticDepositMadeEvent @event) => new MerchantBalanceChangedEntry { MerchantId = @event.MerchantId, EstateId = @event.EstateId, diff --git a/TransactionProcessor.Repository/ITransactionProcessorReadModelRepository.cs b/TransactionProcessor.Repository/ITransactionProcessorReadModelRepository.cs index b21c158f..336e71dc 100644 --- a/TransactionProcessor.Repository/ITransactionProcessorReadModelRepository.cs +++ b/TransactionProcessor.Repository/ITransactionProcessorReadModelRepository.cs @@ -745,7 +745,6 @@ public async Task>> GetMerchants(Guid estateId, { EstateManagementContext context = await this.GetContext(estateId); - Estate estate = await context.Estates.SingleOrDefaultAsync(e => e.EstateId == estateId, cancellationToken: cancellationToken); List merchants = await (from m in context.Merchants where m.EstateId == estateId select m).ToListAsync(cancellationToken); List merchantAddresses = await (from a in context.MerchantAddresses where merchants.Select(m => m.MerchantId).Contains(a.MerchantId) select a).ToListAsync(cancellationToken); List merchantContacts = await (from c in context.MerchantContacts where merchants.Select(m => m.MerchantId).Contains(c.MerchantId) select c).ToListAsync(cancellationToken); @@ -1406,7 +1405,6 @@ public async Task UpdateMerchant(TransactionDomainEvents.TransactionHasB public async Task UpdateReconciliationOverallTotals(ReconciliationDomainEvents.OverallTotalsRecordedEvent domainEvent, CancellationToken cancellationToken) { - Guid estateId = domainEvent.EstateId; EstateManagementContext context = await this.GetContext(domainEvent.EstateId); diff --git a/TransactionProcessor/Bootstrapper/OperatorRegistry.cs b/TransactionProcessor/Bootstrapper/OperatorRegistry.cs index 9249caa6..fa286f25 100644 --- a/TransactionProcessor/Bootstrapper/OperatorRegistry.cs +++ b/TransactionProcessor/Bootstrapper/OperatorRegistry.cs @@ -30,11 +30,9 @@ public class OperatorRegistry : ServiceRegistry /// public OperatorRegistry() { - IConfigurationSection section = Startup.Configuration.GetSection("AppSettings:OperatorConfiguration"); - - this.ConfigureOperator("Safaricom", section); - this.ConfigureOperator("PataPawaPostPay", section); - this.ConfigureOperator("PataPawaPrePay", section); + this.ConfigureOperator("Safaricom"); + this.ConfigureOperator("PataPawaPostPay"); + this.ConfigureOperator("PataPawaPrePay"); this.AddSingleton(new PataPawaPostPayServiceClient(PataPawaPostPayServiceClient.EndpointConfiguration.BasicHttpBinding_IPataPawaPostPayService)); this.For().Add().Named("Safaricom").Singleton(); @@ -60,7 +58,7 @@ public OperatorRegistry() }); } - private void ConfigureOperator(String operatorId, IConfigurationSection operatorConfigurationSection) where T : class { + private void ConfigureOperator(String operatorId) where T : class { T configObject = (T)Activator.CreateInstance(typeof(T)); Startup.Configuration.GetSection($"OperatorConfiguration:{operatorId}").Bind(configObject); diff --git a/TransactionProcessor/Bootstrapper/RepositoryRegistry.cs b/TransactionProcessor/Bootstrapper/RepositoryRegistry.cs index 81ef54a3..9b20ae06 100644 --- a/TransactionProcessor/Bootstrapper/RepositoryRegistry.cs +++ b/TransactionProcessor/Bootstrapper/RepositoryRegistry.cs @@ -137,8 +137,6 @@ public async Task GetConnectionString(String externalIdentifier, String connectionString = string.Empty; String databaseName = string.Empty; - String databaseEngine = ConfigurationReader.GetValue("AppSettings", "DatabaseEngine"); - databaseName = $"{connectionStringIdentifier}{externalIdentifier}"; connectionString = ConfigurationReader.GetConnectionString(connectionStringIdentifier); diff --git a/TransactionProcessor/Common/ClientMessageLoggingBehavior.cs b/TransactionProcessor/Common/ClientMessageLoggingBehavior.cs index 1ee8345a..cad19cdf 100644 --- a/TransactionProcessor/Common/ClientMessageLoggingBehavior.cs +++ b/TransactionProcessor/Common/ClientMessageLoggingBehavior.cs @@ -31,6 +31,7 @@ public ClientMessageLoggingBehavior(String clientName, RequestResponseMiddleware #region Methods public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters){ + // Not needed for client } public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime){ @@ -38,9 +39,11 @@ public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRu } public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher){ + // Not needed for client } public void Validate(ServiceEndpoint endpoint){ + // Not needed } #endregion diff --git a/TransactionProcessor/Controllers/ContractController.cs b/TransactionProcessor/Controllers/ContractController.cs index f1b11356..b30db4eb 100644 --- a/TransactionProcessor/Controllers/ContractController.cs +++ b/TransactionProcessor/Controllers/ContractController.cs @@ -241,7 +241,7 @@ public async Task CreateContract([FromRoute] Guid estateId, /// /// The controller name /// - public const string ControllerName = "contracts"; + private const string ControllerName = "contracts"; /// /// The controller route diff --git a/TransactionProcessor/Controllers/DomainEventController.cs b/TransactionProcessor/Controllers/DomainEventController.cs index deed3c9d..5eb94afe 100644 --- a/TransactionProcessor/Controllers/DomainEventController.cs +++ b/TransactionProcessor/Controllers/DomainEventController.cs @@ -179,7 +179,7 @@ private String ValidateEvent(String domainEventJson) /// /// The controller name /// - public const String ControllerName = "domainevents"; + private const String ControllerName = "domainevents"; /// /// The controller route diff --git a/TransactionProcessor/Controllers/EstateController.cs b/TransactionProcessor/Controllers/EstateController.cs index 8e2881ad..630a8f43 100644 --- a/TransactionProcessor/Controllers/EstateController.cs +++ b/TransactionProcessor/Controllers/EstateController.cs @@ -235,7 +235,7 @@ public async Task RemoveOperator([FromRoute] Guid estateId, /// /// The controller name /// - public const string ControllerName = "estates"; + private const string ControllerName = "estates"; /// /// The controller route diff --git a/TransactionProcessor/Controllers/FloatController.cs b/TransactionProcessor/Controllers/FloatController.cs index b910b420..ccb9cb3b 100644 --- a/TransactionProcessor/Controllers/FloatController.cs +++ b/TransactionProcessor/Controllers/FloatController.cs @@ -26,7 +26,7 @@ public class FloatController : ControllerBase /// /// The controller name /// - public const String ControllerName = "floats"; + private const String ControllerName = "floats"; /// /// The controller route diff --git a/TransactionProcessor/Controllers/MerchantController.cs b/TransactionProcessor/Controllers/MerchantController.cs index 12332e3f..c144c86f 100644 --- a/TransactionProcessor/Controllers/MerchantController.cs +++ b/TransactionProcessor/Controllers/MerchantController.cs @@ -47,7 +47,7 @@ public MerchantController(IMediator mediator) { /// /// The controller name /// - public const String ControllerName = "merchants"; + private const String ControllerName = "merchants"; /// /// The controller route diff --git a/TransactionProcessor/Controllers/OperatorController.cs b/TransactionProcessor/Controllers/OperatorController.cs index e40f50b7..460bf967 100644 --- a/TransactionProcessor/Controllers/OperatorController.cs +++ b/TransactionProcessor/Controllers/OperatorController.cs @@ -129,7 +129,7 @@ public async Task GetOperators([FromRoute] Guid estateId, /// /// The controller name /// - public const string ControllerName = "operators"; + private const string ControllerName = "operators"; /// /// The controller route diff --git a/TransactionProcessor/Controllers/SettlementController.cs b/TransactionProcessor/Controllers/SettlementController.cs index 19e4bccf..ff44d338 100644 --- a/TransactionProcessor/Controllers/SettlementController.cs +++ b/TransactionProcessor/Controllers/SettlementController.cs @@ -28,12 +28,12 @@ namespace TransactionProcessor.Controllers public class SettlementController : ControllerBase { private readonly IMediator Mediator; - #region Others + #region Others /// /// The controller name /// - public const String ControllerName = "settlements"; + private const String ControllerName = "settlements"; /// /// The controller route diff --git a/TransactionProcessor/Controllers/TransactionController.cs b/TransactionProcessor/Controllers/TransactionController.cs index 4aa1adff..57d7ee9c 100644 --- a/TransactionProcessor/Controllers/TransactionController.cs +++ b/TransactionProcessor/Controllers/TransactionController.cs @@ -213,7 +213,7 @@ private async Task> ProcessSpecificMessage(Reconciliat /// /// The controller name /// - public const String ControllerName = "transactions"; + private const String ControllerName = "transactions"; /// /// The controller route diff --git a/TransactionProcessor/Controllers/VoucherController.cs b/TransactionProcessor/Controllers/VoucherController.cs index ebbceb4b..4255d299 100644 --- a/TransactionProcessor/Controllers/VoucherController.cs +++ b/TransactionProcessor/Controllers/VoucherController.cs @@ -125,7 +125,7 @@ public async Task GetVoucher([FromQuery] Guid estateId, /// /// The controller name /// - public const String ControllerName = "vouchers"; + private const String ControllerName = "vouchers"; /// /// The controller route diff --git a/TransactionProcessor/Extensions.cs b/TransactionProcessor/Extensions.cs index 2f084e6b..0362382a 100644 --- a/TransactionProcessor/Extensions.cs +++ b/TransactionProcessor/Extensions.cs @@ -81,16 +81,9 @@ public static void PreWarm(this IApplicationBuilder applicationBuilder) { Func subscriptionRepositoryResolver = Startup.Container.GetInstance>(); - - String connectionString = Startup.Configuration.GetValue("EventStoreSettings:ConnectionString"); - EventStoreClientSettings eventStoreClientSettings = EventStoreClientSettings.Create(connectionString); - + applicationBuilder.ConfigureSubscriptionService(subscriptionWorkersRoot, eventStoreConnectionString, eventHandlerResolvers, Extensions.log, subscriptionRepositoryResolver).Wait(CancellationToken.None); - - // Setup the aggregate service caching - - IMediator mediator = Startup.Container.GetInstance(); StatementFilePollerService statementFilePollerService = new(mediator); statementFilePollerService.Start(); @@ -130,12 +123,12 @@ public void Start() { }; fileSystemWatcher.EnableRaisingEvents = fileProfile.IsEnabled; fileSystemWatcher.Created += (sender, - e) => FileHandler(sender, e, fileProfile); + e) => FileHandler(e, fileProfile); } } - private void FileHandler(object sender, FileSystemEventArgs e, FileProfile fileProfile) + private void FileHandler(FileSystemEventArgs e, FileProfile fileProfile) { // Fire-and-forget async work Task.Run(async () => @@ -143,13 +136,11 @@ private void FileHandler(object sender, FileSystemEventArgs e, FileProfile fileP String processedFolder = Path.Combine(fileProfile.ListeningDirectory, "processed"); String failedFolder = Path.Combine(fileProfile.ListeningDirectory, "failed"); - try - { + try { Logger.LogInformation($"File detected on profile {fileProfile.Name} File name [{e.Name}]"); // Make sure the file is not locked by another process - await using (FileStream stream = new FileStream(e.FullPath, FileMode.Open, FileAccess.Read, FileShare.None)) - { + await using (FileStream stream = new FileStream(e.FullPath, FileMode.Open, FileAccess.Read, FileShare.None)) { // Wait for the file to be released await Task.Delay(1000); } @@ -164,8 +155,8 @@ private void FileHandler(object sender, FileSystemEventArgs e, FileProfile fileP if (Guid.TryParse(parts[0], out Guid estateId) == false) { throw new ArgumentException("Invalid estate ID in file name", nameof(e.FullPath)); } - if (Guid.TryParse(parts[1], out Guid statementId) == false) - { + + if (Guid.TryParse(parts[1], out Guid statementId) == false) { throw new ArgumentException("Invalid statement ID in file name", nameof(e.FullPath)); } @@ -174,20 +165,19 @@ private void FileHandler(object sender, FileSystemEventArgs e, FileProfile fileP if (String.IsNullOrEmpty(pdfData)) { throw new InvalidDataException("PDF Data is null or Empty"); } + // Create the email statement command EmailMerchantStatementCommand command = new(estateId, statementId, pdfData); - + Result result = await this.Mediator.Send(command, CancellationToken.None); - if (result.IsFailed) - { + if (result.IsFailed) { // Move the file to the failed folder String failedFilePath = Path.Combine(failedFolder, e.Name); File.Move(e.FullPath, failedFilePath); // Log the error Logger.LogWarning($"Failed to process file [{e.FullPath}]: {result.Message}"); } - else - { + else { // Move the file to the processed folder String processedFilePath = Path.Combine(processedFolder, e.Name); File.Move(e.FullPath, processedFilePath); @@ -195,15 +185,14 @@ private void FileHandler(object sender, FileSystemEventArgs e, FileProfile fileP Logger.LogInformation($"Successfully processed file [{e.FullPath}]"); } } - catch (Exception ex) - { + catch (Exception ex) { // Log or handle exception // Move the file to the failed folder String failedFilePath = Path.Combine(failedFolder, e.Name); File.Move(e.FullPath, failedFilePath); // Log the error Console.Error.WriteLine($"Failed to process file [{e.FullPath}]: {ex.Message}"); - Logger.LogError($"Failed to process file [{e.FullPath}]",ex); + Logger.LogError($"Failed to process file [{e.FullPath}]", ex); } }); } diff --git a/TransactionProcessor/Startup.cs b/TransactionProcessor/Startup.cs index b739e92c..033debe3 100644 --- a/TransactionProcessor/Startup.cs +++ b/TransactionProcessor/Startup.cs @@ -146,7 +146,6 @@ public void Configure(IApplicationBuilder app, app.PreWarm(); - var _ = typeof(Microsoft.IdentityModel.Tokens.TokenValidationResult); // Force load var loadedTokensAssemblies = AppDomain.CurrentDomain .GetAssemblies() .Where(a => a.GetName().Name == "Microsoft.IdentityModel.Tokens")