private static void importPlayer(string sourceFilePath, int sourceReference, bool strict, bool onlyImportPremiership) { HtmlDocument doc = new HtmlDocument(); doc.Load(sourceFilePath); var playerExtractor = new PlayerExtractor(doc); string playerName = playerExtractor.GetPlayerName(); //Skip the import if the minimum required info is not present if (string.IsNullOrEmpty(playerName)) { writeInfoToFile(sourceReference, "No player name found"); return; } int? playerSquadNumber = playerExtractor.GetSquadNumber(); int? playerAge = playerExtractor.GetPlayerAge(); var currentClubDto = playerExtractor.GetCurrentClubDto(); if (strict) { //We are going to be more strict on the import rules here and only allow players with: //A squad number, age and current club to be imported if (playerSquadNumber == null) { writeInfoToFile(sourceReference, "No squad number found for player: " + playerName); return; } if (playerAge == null) { writeInfoToFile(sourceReference, "No age found for player: " + playerName); return; } if (currentClubDto == null) { writeInfoToFile(sourceReference, "Current club not found for player: " + playerName); return; } } IList<PlayerClubDto> formerClubDtos = playerExtractor.GetFormerClubs(); if (currentClubDto == null && formerClubDtos.Count == 0) { writeInfoToFile(sourceReference, "Current or former clubs not found for player: " + playerName); return; } if (OnlyImportPremiership) { bool presentOrPastPremierPlayer = PresentOrPastPremierPlayer(currentClubDto, formerClubDtos); if (presentOrPastPremierPlayer == false) { writeInfoToFile(sourceReference, "Player has not played in premiership: " + playerName); return; } } //Import the Player and clubs using (var session = NHibernateHelper.OpenSession()) { using (var transaction = session.BeginTransaction()) { try { importPlayerRecord(session, currentClubDto, formerClubDtos, playerName, sourceReference, playerSquadNumber, playerAge); transaction.Commit(); } catch (Exception ex) { writeErrorToFile(sourceReference, ex); transaction.Rollback(); } } session.Clear(); } }
private static void Test(string sourceFilePath) { HtmlDocument doc = new HtmlDocument(); doc.Load(sourceFilePath); var playerExtractor = new PlayerExtractor(doc); int? squadNo = playerExtractor.GetSquadNumber(); int? age = playerExtractor.GetPlayerAge(); int? clubId = playerExtractor.GetCurrentClubSourceId(); var clubDto = playerExtractor.GetCurrentClubDto(); }