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

FileIoWebApiService

using Polly; using Relativity.Transfer.WebApi; using System; using System.Globalization; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; namespace Relativity.Transfer.Http.WebApi { [Obsolete("WebAPI support will be removed in upcoming releases. In order to communicate with Relativity use Kepler Services. For more information, see KeplerServiceBase class.")] internal sealed class FileIoWebApiService : WebApiService, IFileIoService, IDisposable { private const string DownloadFileFileArtifactUrlTemplate = "{0}{1}/Download.aspx?ObjectArtifactID={2}&FileID={3}&AppID={4}&FileFieldArtifactID={5}&AuthenticationToken={6}"; private const string DownloadFullTextUrlTemplate = "{0}{1}/Download.aspx?ArtifactID={2}&AppID={3}&ExtractedText=True&AuthenticationToken={4}"; private const string DownloadLongTextFieldArtifactUrlTemplate = "{0}{1}/Download.aspx?ArtifactID={2}&AppID={3}&LongTextFieldArtifactID={4}&AuthenticationToken={5}"; private const string DownloadNativeFileUrlTemplate = "{0}{1}/Download.aspx?ArtifactID={2}&GUID={3}&AppID={4}&AuthenticationToken={5}"; private readonly Workspace workspace; private int httpChunkSize; public FileIoWebApiService(RelativityConnectionInfo connectionInfo, Workspace workspace, HttpClientConfiguration configuration, IUserManagerService userManagerService, ITransferLog log) : base(connectionInfo, configuration, userManagerService, log) { if (workspace == null) throw new ArgumentNullException("workspace"); this.workspace = workspace; httpChunkSize = base.Configuration.HttpChunkSize; } public Task DownloadFileAsync(string targetFile, TransferPath path, CancellationToken token, IProgress<LargeFileProgressEventArgs> progress) { if (string.IsNullOrEmpty(targetFile)) throw new ArgumentNullException("path"); HttpTransferPathData remotePathData = HttpTransferPathData.GetData(path); if (remotePathData == null) throw new ArgumentNullException("path"); Initialize(); <>c__DisplayClass7_0 <>4__this; return RetrySyntaxAsync.WaitAndRetryAsync(Policy.Handle<Exception>(), base.MaxRetryAttempts, (Func<int, TimeSpan>)((int retryAttempt) => TimeSpan.FromSeconds(Math.Pow(2, (double)retryAttempt))), (Action<Exception, TimeSpan, Context>)delegate(Exception exception, TimeSpan timeSpan, Context context) { base.Log.LogError(exception, $"""{timeSpan}", Array.Empty<object>()); CheckLogin(exception); }).ExecuteAsync((Func<CancellationToken, Task>)delegate { <>c__DisplayClass7_0.<<DownloadFileAsync>b__2>d stateMachine = default(<>c__DisplayClass7_0.<<DownloadFileAsync>b__2>d); stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>4__this = <>4__this; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }, token); } public Task<IoResponse> BeginFillAsync(int workspaceId, byte[] data, string targetPath, string fileName, CancellationToken token) { Initialize(); return RetrySyntaxAsync.WaitAndRetryAsync(Policy.Handle<Exception>(), base.MaxRetryAttempts, (Func<int, TimeSpan>)((int retryAttempt) => TimeSpan.FromSeconds(Math.Pow(2, (double)retryAttempt))), (Action<Exception, TimeSpan>)delegate(Exception exception, TimeSpan span) { base.Log.LogError(exception, $"""{span}", Array.Empty<object>()); CheckLogin(exception); }).ExecuteAsync<IoResponse>((Func<CancellationToken, Task<IoResponse>>)((CancellationToken ct) => Task.Factory.FromAsync((Func<AsyncCallback, object, IAsyncResult>)((AsyncCallback callback, object stateObject) => base.ServiceInstance.BeginBeginFill(workspaceId, data, targetPath, fileName, callback, stateObject)), (Func<IAsyncResult, IoResponse>)base.ServiceInstance.EndBeginFill, (object)null)), token); } public Task<IoResponse> FileFillAsync(int workspaceId, byte[] data, string targetPath, string fileName, CancellationToken token) { Initialize(); return RetrySyntaxAsync.WaitAndRetryAsync(Policy.Handle<Exception>(), base.MaxRetryAttempts, (Func<int, TimeSpan>)((int retryAttempt) => TimeSpan.FromSeconds(Math.Pow(2, (double)retryAttempt))), (Action<Exception, TimeSpan>)delegate(Exception exception, TimeSpan span) { base.Log.LogError(exception, $"""{span}", Array.Empty<object>()); CheckLogin(exception); }).ExecuteAsync<IoResponse>((Func<CancellationToken, Task<IoResponse>>)((CancellationToken ct) => Task.Factory.FromAsync((Func<AsyncCallback, object, IAsyncResult>)((AsyncCallback callback, object stateObject) => base.ServiceInstance.BeginFileFill(workspaceId, targetPath, fileName, data, callback, stateObject)), (Func<IAsyncResult, IoResponse>)base.ServiceInstance.EndFileFill, (object)null)), token); } public Task<string[][]> GetDefaultRepositorySpaceReportAsync(int workspaceId, CancellationToken token) { if (workspaceId <= 0) throw new ArgumentOutOfRangeException("workspaceId"); Initialize(); return RetrySyntaxAsync.WaitAndRetryAsync(Policy.Handle<Exception>(), base.MaxRetryAttempts, (Func<int, TimeSpan>)((int retryAttempt) => TimeSpan.FromSeconds(Math.Pow(2, (double)retryAttempt))), (Action<Exception, TimeSpan>)delegate(Exception exception, TimeSpan span) { base.Log.LogError(exception, $"""{span}", Array.Empty<object>()); CheckLogin(exception); }).ExecuteAsync<string[][]>((Func<CancellationToken, Task<string[][]>>)delegate { Task<string[][]> task = Task.Factory.FromAsync((Func<AsyncCallback, object, IAsyncResult>)((AsyncCallback callback, object stateObject) => base.ServiceInstance.BeginGetDefaultRepositorySpaceReport(workspaceId, callback, stateObject)), (Func<IAsyncResult, string[][]>)base.ServiceInstance.EndGetDefaultRepositorySpaceReport, (object)null); task.Wait(token); return task; }, token); } public Task RemoveFillAsync(int workspaceId, string targetPath, string fileGuid, CancellationToken token) { if (workspaceId <= 0) throw new ArgumentOutOfRangeException("workspaceId"); if (string.IsNullOrEmpty(targetPath)) throw new ArgumentNullException("targetPath"); if (string.IsNullOrEmpty(fileGuid)) throw new ArgumentOutOfRangeException("fileGuid"); Initialize(); return RetrySyntaxAsync.WaitAndRetryAsync(Policy.Handle<Exception>(), base.MaxRetryAttempts, (Func<int, TimeSpan>)((int retryAttempt) => TimeSpan.FromSeconds(Math.Pow(2, (double)retryAttempt))), (Action<Exception, TimeSpan>)delegate(Exception exception, TimeSpan span) { base.Log.LogError(exception, $"""{span}", Array.Empty<object>()); CheckLogin(exception); }).ExecuteAsync((Func<CancellationToken, Task>)delegate { Task task = Task.Factory.FromAsync((AsyncCallback callback, object stateObject) => base.ServiceInstance.BeginRemoveFill(workspaceId, targetPath, fileGuid.ToString(), callback, stateObject), base.ServiceInstance.EndRemoveFill, null); task.Wait(token); return task; }, token); } public Task RemoveTempFile(int workspaceId, string fileGuid, CancellationToken token) { if (workspaceId <= 0) throw new ArgumentOutOfRangeException("workspaceId"); if (string.IsNullOrEmpty(fileGuid)) throw new ArgumentOutOfRangeException("fileGuid"); Initialize(); return RetrySyntaxAsync.WaitAndRetryAsync(Policy.Handle<Exception>(), base.MaxRetryAttempts, (Func<int, TimeSpan>)((int retryAttempt) => TimeSpan.FromSeconds(Math.Pow(2, (double)retryAttempt))), (Action<Exception, TimeSpan>)delegate(Exception exception, TimeSpan span) { base.Log.LogError(exception, $"""{span}", Array.Empty<object>()); CheckLogin(exception); }).ExecuteAsync((Func<CancellationToken, Task>)delegate { Task task = Task.Factory.FromAsync((AsyncCallback callback, object stateObject) => base.ServiceInstance.BeginRemoveTempFile(workspaceId, fileGuid, callback, stateObject), base.ServiceInstance.EndRemoveTempFile, null); task.Wait(token); return task; }, token); } private string GetDownloadUrl(HttpTransferPathData remotePathData) { Uri host = base.ConnectionInfo.Host; string text = workspace.DownloadHandlerUrl ?? "relativity.distributed"; switch (remotePathData.ExportType) { case ExportType.FileFieldArtifact: return string.Format(CultureInfo.InvariantCulture, "{0}{1}/Download.aspx?ObjectArtifactID={2}&FileID={3}&AppID={4}&FileFieldArtifactID={5}&AuthenticationToken={6}", host, text, remotePathData.ArtifactId, remotePathData.FileId, base.ConnectionInfo.WorkspaceId, remotePathData.FileFieldArtifactId, base.UserManagerService.DistributedToken); case ExportType.FullText: return string.Format(CultureInfo.InvariantCulture, "{0}{1}/Download.aspx?ArtifactID={2}&AppID={3}&ExtractedText=True&AuthenticationToken={4}", host, text, remotePathData.ArtifactId, base.ConnectionInfo.WorkspaceId, base.UserManagerService.DistributedToken); case ExportType.LongTextFieldArtifact: return string.Format(CultureInfo.InvariantCulture, "{0}{1}/Download.aspx?ArtifactID={2}&AppID={3}&LongTextFieldArtifactID={4}&AuthenticationToken={5}", host, text, remotePathData.ArtifactId, base.ConnectionInfo.WorkspaceId, remotePathData.LongTextFieldArtifactId, base.UserManagerService.DistributedToken); case ExportType.NativeFile: return string.Format(CultureInfo.InvariantCulture, "{0}{1}/Download.aspx?ArtifactID={2}&GUID={3}&AppID={4}&AuthenticationToken={5}", host, text, remotePathData.ArtifactId, remotePathData.RemoteGuid, base.ConnectionInfo.WorkspaceId, base.UserManagerService.DistributedToken); default: return string.Empty; } } int get_MaxRetryAttempts() { return base.MaxRetryAttempts; } int IFileIoService.get_MaxRetryAttempts() { return this.get_MaxRetryAttempts(); } void set_MaxRetryAttempts(int value) { base.MaxRetryAttempts = value; } void IFileIoService.set_MaxRetryAttempts(int value) { this.set_MaxRetryAttempts(value); } } }