<PackageReference Include="Relativity.Transfer.Client" Version="5.0.7" />

AzureFilesUncPathResolver

using Relativity.Transfer.AzureFiles.Resources; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; namespace Relativity.Transfer.AzureFiles { public class AzureFilesUncPathResolver : RemotePathResolverBase { private readonly List<string> fileShareUncPathSplit = new List<string>(); private string fileShareUncPath; private int pathComponentsToRemove; public int DocRootLevels { get; set; } public string FileShareUncPath { get { return fileShareUncPath; } set { if (!string.IsNullOrEmpty(value)) value = RemotePathResolverBase.FileSystemService.TrimTrailingSlash(value); fileShareUncPath = value; fileShareUncPathSplit.Clear(); pathComponentsToRemove = 0; } } public bool ValidateFolderNames { get; set; } public AzureFilesUncPathResolver(string fileShareUncPath) { DocRootLevels = 1; FileShareUncPath = fileShareUncPath; ValidateFolderNames = false; } 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)) throw new TransferException(string.Format(CultureInfo.CurrentCulture, AzureFilesStrings.AzureFilesUncPathResolverFileShareNullExceptionMessage, path), 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; } List<string> list = (from x in path.Split(new char[1] { '\\' }, StringSplitOptions.RemoveEmptyEntries) select x.TrimEnd(Array.Empty<char>())).ToList(); if (list.Count < fileShareUncPathSplit.Count) throw new TransferException(string.Format(CultureInfo.CurrentCulture, AzureFilesStrings.AzureFilesUncPathResolverFolderCountExceptionMessage, FileShareUncPath, fileShareUncPathSplit.Count - 1, path, list.Count - 1), true); if (ValidateFolderNames) { for (int i = 1; i < fileShareUncPathSplit.Count; i++) { if (string.Compare(list[i], fileShareUncPathSplit[i], StringComparison.OrdinalIgnoreCase) != 0) throw new TransferException(string.Format(CultureInfo.CurrentCulture, AzureFilesStrings.AzureFilesUncPathResolverFolderNameMatchExceptionMessage, FileShareUncPath, path), true); } } return PathHelper.NormalizeUnixPath(string.Join("\\", list.Skip(pathComponentsToRemove))); } private static string Normalize(string path) { return "\\\\" + path.Substring(2).Replace("\\\\", "\\"); } } }