public async Task AddIfMissingMultipleAsync(IEnumerable <ITrade> trades)
        {
            if (trades == null || !trades.Any())
            {
                return;
            }

            var tradesToWrite = new List <ITrade>();

            foreach (var trade in trades)
            {
                if (await GetAsync(trade.Id) == null)
                {
                    tradesToWrite.Add(trade);
                }
            }

            if (!tradesToWrite.Any())
            {
                return;
            }

            var entities = tradesToWrite.Select(TradeLogEntity.Create).ToArray();

            await _tableStorage.InsertAsync(entities);

            await _idIndexStorage.InsertAsync(entities.Select(t => AzureIndex.Create(IndexId, t.Id, t.PartitionKey, t.RowKey)));
        }
Beispiel #2
0
        public async Task <Invoice> FindByIdAsync(string invoiceId)
        {
            string partitionKey;
            string rowKey = GetRowKey(invoiceId);

            if (!_partitionKeyByRowKey.TryGetValue(rowKey, out partitionKey))
            {
                AzureIndex index =
                    await _invoiceIdIndexStorage.GetDataAsync(GetInvoiceIdIndexPartitionKey(invoiceId), GetInvoiceIdIndexRowKey());

                if (index == null)
                {
                    return(null);
                }

                partitionKey = index.PrimaryPartitionKey;
                _partitionKeyByRowKey.TryAdd(rowKey, partitionKey);
            }

            InvoiceEntity entity = await _storage.GetDataAsync(partitionKey, rowKey);

            var invoice = Mapper.Map <Invoice>(entity);

            return(invoice);
        }
Beispiel #3
0
        public async Task <Core.Domain.ResetPasswordAccessToken> UpdateAsync(Core.Domain.ResetPasswordAccessToken src)
        {
            AzureIndex index = await _indexByPublicIdStorage.GetDataAsync(
                ResetPasswordAccessTokenEntity.IndexByPublicId.GeneratePartitionKey(src.PublicId),
                ResetPasswordAccessTokenEntity.IndexByPublicId.GenerateRowKey());

            if (index == null)
            {
                throw new KeyNotFoundException();
            }

            ResetPasswordAccessTokenEntity updatedEntity = await _storage.MergeAsync(
                ResetPasswordAccessTokenEntity.ByEmployeeId.GeneratePartitionKey(index.PrimaryPartitionKey),
                ResetPasswordAccessTokenEntity.ByEmployeeId.GenerateRowKey(index.PrimaryRowKey),
                entity =>
            {
                entity.Redeemed = src.Redeemed;

                return(entity);
            });

            if (updatedEntity == null)
            {
                throw new KeyNotFoundException();
            }

            return(Mapper.Map <Core.Domain.ResetPasswordAccessToken>(updatedEntity));
        }
        public async Task UpdateBlockChainHashAsync(string clientId, string id, string blockChainHash)
        {
            var partitionKey = TransferEventEntity.ByClientId.GeneratePartitionKey(clientId);
            var rowKey       = TransferEventEntity.ByClientId.GenerateRowKey(id);

            var item = await _tableStorage.GetDataAsync(partitionKey, rowKey);

            if (item.State == TransactionStates.SettledOffchain || item.State == TransactionStates.InProcessOffchain)
            {
                return;
            }

            item.BlockChainHash = blockChainHash;

            var multisigPartitionKey = TransferEventEntity.ByMultisig.GeneratePartitionKey(item.Multisig);
            var multisigRowKey       = TransferEventEntity.ByMultisig.GenerateRowKey(id);

            var multisigItem = await _tableStorage.GetDataAsync(multisigPartitionKey, multisigRowKey);

            multisigItem.BlockChainHash = blockChainHash;
            multisigItem.State          = TransactionStates.SettledOnchain;

            var indexEntity = AzureIndex.Create(blockChainHash, rowKey, partitionKey, rowKey);
            await _blockChainHashIndices.InsertOrReplaceAsync(indexEntity);

            await _tableStorage.InsertOrReplaceAsync(item);

            await _tableStorage.InsertOrReplaceAsync(multisigItem);
        }
        public async Task UpdateBlockchainHashAsync(string clientId, string id, string hash)
        {
            var partitionkey = CashInOutOperationEntity.ByClientId.GeneratePartitionKey(clientId);
            var rowKey       = CashInOutOperationEntity.ByClientId.GenerateRowKey(id);

            var record = await _tableStorage.GetDataAsync(partitionkey, rowKey);

            var multisigPartitionkey = CashInOutOperationEntity.ByMultisig.GeneratePartitionKey(record.Multisig);
            var multisigRowKey       = CashInOutOperationEntity.ByMultisig.GenerateRowKey(id);

            var indexEntity = AzureIndex.Create(hash, rowKey, partitionkey, rowKey);
            await _blockChainHashIndices.InsertOrReplaceAsync(indexEntity);

            await _tableStorage.MergeAsync(partitionkey, rowKey, entity =>
            {
                entity.BlockChainHash = hash;
                entity.State          = TransactionStates.SettledOnchain;
                return(entity);
            });

            await _tableStorage.MergeAsync(multisigPartitionkey, multisigRowKey, entity =>
            {
                entity.BlockChainHash = hash;
                entity.State          = TransactionStates.SettledOnchain;
                return(entity);
            });
        }
        public async Task <IHistoryOperation> GetAsync(string id)
        {
            AzureIndex index =
                await _indexById.GetDataAsync(IndexById.GeneratePartitionKey(id), IndexById.GenerateRowKey());

            return(await _storage.GetDataAsync(index));
        }
