Example #1
0
        private async Task SaveBlobEntityAsync(
            Guid operationId,
            string blockchainType,
            TransactionExecutionBlobEntity blobEntity)
        {
            var containerName = TransactionExecutionBlobEntity.GetContainerName(blockchainType);
            var blobName      = TransactionExecutionBlobEntity.GetBlobName(operationId);

            using (var stream = new MemoryStream())
                using (var textWriter = new StreamWriter(stream))
                    using (var jsonWriter = new JsonTextWriter(textWriter))
                    {
                        _blobJsonSerializer.Serialize(jsonWriter, blobEntity);

                        await jsonWriter.FlushAsync();

                        await textWriter.FlushAsync();

                        await stream.FlushAsync();

                        stream.Position = 0;

                        await _blob.SaveBlobAsync(containerName, blobName, stream);
                    }
        }
Example #2
0
        public Task SaveAsync(TransactionExecutionAggregate aggregate)
        {
            var blobEntity = TransactionExecutionBlobEntity.FromDomain(aggregate);

            return(Task.WhenAll
                   (
                       SaveBlobEntityAsync(aggregate.TransactionId, aggregate.BlockchainType, blobEntity),
                       _aggregateRepository.SaveAsync(aggregate)
                   ));
        }
Example #3
0
        private async Task <TransactionExecutionBlobEntity> TryGetBlobEntityAsync(
            Guid operationId,
            string blockchainType)
        {
            var containerName = TransactionExecutionBlobEntity.GetContainerName(blockchainType);
            var blobName      = TransactionExecutionBlobEntity.GetBlobName(operationId);

            if (!await _blob.HasBlobAsync(containerName, blobName))
            {
                return(null);
            }

            using (var stream = await _blob.GetAsync(containerName, blobName))
                using (var textReader = new StreamReader(stream))
                    using (var jsonReader = new JsonTextReader(textReader))
                    {
                        stream.Position = 0;

                        return(_blobJsonSerializer.Deserialize <TransactionExecutionBlobEntity>(jsonReader));
                    }
        }
Example #4
0
 public TransactionExecutionAggregate ToDomain([CanBeNull] TransactionExecutionBlobEntity blobData)
 {
     return(TransactionExecutionAggregate.Restore(
                ETag,
                State,
                Result,
                StartMoment,
                SourceAddressLockingMoment,
                BuildingMoment,
                SigningMoment,
                BroadcastingMoment,
                FinishMoment,
                SourceAddressReleaseMoment,
                ClearedMoment,
                BuildingFailureMoment,
                BroadcastinFailureMoment,
                WaitingForEndingStartMoment,
                WaitingForEndingFailureMoment,
                OperationId,
                TransactionId,
                TransactionNumber,
                BlockchainType,
                FromAddress,
                FromAddressContext,
                Outputs
                .Select(x => x.ToDomain())
                .ToArray(),
                AssetId,
                IncludeFee,
                blobData?.TransactionContext,
                BlockchainAssetId,
                blobData?.SignedTransaction,
                TransactionOutputs?
                .Select(o => o.ToDomain())
                .ToArray(),
                Block,
                Fee,
                Hash,
                Error));
 }