private void CheckTransactionsStatuses() { if (_pendingTransactions.Count > 0) { for (int i = 0; i < _pendingTransactions.Count; i++) { var transaction = _pendingTransactions[i]; int transactionConnectionId = transaction.Sender.ConnectionId; string playerMarketAccessToken = Model.GetPlayerMarketAccessToken(transactionConnectionId); DMarketApi.CheckAsyncOperation(playerMarketAccessToken, transaction.OperationIds, (response, request) => { var answerMessage = new AppChangingItemsAnswerMessage(new ItemsChangingResponse()); foreach (var transactionItem in response.Items) { var status = _apiResponseAdapter.GetTransactionStatusType(transactionItem.status); switch (status) { case DMarketTransactionStatusType.Fail: { answerMessage.Response.MarketError = (ErrorCode)transactionItem.transferError.code; transaction.RemoveOperation(transactionItem.operationId); break; } case DMarketTransactionStatusType.Success: { OnSuccessMarketOperation(transactionItem, transaction); transaction.RemoveOperation(transactionItem.operationId); break; } } } var transactionLog = string.Format("Transaction for connection: {0}, operation left: {1}", transaction.Sender.ConnectionId, transaction.OperationsCount); DevLogger.Log(transactionLog, DTanksLogChannel.GameServer); if (transaction.OperationsCount == 0) { SendMessageToClient(answerMessage, transactionConnectionId); _pendingTransactions.Remove(transaction); } Storage.Change(GetPlayer(transactionConnectionId)); }, error => { foreach (var transactionInfo in _pendingTransactions) { OnItemOperationError(transactionInfo.Sender, error); } _pendingTransactions.Clear(); }); } } }
private void CheckTransactionsStatuses() { if (_pendingOperations.Count == 0) { return; } var transactionIds = _pendingOperations.Keys; DMarketApi.CheckAsyncOperation(Model.GetPlayerMarketAccessToken(_connectionId), transactionIds.ToArray(), (response, request) => { foreach (var item in response.Items) { string itemAssetId = item.assetId; string operationId = item.operationId; var transactionStatus = _apiResponseAdapter.GetTransactionStatusType(item.status); switch (transactionStatus) { case DMarketTransactionStatusType.Fail: _pendingOperations.Remove(operationId); DevLogger.Error(string.Format("Transaction for item: {0} was failed.", itemAssetId)); break; case DMarketTransactionStatusType.Pending: break; case DMarketTransactionStatusType.Success: _pendingOperations.Remove(operationId); _successItemsIds.Add(itemAssetId); break; } } if (_pendingOperations.Count == 0) { if (_actionType == ItemActionType.FromMarket) { AddMovedItemsToInventory(); } else { RemoveMovedItemsFromInventory(); } SendLoadInventoryData(); Terminate(); } }, error => { _pendingOperations.Clear();; OnItemOperationError(error); }); }