Beispiel #7
0
        private async Task UpdateIndexes(InventorySnapshotEntity inventorySnapshotEntity)
        {
            var existingIndex = await _indexStorage.GetDataAsync(GetIndexPartitionKey(inventorySnapshotEntity.Time),
                                                                 IndexForLastRowKey);

            if (existingIndex == null || (await _storage.GetDataAsync(existingIndex)).Time < inventorySnapshotEntity.Time)
            {
                // Update index for current day, it now must point to this the last received snapshot
                await _indexStorage.InsertOrReplaceAsync(
                    AzureIndex.Create(GetIndexPartitionKey(inventorySnapshotEntity.Time), IndexForLastRowKey,
                                      inventorySnapshotEntity));
            }

            // If we have index entries for any future date, they are now are invalid, we can just remove them,
            // as they will be reconstructed if needed

            var filter = TableQuery.GenerateFilterCondition(nameof(AzureIndex.PartitionKey),
                                                            QueryComparisons.GreaterThan,
                                                            GetIndexPartitionKey(inventorySnapshotEntity.Time));

            var query = new TableQuery <AzureIndex>().Where(filter);

            var allNowInvalidIndexEntriesFromTheFuture = (await _indexStorage.WhereAsync(query)).ToList();

            foreach (var indexEntity in allNowInvalidIndexEntriesFromTheFuture)
            {
                await _indexStorage.DeleteAsync(indexEntity);
            }
        }
Beispiel #8
0
        public async Task InsertAsync(IBlockSyncedByHash block)
        {
            var entity = BlockSyncedByHashEntity.CreateEntity(block);
            var index  = new AzureIndex(_lastSyncedPartition, block.Partition, entity);
            await _table.InsertOrReplaceAsync(entity);

            await _index.InsertOrReplaceAsync(index);
        }
Beispiel #9
0
        public async Task InsertOrReplace(IPendingTransaction pendingTransactions)
        {
            var        entity = PendingTransactionEntity.CreateEntity(pendingTransactions);
            AzureIndex index  = new AzureIndex(_indexName, pendingTransactions.TransactionHash, entity);
            await _table.InsertOrReplaceAsync(entity);

            await _index.InsertOrReplaceAsync(index);
        }
        public async Task InsertAsync(IBlockSynced block)
        {
            var entity = BlockSyncedEntity.CreateEntity(block);
            var index  = new AzureIndex(_lastSyncedPartition, block.CoinAdapterAddress, entity);
            await _table.InsertOrReplaceAsync(entity);

            await _index.InsertOrReplaceAsync(index);
        }
        public async Task InsertOrReplace(ICoinEvent coinEvent)
        {
            var entity = CoinEventEntity.CreateEntity(coinEvent);
            var index  = new AzureIndex(_operationIdIndex, coinEvent.OperationId, entity);

            await _table.InsertOrReplaceAsync(entity);

            await _index.InsertOrReplaceAsync(index);
        }
        public async Task InsertOrReplace(ICoin coin)
        {
            var entity = CoinEntity.CreateCoinEntity(coin);
            var index  = AzureIndex.Create(_addressIndexName, coin.AdapterAddress, entity);

            await _table.InsertOrReplaceAsync(entity);

            await _addressIndex.InsertAsync(index);
        }
        public async Task <IMerchant> FindEmailAsync(string email)
        {
            AzureIndex index = await _emailIndexStorage.GetDataAsync(
                MerchantEntity.IndexByEmail.GeneratePartitionKey(email),
                MerchantEntity.IndexByEmail.GenerateRowKey());

            MerchantEntity entity = await _storage.GetDataAsync(index);

            return(Mapper.Map <Merchant>(entity));
        }
        public async Task <string> AddAsync(SmsMessage message)
        {
            var entity = SmsMessageEntity.Create(message);
            await _tableStorage.TryInsertAsync(entity);

            var indexEntity = AzureIndex.Create(IdIndex, entity.Id, entity);
            await _index.InsertAsync(indexEntity);

            return(entity.Id);
        }
