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

FileIoKeplerService

using Polly; using Relativity.DataTransfer.Legacy.SDK.ImportExport.V1; using Relativity.DataTransfer.Legacy.SDK.ImportExport.V1.Models; using Relativity.Kepler.Transport; using Relativity.Transfer.Kepler; using System; using System.IO; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; namespace Relativity.Transfer.Http.Kepler { internal sealed class FileIoKeplerService : KeplerServiceBase, IFileIoService, IDisposable { private readonly int httpChunkSize; public FileIoKeplerService(RelativityConnectionInfo connectionInfo, ClientConfiguration configuration, ITransferLog log) : base(connectionInfo, configuration, log) { httpChunkSize = configuration.HttpChunkSize; } public void Dispose() { } public Task<string[][]> GetDefaultRepositorySpaceReportAsync(int workspaceId, CancellationToken token) { if (workspaceId <= 0) throw new ArgumentOutOfRangeException("workspaceId"); string correlationId = Guid.NewGuid().ToString(); <>c__DisplayClass3_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>)delegate(Exception exception, TimeSpan span) { base.Log.LogError(exception, $"""{correlationId}""{span}", Array.Empty<object>()); }).ExecuteAsync<string[][]>((Func<CancellationToken, Task<string[][]>>)delegate { <>c__DisplayClass3_0.<<GetDefaultRepositorySpaceReportAsync>b__2>d stateMachine = default(<>c__DisplayClass3_0.<<GetDefaultRepositorySpaceReportAsync>b__2>d); stateMachine.<>t__builder = AsyncTaskMethodBuilder<string[][]>.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) { string correlationId = Guid.NewGuid().ToString(); <>c__DisplayClass4_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>)delegate(Exception exception, TimeSpan span) { base.Log.LogError(exception, $"""{correlationId}""{span}", Array.Empty<object>()); }).ExecuteAsync<IoResponse>((Func<CancellationToken, Task<IoResponse>>)delegate { <>c__DisplayClass4_0.<<BeginFillAsync>b__2>d stateMachine = default(<>c__DisplayClass4_0.<<BeginFillAsync>b__2>d); stateMachine.<>t__builder = AsyncTaskMethodBuilder<IoResponse>.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> FileFillAsync(int workspaceId, byte[] data, string targetPath, string fileName, CancellationToken token) { string correlationId = Guid.NewGuid().ToString(); <>c__DisplayClass5_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>)delegate(Exception exception, TimeSpan span) { base.Log.LogError(exception, $"""{correlationId}""{span}", Array.Empty<object>()); }).ExecuteAsync<IoResponse>((Func<CancellationToken, Task<IoResponse>>)delegate { <>c__DisplayClass5_0.<<FileFillAsync>b__2>d stateMachine = default(<>c__DisplayClass5_0.<<FileFillAsync>b__2>d); stateMachine.<>t__builder = AsyncTaskMethodBuilder<IoResponse>.Create(); stateMachine.<>4__this = <>4__this; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.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"); string correlationId = Guid.NewGuid().ToString(); <>c__DisplayClass6_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>)delegate(Exception exception, TimeSpan span) { base.Log.LogError(exception, $"""{correlationId}""{span}", Array.Empty<object>()); }).ExecuteAsync((Func<CancellationToken, Task>)delegate { <>c__DisplayClass6_0.<<RemoveFillAsync>b__2>d stateMachine = default(<>c__DisplayClass6_0.<<RemoveFillAsync>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 RemoveTempFile(int workspaceId, string fileGuid, CancellationToken token) { if (workspaceId <= 0) throw new ArgumentOutOfRangeException("workspaceId"); if (string.IsNullOrEmpty(fileGuid)) throw new ArgumentOutOfRangeException("fileGuid"); string correlationId = Guid.NewGuid().ToString(); <>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>)delegate(Exception exception, TimeSpan span) { base.Log.LogError(exception, $"""{correlationId}""{span}", Array.Empty<object>()); }).ExecuteAsync((Func<CancellationToken, Task>)delegate { <>c__DisplayClass7_0.<<RemoveTempFile>b__2>d stateMachine = default(<>c__DisplayClass7_0.<<RemoveTempFile>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); } [AsyncStateMachine(typeof(<DownloadFileAsync>d__8))] public Task DownloadFileAsync(string targetFile, TransferPath path, CancellationToken token, IProgress<LargeFileProgressEventArgs> progress) { <DownloadFileAsync>d__8 stateMachine = default(<DownloadFileAsync>d__8); stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>4__this = this; stateMachine.targetFile = targetFile; stateMachine.path = path; stateMachine.token = token; stateMachine.progress = progress; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } [AsyncStateMachine(typeof(<GetKeplerStreamForDownload>d__9))] private Task<IKeplerStream> GetKeplerStreamForDownload(IWebDistributedService service, HttpTransferPathData data, string correlationId) { <GetKeplerStreamForDownload>d__9 stateMachine = default(<GetKeplerStreamForDownload>d__9); stateMachine.<>t__builder = AsyncTaskMethodBuilder<IKeplerStream>.Create(); stateMachine.<>4__this = this; stateMachine.service = service; stateMachine.data = data; stateMachine.correlationId = correlationId; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } private long GetTotalRequestBytesForDownload(IKeplerStream keplerStream, string correlationId) { try { long result = 0; string name = 11.ToString(); if (keplerStream.get_Headers()?[name] != null) long.TryParse(keplerStream.get_Headers()[name], out result); return result; } catch (Exception exception) { base.Log.LogError(exception, "Error occurred during obtaining total requested bytes from headers. CorrelationId = {CorrelationId}", correlationId); throw; } } [AsyncStateMachine(typeof(<GetRemoteStreamForDownload>d__11))] private Task<Stream> GetRemoteStreamForDownload(IKeplerStream keplerStream, string correlationId) { <GetRemoteStreamForDownload>d__11 stateMachine = default(<GetRemoteStreamForDownload>d__11); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Stream>.Create(); stateMachine.<>4__this = this; stateMachine.keplerStream = keplerStream; stateMachine.correlationId = correlationId; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } [AsyncStateMachine(typeof(<CopyFromRemoteToLocalStreamAsync>d__12))] private Task CopyFromRemoteToLocalStreamAsync(Stream remoteStream, Stream localStream, string correlationId) { <CopyFromRemoteToLocalStreamAsync>d__12 stateMachine = default(<CopyFromRemoteToLocalStreamAsync>d__12); stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>4__this = this; stateMachine.remoteStream = remoteStream; stateMachine.localStream = localStream; stateMachine.correlationId = correlationId; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } [AsyncStateMachine(typeof(<CopyFromToLocalStreamWithBufferAsync>d__13))] private Task CopyFromToLocalStreamWithBufferAsync(TransferPath path, IProgress<LargeFileProgressEventArgs> progress, long totalRequestBytes, Stream downloadStream, Stream fileStream, string correlationId, CancellationToken token) { <CopyFromToLocalStreamWithBufferAsync>d__13 stateMachine = default(<CopyFromToLocalStreamWithBufferAsync>d__13); stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>4__this = this; stateMachine.path = path; stateMachine.progress = progress; stateMachine.totalRequestBytes = totalRequestBytes; stateMachine.downloadStream = downloadStream; stateMachine.fileStream = fileStream; stateMachine.correlationId = correlationId; stateMachine.token = token; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } [AsyncStateMachine(typeof(<ReadToBufferAsync>d__14))] private Task<int> ReadToBufferAsync(Stream downloadStream, byte[] buffer, string correlationId, CancellationToken token) { <ReadToBufferAsync>d__14 stateMachine = default(<ReadToBufferAsync>d__14); stateMachine.<>t__builder = AsyncTaskMethodBuilder<int>.Create(); stateMachine.<>4__this = this; stateMachine.downloadStream = downloadStream; stateMachine.buffer = buffer; stateMachine.correlationId = correlationId; stateMachine.token = token; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } [AsyncStateMachine(typeof(<WriteFromBufferAsync>d__15))] private Task WriteFromBufferAsync(Stream fileStream, byte[] buffer, int bytesRead, string correlationId, CancellationToken token) { <WriteFromBufferAsync>d__15 stateMachine = default(<WriteFromBufferAsync>d__15); stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>4__this = this; stateMachine.fileStream = fileStream; stateMachine.buffer = buffer; stateMachine.bytesRead = bytesRead; stateMachine.correlationId = correlationId; stateMachine.token = token; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } private IoResponse Convert(IoResponse response) { return new IoResponse { ErrorMessage = response.get_ErrorMessage(), ErrorText = response.get_ErrorText(), Filename = response.get_Filename(), Success = response.get_Success() }; } 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); } } }