public async Task DeleteAsync(string campaignId, string templateId = null)
        {
            var templates = string.IsNullOrEmpty(templateId)
                ? await _templateStorage.GetDataAsync(GetPartitionKey(campaignId))
                : await _templateStorage.GetDataAsync(GetPartitionKey(campaignId), t => t.TemplateId == templateId);

            if (templates.Any())
            {
                await _templateStorage.DeleteAsync(templates);
            }

            // if it's a campaign deletion then delete history too

            if (string.IsNullOrEmpty(templateId))
            {
                var query = new TableQuery <EmailTemplateHistoryItemEntity>()
                            .Where(TableQuery.GenerateFilterCondition(nameof(EmailTemplateHistoryItemEntity.CampaignId), QueryComparisons.Equal, campaignId));

                var entities = new List <EmailTemplateHistoryItemEntity>();

                await _templateHistoryStorage.ExecuteAsync(query, chunk => entities.AddRange(chunk));

                if (entities.Any())
                {
                    await _templateHistoryStorage.DeleteAsync(entities);
                }
            }
        }
        public static async Task <StatusReport> Create(INoSQLTableStorage <PriceTableEntity> pricesStorage)
        {
//            var assetsStorage = new AzureTableStorage<TableEntity>(
//                config.AzureTable.StorageConnectionString,
//                config.AzureTable.AssetsTableName,
//                new LogToConsole());
//
//            var assets = await assetsStorage.GetDataAsync();

            var now       = DateTime.UtcNow;
            var timePoint = now.AddMinutes(-3);
            var rowKey    = timePoint.ToString("yyyy-MM-dd HH:mm:ss");

            var query = new TableQuery <PriceTableEntity>()
                        .Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThan, rowKey));

            IEnumerable <PriceTableEntity> prices = Enumerable.Empty <PriceTableEntity>();
            await pricesStorage.ExecuteAsync(query, result => prices = result);

            var lastPrices = prices.OrderByDescending(x => x.Timestamp).Take(10);

            return(new StatusReport()
            {
                LastPrices = lastPrices.ToList()
            });
        }
        private async Task <IEnumerable <string> > GetPartitionKeys()
        {
            var partitionKeys = new ConcurrentBag <string>();
            await _tableStorage.ExecuteAsync(new TableQuery <AccountMarginEventReportEntity>(), entity =>
                                             entity.Select(m => m.PartitionKey).ForEach(pk => partitionKeys.Add(pk)));

            return(partitionKeys.Distinct());
        }
Exemple #4
0
        private async Task <IEnumerable <string> > GetPartitionKeys()
        {
            var partitionKeys = new ConcurrentBag <string>();
            await _tableStorage.ExecuteAsync(new TableQuery <TradingOrderEntity>(), entity =>
                                             entity.Select(m => m.PartitionKey).ForEach(pk => partitionKeys.Add(pk)));

            return(partitionKeys);
        }
Exemple #5
0
        public async Task <int> GetActiveOrdersCountAsync(string clientId)
        {
            var partitionKey = LimitOrderEntity.ByClientIdActive.GeneratePartitionKey(clientId);

            var count = 0;

            await _tableStorage.ExecuteAsync(GetIdsOnly(partitionKey), entities => count += entities.Count());

            return(count);
        }
        public static Task WhereAsync <T>(this INoSQLTableStorage <T> tableStorage, string partitionKey,
                                          int year, int month, Action <IEnumerable <T> > chunk = null)
            where T : ITableEntity, new()
        {
            var from = new DateTime(year, month, 1);
            var to   = from.AddMonths(1);

            var rangeQuery = QueryGenerator <T> .BetweenQuery(partitionKey, from, to, ToIntervalOption.ExcludeTo);

            return(tableStorage.ExecuteAsync(rangeQuery, chunk));
        }
        private async Task <IEnumerable <string> > GetPartitionKeys()
        {
            System.Collections.Concurrent.ConcurrentDictionary <string, byte> partitionKeys = new System.Collections.Concurrent.ConcurrentDictionary <string, byte>();
            await _tableStorage.ExecuteAsync(new TableQuery <CheckResultEntity>(), entity =>
            {
                foreach (var et in entity.Select(m => m.PartitionKey))
                {
                    partitionKeys.TryAdd(et, 0);
                }
            });

            return(partitionKeys.Select(m => m.Key));
        }
