Пример #1
0
        public async Task <DepositWalletLock> LockAsync(
            DepositWalletKey key,
            decimal balance,
            long block,
            Func <Guid> operationIdFactory)
        {
            var partitionKey = DepositWalletLockEntity.GetPartitionKey(key);
            var rowKey       = DepositWalletLockEntity.GetRowKey(key);

            var entity = await _storage.GetOrInsertAsync
                         (
                partitionKey,
                rowKey,
                // ReSharper disable once ImplicitlyCapturedClosure
                () => DepositWalletLockEntity.Create
                (
                    key,
                    balance,
                    block,
                    operationIdFactory()
                )
                         );

            return(DepositWalletLock.Create(key, entity.OperationId, entity.Balance, entity.Block));
        }
        public async Task <OperationAggregate> GetOrInsert(Guid operationId, Func <OperationAggregate> factory)
        {
            var rowKey       = OperationEntity.GenerateRowKey();
            var partitionKey = OperationEntity.GeneratePartitionKey(operationId);

            return((await _storage.GetOrInsertAsync(partitionKey, rowKey, () => OperationEntity.FromDomain(factory())))
                   .ToDomain());
        }
Пример #3
0
        public async Task <Guid> GetOperationIdAsync(long depositId)
        {
            var entity = await _tableStorage.GetOrInsertAsync(OperationIdEntity.GetPk(depositId),
                                                              OperationIdEntity.GetRk(depositId),
                                                              () => OperationIdEntity.Create(depositId));

            return(Guid.Parse(entity.OperationId));
        }
        public async Task <string> GetKey(string clientId, string key)
        {
            var entity = await _tableStorage.GetOrInsertAsync(
                ClientKeysToBlobKeyEntity.GetPartitionKey(clientId),
                ClientKeysToBlobKeyEntity.GetRowKey(key),
                () => ClientKeysToBlobKeyEntity.Create(clientId, key, Guid.NewGuid().ToString()));

            return(entity.BlobKey);
        }
Пример #5
0
        public async Task <IOperationExecutionInfo <TData> > GetOrAddAsync <TData>(string operationName, string operationId,
                                                                                   Func <IOperationExecutionInfo <TData> > factory) where TData : class
        {
            var entity = await _tableStorage.GetOrInsertAsync(
                OperationExecutionInfoEntity.GeneratePartitionKey(operationName),
                OperationExecutionInfoEntity.GeneratePartitionKey(operationId),
                () => Convert(factory()));

            return(Convert <TData>(entity));
        }
        public async Task <bool> TryLockAsync(Guid owner)
        {
            var partition = GeneratePartitionKey();
            var row       = GenerateRowKey();

            return((await _storage.GetOrInsertAsync(partition, row, () => new DistriibutedLockEntity
            {
                PartitionKey = partition,
                RowKey = row,
                Owner = owner
            })).Owner == owner);
        }
Пример #7
0
        public async Task <bool> TryGetLockAsync(string blockchainType, string address, Guid transactionId)
        {
            var partitionKey = SourceAddressLockEntity.GetPartitionKey(blockchainType, address);
            var rowKey       = SourceAddressLockEntity.GetRowKey(address);

            var lockEntity = await _storage.GetOrInsertAsync(partitionKey, rowKey,
                                                             () => new SourceAddressLockEntity
            {
                PartitionKey       = partitionKey,
                RowKey             = rowKey,
                OwnerTransactionId = transactionId
            });

            return(lockEntity.OwnerTransactionId == transactionId);
        }
        public async Task <IOperationExecutionInfo <TData> > GetOrAddAsync <TData>(
            string operationName, string operationId, Func <IOperationExecutionInfo <TData> > factory) where TData : class
        {
            var entity = await _tableStorage.GetOrInsertAsync(
                partitionKey : OperationExecutionInfoEntity.GeneratePartitionKey(operationName),
                rowKey : OperationExecutionInfoEntity.GeneratePartitionKey(operationId),
                createNew : () =>
            {
                var result          = Convert(factory());
                result.LastModified = _systemClock.UtcNow.UtcDateTime;
                return(result);
            });

            return(Convert <TData>(entity));
        }
Пример #9
0
        public async Task <string> MapAsync(string clinetId, string requestId)
        {
            var id = Guid.NewGuid().ToString();

            var entity = await _tableStorage.GetOrInsertAsync(
                clinetId,
                requestId,
                () => new IdMappingEntity
            {
                PartitionKey = clinetId,
                RowKey       = requestId,
                Id           = id
            });

            return(entity.Id);
        }
