<PackageReference Include="Relativity.Server.Transfer.SDK" Version="25000.0.6" />

FileShareDiagnosticsService

using Polly; using Relativity.Transfer.FileShare.Resources; using System; using System.IO; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; namespace Relativity.Transfer.FileShare { public class FileShareDiagnosticsService { private const string TestFileNamePrefix = "REL_FSClient_DiagTest_"; private readonly string testFileName; private readonly FileShareClientConfiguration configuration; private readonly IFileSystemService fileSystemService; private readonly ITransferLog transferLog; public FileShareDiagnosticsService(FileShareClientConfiguration configuration, IFileSystemService fileSystemService, ITransferLog log) { if (configuration == null) throw new ArgumentNullException("configuration"); if (fileSystemService == null) throw new ArgumentNullException("fileSystemService"); if (log == null) throw new ArgumentNullException("log"); this.configuration = configuration; transferLog = log; this.fileSystemService = fileSystemService; testFileName = string.Format("{0}{1}", "REL_FSClient_DiagTest_", Guid.NewGuid()); } [AsyncStateMachine(typeof(<TestConnectivityAsync>d__6))] public Task<ISupportCheckResult> TestConnectivityAsync(CancellationToken token) { <TestConnectivityAsync>d__6 stateMachine = default(<TestConnectivityAsync>d__6); stateMachine.<>t__builder = AsyncTaskMethodBuilder<ISupportCheckResult>.Create(); stateMachine.<>4__this = this; stateMachine.token = token; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } public Task<ISupportCheckResult> TestConnectivityAsync(string fileShareUncPath, CancellationToken token) { return Task.Run(() => RetrySyntax.WaitAndRetry(Policy.Handle<Exception>(), configuration.MaxHttpRetryAttempts, (Func<int, TimeSpan>)((int retryAttempt) => TimeSpan.FromSeconds(Math.Pow(2, (double)retryAttempt))), (Action<Exception, TimeSpan, Context>)delegate(Exception exception, TimeSpan timespan, Context context) { transferLog.LogError(exception, "Retry - {TimeSpan} - FileShare Connectivity Test Failed.", timespan); }).Execute<ISupportCheckResult>((Func<ISupportCheckResult>)delegate { SupportCheckResult supportCheckResult = new SupportCheckResult(); if (!string.IsNullOrEmpty(fileShareUncPath)) try { string pathRoot = fileSystemService.GetPathRoot(fileShareUncPath); if (fileSystemService.DirectoryExists(pathRoot)) { using (fileSystemService.CreateNewFileStreamWithReadWriteAccess(fileSystemService.Combine(fileShareUncPath, testFileName))) { } supportCheckResult.IsSupported = true; return supportCheckResult; } transferLog.LogError(FileShareStrings.FileShareDriveNotFoundExceptionMessage, fileShareUncPath, LogRedaction.OnPositions(default(int))); supportCheckResult.IsSupported = false; supportCheckResult.ErrorMessage = "The drive or share is not available - check logs for more details."; return supportCheckResult; } catch (DirectoryNotFoundException) { transferLog.LogError(FileShareStrings.DirectoryCouldNotBeFoundExceptionMessage, fileShareUncPath, LogRedaction.OnPositions(default(int))); supportCheckResult.IsSupported = false; supportCheckResult.ErrorMessage = "The Workspace's Default FileShare could not be found - check logs for more details."; return supportCheckResult; } catch (UnauthorizedAccessException) { transferLog.LogError(FileShareStrings.DirectoryUnauthorizedAccessExceptionMessage, fileShareUncPath, LogRedaction.OnPositions(default(int))); supportCheckResult.IsSupported = false; supportCheckResult.ErrorMessage = "You do not have authorization to access the FileShare - check logs for more details."; return supportCheckResult; } catch (PathTooLongException) { transferLog.LogError(FileShareStrings.FileSharePathTooLongExceptionMessage, fileShareUncPath, LogRedaction.OnPositions(default(int))); supportCheckResult.IsSupported = false; supportCheckResult.ErrorMessage = "The path is longer than allowed - check logs for more details."; return supportCheckResult; } catch (IOException ex4) { transferLog.LogWarning(ex4.Message, LogRedaction.OnPositions(default(int))); throw; } catch (Exception ex5) { transferLog.LogError(ex5.Message, LogRedaction.OnPositions(default(int))); supportCheckResult.ErrorMessage = "Unexpected exception - check logs for more details."; supportCheckResult.IsSupported = false; return supportCheckResult; } finally { if (fileSystemService.FileExists(fileSystemService.Combine(fileShareUncPath, testFileName))) fileSystemService.DeleteFile(fileSystemService.Combine(fileShareUncPath, testFileName)); } transferLog.LogError(FileShareStrings.PathIsNullOrEmptyExceptionMessage, Array.Empty<object>()); supportCheckResult.ErrorMessage = FileShareStrings.PathIsNullOrEmptyExceptionMessage; supportCheckResult.IsSupported = false; return supportCheckResult; }), token); } } }