Essentially I have two different flat files Credit & Account with different record structures. I have created separate entities for their Header, Detail and Footer records and for the whole file.
File Account:
namespace Data.Entities
{
[FlatFileContainerRecord(RecordLength = 100)]
public class AccountFlatFile
{
public AccountHeader Header { get; set; }
public List<Data.Entities.AccountDetail> Details { get; set; }
public AccountFooter Control { get; set; }
public AccountFlatFile()
{
Details = new List<AccountDetail>();
}
File Credit:
namespace Data.Entities
{
[FlatFileContainerRecord(RecordLength = 90)]
public class CreditFlatFile
{
public CreditHeader Header { get; set; }
public List<Data.Entities.CreditDetail> Details { get; set; }
public CreditFooter Control { get; set; }
public CreditFlatFile()
{
Details = new List<CreditDetail>();
}
}
I created a generic job to execute the files. This is where I am stuck.
foreach (string file in incomingFile)
{
GenericFile<T> genericFile = new GenericFile<T>();
using (Stream stream = File.OpenRead(file))
{
**genericFile = serializer.Deserialize<GenericFile<T>>(stream);**
}
if (genericFile.Details.Count > 0)
{
System.Threading.Tasks.Parallel.For(0, genericFile.Details.Count, parallelOptions, index =>
{
Repo.Upsert(genericFile.Details[index]);
});
}
else
{
//log error
}
}
I am not sure how exactly the GenericFile class should look like and how it would relate to the actual entity classes.
Hope I am clear with the question. Any suggestion is appreciated
Finally this is the generic structure I got.
I removed the Account and Credit flatfile entities and now have only the detailrecord entities for those two.