从平面文件加载数据的通用实体

发布于 2024-12-13 11:07:27 字数 1713 浏览 0 评论 0 原文

本质上我有两个不同的平面文件 Credit &具有不同记录结构的帐户。我已经为它们的页眉、详细信息和页脚记录以及整个文件创建了单独的实体。

文件帐户:

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>();
 }

文件信用:

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>();
    }
}

我创建了一个通用作业来执行文件。这就是我被困住的地方。

 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
          }

 }

我不确定 GenericFile 类到底应该是什么样子以及它与实际实体类有何关系。

希望我能清楚地回答这个问题。任何建议表示赞赏

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云之铃。 2024-12-20 11:07:27

最后这是我得到的通用结构。

我删除了帐户和信用平面文件实体,现在只有这两个实体的详细记录实体。

namespace Data.Entities
{
   [FlatFileContainerRecord(RecordLength = 157)]
    public class FlatFile<FlatFileHeader, DT, FlatFileFooter> 
    {
       public FlatFileHeader Header { get; set; }
       public List<DT> Details { get; set; }
       public FlatFileFooter Control { get; set; }
       public FlatFile()
    {
        Details = new List<DT>();
    }
}

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.

namespace Data.Entities
{
   [FlatFileContainerRecord(RecordLength = 157)]
    public class FlatFile<FlatFileHeader, DT, FlatFileFooter> 
    {
       public FlatFileHeader Header { get; set; }
       public List<DT> Details { get; set; }
       public FlatFileFooter Control { get; set; }
       public FlatFile()
    {
        Details = new List<DT>();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文