VirtualPhotonics / VTS

Virtual Tissue Simulator
https://virtualphotonics.org
Other
34 stars 9 forks source link

Add resiliency to CustomBinaryStreamWriterOfT #84

Closed dcuccia closed 1 year ago

dcuccia commented 1 year ago

Currently, if the "results" folder is not written ahead of time, PhotonDatabaseWriter will throw an exception when attempting to write to a file within the specified folder. When consuming the Vts library, it is not obvious that this folder must exist before a simulation is run, and leads to exceptions that a consumer of the library should not have to debug/fix.

In order to fix this, add the following guard to the top of CustomBinaryStreamWriter<T>.OpenStream():

try
{
    // guard against directory not existing ahead of time
    var directory = Path.GetDirectoryName(_filename);
    if (!Directory.Exists(directory))
    {
        Directory.CreateDirectory(directory);
    }
    ...
}
dcuccia commented 1 year ago

Updated the design above ↑ to be at the level currently responsible for file creation, CustomBinaryStreamWriter<T>.OpenStream()