private Task <PlaceFileResult> PlaceFileAsync( OperationContext operationContext, SessionContext context, ContentHash contentHash, AbsolutePath path, FileAccessMode accessMode, FileReplacementMode replacementMode, FileRealizationMode realizationMode) { return(PerformOperationAsync( context, _ => Client.PlaceFileAsync( new PlaceFileRequest { Header = context.CreateHeader(), HashType = (int)contentHash.HashType, ContentHash = contentHash.ToByteString(), Path = path.Path, FileAccessMode = (int)accessMode, FileRealizationMode = (int)realizationMode, FileReplacementMode = (int)replacementMode }, options: GetCallOptions(Configuration.PlaceDeadline, operationContext.Token)), response => { // Workaround: Handle the service returning negative result codes in error cases PlaceFileResult.ResultCode resultCode = response.Header.Result < 0 ? PlaceFileResult.ResultCode.Error : (PlaceFileResult.ResultCode)response.Header.Result; if (!response.Header.Succeeded) { var message = string.IsNullOrEmpty(response.Header.ErrorMessage) ? resultCode.ToString() : response.Header.ErrorMessage; return new PlaceFileResult(resultCode, message, response.Header.Diagnostics); } else { return new PlaceFileResult(resultCode, response.ContentSize); } })); }
private async Task <PlaceFileResult> PlaceFileAsync( Context context, ContentHash contentHash, AbsolutePath path, FileAccessMode accessMode, FileReplacementMode replacementMode, FileRealizationMode realizationMode, int sessionId) { var startTime = DateTime.UtcNow; PlaceFileResponse response = await RunClientActionAndThrowIfFailedAsync(context, async() => await _client.PlaceFileAsync( new PlaceFileRequest { Header = new RequestHeader(context.Id, sessionId), HashType = (int)contentHash.HashType, ContentHash = contentHash.ToByteString(), Path = path.Path, FileAccessMode = (int)accessMode, FileRealizationMode = (int)realizationMode, FileReplacementMode = (int)replacementMode })); long ticksWaited = response.Header.ServerReceiptTimeUtcTicks - startTime.Ticks; _tracer.TrackClientWaitForServerTicks(ticksWaited); // Workaround: Handle the service returning negative result codes in error cases PlaceFileResult.ResultCode resultCode = response.Header.Result < 0 ? PlaceFileResult.ResultCode.Error : (PlaceFileResult.ResultCode)response.Header.Result; if (!response.Header.Succeeded) { await ResetOnUnknownSessionAsync(context, response.Header, sessionId); var message = string.IsNullOrEmpty(response.Header.ErrorMessage) ? resultCode.ToString() : response.Header.ErrorMessage; return(new PlaceFileResult(resultCode, message, response.Header.Diagnostics)); } else { return(new PlaceFileResult(resultCode, response.ContentSize)); } }