private void buttonParse_Click(object sender, EventArgs e) { if (listBoxSite.SelectedIndex == -1) { MessageBox.Show(this, "Please pick a site"); return; } IHandHistoryParserFactory factory = new HandHistoryParserFactoryImpl(); var handParser = factory.GetFullHandHistoryParser((SiteName)listBoxSite.SelectedItem); try { var hands = handParser.SplitUpMultipleHands(richTextBoxHandText.Text).ToList(); foreach (var hand in hands) { var parsedHand = handParser.ParseFullHandHistory(hand, true); } MessageBox.Show(this, "Parsed " + hands.Count + " hands."); } catch (Exception ex) { MessageBox.Show(this, ex.Message + "\r\n" + ex.StackTrace, "Error"); } }
private List <string> ParseHands(SiteName site, string handText, ref int parsedHands, ref int thrownOutHands) { List <string> messages = new List <string>(); // Each poker site has its own parser so we use a factory to get the right parser. IHandHistoryParserFactory handHistoryParserFactory = new HandHistoryParserFactoryImpl(); // Get the correct parser from the factory. IHandHistoryParser handHistoryParser = handHistoryParserFactory.GetFullHandHistoryParser(site); try { List <string> hands = new List <string>(); hands = handHistoryParser.SplitUpMultipleHands(handText).ToList(); db.Configuration.AutoDetectChangesEnabled = false; foreach (string hand in hands) { try { // The true causes hand-parse errors to get thrown. If this is false, hand-errors will // be silent and null will be returned. HandHistory handHistory = handHistoryParser.ParseFullHandHistory(hand, true); //handhistory can now be broken down to be put into the database // Add to player table Dictionary <string, player> playerDict = addPlayersToDB(handHistory); // Add to table table table dbTable = addTableToDB(handHistory); db.SaveChanges(); //Add to hand table hand dbHand = addHandToDB(handHistory, dbTable); // Add to hand_action table addHandActionToDB(handHistory, dbHand, playerDict); // Add to plays table addPlaysToDB(handHistory, playerDict); db.SaveChanges(); parsedHands++; } catch (Exception ex) { messages.Add("Parsing Error: " + ex.Message); thrownOutHands++; } } } catch (Exception ex) // Catch hand-parsing exceptions { messages.Add("Parsing Error: " + ex.Message); } db.Configuration.AutoDetectChangesEnabled = true; return(messages); }
public void ParsingDoesNotThrowExceptions(string culture) { var cultureInfo = new CultureInfo(culture); Thread.CurrentThread.CurrentCulture = cultureInfo; var testDataDirectoryInfo = new DirectoryInfo(TestDataFolder); var handHistoryFiles = testDataDirectoryInfo.GetFiles("*.txt", SearchOption.AllDirectories); var succeded = 0; var total = 0; foreach (var handHistoryFile in handHistoryFiles) { if (handHistoryFile.FullName.Contains("Tournaments") || handHistoryFile.FullName.Contains("WithInvalid")) { continue; } var handHistory = File.ReadAllText(handHistoryFile.FullName); var parserFactory = new HandHistoryParserFactoryImpl(); var parser = parserFactory.GetFullHandHistoryParser(handHistory); var hands = parser.SplitUpMultipleHands(handHistory).ToArray(); total += hands.Length; var hash = new HashSet <string>(); foreach (var hand in hands) { try { parser.ParseFullHandHistory(hand, true); succeded++; } catch (Exception e) { if (!hash.Contains(handHistoryFile.FullName)) { Debug.WriteLine(handHistoryFile.FullName); } Assert.Fail(e.ToString()); } } } Assert.AreEqual(total, succeded); Debug.WriteLine("Processed hands: {0}/{1}", succeded, total); }
public void GetFullHandHistoryParserReturnsExpectedParser(string fileName, EnumPokerSites expectedSite) { var file = Path.Combine(testFolder, fileName); if (!File.Exists(file)) { throw new Exception(string.Format("Test file '{0}' doesn't exist", file)); } var handText = File.ReadAllText(file); var handHistoryParserFactory = new HandHistoryParserFactoryImpl(); var parser = handHistoryParserFactory.GetFullHandHistoryParser(handText); Assert.That(parser.SiteName, Is.EqualTo(expectedSite)); }
private HandHistories.Objects.Hand.HandHistory ReadHandHistory(string file) { file = Path.Combine("UnitTests\\TestData\\EquitySolverData", file); FileAssert.Exists(file); var handHistoryText = File.ReadAllText(file); Assert.IsNotEmpty(handHistoryText); var parserFactory = new HandHistoryParserFactoryImpl(); var parser = parserFactory.GetFullHandHistoryParser(handHistoryText); var handHistory = parser.ParseFullHandHistory(handHistoryText); Assert.IsNotNull(handHistory); return(handHistory); }
private HandHistories.Objects.Hand.HandHistory ParseHand(string fileName) { fileName = Path.Combine(commonHandsFolder, fileName); if (parsedHandHistories.TryGetValue(fileName, out HandHistories.Objects.Hand.HandHistory hand)) { return(hand); } var handText = File.ReadAllText(fileName); var factory = new HandHistoryParserFactoryImpl(); var parser = factory.GetFullHandHistoryParser(handText); hand = parser.ParseFullHandHistory(handText); parsedHandHistories[fileName] = hand; return(hand); }
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)); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); IHandHistoryParserFactory handHistoryParserFactory = new HandHistoryParserFactoryImpl(); // Get the correct parser from the factory. IHandHistoryParser handHistoryParser = handHistoryParserFactory.GetFullHandHistoryParser(HandHistories.Objects.GameDescription.SiteName.PokerStars); var handText = System.IO.File.ReadAllText("input.txt"); try { // The true causes hand-parse errors to get thrown. If this is false, hand-errors will // be silent and null will be returned. HandHistory handHistory = handHistoryParser.ParseFullHandHistory(handText, true); } catch (Exception ex) // Catch hand-parsing exceptions { Console.WriteLine("Parsing Error: {0}", ex.Message); // Example logging. } }
private void buttonParse_Click(object sender, EventArgs e) { if (listBoxSite.SelectedIndex == -1) { MessageBox.Show(this, "Please pick a site"); return; } IHandHistoryParserFactory factory = new HandHistoryParserFactoryImpl(); var handParser = factory.GetFullHandHistoryParser((SiteName) listBoxSite.SelectedItem); try { string text = richTextBoxHandText.Text; int parsedHands = 0; Stopwatch SW = new Stopwatch(); SW.Start(); HandHistoryParserFastImpl fastParser = handParser as HandHistoryParserFastImpl; var hands = fastParser.SplitUpMultipleHandsToLines(text); foreach (var hand in hands) { var parsedHand = fastParser.ParseFullHandHistory(hand, true); parsedHands++; } SW.Stop(); MessageBox.Show(this, "Parsed " + parsedHands + " hands." + Math.Round(SW.Elapsed.TotalMilliseconds, 2) + "ms"); } catch (Exception ex) { MessageBox.Show(this, ex.Message + "\r\n" + ex.StackTrace, "Error"); } }
public HandHistory ParseHand(SiteName site, string handText, ref int parsedHands, ref int thrownOutHands) { // Each poker site has its own parser so we use a factory to get the right parser. IHandHistoryParserFactory handHistoryParserFactory = new HandHistoryParserFactoryImpl(); // Get the correct parser from the factory. IHandHistoryParser handHistoryParser = handHistoryParserFactory.GetFullHandHistoryParser(site); try { // The true causes hand-parse errors to get thrown. If this is false, hand-errors will // be silent and null will be returned. List <string> hands = new List <string>(); hands = handHistoryParser.SplitUpMultipleHands(handText).ToList(); foreach (string hand in hands) { try { HandHistory handHistory = handHistoryParser.ParseFullHandHistory(hand, true); Console.WriteLine(handHistory.HandId); parsedHands++; } catch (Exception ex) { Console.WriteLine("Parsing Error: {0}", ex.Message); // Example logging. thrownOutHands++; } } return(null); } catch (Exception ex) // Catch hand-parsing exceptions { Console.WriteLine("Parsing Error: {0}", ex.Message); // Example logging. return(null); } }