public async Task AddAsync(SmsProvider provider, string countryCode, SmsDeliveryStatus status)
        {
            var entity = await _tableStorage.GetDataAsync(SmsProviderInfoEntity.GeneratePartitionKey(provider),
                                                          SmsProviderInfoEntity.GenerateRowKey(countryCode));

            if (entity == null)
            {
                entity = SmsProviderInfoEntity.Create(provider, countryCode, status);
                await _tableStorage.TryInsertAsync(entity);
            }
            else
            {
                await _tableStorage.MergeAsync(SmsProviderInfoEntity.GeneratePartitionKey(provider), SmsProviderInfoEntity.GenerateRowKey(countryCode),
                                               infoEntity =>
                {
                    switch (status)
                    {
                    case SmsDeliveryStatus.Delivered:
                        infoEntity.DeliveredCount++;
                        break;

                    case SmsDeliveryStatus.Failed:
                        infoEntity.DeliveryFailedCount++;
                        break;

                    case SmsDeliveryStatus.Unknown:
                        infoEntity.UnknownCount++;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(status), status, null);
                    }

                    return(infoEntity);
                });
            }
        }
예제 #2
0
        public static async Task <IEnumerable <T> > GetDataAsync <T>(this INoSQLTableStorage <T> tableStorage,
                                                                     IEnumerable <IAzureIndex> indices, int pieces = 15, Func <T, bool> filter = null) where T : ITableEntity, new()
        {
            var idx = indices.ToArray();

            if (idx.Length == 0)
            {
                return(new T[0]);
            }

            var partitionKey = idx.First().PrimaryPartitionKey;
            var rowKeys      = idx.Select(itm => itm.PrimaryRowKey).ToArray();

            return(await tableStorage.GetDataAsync(partitionKey, rowKeys, pieces, filter));
        }
        public async Task <ISupervisorMembership> GetAsync(string employeeId)
        {
            AzureIndex index = await _employeeIndexStorage.GetDataAsync(
                SupervisorMembershipEntity.IndexByEmployee.GeneratePartitionKey(employeeId),
                SupervisorMembershipEntity.IndexByEmployee.GenerateRowKey());

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

            var entity = await _tableStorage.GetDataAsync(index);

            return(Mapper.Map <Core.Domain.SupervisorMembership.SupervisorMembership>(entity));
        }
예제 #4
0
        public async Task <IVirtualWallet> FindAsync(string walletId)
        {
            AzureIndex index = await _walletIdIndexStorage.GetDataAsync(
                VirtualWalletEntity.IndexByWalletId.GeneratePartitionKey(walletId),
                VirtualWalletEntity.IndexByWalletId.GenerateRowKey());

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

            VirtualWalletEntity entity = await _tableStorage.GetDataAsync(index);

            return(Mapper.Map <VirtualWallet>(entity));
        }
예제 #5
0
        public async Task <Core.Domain.ResetPasswordAccessToken> GetByPublicIdAsync(string publicId)
        {
            AzureIndex index = await _indexByPublicIdStorage.GetDataAsync(
                ResetPasswordAccessTokenEntity.IndexByPublicId.GeneratePartitionKey(publicId),
                ResetPasswordAccessTokenEntity.IndexByPublicId.GenerateRowKey());

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

            ResetPasswordAccessTokenEntity entity = await _storage.GetDataAsync(index);

            return(Mapper.Map <Core.Domain.ResetPasswordAccessToken>(entity));
        }
예제 #6
0
        public async Task <IMerchantWallet> GetByAddressAsync(BlockchainType network, string walletAddress)
        {
            AzureIndex index = await _indexByAddressStorage.GetDataAsync(
                MerchantWalletEntity.IndexByAddress.GeneratePartitionKey(network, walletAddress),
                MerchantWalletEntity.IndexByAddress.GenerateRowKey());

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

            MerchantWalletEntity entity = await _tableStorage.GetDataAsync(index);

            return(Mapper.Map <Core.Domain.MerchantWallet.MerchantWallet>(entity));
        }
예제 #7
0
        public async Task <IPaymentRequest> FindAsync(string walletAddress)
        {
            AzureIndex index = await _walletAddressIndexStorage.GetDataAsync(
                PaymentRequestEntity.IndexByWallet.GeneratePartitionKey(walletAddress),
                PaymentRequestEntity.IndexByWallet.GenerateRowKey());

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

            PaymentRequestEntity entity = await _storage.GetDataAsync(index);

            return(Mapper.Map <Core.Domain.PaymentRequests.PaymentRequest>(entity));
        }
