private void GameCount() { string content = File.ReadAllText(filepath); Regex expression = new Regex(@"\[Event \""", RegexOptions.Singleline); int count = expression.Matches(content).Count; TotalGames = count; isTotalGamesCalculated = true; if (OnProgressBarInitialized != null) { ProgressBarEventArgs args = new ProgressBarEventArgs(0, count); OnProgressBarInitialized(null, args); } }
void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { int count = 0; pgnFileWriter = new StringBuilder(); string filename = e.Argument as string; workEventArgument = e; List <GameItem> games = Ap.Database.GetGamesItems(); int totalGamesCount = games.Count; if (OnProgressBarInitialized != null) { ProgressBarEventArgs args = new ProgressBarEventArgs(0, totalGamesCount); OnProgressBarInitialized(null, args); } backgroundWorker.ReportProgress(0); foreach (GameItem item in games) { count++; if (isImportInCurrentGameBook) { book.ImportGame(item); } else { GameData gameData = item.GameData; Moves moves = item.Moves; ConvertGameData(pgnFileWriter, gameData); ConvertMovesData(pgnFileWriter, moves); ConvertResultData(pgnFileWriter, gameData.Result); } backgroundWorker.ReportProgress(count); if (backgroundWorker.CancellationPending) { if (workEventArgument != null) { workEventArgument.Cancel = true; return; } } } book.Save(); }