AsperaUncPathResolver
using Relativity.Transfer.Aspera.Resources;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Relativity.Transfer.Aspera
{
public class AsperaUncPathResolver : RemotePathResolverBase
{
private readonly List<string> = new List<string>();
private string ;
private int pathComponentsToRemove;
public int DocRootLevels { get; set; }
public string {
get {
return fileShareUncPath;
}
set {
if (!string.IsNullOrEmpty(value))
value = RemotePathResolverBase.FileSystemService.TrimTrailingSlash(value);
fileShareUncPath = value;
fileShareUncPathSplit.Clear();
pathComponentsToRemove = 0;
}
}
public AsperaUncPathResolver(ITransferLog transferLog)
: this(null, 0, transferLog)
{
}
public AsperaUncPathResolver(string fileShareUncPath, int docRootLevels, ITransferLog transferLog)
: base(transferLog)
{
FileShareUncPath = fileShareUncPath;
DocRootLevels = docRootLevels;
}
protected override string OnResolvePath(string path)
{
if (string.IsNullOrEmpty(path))
throw new ArgumentNullException("path");
if (!RemotePathResolverBase.FileSystemService.IsUncPath(path))
return path;
if (string.IsNullOrEmpty(FileShareUncPath)) {
transferLog.LogError(AsperaStrings.AsperaUncPathResolverFileShareNullExceptionMessage, path, LogRedaction.OnPositions(default(int)));
throw new TransferException(AsperaStrings.GeneralOperationErrorCheckLogs, true);
}
path = Normalize(path);
if (fileShareUncPathSplit.Count == 0) {
fileShareUncPathSplit.AddRange(from x in FileShareUncPath.Split(new char[1] {
'\\'
}, StringSplitOptions.RemoveEmptyEntries)
select x.TrimEnd(Array.Empty<char>()));
pathComponentsToRemove = fileShareUncPathSplit.Count - DocRootLevels;
}
if (pathComponentsToRemove < 1 && DocRootLevels > 0 && GlobalSettings.Instance.ValidateResolvedPaths) {
transferLog.LogError(AsperaStrings.AsperaUncPathResolverLevelsExceptionMessage, DocRootLevels, FileShareUncPath, path, LogRedaction.OnPositions(1, 2));
throw new TransferException(AsperaStrings.GeneralOperationErrorCheckLogs, true);
}
List<string> list = (from x in path.Split(new char[1] {
'\\'
}, StringSplitOptions.RemoveEmptyEntries)
select x.TrimEnd(Array.Empty<char>())).ToList();
bool flag = list.Count < fileShareUncPathSplit.Count;
if (flag && GlobalSettings.Instance.ValidateResolvedPaths) {
transferLog.LogError(AsperaStrings.AsperaUncPathResolverFolderCountExceptionMessage, FileShareUncPath, fileShareUncPathSplit.Count - 1, path, list.Count - 1, LogRedaction.OnPositions(0, 2));
throw new TransferException(AsperaStrings.GeneralOperationErrorCheckLogs, true);
}
if (!flag && GlobalSettings.Instance.ValidateResolvedPaths) {
for (int i = 1; i < fileShareUncPathSplit.Count; i++) {
if (string.Compare(list[i], fileShareUncPathSplit[i], StringComparison.OrdinalIgnoreCase) != 0) {
transferLog.LogError(AsperaStrings.AsperaUncPathResolverFolderNameMatchExceptionMessage, FileShareUncPath, path, list[i], fileShareUncPathSplit[i], LogRedaction.OnPositions(0, 1, 2, 3));
throw new TransferException(AsperaStrings.GeneralOperationErrorCheckLogs, true);
}
}
}
string text = PathHelper.NormalizeUnixPath(string.Join("\\", list.Skip(pathComponentsToRemove)));
if (!RemotePathResolverBase.FileSystemService.IsUnixPath(text) && GlobalSettings.Instance.ValidateResolvedPaths) {
transferLog.LogError(AsperaStrings.AsperaUncPathResolverNotUnixPathExceptionMessage, FileShareUncPath, path, LogRedaction.OnPositions(0, 1));
throw new TransferException(AsperaStrings.GeneralOperationErrorCheckLogs, true);
}
return text;
}
private static string Normalize(string path)
{
return "\\\\" + path.Substring(2).Replace("\\\\", "\\");
}
}
}