void RetrieveDecrytpedTransactionStorage <T>(TransactionDownloadData <T> transactionData) where T : Operation
        {
            if ((Flags & TransactionDownloadManagerFlags.DecrytpedTransactionStorage) != 0)
            {
                var transaction   = transactionData.Transaction;
                var transactionId = transaction.OperationId;

                if (transactionData.GetDecryptedData() == null)
                {
                    var decrytedStorage = _decryptedAttachementsStorage.Value;
                    if (decrytedStorage.ContainsIndex(transactionId))
                    {
                        var data = decrytedStorage.GetBlockData(transactionId);
                        if (data != null)
                        {
                            try
                            {
                                var attachements = new TransactionAttachements(new Unpacker(data));
                                transactionData.UpdateDecryptedData(attachements);
                            }
                            catch { }
                        }
                    }
                }
            }
        }
        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);
        }
Beispiel #3
0
        public void AddDecryptedAttachement(string name, byte[] data)
        {
            if (_decryptedData == null)
            {
                _decryptedData = new TransactionAttachements(Transaction.OperationId);
            }

            _decryptedData.AddData(name, data);
        }
Beispiel #4
0
        public void UpdateAttachement(TransactionAttachementsState state, TransactionAttachements attachementData)
        {
            if (state == TransactionAttachementsState.Ok && attachementData == null)
            {
                return;
            }

            AttachementsState = state;
            _attachements     = attachementData;
        }
Beispiel #5
0
 public void UpdateDecryptedData(TransactionAttachements attachementData)
 {
     _decryptedData = attachementData;
 }