11using System ;
2+ using SimpleResults ;
23using TransactionProcessing . SchedulerService . DataGenerator ;
34using TransactionProcessor . DataTransferObjects . Responses . Contract ;
45using TransactionProcessor . DataTransferObjects . Responses . Merchant ;
@@ -66,7 +67,7 @@ static async Task Main(string[] args){
6667 Guid estateId = Guid . Parse ( "435613ac-a468-47a3-ac4f-649d89764c22" ) ;
6768
6869 // Get a token to talk to the estate service
69- CancellationToken cancellationToken = new CancellationToken ( ) ;
70+ CancellationToken cancellationToken = new ( ) ;
7071 String clientId = "serviceClient" ;
7172 String clientSecret = "d192cbc46d834d0da90e8a9d50ded543" ;
7273 ITransactionDataGeneratorService g = new TransactionDataGeneratorService ( Program . SecurityServiceClient ,
@@ -97,14 +98,25 @@ private static async Task GenerateStatements(ITransactionDataGeneratorService g,
9798
9899 private static async Task GenerateTransactions ( ITransactionDataGeneratorService g , Guid estateId , CancellationToken cancellationToken ) {
99100 // Set the date range
100- DateTime startDate = new DateTime ( 2025 , 3 , 1 ) ; //27/7
101- DateTime endDate = new DateTime ( 2025 , 3 , 2 ) ; // This is the date of the last generated transaction
102-
103- List < DateTime > dateRange = g . GenerateDateRange ( startDate , endDate ) ;
104- List < ContractResponse > allContracts = await g . GetEstateContracts ( estateId , cancellationToken ) ;
105- List < MerchantResponse > merchants = await g . GetMerchants ( estateId , cancellationToken ) ;
106-
107- Dictionary < ( String , String ) , Decimal > floatDeposits = new Dictionary < ( String , String ) , Decimal > {
101+ DateTime startDate = new DateTime ( 2025 , 4 , 14 ) ; //27/7
102+ DateTime endDate = new DateTime ( 2025 , 4 , 30 ) ; // This is the date of the last generated transaction
103+
104+ Result < List < DateTime > > dateRangeResult = g . GenerateDateRange ( startDate , endDate ) ;
105+ if ( dateRangeResult . IsFailed )
106+ {
107+ Console . WriteLine ( $ "Failed to generate date range: { dateRangeResult . Message } ") ;
108+ return ;
109+ }
110+ var allContractsResult = await g . GetEstateContracts ( estateId , cancellationToken ) ;
111+ if ( allContractsResult . IsFailed ) {
112+ Console . WriteLine ( $ "Failed to get estate contracts: { allContractsResult . Message } ") ;
113+ }
114+ var merchantsResult = await g . GetMerchants ( estateId , cancellationToken ) ;
115+ if ( merchantsResult . IsFailed )
116+ {
117+ Console . WriteLine ( $ "Failed to get merchants: { merchantsResult . Message } ") ;
118+ }
119+ Dictionary < ( String , String ) , Decimal > floatDeposits = new ( ) {
108120 { ( "Healthcare Centre 1 Contract" , "10 KES Voucher" ) , 1400 } ,
109121 { ( "Healthcare Centre 1 Contract" , "Custom" ) , 27000 } ,
110122 { ( "Safaricom Contract" , "100 KES Topup" ) , 14000 } ,
@@ -133,14 +145,14 @@ private static async Task GenerateTransactions(ITransactionDataGeneratorService
133145 // Settlement
134146 DataToSend dataToSend = DataToSend . Settlement ;
135147
136- foreach ( DateTime dateTime in dateRange ) {
148+ foreach ( DateTime dateTime in dateRangeResult . Data ) {
137149
138150 if ( ( dataToSend & DataToSend . FloatDeposits ) == DataToSend . FloatDeposits )
139151 {
140- foreach ( ContractResponse contractResponse in allContracts ) {
152+ foreach ( ContractResponse contractResponse in allContractsResult . Data ) {
141153 foreach ( ContractProduct contractResponseProduct in contractResponse . Products ) {
142154 // Lookup the deposit amount here
143- var depositAmount = floatDeposits . SingleOrDefault ( f =>
155+ KeyValuePair < ( String , String ) , Decimal > depositAmount = floatDeposits . SingleOrDefault ( f =>
144156 f . Key . Item1 == contractResponse . Description &&
145157 f . Key . Item2 == contractResponseProduct . Name ) ;
146158
@@ -151,7 +163,7 @@ await g.MakeFloatDeposit(dateTime, estateId, contractResponse.ContractId,
151163 }
152164
153165 if ( ( dataToSend & DataToSend . Logons ) == DataToSend . Logons ) {
154- foreach ( MerchantResponse merchant in merchants ) {
166+ foreach ( MerchantResponse merchant in merchantsResult . Data ) {
155167
156168 // Send a logon transaction
157169 await g . PerformMerchantLogon ( dateTime , merchant , cancellationToken ) ;
@@ -160,7 +172,7 @@ await g.MakeFloatDeposit(dateTime, estateId, contractResponse.ContractId,
160172
161173 if ( ( dataToSend & DataToSend . Sales ) == DataToSend . Sales )
162174 {
163- foreach ( MerchantResponse merchant in merchants ) {
175+ foreach ( MerchantResponse merchant in merchantsResult . Data ) {
164176 // Get the merchants contracts
165177 List < ContractResponse > contracts = await g . GetMerchantContracts ( merchant , cancellationToken ) ;
166178 foreach ( ContractResponse contract in contracts ) {
@@ -173,7 +185,7 @@ await g.MakeFloatDeposit(dateTime, estateId, contractResponse.ContractId,
173185 }
174186
175187 if ( ( dataToSend & DataToSend . Files ) == DataToSend . Files ) {
176- foreach ( MerchantResponse merchant in merchants ) {
188+ foreach ( MerchantResponse merchant in merchantsResult . Data ) {
177189 // Get the merchants contracts
178190 List < ContractResponse > contracts = await g . GetMerchantContracts ( merchant , cancellationToken ) ;
179191
0 commit comments