/// <summary> /// Exports captured hand history to the supported DB /// </summary> protected virtual void ExportHandHistory(List <HandHistoryData> handHistories) { // merge hands var playerWithHoleCards = handHistories .SelectMany(x => x.HandHistory.Players) .Where(x => x.hasHoleCards) .DistinctBy(x => x.SeatNumber) .ToDictionary(x => x.SeatNumber, x => x.HoleCards); GameInfo mainGameInfo = null; foreach (var handHistoryData in handHistories) { handHistoryData.HandHistory.Players.ForEach(player => { if (!player.hasHoleCards && playerWithHoleCards.ContainsKey(player.SeatNumber)) { player.HoleCards = playerWithHoleCards[player.SeatNumber]; } }); var handHistoryText = SerializationHelper.SerializeObject(handHistoryData.HandHistory); #if DEBUG if (!Directory.Exists("Hands")) { Directory.CreateDirectory("Hands"); } File.WriteAllText($"Hands\\{HandHistoryFilePrefix}_hand_exported_{handHistoryData.Uuid}_{handHistoryData.HandHistory.HandId}.xml", handHistoryText); #endif var gameInfo = new GameInfo { PokerSite = Site, WindowHandle = handHistoryData.WindowHandle.ToInt32(), GameNumber = handHistoryData.HandHistory.HandId, Session = GetSession(handHistoryData) }; if (mainGameInfo == null) { mainGameInfo = gameInfo; } else { var playersCashInfo = mainGameInfo.GetPlayersCacheInfo(); if (playersCashInfo != null) { gameInfo.ResetPlayersCacheInfo(); gameInfo.DoNotReset = true; foreach (var playerCashInfo in playersCashInfo) { var cacheInfo = new PlayerStatsSessionCacheInfo { Session = gameInfo.Session, Player = new PlayerCollectionItem { PlayerId = playerCashInfo.Player.PlayerId, Name = playerCashInfo.Player.Name, PokerSite = playerCashInfo.Player.PokerSite, }, Stats = playerCashInfo.Stats.Copy(), IsHero = handHistoryData.HandHistory.HeroName != null && handHistoryData.HandHistory.HeroName.Equals(playerCashInfo.Player.Name), GameFormat = playerCashInfo.GameFormat, GameNumber = playerCashInfo.GameNumber }; gameInfo.AddToPlayersCacheInfo(cacheInfo); } } } ProcessHand(handHistoryText, gameInfo); } }