async Task <TransactionDownloadData <T> > DownloadTransactionAttachement <T>(TransactionDownloadData <T> transactionData, bool commit) where T : Operation { var transaction = transactionData.Transaction; var transactionId = transaction.OperationId; if (transactionData.HasAttachements) { if (transactionData.AttachementsState != TransactionAttachementsState.Ok) { var attachementStorage = _attachementsStorage.Value; if (!attachementStorage.ContainsIndex(transactionId)) { var attachementData = new TransactionAttachements(transactionId); var attachementTransaction = transaction as AttachementDataTransaction; var count = attachementTransaction.Items.Count; for (var i = 0; i < attachementTransaction.Items.Count; i++) { var item = attachementTransaction.Items[i]; var data = (await Client.DownloadAttachement(attachementTransaction, i)).Data; if (data != null) { attachementData.AddData(item.Name, data); } } if (count == attachementData.Count) { attachementStorage.AddEntry(transactionId, attachementData.ToByteArray()); if (commit) { attachementStorage.Commit(); } transactionData.UpdateAttachement(TransactionAttachementsState.Ok, attachementData); } else { transactionData.UpdateAttachement(TransactionAttachementsState.DownloadFailed, null); } } else { var data = attachementStorage.GetBlockData(transactionId); if (data != null) { try { transactionData.UpdateAttachement(TransactionAttachementsState.Ok, new TransactionAttachements(new Unpacker(data))); } catch { } } } } } return(transactionData); }
public void AddDecryptedAttachement(string name, byte[] data) { if (_decryptedData == null) { _decryptedData = new TransactionAttachements(Transaction.OperationId); } _decryptedData.AddData(name, data); }