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

LoadAsync() public method

public LoadAsync ( string storageKey, bool isEncrypted ) : Task
storageKey string
isEncrypted bool
return Task
        public async Task<StatementModel> LoadAsync(string storageKey, bool isEncrypted)
        {
            if (storageKey.IsNothing())
            {
                throw new ArgumentNullException(nameof(storageKey));
            }

            try
            {
                this.importUtilities.AbortIfFileDoesntExist(storageKey);
            }
            catch (FileNotFoundException ex)
            {
                throw new KeyNotFoundException(ex.Message, ex);
            }

            if (!await IsStatementModelAsync(storageKey, isEncrypted))
            {
                throw new NotSupportedException("The CSV file is not supported by this version of the Budget Analyser.");
            }

            List<string> allLines = (await ReadLinesAsync(storageKey, isEncrypted)).ToList();
            var totalLines = allLines.LongCount();
            if (totalLines < 2)
            {
                return new StatementModel(this.logger) { StorageKey = storageKey }.LoadTransactions(new List<Transaction>());
            }

            List<TransactionDto> transactions = ReadTransactions(totalLines, allLines);
            var transactionSet = CreateTransactionSet(storageKey, allLines, transactions);

            ValidateChecksumIntegrity(transactionSet);

            return this.mapper.ToModel(transactionSet);
        }