public Task <Transfer> RedeemTokenInternal( Token token, double?amount, string currency, string description, TransferEndpoint destination, string refId) { var payload = new TransferPayload { TokenId = token.Id, Description = token.Payload.Description }; if (destination != null) { payload.Destinations.Add(destination); } if (amount.HasValue) { var money = new Money { Value = Util.DoubleToString(amount.Value) }; payload.Amount = money; } if (currency != null) { payload.Amount.Currency = currency; } if (description != null) { payload.Description = description; } if (refId != null) { payload.RefId = refId; } else if (!string.IsNullOrEmpty(token.Payload.RefId) && amount == null) { payload.RefId = token.Payload.RefId; } else { logger.Warn("refId is not set. A random ID will be used."); payload.RefId = Util.Nonce(); } return(client.CreateTransfer(payload)); }
/// <summary> /// Creates a transfer redeeming a transfer token. /// </summary> /// <param name="payload">the transfer payload</param> /// <returns></returns> public Task <Transfer> CreateTransfer(TransferPayload payload) { var signer = cryptoEngine.CreateSigner(Level.Low); var request = new CreateTransferRequest { Payload = payload, PayloadSignature = new Signature { MemberId = MemberId, KeyId = signer.GetKeyId(), Signature_ = signer.Sign(payload) } }; return(gateway(authenticationContext()).CreateTransferAsync(request) .ToTask(response => response.Transfer)); }
/// <summary> /// Sends the transfer payload to the target providers. /// </summary> /// <param name="file"></param> /// <param name="source"></param> /// <param name="payload"></param> /// <param name="cancelToken"></param> /// <returns></returns> private async Task SendTransferPayloadToFileTargetsAsync(BackupFile file, SourceLocation source, TransferPayload payload, CancellationToken cancelToken) { var directory = await Database.GetDirectoryMapItemAsync(file.Directory).ConfigureAwait(false); foreach (var providerName in payload.DestinationProviders) { var destination = Providers[providerName]; try { // upload this chunk to the destination cloud provider. // note: the provider implementation will automatically handle retries of transient issues. await destination.UploadFileBlockAsync(file, source, directory, payload.Data, (int)payload.CurrentBlockNumber, (int)payload.TotalBlocks, cancelToken).ConfigureAwait(false); // flag the chunk as sent in the file status. file.SetBlockAsSent((int)payload.CurrentBlockNumber, providerName); } catch (OperationCanceledException) { // cancellation was requested. // bubble up to the next level. throw; } catch (Exception ex) { Logger.WriteTraceError("An error occurred during a file transfer.", ex, Logger.GenerateFullContextStackTrace(), InstanceID); file.SetProviderToFailed(providerName); // sets the error message/stack trace await Database.SetBackupFileAsFailedAsync(file, ex.ToString()).ConfigureAwait(false); await Database.RemoveFileFromBackupQueueAsync(file).ConfigureAwait(false); } finally { // commit the status changes to the local state database. await Database.UpdateBackupFileCopyStateAsync(file).ConfigureAwait(false); } } }