I am using the following line of code to add a file to a Vault.
It is run in a loop as the tool handles potentially hundreds of thousands of files.
using (Stream sr = new FileStream(fpath, FileMode.Open, FileAccess.Read))
{
fileIteration = Conn.FileManager.AddFile(fldr, Path.GetFileName(fpath), "Added by Vault Migration", DateTime.Now, assocs, null, FileClassification.None, false, sr);
}
Most of the time this works fine but every now and then the vault or server is busy and this call throws an exception (which is caught and logged).
Is there a better way to retry the AddFile call than trying to do so in the catch clause?
I currently use
try
{
AddFileToFolder(fpath, fldr);
}
catch(Exception ex)
{
if (ExceptionAllowsRetry(ex))
{
try
{
AddFileToFolder(fpath, fldr);
}
catch (Exception ex2)
{
AddToLog($"File {fpath} could not be added to the Vault ({ex.Message} - {ex2.Message})")
}
}
}
This works some of the time, but not always, and it puts a heavy load on the vault server as files are added as quickly as possible. Not to mention the code looks clunky.
I wonder if there is a better way to wrap the AddFile() call in such a way that it does not put such a heavy load on the server, and can more gracefully deal with the inevitable conflicts that arise when adding terabytes of data to a vault.