/// <summary> /// Create a book from a list of PGN games /// </summary> /// <returns></returns> private bool CreateBook() { bool bRetVal; try { m_iTotalSkipped = 0; m_iTotalTruncated = 0; m_strError = null; m_ePhase = ParsingPhaseE.None; bRetVal = PgnParser.ExtractMoveListFromMultipleFiles(m_arrFileNames, true /*bNoAttr*/, (cookie, ePhase, iFileIndex, iFileCount, strFileName, iGameProcessed, iGameCount) => { ProgressCallBack(cookie, ePhase, iFileIndex, iFileCount, strFileName, iGameProcessed, iGameCount); }, this, out m_listMoveList, out m_iTotalSkipped, out m_iTotalTruncated, out m_strError); if (bRetVal) { Book = new Book(); BookEntryCount = Book.CreateBookList(m_listMoveList, 30 /*iMinMoveCount*/, 10 /*iMaxDepth*/, (cookie, ePhase, iFileIndex, iFileCount, strFileName, iGameProcessed, iGameCount) => { ProgressCallBack(cookie, ePhase, iFileIndex, iFileCount, strFileName, iGameProcessed, iGameCount); }, this); } } catch (System.Exception ex) { MessageBox.Show(ex.Message); bRetVal = false; } m_bResult = bRetVal; ProgressCallBack(this, ParsingPhaseE.Finished, 0, 0, null, 0, 0); return(bRetVal); }
/// <summary> /// Load the PGN games from the specified file /// </summary> /// <returns></returns> private bool LoadPGN() { bool bRetVal; try { m_iTotalSkipped = 0; m_iTotalTruncated = 0; m_strError = null; m_ePhase = ParsingPhaseE.None; m_pgnParser = new PgnParser(false /*bDiagnose*/); bRetVal = m_pgnParser.InitFromFile(m_strFileName); if (bRetVal) { m_pgnGames = m_pgnParser.GetAllRawPGN(true /*bAttrList*/, false /*bMoveList*/, out m_iTotalSkipped, (cookie, ePhase, iFileIndex, iFileCount, strFileName, iGameProcessed, iGameCount) => { ProgressCallBack(cookie, ePhase, iFileIndex, iFileCount, strFileName, iGameProcessed, iGameCount); }, this); bRetVal = m_pgnGames != null; } } catch (System.Exception ex) { MessageBox.Show(ex.Message); bRetVal = false; } m_bResult = bRetVal; ProgressCallBack(this, ParsingPhaseE.Finished, 0, 0, null, 0, 0); return(bRetVal); }
/// <summary> /// Progress bar /// </summary> /// <param name="ePhase"> Phase</param> /// <param name="iFileIndex"> File index</param> /// <param name="iFileCount"> File count</param> /// <param name="strFileName"> File name</param> /// <param name="iGameDone"> Games processed since the last call</param> /// <param name="iGameCount"> Game count</param> private void WndCallBack(ParsingPhaseE ePhase, int iFileIndex, int iFileCount, string strFileName, int iGameDone, int iGameCount) { if (m_ePhase != ePhase) { switch (ePhase) { case ParsingPhaseE.OpeningFile: ctlPhase.Content = "Openning the file"; ctlFileBeingProcessed.Content = System.IO.Path.GetFileName(strFileName); ctlStep.Content = ""; break; case ParsingPhaseE.ReadingFile: ctlPhase.Content = "Reading the file content into memory"; ctlStep.Content = ""; break; case ParsingPhaseE.RawParsing: ctlPhase.Content = "Parsing the PGN"; ctlStep.Content = "0 / " + iGameCount.ToString() + "mb"; break; case ParsingPhaseE.Finished: ctlPhase.Content = "Done"; break; default: break; } m_ePhase = ePhase; } switch (ePhase) { case ParsingPhaseE.OpeningFile: break; case ParsingPhaseE.ReadingFile: ctlPhase.Content = "Reading the file content into memory"; break; case ParsingPhaseE.RawParsing: ctlStep.Content = iGameDone.ToString() + " / " + iGameCount.ToString() + " mb"; break; case ParsingPhaseE.Finished: if (PgnParser.IsJobCancelled) { DialogResult = false; } else { DialogResult = m_bResult; } break; default: break; } }
/// <summary> /// Progress bar /// </summary> /// <param name="cookie"> Cookie</param> /// <param name="ePhase"> Phase</param> /// <param name="iFileIndex"> File index</param> /// <param name="iFileCount"> File count</param> /// <param name="strFileName"> File name</param> /// <param name="iGameProcessed"> Games processed since the last call</param> /// <param name="iGameCount"> Game count</param> static void ProgressCallBack(object cookie, ParsingPhaseE ePhase, int iFileIndex, int iFileCount, string strFileName, int iGameProcessed, int iGameCount) { frmCreatingBookFromPGN wnd; delProgressCallBack del; wnd = (frmCreatingBookFromPGN)cookie; del = wnd.WndCallBack; wnd.Dispatcher.Invoke(del, System.Windows.Threading.DispatcherPriority.Normal, new object[] { ePhase, iFileIndex, iFileCount, strFileName, iGameProcessed, iGameCount }); }
/// <summary> /// Progress bar /// </summary> /// <param name="cookie"> Cookie</param> /// <param name="ePhase"> Phase</param> /// <param name="iFileIndex"> File index</param> /// <param name="iFileCount"> File count</param> /// <param name="strFileName"> File name</param> /// <param name="iGameProcessed"> Games processed since the last call</param> /// <param name="iGameCount"> Game count</param> static void ProgressCallBack(object cookie, ParsingPhaseE ePhase, int iFileIndex, int iFileCount, string strFileName, int iGameProcessed, int iGameCount) { frmLoadPGNGames frm; delProgressCallBack del; frm = (frmLoadPGNGames)cookie; del = frm.WndCallBack; frm.Dispatcher.Invoke(del, System.Windows.Threading.DispatcherPriority.Normal, new object[] { ePhase, iFileIndex, iFileCount, strFileName, iGameProcessed, iGameCount }); }