public async Task AddOrUpdateAsync(string ruleId, DateTime expires) { var nosqlModel = NotificationNoSql.Create(ruleId, expires); await _myNoSqlServerDataWriter.InsertOrReplaceAsync(nosqlModel); await _myNoSqlServerDataWriter.CleanAndKeepMaxRecords(NotificationNoSql.GeneratePartitionKey(), 3500); }
public async Task UpdateProfile(KycProfile profile, string operation, string agent, string comment) { await using var context = new DatabaseContext(_dbContextOptionsBuilder.Options); await context.UpsertAsync(new[] { profile }); await _cache.InsertOrReplaceAsync(KycProfileNoSqlEntity.Create(profile)); await _cache.CleanAndKeepMaxRecords(KycProfileNoSqlEntity.GeneratePartitionKey(), 10000); context.AuditLogs.Add(KycAuditLog.Create(profile, operation, agent, comment)); await context.SaveChangesAsync(); }
private async Task ProcessMessageAsync(ExecutionEvent message) { var orders = new List <OrderEntity>(); var trades = new List <TradeEntity>(); foreach (var order in message.Orders) { var orderEntity = _mapper.Map <OrderEntity>(order); orders.Add(orderEntity); if (order.Trades == null) { continue; } foreach (var trade in order.Trades) { var tradeEntity = _mapper.Map <TradeEntity>(trade); tradeEntity.AssetPairId = orderEntity.AssetPairId; tradeEntity.OrderId = orderEntity.Id; tradeEntity.PartitionKey = orderEntity.WalletId; tradeEntity.WalletId = orderEntity.WalletId; trades.Add(tradeEntity); } } await _orderWriter.BulkInsertOrReplaceAsync(orders); await _tradeWriter.BulkInsertOrReplaceAsync(trades); Task.Run(async() => { var ordersToRemove = orders .Where(x => x.Status == OrderStatus.Matched.ToString() || x.Status == OrderStatus.Cancelled.ToString() || x.Status == OrderStatus.Rejected.ToString()).ToList(); foreach (var order in ordersToRemove) { await _orderWriter.DeleteAsync(order.WalletId, order.Id); } var walletIds = trades.Select(x => x.WalletId).Distinct().ToList(); foreach (var walletId in walletIds) { await _tradeWriter.CleanAndKeepMaxRecords(walletId, 0); } }); }