LocalPathEnumerator
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Relativity.Transfer
{
[Obsolete("This enumeration support will be removed in next release. In order to perform file enumeration use EnumerationBuilder and IEnumerationOrchestrator")]
internal class LocalPathEnumerator : PathEnumeratorBase
{
public LocalPathEnumerator(IFileSystemService service, IPathValidationProvider pathValidator, ITransferLog log)
: base(log, pathValidator, service)
{
}
protected override Task<bool> OnCheckFileExistsAsync(string path, CancellationToken token)
{
return Task.Run(() => base.FileSystemService.FileExists(path), token);
}
protected override Task<bool> OnCheckFolderExistsAsync(string path, CancellationToken token)
{
return Task.Run(() => base.FileSystemService.DirectoryExists(path), token);
}
protected override Task<bool> OnCheckIsEmptyAsync(string path, CancellationToken token)
{
return Task.Run(() => base.FileSystemService.IsDirectoryEmpty(path), token);
}
protected override Task<IEnumerable<FileItem>> OnEnumerateFilesAsync(string path, PathEnumeratorContext context, CancellationToken token)
{
return Task.Run(delegate {
if (context.FileNames.Count == 0)
return base.FileSystemService.EnumerateFiles(path);
return context.FileNames.SelectMany((string x) => base.FileSystemService.EnumerateFiles(path, x));
}, token);
}
protected override Task<IEnumerable<FolderItem>> OnEnumerateFoldersAsync(string path, PathEnumeratorContext context, CancellationToken token)
{
return Task.Run(() => base.FileSystemService.EnumerateDirectories(path), token);
}
protected override Task<FileItem> OnGetFileItemAsync(string path, CancellationToken token)
{
return Task.Run(() => base.FileSystemService.GetFileItem(path), token);
}
protected override Task<FolderItem> OnGetFolderItemAsync(string path, CancellationToken token)
{
return Task.Run(() => base.FileSystemService.GetFolderItem(path), token);
}
protected override string GetLocalPath(string path)
{
if (base.FileSystemService.IsPathRooted(path))
try {
if (Uri.TryCreate(path, UriKind.RelativeOrAbsolute, out Uri result) && result.IsFile)
PathHelper.NormalizePath(ref path);
return path;
} catch (InvalidOperationException) {
return path;
}
return path;
}
}
}