Пример #10
0
        public async Task <Guid> GetOrStartTransactionAsync(Guid operationId, Func <Guid> newTransactionIdFactory)
        {
            var partitionKey = ActiveTransactionEntity.GetPartitionKey(operationId);
            var rowKey       = ActiveTransactionEntity.GetRowKey(operationId);

            var entity = await _storage.GetOrInsertAsync(
                partitionKey,
                rowKey,
                () => new ActiveTransactionEntity
            {
                PartitionKey  = partitionKey,
                RowKey        = rowKey,
                TransactionId = newTransactionIdFactory()
            });

            return(entity.TransactionId);
        }
        public async Task <CashoutRiskControlAggregate> GetOrAddAsync(Guid operationId, Func <CashoutRiskControlAggregate> newAggregateFactory)
        {
            var partitionKey = CashoutRiskControlEntity.GetPartitionKey(operationId);
            var rowKey       = CashoutRiskControlEntity.GetRowKey();

            var startedEntity = await _storage.GetOrInsertAsync(
                partitionKey,
                rowKey,
                () =>
            {
                var newAggregate = newAggregateFactory();

                return(CashoutRiskControlEntity.FromDomain(newAggregate));
            });

            return(startedEntity.ToDomain());
        }
        public async Task <bool> TryLockAsync(string assetId, Guid operationId, DateTime lockedAt)
        {
            var partitionKey = CashoutLockEntity.GetPartitionKey(assetId);
            var rowKey       = CashoutLockEntity.GetRowKey(assetId);

            var lockEntity = await _storage.GetOrInsertAsync(partitionKey, rowKey,
                                                             () => new CashoutLockEntity
            {
                PartitionKey = partitionKey,
                RowKey       = rowKey,
                OperationId  = operationId,
                AssetId      = assetId,
                LockedAt     = lockedAt
            });

            return(lockEntity?.OperationId == operationId);
        }
Пример #13
0
        public async Task <TAggregate> GetOrAddAsync(Guid aggregateId, Func <TAggregate> newAggregateFactory)
        {
            var partitionKey = AggregateKeysBuilder.BuildPartitionKey(aggregateId);
            var rowKey       = AggregateKeysBuilder.BuildRowKey(aggregateId);

            var startedEntity = await _storage.GetOrInsertAsync(
                partitionKey,
                rowKey,
                () =>
            {
                var newAggregate = newAggregateFactory();

                return(_mapAggregateToEntity(newAggregate));
            });

            return(await _mapEntityToAggregate(startedEntity));
        }
Пример #14
0
        public async Task <EthereumCashinAggregate> GetOrAddAsync(string trHash, Func <EthereumCashinAggregate> newAggregateFactory)
        {
            var partitionKey = EthereumCashinAggregateEntity.GetPartitionKey(trHash);
            var rowKey       = EthereumCashinAggregateEntity.GetRowKey(trHash);

            var startedEntity = await _storage.GetOrInsertAsync(
                partitionKey,
                rowKey,
                () =>
            {
                var newAggregate = newAggregateFactory();

                return(EthereumCashinAggregateEntity.FromDomain(newAggregate));
            });

            return(startedEntity.ToDomain());
        }
        public async Task <BlackListModel> GetOrAddAsync(string blockchainType, string blockedAddress, Func <BlackListModel> newAggregateFactory)
        {
            var partitionKey = BlackListEntity.GetPartitionKey(blockchainType);
            var rowKey       = BlackListEntity.GetRowKey(blockedAddress);

            var startedEntity = await _storage.GetOrInsertAsync(
                partitionKey,
                rowKey,
                () =>
            {
                var newAggregate = newAggregateFactory();

                return(BlackListEntity.FromDomain(newAggregate));
            });

            return(startedEntity.ToDomain());
        }
        public async Task <Guid> GetOrCreateCashInOutIdAsync(
            string clientId,
            string assetId)
        {
            var migration = await _migrations.GetOrInsertAsync
                            (
                clientId,
                assetId,
                () => new MigrationEntity
            {
                CashInOutId = Guid.NewGuid(),

                PartitionKey = clientId,
                RowKey       = assetId
            }
                            );

            return(migration.CashInOutId);
        }
        public async Task <CashinAggregate> GetOrAddAsync(
            string blockchainType,
            string depositWalletAddress,
            string blockchainAssetId,
            Guid operationId,
            Func <CashinAggregate> newAggregateFactory)
        {
            var partitionKey = CashinEntity.GetPartitionKey(operationId);
            var rowKey       = CashinEntity.GetRowKey(operationId);

            var startedEntity = await _storage.GetOrInsertAsync(
                partitionKey,
                rowKey,
                () =>
            {
                var newAggregate = newAggregateFactory();

                return(CashinEntity.FromDomain(newAggregate));
            });

            return(startedEntity.ToDomain());
        }
        public async Task <ActiveCashoutBatchId> GetActiveOrNextBatchId(string blockchainType, string blockchainAssetId, string hotWallet, Func <Guid> getNextId)
        {
            var partitionKey = ActiveCashoutsBatchIdEntity.GeneratePartitionKey(blockchainType);
            var rowKey       = ActiveCashoutsBatchIdEntity.GenerateRowKey(blockchainAssetId, hotWallet);

            var entity = await _storage.GetOrInsertAsync(
                partitionKey,
                rowKey,
                () =>
            {
                var id = getNextId();

                return(ActiveCashoutsBatchIdEntity.FromDomain
                       (
                           blockchainType,
                           blockchainAssetId,
                           hotWallet,
                           id
                       ));
            });

            return(entity.ToDomain());
        }