Beispiel #15
0
        public async Task CancelDisputeAsync(string invoiceId)
        {
            AzureIndex index = await _invoiceIdIndexStorage.GetDataAsync(GetInvoiceIdIndexPartitionKey(invoiceId), GetInvoiceIdIndexRowKey());

            await _storage.MergeAsync(index.PrimaryPartitionKey, index.PrimaryRowKey, entity =>
            {
                entity.Dispute = false;
                return(entity);
            });
        }
Beispiel #16
0
        public Task AddLogAsync <T>(string author, string entityId, string entityName, string change) where T : class
        {
            var entity      = AuditLogEntity.Create <T>(author, entityId, entityName, change);
            var authorIndex = AzureIndex.Create(AuditLogEntity.GenerateAuthorIndexPk(author), Guid.NewGuid().ToString(), entity.PartitionKey, entity.RowKey);

            return(Task.WhenAll(
                       _tableStorage.InsertOrMergeAsync(entity),
                       _authorIndex.InsertOrMergeAsync(authorIndex)
                       ));
        }
Beispiel #17
0
        private async Task InsertPaymentRequestIdIndexAsync(InvoiceEntity entity)
        {
            if (string.IsNullOrEmpty(entity.PaymentRequestId))
            {
                return;
            }

            var index = AzureIndex.Create(GetPaymentRequestIndexPartitionKey(entity.PaymentRequestId), GetPaymentRequestIndexRowKey(), entity);

            await _paymentRequestIdIndexStorage.InsertOrReplaceAsync(index);
        }
Beispiel #18
0
        public async Task <IClientAccount> RegisterAsync(IClientAccount clientAccount, string password)
        {
            var newEntity   = ClientAccountEntity.CreateNew(clientAccount, password);
            var indexEntity = AzureIndex.Create(IndexEmail, newEntity.Email, newEntity);

            await _emailIndices.InsertAsync(indexEntity);

            await _clientsTablestorage.InsertAsync(newEntity);

            return(newEntity);
        }
        public async Task AddAsync(string clientId, AccountTier tier, KycStatus status, string comment = null, DateTime?date = null)
        {
            var item = TierUpgradeRequestEntity.Create(clientId, tier, status, comment, date);
            await _tableStorage.InsertOrReplaceAsync(item);

            if (status == KycStatus.Pending)
            {
                var indexEntity = AzureIndex.Create(PendingRequestsIndex, GetPendingRequestIndexRk(clientId, tier), item);
                await _index.InsertOrMergeAsync(indexEntity);
            }
        }
Beispiel #20
0
        private async Task <AzureIndex> CreateIndexForLastEntry(DateTime date, IEnumerable <InventorySnapshotEntity> snapshotsFromTheDay, bool getFirst = false)
        {
            var lastFromTheDay = getFirst
                ? snapshotsFromTheDay.OrderBy(x => x.Time).First()
                : snapshotsFromTheDay.OrderBy(x => x.Time).Last();

            var index = AzureIndex.Create(GetIndexPartitionKey(date), IndexForLastRowKey, lastFromTheDay);

            await _indexStorage.InsertOrReplaceAsync(index);

            return(index);
        }
        public async Task InsertAsync(Position position)
        {
            var entity = new PositionEntity(GetPartitionKey(position.Date), GetRowKey(position.Id));

            Mapper.Map(position, entity);

            await _storage.InsertAsync(entity);

            AzureIndex index = new AzureIndex(GetIndexPartitionKey(position.Id), GetIndexRowKey(position.Id), entity);

            await _indicesStorage.InsertAsync(index);
        }
        public async Task <ISupervisorMembership> AddAsync(ISupervisorMembership src)
        {
            SupervisorMembershipEntity entity = SupervisorMembershipEntity.ByMerchant.Create(src);

            await _tableStorage.InsertThrowConflict(entity);

            AzureIndex index = SupervisorMembershipEntity.IndexByEmployee.Create(entity);

            await _employeeIndexStorage.InsertThrowConflict(index);

            return(Mapper.Map <Core.Domain.SupervisorMembership.SupervisorMembership>(entity));
        }