예제 #8
0
        public async Task ShouldSaveQuotes()
        {
            var quotes = new[]
            {
                _rur, _usd
            };

            await _repository.SaveAsync(quotes);

            var stored = await _storage.GetDataAsync();

            Assert.That(stored.Count, Is.EqualTo(2));
            Assert.That(stored.Count(s => s.Id == _rur.AssetPair), Is.EqualTo(1));
            Assert.That(stored.Count(s => s.Id == _usd.AssetPair), Is.EqualTo(1));
        }
예제 #9
0
        public async Task <IEnumerable <ILogItem> > GetRange(DateTime dateFrom, DateTime dateTo, string clientId)
        {
            DateTime startDate   = dateFrom.Date;
            DateTime endDate     = dateTo.Date.AddDays(1);
            DateTime currentDate = startDate;

            List <LogEntity> retval = new List <LogEntity>();

            do
            {
                string partitionKey = LogEntity.GetPartitionKey(clientId, currentDate);
                var    entities     = (await _storage.GetDataAsync(new[] { partitionKey }, int.MaxValue))
                                      .OrderByDescending(item => item.Timestamp);
                retval.AddRange(entities);

                currentDate = currentDate.AddDays(1);
            } while (currentDate < endDate);

            //var entities = (await _storage.GetDataAsync(new[] { clientId }, int.MaxValue,
            //        entity => entity.Timestamp >= dateFrom && entity.Timestamp < dateTo))
            //    .OrderByDescending(item => item.Timestamp);

            return(retval.Select(LogEntity.CreateDto));
        }
예제 #10
0
        public async Task <Core.Domain.Transfer.Transfer> GetAsync(string id)
        {
            AzureIndex index = await _transferIdIndexStorage.GetDataAsync(
                TransferEntity.IndexById.GeneratePartitionKey(id),
                TransferEntity.IndexById.GenerateRowKey());

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

            TransferEntity entity = await _storage.GetDataAsync(index);

            return(Mapper.Map <Core.Domain.Transfer.Transfer>(entity));
        }
예제 #11
0
        public async Task <IClientAccount> AuthenticateAsync(string email, string password)
        {
            if (email == null || password == null)
            {
                return(null);
            }

            var indexEntity = await _emailIndices.GetDataAsync(IndexEmail, email.ToLower());

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

            var entity = await _clientsTablestorage.GetDataAsync(indexEntity);

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


            return(entity.CheckPassword(password) ? entity : null);
        }
예제 #12
0
        public async Task <DistributionPlanAggregate> TryGetAsync(
            Guid planId)
        {
            var indexEntity = await _distributionPlanIndexTable.GetDataAsync
                              (
                partition : GetIndexPartitionKey(planId),
                row : GetIndexRowKey()
                              );

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

            var planEntity = await _distributionPlanTable.GetDataAsync
                             (
                partition : indexEntity.PrimaryPartitionKey,
                row : indexEntity.PrimaryRowKey
                             );

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

            var amountEntities     = new List <DistributionAmountEntity>();
            var amountPartitionKey = GetAmountPartitionKey(planEntity.PlanTimestamp);
            var continuationToken  = (string)null;

            do
            {
                IEnumerable <DistributionAmountEntity> entities;

                (entities, continuationToken) = await _distributionAmountTable
                                                .GetDataWithContinuationTokenAsync(amountPartitionKey, 1000, continuationToken);

                amountEntities.AddRange(entities);
            } while (continuationToken != null);

            return(DistributionPlanAggregate.Restore
                   (
                       planEntity.PlanId,
                       planEntity.PlanTimestamp,
                       amountEntities
                       .Select(x => DistributionPlanAggregate.Amount.Restore(walletId: x.WalletId, amountId: x.AmountId, value: x.AmountValue))
                       .ToArray()
                   ));
        }
예제 #13
0
        public async Task <TxBuild> GetAsync(Guid operationId)
        {
            var entity = await _table.GetDataAsync(GetPartitionKey(), GetRowKey(operationId));

            if (entity != null)
            {
                return(new TxBuild
                {
                    OperationId = entity.OperationId,
                    Timestamp = entity.Timestamp,
                    XdrBase64 = entity.XdrBase64
                });
            }

            return(null);
        }
