Additional tests to make sure watch folder uploads file which is not actively written

This commit is contained in:
Jaex 2017-10-08 03:49:55 +03:00
parent 50495242c4
commit 7fc5c51596
2 changed files with 37 additions and 2 deletions

View file

@ -828,6 +828,19 @@ public static bool IsFileLocked(string path)
return false;
}
public static long GetFileSize(string path)
{
try
{
return new FileInfo(path).Length;
}
catch
{
}
return -1;
}
public static void CreateDirectoryFromDirectoryPath(string path)
{
if (!string.IsNullOrEmpty(path) && !Directory.Exists(path))

View file

@ -86,8 +86,30 @@ private void fileWatcher_Created(object sender, FileSystemEventArgs e)
timers.Add(new WatchFolderDuplicateEventTimer(path));
Action onCompleted = () => context.Post(state => OnFileWatcherTrigger(path), null);
Helpers.WaitWhileAsync(() => Helpers.IsFileLocked(path), 250, 5000, onCompleted, 1000);
int successCount = 0;
long previousSize = -1;
Helpers.WaitWhileAsync(() =>
{
if (!Helpers.IsFileLocked(path))
{
long currentSize = Helpers.GetFileSize(path);
if (currentSize > 0 && currentSize == previousSize)
{
successCount++;
}
previousSize = currentSize;
return successCount < 4;
}
previousSize = -1;
return true;
}, 250, 5000, () =>
{
context.Post(state => OnFileWatcherTrigger(path), null);
}, 1000);
}
protected void CleanElapsedTimers()