BudgetAnalyser.Engine.Statement.AnzAccountStatementImporterV1.LoadAsync C# (CSharp) Method

LoadAsync() public method

Load the given file into a StatementModel.
public LoadAsync ( string fileName, Account account ) : Task
fileName string The file to load.
account BudgetAnalyser.Engine.BankAccount.Account /// The account to classify these transactions. This is useful when merging one statement to another. For example, /// merging a cheque account export with visa account export, each can be classified using an account. ///
return Task
        public async Task<StatementModel> LoadAsync(string fileName, Account account)
        {
            try
            {
                this.importUtilities.AbortIfFileDoesntExist(fileName);
            }
            catch (FileNotFoundException ex)
            {
                throw new KeyNotFoundException(ex.Message, ex);
            }

            var transactions = new List<Transaction>();
            var firstTime = true;
            foreach (var line in await ReadLinesAsync(fileName))
            {
                if (firstTime)
                {
                    // File contains column headers
                    firstTime = false;
                    continue;
                }

                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                string[] split = line.Split(',');
                var transaction = new Transaction
                {
                    Account = account,
                    Description = this.importUtilities.FetchString(split, DescriptionIndex),
                    Reference1 = this.importUtilities.FetchString(split, Reference1Index),
                    Reference2 = this.importUtilities.FetchString(split, Reference2Index),
                    Reference3 = this.importUtilities.FetchString(split, Reference3Index),
                    Amount = this.importUtilities.FetchDecimal(split, AmountIndex),
                    Date = this.importUtilities.FetchDate(split, DateIndex)
                };
                transaction.TransactionType = FetchTransactionType(split, transaction.Amount);
                transactions.Add(transaction);
            }

            var statement = new StatementModel(this.logger)
            {
                StorageKey = fileName,
                LastImport = DateTime.Now
            }.LoadTransactions(transactions);

            return statement;
        }