private async void ExportHand(object obj) { if (layout == null) { return; } EnumExportType exportType = EnumExportType.Raw; if (obj == null || !Enum.TryParse(obj.ToString(), out exportType)) { return; } await Task.Run(() => { using (var readToken = readerWriterLock.Read()) { LogProvider.Log.Info($"Exporting hand {layout.GameNumber}, {exportType} [{layout.PokerSite}]"); ExportFunctions.ExportHand(layout.GameNumber, (short)layout.PokerSite, exportType, true); RaiseNotification(CommonResourceManager.Instance.GetResourceString(ResourceStrings.DataExportedMessageResourceString), "Hand Export"); } }); }
public static string ExportHand(long gamenumber, short pokerSiteId, EnumExportType exportType, bool isSetClipboard = false) { var resultString = string.Empty; try { var handHistory = ServiceLocator.Current.GetInstance <IDataService>().GetGame(gamenumber, pokerSiteId); switch (exportType) { case EnumExportType.TwoPlusTwo: case EnumExportType.CardsChat: case EnumExportType.PokerStrategy: case EnumExportType.PlainText: resultString = ConvertHHToForumFormat(handHistory, exportType); break; case EnumExportType.Raw: default: resultString = handHistory.FullHandHistoryText; break; } if (isSetClipboard) { Application.Current.Dispatcher.Invoke(() => Clipboard.SetText(resultString)); } } catch (Exception ex) { LogProvider.Log.Error(ex); } return(resultString); }
public static string ConvertHHToForumFormat(HandHistory handHistory, EnumExportType exportType, bool withStats = true) { if (handHistory == null || handHistory.GameDescription == null) { LogProvider.Log.Error(typeof(ExportFunctions), $"{nameof(ConvertHHToForumFormat)}: Could not export empty hand."); return(string.Empty); } var result = new StringBuilder(); try { IDictionary <string, ExportIndicators> playerIndicators = null; var playersNames = new Dictionary <string, string>(); if (withStats) { var playerStatisticRepository = ServiceLocator.Current.GetInstance <IPlayerStatisticRepository>(); var playerNames = handHistory.Players.Select(x => x.PlayerName).ToArray(); playerIndicators = playerStatisticRepository.GetPlayersIndicators <ExportIndicators>(playerNames, (short)handHistory.GameDescription.Site); } var headerRandomNumber = HeaderRandom.Next(0, 2); if (headerRandomNumber == 0) { result.AppendLine("Hand History driven straight to this forum with DriveHUD [url=http://drivehud.com/?t=hh]Poker Tracking[/url] Software"); } else { result.AppendLine("Hand History driven straight to this forum with DriveHUD [url=http://drivehud.com/?t=hh]Poker HUD[/url] and Database Software"); } result.AppendLine(); result.AppendLine($"[U][B]{ConvertGameType(handHistory)} ${handHistory.GameDescription.Limit.BigBlind}(BB)[/B][/U]"); // players foreach (var player in handHistory.Players) { var playerName = handHistory.Hero != null && handHistory.Hero == player ? HeroName : GetPositionName(player.PlayerName, handHistory); if (!playersNames.ContainsKey(player.PlayerName)) { playersNames.Add(player.PlayerName, playerName); } var isInPot = handHistory.HandActions.Any(x => x.Street == Street.Flop && x.PlayerName == player.PlayerName); var beginFormatTag = string.Empty; var endFormatTag = string.Empty; if (isInPot) { beginFormatTag = "[color=blue][B]"; endFormatTag = "[/B][/color]"; } result.Append($"{beginFormatTag}{playerName} (${player.StartingStack}){endFormatTag}"); if (playerIndicators != null && playerIndicators.ContainsKey(player.PlayerName)) { var indicator = playerIndicators[player.PlayerName]; if (isInPot) { beginFormatTag = "[B]"; endFormatTag = "[/B]"; } result.Append($" {beginFormatTag}[VPIP: {indicator.VPIP:0.#}% | PFR: {indicator.PFR:0.#}% | AGG: {indicator.AggPr:0.#}% | 3-Bet: {indicator.ThreeBet:0.#}% | Hands: {indicator.TotalHands}]{endFormatTag}"); } result.Append(Environment.NewLine); } result.AppendLine(); // dealt to if (handHistory.Hero != null && handHistory.Hero.hasHoleCards) { result.AppendLine($"[B]Dealt to Hero:[/B] {string.Join(" ", handHistory.Hero.HoleCards.Select(x => ConvertCardToForumFormat(x.ToString())))}"); result.AppendLine(); } var pot = handHistory.HandActions.Where(x => x.IsBlinds).Sum(x => Math.Abs(x.Amount)); // street headers and hand actions result.AppendLine(BuildActionLine(handHistory.PreFlop, handHistory, playersNames, ref pot)); foreach (var street in new[] { Street.Flop, Street.Turn, Street.River }) { if (CardHelper.IsStreetAvailable(handHistory.CommunityCards, street)) { result.AppendLine(); // if hero presented then build spr line if (street == Street.Flop && handHistory.Hero != null && handHistory.Flop.Any(x => x.PlayerName == handHistory.Hero.PlayerName)) { result.AppendLine(BuildSPROnFlopLine(handHistory, pot)); } result.AppendLine(GetStreetString(street, pot, handHistory)); var streetActions = handHistory.HandActions.Where(x => x.Street == street); if (streetActions.Any()) { result.AppendLine(BuildActionLine(streetActions, handHistory, playersNames, ref pot)); } } } result.AppendLine(); var spoilTag = exportType == EnumExportType.CardsChat ? "SPOILER" : "spoil"; result.AppendLine($"[{spoilTag}]"); var doAppendLine = false; // show cards foreach (var player in handHistory.Players.Where(x => x.hasHoleCards && x != handHistory.Hero)) { if (!doAppendLine) { doAppendLine = true; } result.AppendLine($"{playersNames[player.PlayerName]} shows: {string.Join(" ", player.HoleCards.Select(x => ConvertCardToForumFormat(x.CardStringValue)))}"); } if (doAppendLine) { result.AppendLine(); } // winners foreach (var winAction in handHistory.WinningActions) { result.AppendLine($"{playersNames[winAction.PlayerName]} wins: ${winAction.Amount}"); } result.AppendLine($"[/{spoilTag}]"); } catch (Exception e) { LogProvider.Log.Error(typeof(ExportFunctions), $"Could not export hand {handHistory.HandId} {handHistory.GameDescription.Site} in {exportType} format with stats = {withStats}", e); } var handHistoryText = result.ToString().Trim(); return(exportType == EnumExportType.PlainText ? ConvertToPlainText(handHistoryText) : handHistoryText); }
public void HandHistoryIsConvertedIntoForumFormatV2(string sourceFileName, string expectedResultFileName, EnumExportType exportType, EnumPokerSites site, TestIndicators[] testIndicators) { var pr = Process.GetProcesses(); var playerStatisticRepository = ServiceLocator.Current.GetInstance <IPlayerStatisticRepository>(); playerStatisticRepository .GetPlayersIndicators <ExportIndicators>(Arg.Any <string[]>(), Arg.Any <short?>()) .Returns(testIndicators?.ToDictionary(x => x.PlayerName, x => (ExportIndicators)x)); var sourceFile = Path.Combine(testFolder, sourceFileName); var expectedResultFile = Path.Combine(testFolder, expectedResultFileName); if (!File.Exists(sourceFile)) { throw new Exception(string.Format("Test file '{0}' doesn't exist", sourceFile)); } if (!File.Exists(expectedResultFile)) { throw new Exception(string.Format("Test file '{0}' doesn't exist", expectedResultFile)); } var handHistoryText = File.ReadAllText(sourceFile); var factory = new HandHistoryParserFactoryImpl(); var parser = factory.GetFullHandHistoryParser(site); var handHistory = parser.ParseFullHandHistory(handHistoryText); var actualHandHistoryForumText = ExportFunctions.ConvertHHToForumFormat(handHistory, exportType, true); actualHandHistoryForumText = ReplaceHeader(actualHandHistoryForumText); var expectedHandHistoryForumText = File.ReadAllText(expectedResultFile); Assert.That(actualHandHistoryForumText, Is.EqualTo(expectedHandHistoryForumText)); }