Exemple #8
0
        public async Task DeleteAsync(string campaignId)
        {
            var query = new TableQuery <PayInAddressEntity>()
                        .Where(TableQuery.GenerateFilterCondition(nameof(PayInAddressEntity.CampaignId), QueryComparisons.Equal, campaignId));

            var entities = new List <PayInAddressEntity>();

            await _tableStorage.ExecuteAsync(query, chunk => entities.AddRange(chunk));

            if (entities.Any())
            {
                await _tableStorage.DeleteAsync(entities);
            }
        }
        public async Task <(IEnumerable <IConnectionUrlHistory>, int)> GetPageAsync(int pageNum, int pageSize)
        {
            var pk         = ConnectionUrlHistory.GeneratePartitionKey();
            var filter     = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, pk);
            var query      = new TableQuery <ConnectionUrlHistory>().Where(filter);
            var pageItems  = new List <ConnectionUrlHistory>();
            int batchCount = -1;
            int count      = 0;
            int skip       = (pageNum - 1) * pageSize;
            await _tableStorage.ExecuteAsync(
                query,
                batch => {
                batchCount = batch.Count();
                if (count + batchCount < skip)
                {
                    return;
                }
                foreach (var item in batch)
                {
                    if (count < skip)
                    {
                        ++count;
                        continue;
                    }
                    if (pageItems.Count == pageSize)
                    {
                        return;
                    }
                    pageItems.Add(item);
                }
                count += batchCount;
            },
                () => batchCount > 0 && pageItems.Count < pageSize);

            var totalCount = 10 * pageSize;

            if (_totalCount.HasValue)
            {
                totalCount = _totalCount.Value;
            }
            else if (_totalCountTask == null)
            {
                Task.Run(async() =>
                {
                    _totalCountTask = CalculateTotalCountAsync();
                    await _totalCountTask;
                });
            }
            return(pageItems, totalCount);
        }
        public async Task <IFeedHistory> GetСlosestAvailableAsync(string assetPairId, string priceType, DateTime feedTime)
        {
            var rangeQuery = AzureStorageUtils.QueryGenerator <FeedHistoryEntity>
                             .GreaterThanQuery(FeedHistoryEntity.GeneratePartition(assetPairId, priceType),
                                               FeedHistoryEntity.GenerateRowKey(feedTime)).Take(1);

            var resList = new List <FeedHistoryEntity>();
            await _tableStorage.ExecuteAsync(rangeQuery, entities =>
            {
                resList.AddRange(entities);
            }, () => false);

            return(resList.Any() ? resList.First().ToDto() : null);
        }
        public async Task <IActionResult> Fix()
        {
            var query = new TableQuery <FixMessageTableEntity>
            {
                TakeCount = entriesCount
            };

            var logs = new List <FixMessageTableEntity>(entriesCount);
            await _fixMessagesStorage.ExecuteAsync(query, result => logs.AddRange(result));

            var lastEntries = logs.OrderBy(x => x.RowKey);

            return(View(lastEntries));
        }
        public async Task <IActionResult> Index()
        {
            var query = new TableQuery <LogEntity>()
            {
                TakeCount = entriesCount
            };

            var logs = new List <LogEntity>(entriesCount);
            await _logsStorage.ExecuteAsync(query, result => logs.AddRange(result));

            var lastEntries = logs.OrderByDescending(x => x.Timestamp);

            return(View(lastEntries));
        }
 public Task ExecuteAsync(TableQuery <TEntity> rangeQuery, Action <IEnumerable <TEntity> > yieldResult, Func <bool> stopCondition = null)
 {
     return(_impl.ExecuteAsync(rangeQuery, yieldResult, stopCondition));
 }
 public Task ExecuteAsync(TableQuery <T> rangeQuery, Action <IEnumerable <T> > yieldResult, Func <bool> stopCondition)
 => _table.ExecuteAsync(rangeQuery, yieldResult, stopCondition);
Exemple #15
0
 public Task ExecuteAsync(TableQuery <TEntity> rangeQuery, Action <IEnumerable <TEntity> > yieldResult, Func <bool> stopCondition = null)
 => WrapAsync(() => _impl.ExecuteAsync(rangeQuery, yieldResult, stopCondition), nameof(ExecuteAsync), rangeQuery.FilterString);