Exemplo n.º 1
0
        private async Task ProcessQueueUntillTimeSpanIsMet(TimeSpan timeSpan)
        {
            int i = 0;

            while (timeSpan.TotalMilliseconds < 200)
            {
                if (_betQueue.IsEmpty())
                {
                    break;
                }

                var stopWatch = Stopwatch.StartNew();
                await ProcessItemInQueue();

                stopWatch.Stop();
                timeSpan.Add(stopWatch.Elapsed);
                i++;
            }

            if (i > 0)
            {
                _logService.Info($"Prosecced {i} nr of bets in one tick");
            }
        }
Exemplo n.º 2
0
        private async void ProcessItemInQueue()
        {
            while (true)
            {
                if (_betQueue.IsEmpty())
                {
                    await Task.Delay(200);

                    continue;
                }

                var item = _betQueue.Next();

                if (_betOrWithdrawQueueManager.DoesExist(item.SteamId))
                {
                    await _betHubConnections.Error(item.SteamId, item.RoundId, "You alredy have a pending bet or withdraw.");

                    continue;
                }

                DatabaseModel.CoinFlip       match;
                DatabaseModel.JackpotSetting matchSetting;
                try
                {
                    match = await _repoServiceFactory.CoinFlipMatchRepoService.FindAsync(item.RoundId);

                    matchSetting = await _repoServiceFactory.JackpotSettingRepo.Find(match.SettingId);
                }
                catch (Exception e)
                {
                    _logService.Error(null, null, e, new Dictionary <string, object>());
                    await _betHubConnections.Error(item.SteamId, item.RoundId, "Something went wrong, please try again later.");

                    continue;
                }

                var bets = await _repoServiceFactory.BetRepoService.FindAsync(item.RoundId, _currentGamemode.Id);

                if (bets.Count == 2)
                {
                    await _betHubConnections.Error(item.SteamId, item.RoundId, "The match has no empty slots");

                    continue;
                }

                _betOrWithdrawQueueManager.Add(item.SteamId, QueueAction.Bet);
                try
                {
                    await _betService.PlaceBetOnCoinFlipMatch(match, matchSetting.ToJackpotMatchSetting(), item.GamMode, item.AssetAndDescriptionIds,
                                                              item.SteamId);
                }
                catch (Exception ex)
                {
                    _logService.Error(null, null, ex, new Dictionary <string, object>());

                    if (
                        ex is GameModeIsNotEnabledException ||
                        ex is ToManyItemsOnBetException ||
                        ex is ToFewItemsOnBetException ||
                        ex is NotAllowedAppIdOnMatchException ||
                        ex is ToMuchValueOnBetException ||
                        ex is ToLittleValueOnBetException ||
                        ex is InvalidItemException
                        )
                    {
                        await _betHubConnections.Error(item.SteamId, item.RoundId, ex.Message);

                        continue;
                    }

                    await _betHubConnections.Error(item.SteamId, item.RoundId, "Something went wrong, please try again later.");

                    continue;
                }
                finally
                {
                    _betOrWithdrawQueueManager.Remover(item.SteamId);
                }

                await _betHubConnections.Success(item.SteamId, item.RoundId);
            }
        }