예제 #14
0
        public async Task <Employee> FindAsync(string email)
        {
            AzureIndex index =
                await _indexStorage.GetDataAsync(GetEmailIndexPartitionKey(), GetEmailIndexRowKey(email));

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

            EmployeeEntity entity = await _storage.GetDataAsync(index);

            var employee = Mapper.Map <Employee>(entity);

            return(employee);
        }
예제 #15
0
        public async Task <Invoice> FindByPaymentRequestIdAsync(string paymentRequestId)
        {
            AzureIndex index =
                await _paymentRequestIdIndexStorage.GetDataAsync(GetPaymentRequestIndexPartitionKey(paymentRequestId), GetPaymentRequestIndexRowKey());

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

            InvoiceEntity entity = await _storage.GetDataAsync(index);

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

            return(invoice);
        }
예제 #16
0
        public async Task <IEnumerable <IClientAccount> > GetByEmailAsync(string email)
        {
            if (string.IsNullOrEmpty(email))
            {
                return(null);
            }

            IEnumerable <ClientPartnerRelationEntity> relations =
                await _clientPartnerTablestorage.GetDataAsync(ClientPartnerRelationEntity.GeneratePartitionKey(email));

            IEnumerable <string> rowKeys = relations.Select(x => x.ClientId);

            return((await _clientsTablestorage.GetDataAsync(ClientAccountEntity.GeneratePartitionKey(), rowKeys))
                   .Append(await _clientsTablestorage.GetDataAsync(_emailIndices, IndexEmail, GetEmailPartnerIndexRowKey(email, null)))
                   .Except(new ClientAccountEntity[] { null }, ClientAccountEntity.ComparerById)
                   .Distinct(ClientAccountEntity.ComparerById).ToArray());
        }
예제 #17
0
        private static async Task DeleteCodesInRepository <T>(string partnerId, string phoneNum,
                                                              INoSQLTableStorage <T> storage) where T : ITableEntity, new()
        {
            var batchOperation   = new TableBatchOperation();
            var entitiesToDelete =
                (await storage.GetDataAsync(SmsVerificationCodeEntity.GeneratePartitionKey(partnerId, phoneNum)))
                .ToArray();

            if (entitiesToDelete.Any())
            {
                foreach (var e in entitiesToDelete)
                {
                    batchOperation.Delete(e);
                }
                await storage.DoBatchAsync(batchOperation);
            }
        }
        private async Task CheckIsEncrypted(TestEntity entity)
        {
            var plain = await Storage.GetDataAsync(entity.PartitionKey, entity.RowKey);

            var encrypted = await _innerStorage.GetDataAsync(entity.PartitionKey, entity.RowKey);

            Assert.IsTrue(_cryptoSerializer.IsEncrypted(encrypted.PropertyAsEncrypted));
            Assert.AreEqual(plain.PropertyAsEncrypted, _cryptoSerializer.Deserialize(encrypted.PropertyAsEncrypted));

            Assert.IsFalse(_cryptoSerializer.IsEncrypted(encrypted.PlainProperty));
            Assert.AreEqual(plain.PlainProperty, encrypted.PlainProperty);

            if (plain.SecondPropertyAsEncrypted != null)
            {
                Assert.IsTrue(_cryptoSerializer.IsEncrypted(encrypted.SecondPropertyAsEncrypted));
                Assert.AreEqual(plain.SecondPropertyAsEncrypted, _cryptoSerializer.Deserialize(encrypted.SecondPropertyAsEncrypted));
            }
        }
예제 #19
0
        public static async Task <T> GetFirstOrDefaultAsync <T>(this INoSQLTableStorage <AzureMultiIndex> indexTable, string partitionKey, string rowKey, INoSQLTableStorage <T> dataTable) where T : class, ITableEntity, new()
        {
            var indexEntity = await indexTable.GetDataAsync(partitionKey, rowKey);

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

            var indices = indexEntity.GetData();

            if (indices.Length == 0)
            {
                return(null);
            }

            return(await dataTable.GetDataAsync(indices[0].Pk, indices[0].Rk));
        }
