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 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); } }