Skip to content

Commit 2198b2e

Browse files
Fix quick Codacy issues: performance improvement and best practice violations
Agent-Logs-Url: https://github.com/TransactionProcessing/SupportTools/sessions/7373b758-d29d-43de-a82d-3bc060d3ecb2 Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
1 parent bcad006 commit 2198b2e

5 files changed

Lines changed: 13 additions & 13 deletions

File tree

TransactionProcessing.MerchantFileProcessor/Clients/FileProcessingClient.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public async Task<Result<Guid>> Upload(MerchantOptions merchant,
4343
};
4444

4545
Result<Guid>? result = await fileProcessorClient.UploadFile(accessToken, file.FileName, file.Content, request, cancellationToken);
46-
//var result = Result.Success(Guid.NewGuid()); // TODO: Replace with actual file upload call
4746

4847
if (result.IsFailed) {
4948
return new Result<Guid> { IsSuccess = false, Status = ResultStatus.Failure, Message = $"File processor client failed to upload file '{file.FileName}'." };
@@ -71,7 +70,7 @@ public async Task<Result<FileProcessingStatusSnapshot>> GetFileStatus(string acc
7170
private static FileProcessingLineStatusSnapshot MapLineStatus(FileLine line) => new(line.LineNumber, line.LineData, line.ProcessingResult.ToString(), string.IsNullOrWhiteSpace(line.RejectionReason) ? null : line.RejectionReason, line.TransactionId == Guid.Empty ? null : line.TransactionId);
7271

7372
private static bool AreAllLinesResolved(IEnumerable<FileProcessingLineStatusSnapshot> lines) {
74-
Boolean hasLines = false;
73+
bool hasLines = false;
7574

7675
foreach (FileProcessingLineStatusSnapshot line in lines) {
7776
hasLines = true;

TransactionProcessing.MerchantFileProcessor/FileBuilding/DelimitedTransactionFileBuilder.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public GeneratedFile Build(MerchantOptions merchant,
1111
FileProfileOptions fileProfile,
1212
IReadOnlyList<GeneratedTransaction> transactions,
1313
DateTimeOffset processingTimestampUtc) {
14-
String delimiter = NormalizeDelimiter(fileProfile.Delimited.Delimiter);
15-
List<String> lines = new List<string>();
16-
Decimal fileTotalAmount = transactions.Sum(transaction => transaction.TotalAmount);
14+
string delimiter = NormalizeDelimiter(fileProfile.Delimited.Delimiter);
15+
List<string> lines = new List<string>();
16+
decimal fileTotalAmount = transactions.Sum(transaction => transaction.TotalAmount);
1717

1818
if (fileProfile.Delimited.HeaderFields.Count > 0) {
1919
TransactionFileContext headerContext = new TransactionFileContext(merchant, contract, null, processingTimestampUtc, transactions.Count, fileTotalAmount);
@@ -43,8 +43,8 @@ public GeneratedFile Build(MerchantOptions merchant,
4343

4444
private static string Escape(string value,
4545
string delimiter) {
46-
Boolean shouldQuote = value.Contains('"') || value.Contains('\r') || value.Contains('\n') || value.Contains(delimiter, StringComparison.Ordinal);
47-
String escapedValue = value.Replace("\"", "\"\"", StringComparison.Ordinal);
46+
bool shouldQuote = value.Contains('"') || value.Contains('\r') || value.Contains('\n') || value.Contains(delimiter, StringComparison.Ordinal);
47+
string escapedValue = value.Replace("\"", "\"\"", StringComparison.Ordinal);
4848

4949
return shouldQuote ? $"\"{escapedValue}\"" : escapedValue;
5050
}

TransactionProcessing.MerchantFileProcessor/FileBuilding/JsonTransactionFileBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public GeneratedFile Build(
1414
IReadOnlyList<GeneratedTransaction> transactions,
1515
DateTimeOffset processingTimestampUtc)
1616
{
17+
var fileTotalAmount = transactions.Sum(transaction => transaction.TotalAmount);
1718
var mappedRecords = transactions
1819
.Select(transaction =>
1920
{
@@ -23,7 +24,7 @@ public GeneratedFile Build(
2324
transaction,
2425
processingTimestampUtc,
2526
transactions.Count,
26-
transactions.Sum(candidate => candidate.TotalAmount));
27+
fileTotalAmount);
2728

2829
return fileProfile.Fields.ToDictionary(
2930
field => field.Name,

TransactionProcessing.MerchantFileProcessor/Reporting/FileStatusReportService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public async Task<string> RenderHtmlAsync(CancellationToken cancellationToken)
141141
var html = new StringBuilder();
142142

143143
AppendDocumentStart(html, "Merchant File Status");
144-
html.AppendLine($" <h1>Merchant File Status</h1>");
144+
html.AppendLine(" <h1>Merchant File Status</h1>");
145145
html.AppendLine($" <p>Generated at {Encode(report.GeneratedUtc.ToString("u"))}. Auto-refreshes every 30 seconds.</p>");
146146
html.AppendLine(" <h2>Merchants</h2>");
147147
html.AppendLine(" <table>");
@@ -171,7 +171,7 @@ public async Task<string> RenderHtmlAsync(CancellationToken cancellationToken)
171171

172172
var html = new StringBuilder();
173173
AppendDocumentStart(html, $"Merchant {report.Merchant.MerchantName} Details");
174-
html.AppendLine($" <p><a href=\"/status\">&larr; Back to merchants</a></p>");
174+
html.AppendLine(" <p><a href=\"/status\">&larr; Back to merchants</a></p>");
175175
html.AppendLine($" <h1>{Encode(report.Merchant.MerchantName)}</h1>");
176176
html.AppendLine($" <p class=\"mono\">{Encode(report.Merchant.MerchantId)}</p>");
177177
html.AppendLine($" <p>Generated at {Encode(report.GeneratedUtc.ToString("u"))}. Auto-refreshes every 30 seconds.</p>");
@@ -218,7 +218,7 @@ public async Task<string> RenderHtmlAsync(CancellationToken cancellationToken)
218218
var html = new StringBuilder();
219219
AppendDocumentStart(html, $"Merchant {report.Merchant.MerchantName} File {report.File.Id}");
220220
html.AppendLine($" <p><a href=\"/status/{Uri.EscapeDataString(report.Merchant.MerchantId)}\">&larr; Back to merchant</a></p>");
221-
html.AppendLine($" <h1>File Details</h1>");
221+
html.AppendLine(" <h1>File Details</h1>");
222222
html.AppendLine($" <p>Merchant {Encode(report.Merchant.MerchantName)}<br /><span class=\"mono\">{Encode(report.Merchant.MerchantId)}</span></p>");
223223
html.AppendLine(" <table>");
224224
html.AppendLine(" <thead><tr><th>Processed (UTC)</th><th>Contract</th><th>Upload Status</th><th>Processing</th><th>Profile</th><th>Format</th></tr></thead>");

TransactionProcessing.MerchantFileProcessor/Worker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ private async Task<ScheduledMerchant> GetNextRunUtcAsync(DateTimeOffset now,
7676
IReadOnlyList<TimeOnly> runTimes = merchant.GetDailyRunTimesUtc();
7777
DateOnly currentDate = DateOnly.FromDateTime(now.UtcDateTime);
7878

79-
for (Int32 dayOffset = 0; dayOffset <= 1; dayOffset++) {
79+
for (int dayOffset = 0; dayOffset <= 1; dayOffset++) {
8080
DateOnly candidateDate = currentDate.AddDays(dayOffset);
8181

8282
foreach (TimeOnly runTime in runTimes) {
8383
DateTimeOffset scheduledRunUtc = new DateTimeOffset(candidateDate.Year, candidateDate.Month, candidateDate.Day, runTime.Hour, runTime.Minute, runTime.Second, TimeSpan.Zero);
8484

8585
if (scheduledRunUtc <= now) {
86-
Boolean isComplete = await fileStatusStore.IsMerchantRunCompleteAsync(merchant, scheduledRunUtc, cancellationToken);
86+
bool isComplete = await fileStatusStore.IsMerchantRunCompleteAsync(merchant, scheduledRunUtc, cancellationToken);
8787
if (!isComplete) {
8888
LocalLogger.For(merchant.MerchantId).LogInformation($"Missed scheduled run at {scheduledRunUtc:O}. Scheduling an immediate catch-up run.");
8989
return new ScheduledMerchant(merchant, scheduledRunUtc, now);

0 commit comments

Comments
 (0)