Beispiel #23
0
        public async Task InsertAsync(Order order)
        {
            var entity = new OrderEntity(GetPartitionKey(order.WalletId), GetRowKey(order.Id));

            Mapper.Map(order, entity);

            await _storage.InsertThrowConflictAsync(entity);

            var index = new AzureIndex(GetIndexPartitionKey(order.Status), GetIndexRowKey(order.Id), entity);

            await _indices.InsertAsync(index);
        }
Beispiel #24
0
        public async Task <Core.Domain.Transfer.Transfer> AddAsync(ITransfer transfer)
        {
            TransferEntity entity = TransferEntity.ByDate.Create(transfer);

            await _storage.InsertAsync(entity);

            AzureIndex indexById = TransferEntity.IndexById.Create(entity);

            await _transferIdIndexStorage.InsertAsync(indexById);

            return(Mapper.Map <Core.Domain.Transfer.Transfer>(entity));
        }
Beispiel #25
0
        public async Task <Core.Domain.ResetPasswordAccessToken> CreateAsync(Core.Domain.ResetPasswordAccessToken token)
        {
            ResetPasswordAccessTokenEntity entity = ResetPasswordAccessTokenEntity.ByEmployeeId.Create(token);

            await _storage.InsertThrowConflict(entity);

            AzureIndex index = ResetPasswordAccessTokenEntity.IndexByPublicId.Create(entity);

            await _indexByPublicIdStorage.InsertThrowConflict(index);

            return(Mapper.Map <Core.Domain.ResetPasswordAccessToken>(entity));
        }
        public async Task <IMerchantGroup> CreateAsync(IMerchantGroup src)
        {
            MerchantGroupEntity entity = MerchantGroupEntity.ByOwner.Create(src);

            await _tableStorage.InsertThrowConflict(entity);

            AzureIndex index = MerchantGroupEntity.IndexById.Create(entity);

            await _groupIndexStorage.InsertThrowConflict(index);

            return(Mapper.Map <MerchantGroup>(entity));
        }
Beispiel #27
0
        public async Task <IMarkup> SetAsync(IMarkup markup)
        {
            MarkupEntity entity = MarkupEntity.ByAssetPair.Create(markup);

            await _tableStorage.InsertOrReplaceAsync(entity);

            AzureIndex index = MarkupEntity.IndexByIdentity.Create(entity);

            await _indexByIdentity.InsertOrReplaceAsync(index);

            return(Mapper.Map <Core.Domain.Markup.Markup>(entity));
        }
        public async Task <ICoin> GetCoinByAddress(string coinAddress)
        {
            AzureIndex index = await _addressIndex.GetDataAsync(_addressIndexName, coinAddress);

            if (index == null)
            {
                return(null);
            }
            var coin = await _table.GetDataAsync(index);

            return(coin);
        }
Beispiel #29
0
        public async Task InsertAsync(InternalTrade internalTrade)
        {
            var entity = new InternalTradeEntity(GetPartitionKey(internalTrade.Time), GetRowKey(internalTrade.Id));

            Mapper.Map(internalTrade, entity);

            await _storage.InsertOrReplaceAsync(entity);

            AzureIndex index = new AzureIndex(GetIndexPartitionKey(internalTrade.Id), GetRowKey(internalTrade.Id),
                                              entity);

            await _indicesStorage.InsertOrReplaceAsync(index);
        }
        public async Task InsertAsync(string parentId, ExternalLimitOrder externalLimitOrder)
        {
            var entity = new ExternalLimitOrderEntity(GetPartitionKey(externalLimitOrder.Id),
                                                      GetRowKey(externalLimitOrder.Id));

            Mapper.Map(externalLimitOrder, entity);

            await _storage.InsertAsync(entity);

            var index = new AzureIndex(GetIndexPartitionKey(parentId), GetIndexRowKey(externalLimitOrder.Id), entity);

            await _indices.InsertAsync(index);
        }