예제 #20
0
        public async Task <IEnumerable <IBestBidAsk> > GetRange(DateTime dateFrom, DateTime dateTo, string assetPair)
        {
            DateTime currentDate           = dateFrom.Date;
            List <BestBidAskEntity> retval = new List <BestBidAskEntity>();

            do
            {
                string PartitionKey = string.Format("{0}_{1}", assetPair, currentDate.ToString("yyyyMMdd_HH"));

                var entities = (await _storage.GetDataAsync(new[] { PartitionKey }, int.MaxValue))
                               .OrderByDescending(item => item.Timestamp);
                retval.AddRange(entities);
                // Next partition key (hours)
                currentDate = currentDate.AddHours(1);
            } while (currentDate < dateTo.Date.AddDays(1));

            return(retval.Select(BestBidAskEntity.CreateDto));
        }
예제 #21
0
        public async Task <IEnumerable <IAuditLog> > GetLogsAsync(AuditLogsQuery query)
        {
            IEnumerable <IAuditLog> logs;

            if (!string.IsNullOrEmpty(query.Author))
            {
                var authorIndexes = await _authorIndex.GetDataAsync(AuditLogEntity.GenerateAuthorIndexPk(query.Author));

                logs = (await _tableStorage.GetDataAsync(authorIndexes))
                       .Where(entity => entity.PartitionKey == AuditLogEntity.GenerateTypePk(query.Type));
            }
            else
            {
                logs = await _tableStorage.GetDataAsync(AuditLogEntity.GenerateTypePk(query.Type));
            }

            return(logs.Where(item => (!query.StartDate.HasValue || item.CreateDate >= query.StartDate) && (!query.EndDate.HasValue || item.CreateDate <= query.EndDate)));
        }
예제 #22
0
        public async Task <Transaction> TryGetAsync(
            Guid transactionId)
        {
            var(partitionKey, rowKey) = GetTransactionKeys(transactionId);

            var transactionEntity = await _transactions.GetDataAsync
                                    (
                partition : partitionKey,
                row : rowKey
                                    );

            if (transactionEntity != null)
            {
                return(new Transaction
                       (
                           amount: transactionEntity.Amount,
                           blockNumber: transactionEntity.BlockNumber,
                           broadcastedOn: transactionEntity.BroadcastedOn,
                           builtOn: transactionEntity.BuiltOn,
                           completedOn: transactionEntity.CompletedOn,
                           confirmationLevel: transactionEntity.ConfirmationLevel,
                           confirmedOn: transactionEntity.ConfirmedOn,
                           data: transactionEntity.Data,
                           deletedOn: transactionEntity.DeletedOn,
                           error: transactionEntity.Error,
                           from: transactionEntity.From,
                           gasAmount: transactionEntity.GasAmount,
                           gasPrice: transactionEntity.GasPrice,
                           hash: transactionEntity.Hash,
                           includeFee: transactionEntity.IncludeFee,
                           isConfirmed: transactionEntity.IsConfirmed,
                           nonce: transactionEntity.Nonce,
                           signedData: transactionEntity.SignedData,
                           state: transactionEntity.State,
                           to: transactionEntity.To,
                           transactionId: transactionEntity.TransactionId
                       ));
            }
            else
            {
                return(null);
            }
        }
예제 #23
0
        public async Task Delete(string transactionHash)
        {
            AzureIndex index = await _index.GetDataAsync(_indexName, transactionHash);

            if (index == null)
            {
                return;
            }

            IPendingTransaction transaction = await _table.GetDataAsync(index);

            if (transaction == null)
            {
                return;
            }
            await _table.DeleteIfExistAsync(PendingTransactionEntity.GeneratePartitionKey(transaction.CoinAdapterAddress), transaction.UserAddress);

            await _table.DeleteIfExistAsync(_indexName, index.RowKey);
        }
        public async Task <WalletDto> TryGetAsync(string blockchainType, string address)
        {
            var(indexPartitionKey, indexRowKey) = GetAddressIndexKeys(blockchainType, address);

            var index = await _addressIndexTable.GetDataAsync
                        (
                partition : indexPartitionKey,
                row : indexRowKey
                        );

            if (index != null)
            {
                var entity = await _walletsTable.GetDataAsync(index.PrimaryPartitionKey, index.PrimaryRowKey);

                return(entity != null
                    ? ConvertEntityToDto(entity)
                    : null);
            }

            return(null);
        }
