internal virtual bool CanBalance(BalanceOperationType operationType) { if (this.scheduledRemoveAnimations.Count == 0) { return(true); } if ((operationType == BalanceOperationType.ManageLowerViewport) || (operationType == BalanceOperationType.ManageUpperViewport)) { return(true); } if (this.firstItemCache == null) { return(false); } foreach (SingleItemAnimationContext context in this.scheduledRemoveAnimations) { if (context.AssociatedItem.CurrentOffset < this.firstItemCache.CurrentOffset) { return(false); } if (context.AssociatedItem.CurrentOffset > this.lastItemCache.CurrentOffset) { return(false); } } return(true); }
internal override bool CanBalance(BalanceOperationType operationType) { if (operationType != BalanceOperationType.TopBoundsCheck) { return(base.CanBalance(operationType)); } if ((this.refreshRequested && this.isIndicatorVisible) || (this.animating && this.isIndicatorVisible)) { return(false); } return(base.CanBalance(operationType)); }
private Base.Model ChooseBalanceOperationType(BalanceOperationType type) { switch (type) { case BalanceOperationType.Anticipation: return(ChooseMovementObject(type)); case BalanceOperationType.Payable: return(ChooseMovementObject(type)); case BalanceOperationType.Transfer: return(ChooseMovementObject(type)); default: return(null); } }
private Base.Model ChooseMovementObject(BalanceOperationType type) { switch (GetAttribute <BalanceOperationType>("type")) { case BalanceOperationType.Anticipation: if (type == BalanceOperationType.Anticipation) { return(GetAttribute <BulkAnticipation>("movement_object")); } else { return(null); } case BalanceOperationType.Payable: if (type == BalanceOperationType.Payable) { return(GetAttribute <Payable>("movement_object")); } else { return(null); } case BalanceOperationType.Transfer: if (type == BalanceOperationType.Transfer) { return(GetAttribute <Transfer>("movement_object")); } else { return(null); } default: return(null); } }
private Base.Model ChooseBalanceOperationType(BalanceOperationType type) { switch (type) { case BalanceOperationType.Anticipation : return ChooseMovementObject(type); case BalanceOperationType.Payable : return ChooseMovementObject(type); case BalanceOperationType.Transfer : return ChooseMovementObject(type); default : return null; } }
private Base.Model ChooseMovementObject(BalanceOperationType type) { switch (GetAttribute<BalanceOperationType>("type")) { case BalanceOperationType.Anticipation: if (type == BalanceOperationType.Anticipation) return GetAttribute<BulkAnticipation>("movement_object"); else return null; case BalanceOperationType.Payable: if (type == BalanceOperationType.Payable) return GetAttribute<Payable>("movement_object"); else return null; case BalanceOperationType.Transfer: if (type == BalanceOperationType.Transfer) return GetAttribute<Transfer>("movement_object"); else return null; default: return null; } }
public async Task UpdateAmountAsync(string assetId, BalanceOperationType balanceOperationType, decimal amount, string comment, string userId) { await _semaphore.WaitAsync(); try { Token previousToken = await GetAsync(assetId); Token currentToken = previousToken.Copy(); string walletId = _settingsService.GetWalletId(); string transactionId; switch (balanceOperationType) { case BalanceOperationType.CashIn: currentToken.IncreaseAmount(amount); transactionId = await _lykkeExchangeService .CashInAsync(walletId, assetId, amount, userId, comment); break; case BalanceOperationType.CashOut: currentToken.DecreaseAmount(amount); try { transactionId = await _lykkeExchangeService .CashOutAsync(walletId, assetId, amount, userId, comment); } catch (NotEnoughFundsException) { throw new InvalidOperationException("No enough funds"); } break; default: throw new InvalidEnumArgumentException(nameof(balanceOperationType), (int)balanceOperationType, typeof(BalanceOperationType)); } await _tokenRepository.SaveAsync(currentToken); _cache.Set(currentToken); var balanceOperation = new BalanceOperation { Timestamp = DateTime.UtcNow, AssetId = assetId, Type = balanceOperationType, Amount = amount, IsCredit = false, Comment = comment, UserId = userId, TransactionId = transactionId }; await _balanceOperationService.AddAsync(balanceOperation); _log.InfoWithDetails("Token amount updated", new { PreviuosToken = previousToken, CurrentToken = currentToken, BalanceOperation = balanceOperation }); } catch (Exception exception) { _log.WarningWithDetails("An error occurred while updating token", exception, new { AssetId = assetId, Type = balanceOperationType, Amount = amount, Comment = comment, UserId = userId }); throw; } finally { _semaphore.Release(); } }
public async Task UpdateAsync(string assetId, BalanceOperationType balanceOperationType, decimal amount, string comment, string userId) { try { string walletId = _settingsService.GetWalletId(); string transactionId; switch (balanceOperationType) { case BalanceOperationType.CashIn: transactionId = await _lykkeExchangeService.CashInAsync(walletId, assetId, amount, userId, comment); break; case BalanceOperationType.CashOut: try { transactionId = await _lykkeExchangeService.CashOutAsync(walletId, assetId, amount, userId, comment); } catch (NotEnoughFundsException) { throw new InvalidOperationException("No enough funds"); } break; default: throw new InvalidEnumArgumentException(nameof(balanceOperationType), (int)balanceOperationType, typeof(BalanceOperationType)); } var balanceOperation = new BalanceOperation { Timestamp = DateTime.UtcNow, AssetId = assetId, Type = balanceOperationType, IsCredit = false, Amount = amount, Comment = comment, UserId = userId, TransactionId = transactionId }; await _balanceOperationService.AddAsync(balanceOperation); _log.InfoWithDetails("Balance changed", balanceOperation); } catch (Exception exception) { _log.WarningWithDetails("An error occurred while changing balance", exception, new { AssetId = assetId, Type = balanceOperationType, Amount = amount, Comment = comment, UserId = userId }); throw; } }
public async Task <IReadOnlyCollection <BalanceOperation> > GetAsync(DateTime startDate, DateTime endDate, int limit, string assetId, BalanceOperationType balanceOperationType) { string filter = TableQuery.CombineFilters( TableQuery.GenerateFilterCondition(nameof(AzureTableEntity.PartitionKey), QueryComparisons.GreaterThan, GetPartitionKey(endDate.Date.AddDays(1))), TableOperators.And, TableQuery.GenerateFilterCondition(nameof(AzureTableEntity.PartitionKey), QueryComparisons.LessThan, GetPartitionKey(startDate.Date.AddMilliseconds(-1)))); if (!string.IsNullOrEmpty(assetId)) { filter = TableQuery.CombineFilters(filter, TableOperators.And, TableQuery.GenerateFilterCondition(nameof(BalanceOperationEntity.AssetId), QueryComparisons.Equal, assetId)); } if (balanceOperationType != BalanceOperationType.None) { filter = TableQuery.CombineFilters(filter, TableOperators.And, TableQuery.GenerateFilterCondition(nameof(BalanceOperationEntity.Type), QueryComparisons.Equal, balanceOperationType.ToString())); } var query = new TableQuery <BalanceOperationEntity>().Where(filter).Take(limit); IEnumerable <BalanceOperationEntity> entities = await _storage.WhereAsync(query); return(Mapper.Map <List <BalanceOperation> >(entities)); }
public async Task UpdateAsync(BalanceOperationType balanceOperationType, decimal amount, string comment, string userId) { await _semaphore.WaitAsync(); try { Funding funding = (await GetAsync()).Copy(); string walletId = _settingsService.GetWalletId(); string transactionId; switch (balanceOperationType) { case BalanceOperationType.CashIn: funding.Add(amount); transactionId = await _lykkeExchangeService.CashInAsync(walletId, AssetId, amount, userId, comment); break; case BalanceOperationType.CashOut: funding.Subtract(amount); try { transactionId = await _lykkeExchangeService.CashOutAsync(walletId, AssetId, amount, userId, comment); } catch (NotEnoughFundsException) { throw new InvalidOperationException("No enough funds"); } break; default: throw new InvalidEnumArgumentException(nameof(balanceOperationType), (int)balanceOperationType, typeof(BalanceOperationType)); } await _fundingRepository.InsertOrReplaceAsync(funding); _cache.Set(funding); var balanceOperation = new BalanceOperation { Timestamp = DateTime.UtcNow, AssetId = AssetId, Type = balanceOperationType, IsCredit = true, Amount = amount, Comment = comment, UserId = userId, TransactionId = transactionId }; await _balanceOperationService.AddAsync(balanceOperation); _log.InfoWithDetails("Funding amount updated", balanceOperation); } catch (Exception exception) { _log.WarningWithDetails("An error occurred while updating funding", exception, new { AssetId, Type = balanceOperationType, Amount = amount, Comment = comment, UserId = userId }); throw; } finally { _semaphore.Release(); } }
public async Task <IReadOnlyCollection <BalanceOperationModel> > GetBalanceOperationsAsync(DateTime startDate, DateTime endDate, int limit, string assetId, BalanceOperationType type) { var modelType = Mapper.Map <Domain.BalanceOperationType>(type); IReadOnlyCollection <Domain.BalanceOperation> balanceOperations = await _balanceOperationService.GetAsync(startDate, endDate, limit, assetId, modelType); return(Mapper.Map <List <BalanceOperationModel> >(balanceOperations)); }
public Task <IReadOnlyCollection <BalanceOperation> > GetAsync(DateTime startDate, DateTime endDate, int limit, string assetId, BalanceOperationType balanceOperationType) { return(_balanceOperationRepository.GetAsync(startDate, endDate, limit, assetId, balanceOperationType)); }