Cinchoo / ChoETL.NACHA

A NACHA library for .NET / c#
MIT License
36 stars 32 forks source link

safely overriding file header fields #42

Closed ok10d closed 3 years ago

ok10d commented 3 years ago

Hi I have seen below code in your test project to override header values

 ChoActivator.Factory = (t, args) =>
            {
                if (t == typeof(ChoNACHAFileHeaderRecord))
                {
                    var header = new ChoNACHAFileHeaderRecord();
                    header.Initialize();

                    //Overrride any values here...
                    header.FileCreationDate = DateTime.Today.AddDays(100);
                    return header;
                }
                return null;
            };

If multiple files are being written with separate ChoNACHAWriters (separate ChoNACHAConfigurations) concurrently, sometimes generated files has wrong filecreationdates. One file had another files FileCreationDate. What do you think?

Cinchoo commented 3 years ago

Putting lock around this block preventing the issue??

ok10d commented 3 years ago

I did not try but it seems not. It is rarely happening, difficult to test. I see that ChoActivator's Factory is static and it seems that this should be set globally. I was attempting to set header.FileCreationDate with a local value which caused the issue.

Cinchoo commented 3 years ago

Put a lock around it in base library. Released new package v1.2.1.10