예제 #25
0
        public async Task <IEnumerable <IUserHistoryItem> > GetUserHistory(string userId, DateTime dateFrom, DateTime dateTo)
        {
            DateTime startDate   = dateFrom.Date;
            DateTime endDate     = dateTo.Date.AddDays(1);
            DateTime currentDate = startDate;

            List <UserHistoryEntity> retval = new List <UserHistoryEntity>();

            do
            {
                string partitionKey = UserHistoryEntity.GetPartitionKey(userId, currentDate);
                var    entities     = (await _hstorage.GetDataAsync(new[] { partitionKey }, int.MaxValue))
                                      .OrderByDescending(item => item.Timestamp);
                retval.AddRange(entities);

                currentDate = currentDate.AddDays(1);
            } while (currentDate < endDate);


            return(retval.Select(UserHistoryEntity.CreateDto));
        }
        public async Task RemoveOutputsAsync(IEnumerable <IOutput> outputs)
        {
            foreach (var output in outputs)
            {
                var index = await _indexByTransactionHash.GetDataAsync(
                    IndexByTransactionHash.GeneratePartitionKey(output.TransactionHash),
                    IndexByTransactionHash.GenerateRowKey(output.N));

                if (index != null)
                {
                    var entity = await _storage.DeleteAsync(index);

                    if (entity != null)
                    {
                        await _indexByAddress.DeleteAsync(IndexByAddress.GeneratePartitionKey(entity.Address),
                                                          IndexByAddress.GenerateRowKey(entity.TransactionHash, entity.N));
                    }
                    await _indexByTransactionHash.DeleteAsync(index);
                }
            }
        }
예제 #27
0
        public async Task <string> GetUser(string lykkeUserId, bool createIfNotExists = true)
        {
            if (string.IsNullOrEmpty(lykkeUserId))
            {
                throw new ArgumentNullException(nameof(lykkeUserId));
            }
            var result = await _repository.GetDataAsync(ProxyUser.GetPartitionKey(), lykkeUserId);

            if (result == null && createIfNotExists)
            {
                result = new ProxyUser
                {
                    PartitionKey = ProxyUser.GetPartitionKey(),
                    LykkeUserId  = lykkeUserId,
                    UserId       = Guid.NewGuid().ToString()
                };
                await _repository.InsertOrMergeAsync(result);
            }

            return(result?.UserId);
        }
예제 #28
0
        public async Task <IGasPrice> GetAsync()
        {
            var entity = await _table.GetDataAsync(PartitionKey, RowKey);

            if (entity != null)
            {
                return(new GasPrice
                {
                    Max = BigInteger.Parse(entity.Max),
                    Min = BigInteger.Parse(entity.Min)
                });
            }
            else
            {
                return(new GasPrice
                {
                    Max = 120000000000,
                    Min = 100000000000
                });
            }
        }
예제 #29
0
        public async Task <bool> IsEmailRegistered(string email)
        {
            if (IsEmailRegisteredFromCache(email))
            {
                return(true);
            }

            var patitionKey = Lkk2YOrderMadeIndexEntity.GeneratePartitionKey();
            var rowKey      = Lkk2YOrderMadeIndexEntity.GenerateRowKey(email);


            var entity = await _tableStorageOrderIndex.GetDataAsync(patitionKey, rowKey);

            var result = entity != null;

            if (result)
            {
                AddToCache(email);
            }

            return(result);
        }
        public async Task ClearBlockAsync(
            BigInteger blockNumber)
        {
            var byBlockIndexPartitionKey = GetByBlockIndexPartitionKey(blockNumber);
            var receiptsInBlock          = await _byBlockIndices.GetDataAsync(byBlockIndexPartitionKey);

            foreach (var receiptInBlock in receiptsInBlock)
            {
                var receiptEntity = await _transactionReceipts.GetDataAsync
                                    (
                    partition : receiptInBlock.PrimaryPartitionKey,
                    row : receiptInBlock.PrimaryRowKey
                                    );

                if (receiptEntity != null)
                {
                    var byFromIndexKeys = GetByFromIndexKeys(receiptEntity);
                    var byToIndexKeys   = GetByToIndexKeys(receiptEntity);

                    await Task.WhenAll
                    (
                        _byFromIndices.DeleteIfExistAsync
                        (
                            byFromIndexKeys.PartitionKey,
                            byFromIndexKeys.RowKey
                        ),
                        _byToIndices.DeleteIfExistAsync
                        (
                            byToIndexKeys.PartitionKey,
                            byToIndexKeys.RowKey
                        )
                    );

                    await _transactionReceipts.DeleteIfExistAsync(receiptEntity.PartitionKey, receiptEntity.RowKey);
                }

                await _byBlockIndices.DeleteIfExistAsync(receiptInBlock.PartitionKey, receiptInBlock.RowKey);
            }
        }