|
|
@@ -306,7 +306,7 @@ namespace BulkPrintingAPI.Controllers
|
|
306
|
306
|
}
|
|
307
|
307
|
|
|
308
|
308
|
public static async Task DownloadVouchersAsync(FTPOptions ftpOptions, MAXContext context,
|
|
309
|
|
- Batch batch)
|
|
|
309
|
+ ILogger logger, Batch batch)
|
|
310
|
310
|
{
|
|
311
|
311
|
var remoteFileName = string.Format("{0}_{1}.dat", batch.Account.Id, batch.Id);
|
|
312
|
312
|
using (var voucherStream = new MemoryStream())
|
|
|
@@ -324,34 +324,43 @@ namespace BulkPrintingAPI.Controllers
|
|
324
|
324
|
{
|
|
325
|
325
|
await downloadStream.CopyToAsync(voucherStream).ConfigureAwait(false);
|
|
326
|
326
|
}
|
|
327
|
|
- }
|
|
328
|
327
|
|
|
329
|
|
- voucherStream.Position = 0;
|
|
330
|
|
- using (var streamReader = new StreamReader(voucherStream))
|
|
331
|
|
- {
|
|
332
|
|
- while (streamReader.Peek() >= 0)
|
|
|
328
|
+ voucherStream.Position = 0;
|
|
|
329
|
+ using (var streamReader = new StreamReader(voucherStream))
|
|
333
|
330
|
{
|
|
334
|
|
- var line = streamReader.ReadLine();
|
|
335
|
|
- var parts = line.Split('|');
|
|
|
331
|
+ while (streamReader.Peek() >= 0)
|
|
|
332
|
+ {
|
|
|
333
|
+ var line = streamReader.ReadLine();
|
|
|
334
|
+ var parts = line.Split('|');
|
|
336
|
335
|
|
|
337
|
|
- VoucherSanityCheck(batch, decimal.Parse(parts[4]), int.Parse(parts[5]),
|
|
338
|
|
- parts[7]);
|
|
|
336
|
+ VoucherSanityCheck(batch, decimal.Parse(parts[4]), int.Parse(parts[5]),
|
|
|
337
|
+ parts[7]);
|
|
339
|
338
|
|
|
340
|
|
- context.Add(new Voucher()
|
|
341
|
|
- {
|
|
342
|
|
- Id = int.Parse(parts[0]),
|
|
343
|
|
- ExpiryDate = DateTime.Parse(parts[1]),
|
|
344
|
|
- Serial = parts[2],
|
|
345
|
|
- EncryptedPIN = parts[3],
|
|
346
|
|
- SequenceNumber = int.Parse(parts[6]),
|
|
347
|
|
- Batch = batch
|
|
348
|
|
- });
|
|
|
339
|
+ context.Add(new Voucher()
|
|
|
340
|
+ {
|
|
|
341
|
+ Id = int.Parse(parts[0]),
|
|
|
342
|
+ ExpiryDate = DateTime.Parse(parts[1]),
|
|
|
343
|
+ Serial = parts[2],
|
|
|
344
|
+ EncryptedPIN = parts[3],
|
|
|
345
|
+ SequenceNumber = int.Parse(parts[6]),
|
|
|
346
|
+ Batch = batch
|
|
|
347
|
+ });
|
|
|
348
|
+ }
|
|
|
349
|
+ }
|
|
|
350
|
+
|
|
|
351
|
+ batch.ReadyForDownload = true;
|
|
|
352
|
+ await context.SaveChangesAsync().ConfigureAwait(false);
|
|
|
353
|
+
|
|
|
354
|
+ try
|
|
|
355
|
+ {
|
|
|
356
|
+ await ftp.DeleteFileAsync(remoteFileName).ConfigureAwait(false);
|
|
|
357
|
+ }
|
|
|
358
|
+ catch (Exception e)
|
|
|
359
|
+ {
|
|
|
360
|
+ logger.LogWarning("Failed to delete file on FTP server: {0}: {1}", remoteFileName, e.Message);
|
|
349
|
361
|
}
|
|
350
|
362
|
}
|
|
351
|
363
|
}
|
|
352
|
|
-
|
|
353
|
|
- batch.ReadyForDownload = true;
|
|
354
|
|
- await context.SaveChangesAsync().ConfigureAwait(false);
|
|
355
|
364
|
}
|
|
356
|
365
|
}
|
|
357
|
366
|
}
|