private void Import(object sender, DoWorkEventArgs e) { var filename = (String)e.Argument; var io = new FileIO(filename, ErrorFilepath); Total = io.Count(); foreach (ChessGame g in io.ImportPGN()) { try { var dbGame = new DBGame(g) { ID = LastID }; var tmpGameStates = GenerateStates(dbGame, LastID); GamesToInsert.Add(dbGame); GameStatesToInsert.AddRange(tmpGameStates); ++LastID; ++Done; ReportProgress(Done, dbGame); } catch (Exception) { io.WriterToLog(new PGNParser().Generate(g), ErrorFilepath); } if (Done % GamesToLoad == 0) SaveChanges(); } SaveChanges(); MakeResults(e); }
private List<DBGameState> GenerateStates(DBGame dbGame, int id) { var result = new List<DBGameState>(); var num = 1; do { var gs = new DBGameState { FEN = ((ChessState)dbGame.Game.State).ToStringShort(), Games = dbGame, Num = num++, Game = id }; dbGame.GameStates.Add(gs); result.Add(gs); } while (dbGame.Game.MakeMove()); while (dbGame.Game.UndoMove()) { } return result; }
/// <summary> /// Create a new DBGame object. /// </summary> /// <param name="id">Initial value of the ID property.</param> public static DBGame CreateDBGame(global::System.Int32 id, ChessGame game) { DBGame dBGame = new DBGame(game); dBGame.ID = id; return dBGame; }
/// <summary> /// Deprecated Method for adding a new object to the Games EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToGames(DBGame dBGame) { base.AddObject("Games", dBGame); }