Пример #1
0
        private ParsingResult ParseHandHistory(Handhistory handHistory)
        {
            if (string.IsNullOrEmpty(handHistory.HandhistoryVal))
            {
                LogProvider.Log.Warn(CustomModulesNames.PlayerXRay, $"Hand #{handHistory.Gamenumber} has been skipped, because it has no history.");
                return(null);
            }

            var pokerSite = (EnumPokerSites)handHistory.PokersiteId;

            var pokerSiteNetwork = EntityUtils.GetSiteNetwork(pokerSite);

            var handHistoryParser = pokerSite == EnumPokerSites.Unknown || pokerSiteNetwork == EnumPokerNetworks.WPN ?
                                    handHistoryParserFactory.GetFullHandHistoryParser(handHistory.HandhistoryVal) :
                                    handHistoryParserFactory.GetFullHandHistoryParser(pokerSite);

            var parsedHand = handHistoryParser.ParseFullHandHistory(handHistory.HandhistoryVal, true);

            var gameType = new Gametypes
            {
                Anteincents       = Utils.ConvertToCents(parsedHand.GameDescription.Limit.Ante),
                Bigblindincents   = Utils.ConvertToCents(parsedHand.GameDescription.Limit.BigBlind),
                CurrencytypeId    = (short)parsedHand.GameDescription.Limit.Currency,
                Istourney         = parsedHand.GameDescription.IsTournament,
                PokergametypeId   = (short)(parsedHand.GameDescription.GameType),
                Smallblindincents = Utils.ConvertToCents(parsedHand.GameDescription.Limit.SmallBlind),
                Tablesize         = (short)parsedHand.GameDescription.SeatType.MaxPlayers
            };

            var players = parsedHand.Players.Select(player =>
            {
                var playerPokerSiteKey = new PlayerPokerSiteKey(player.PlayerName, (int)pokerSite);

                if (playersDictionary.ContainsKey(playerPokerSiteKey))
                {
                    return(playersDictionary[playerPokerSiteKey]);
                }

                return(new Players
                {
                    Playername = player.PlayerName,
                    PokersiteId = (short)pokerSite
                });
            }).ToList();

            var parsingResult = new ParsingResult
            {
                HandHistory = handHistory,
                Players     = players,
                GameType    = gameType,
                Source      = parsedHand
            };

            return(parsingResult);
        }
        /// <summary>
        /// Builds player statistic
        /// </summary>
        /// <param name="handHistory"></param>
        /// <param name="player"></param>
        private void BuildPlayerStatistic(Handhistory dbHandHistory, PlayerStatisticCreationInfo playerStatisticCreationInfo)
        {
            try
            {
                var playerStatisticCalculator = ServiceLocator.Current.GetInstance <IPlayerStatisticCalculator>(playerStatisticCreationInfo.GetServiceName());

                var statistic = playerStatisticCalculator.CalculateStatistic(playerStatisticCreationInfo);

                if (!string.IsNullOrEmpty(dbHandHistory.Tourneynumber))
                {
                    statistic.IsTourney    = true;
                    statistic.TournamentId = dbHandHistory.Tourneynumber;
                }

                StorePlayerStatistic(statistic);
            }
            catch (Exception e)
            {
                LogProvider.Log.Error(this, $"Failed to process hand #{dbHandHistory.Gamenumber}, player {playerStatisticCreationInfo.Player?.Playername} .", e);
                throw new DHInternalException(new NonLocalizableString($"Failed to rebuild stats of hand #{dbHandHistory.Gamenumber}"));
            }
        }