From 46e540fe4e7691509a9b7f9033a7e94312dcaa2d Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Mon, 23 Dec 2019 13:27:08 +0100 Subject: [PATCH] Work on Upload (finally) --- Site/Pages/v5/Ledgers/EndOfMonth.aspx | 1 + Site/Pages/v5/Ledgers/EndOfMonth.aspx.cs | 33 ++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Site/Pages/v5/Ledgers/EndOfMonth.aspx b/Site/Pages/v5/Ledgers/EndOfMonth.aspx index 8d23cac1..eff5eed8 100644 --- a/Site/Pages/v5/Ledgers/EndOfMonth.aspx +++ b/Site/Pages/v5/Ledgers/EndOfMonth.aspx @@ -323,6 +323,7 @@ activeUpload = null; } else { + alert(result.DisplayMessage); // temporary debug function // Todo: add more error handling later, maybe clientFailedUpload(); } diff --git a/Site/Pages/v5/Ledgers/EndOfMonth.aspx.cs b/Site/Pages/v5/Ledgers/EndOfMonth.aspx.cs index 2e2a9443..79aab04c 100644 --- a/Site/Pages/v5/Ledgers/EndOfMonth.aspx.cs +++ b/Site/Pages/v5/Ledgers/EndOfMonth.aspx.cs @@ -390,9 +390,38 @@ namespace Swarmops.Frontend.Pages.Ledgers Documents documents = Documents.RecentFromDescription(guid); - // Continue here + // Safeguard 2019-Dec-23: Abort if more than one document (code below needs hardening against concurrent-threads race conditions) - throw new NotImplementedException(); + if (documents.Count != 1) + { + throw new NotImplementedException(); + } + + // Load documents and process them as loaded strings, one by one + + foreach (Document document in documents) + { + string documentData = document.GetReader().ReadToEnd(); + ExternalBankDataProfile profile = account.ExternalBankDataProfile; + ExternalBankData loadedData = new ExternalBankData(); + loadedData.Profile = profile; + + try + { + loadedData.LoadData(documentData, authData.CurrentOrganization, account.Currency); + } + catch (Exception) + { + return new AjaxCallResult {Success = false, DisplayMessage = "ERROR_FILEDATAFORMAT"}; + } + + // Start async thread to import the data to the SQL database; the caller must + // check the status of the import + + // Continue here + } + + return new AjaxCallResult {Success = true, DisplayMessage = "SUCCESS_UPLOAD_PROCESSING"}; } [WebMethod]