Unicorn.TAF logo Unicorn.TAF

Overview

FileAllocator is a utility class that provides functionality to wait for and allocate files in a file system. It is particularly useful for scenarios involving file downloads or file system monitoring.

Namespace: Unicorn.Taf.Core.Utility

Behavior

Usage Examples

Example 1: Allocating a File with Unknown Name

string downloadFolder = @"C:\Downloads";
var allocator = new FileAllocator(downloadFolder);

// Optional: set expected name part for better filtering
allocator.ExpectedFileNamePart = "report";

// Optional: exclude temporary files
allocator.ExcludeFileNames(".tmp", ".crdownload");

TimeSpan timeout = TimeSpan.FromSeconds(30);
string allocatedFile = allocator.WaitForFileToAppear(timeout);

Console.WriteLine($"File allocated: {allocatedFile}");

Example 2: Waiting for a Specific File

string downloadFolder = @"C:\Downloads";
string expectedFile = "document.pdf";

var allocator = new FileAllocator(downloadFolder, expectedFile);

TimeSpan timeout = TimeSpan.FromSeconds(15);
string file = allocator.WaitForFileToAppear(timeout);

Console.WriteLine($"File found: {file}");