Add initial DTO classes and parser skeleton
This commit is contained in:
83
PriorBankParser/Parser.cs
Normal file
83
PriorBankParser/Parser.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using CsvHelper;
|
||||
using CsvHelper.Configuration;
|
||||
|
||||
namespace PriorBankParser
|
||||
{
|
||||
public class SectionParser
|
||||
{
|
||||
public enum SectionType
|
||||
{
|
||||
AccountInfo,
|
||||
StatementDetails,
|
||||
ContractOperations,
|
||||
ContractLocked,
|
||||
ContractTotal,
|
||||
StatementTotal
|
||||
}
|
||||
|
||||
public SectionParseResultDto Parse(string filePath)
|
||||
{
|
||||
var result = new SectionParseResultDto();
|
||||
var transactions = new List<TransactionInfoDto>();
|
||||
result.Transactions = transactions;
|
||||
|
||||
using var reader = new StreamReader(filePath);
|
||||
using var csv = new CsvReader(reader, CultureInfo.InvariantCulture);
|
||||
csv.Configuration.HasHeaderRecord = false;
|
||||
csv.Configuration.RegisterClassMap<TransactionInfoDtoMap>();
|
||||
//csv.Configuration.
|
||||
|
||||
var currentSection = SectionType.AccountInfo;
|
||||
var contractName = string.Empty;
|
||||
|
||||
while (csv.Read())
|
||||
{
|
||||
var field = csv.GetField(0);
|
||||
if (field.Equals(Constants.SectionNames.OperationSectionPrefix))
|
||||
{
|
||||
currentSection = SectionType.StatementTotal;
|
||||
contractName = field.Replace(Constants.SectionNames.OperationSectionPrefix, string.Empty);
|
||||
continue;
|
||||
}
|
||||
|
||||
//switch (currentSection)
|
||||
//{
|
||||
// case "FooId":
|
||||
// fooRecords.Add(csv.GetRecord<Foo>());
|
||||
// break;
|
||||
// case "BarId":
|
||||
// barRecords.Add(csv.GetRecord<Bar>());
|
||||
// break;
|
||||
// default:
|
||||
// throw new InvalidOperationException("Unknown record type.");
|
||||
//}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public sealed class TransactionInfoDtoMap : ClassMap<TransactionInfoDto>
|
||||
{
|
||||
public TransactionInfoDtoMap()
|
||||
{
|
||||
Map(m => m.TransactionDate).Name("Дата транзакции");
|
||||
Map(m => m.OperationName).Name("Операция");
|
||||
Map(m => m.Amount).Name("Сумма");
|
||||
Map(m => m.Currency).Name("Валюта");
|
||||
Map(m => m.OperationDate).Name("Дата операции по счету");
|
||||
Map(m => m.Commission).Name("Комиссия/Money-back");
|
||||
Map(m => m.AccountTurnover).Name("Обороты по счету");
|
||||
Map(m => m.DigitalCard).Name("Цифровая карта");
|
||||
Map(m => m.OperationCategory).Name("Категория операции");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user