コード例 #1
0
        /// <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          = ChessSharp.ChessLogicF.PgnParser.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, ChessSharp.ChessLogicF.PgnParser.ParsingPhaseE.Finished, 0, 0, null, 0, 0);
            return(bRetVal);
        }
コード例 #2
0
        /// <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(ChessSharp.ChessLogicF.PgnParser.ParsingPhaseE ePhase, int iFileIndex, int iFileCount, string strFileName, int iGameDone, int iGameCount)
        {
            if (m_ePhase != ePhase)
            {
                switch (ePhase)
                {
                case ChessSharp.ChessLogicF.PgnParser.ParsingPhaseE.OpeningFile:
                    ctlPhase.Content = "Openning the file";
                    ctlFileBeingProcessed.Content = System.IO.Path.GetFileName(strFileName);
                    ctlStep.Content = "";
                    break;

                case ChessSharp.ChessLogicF.PgnParser.ParsingPhaseE.ReadingFile:
                    ctlPhase.Content = "Reading the file content into memory";
                    ctlStep.Content  = "";
                    break;

                case ChessSharp.ChessLogicF.PgnParser.ParsingPhaseE.RawParsing:
                    ctlPhase.Content = "Parsing the PGN";
                    ctlStep.Content  = "0 / " + iGameCount.ToString() + "mb";
                    break;

                case ChessSharp.ChessLogicF.PgnParser.ParsingPhaseE.Finished:
                    ctlPhase.Content = "Done";
                    break;

                default:
                    break;
                }
                m_ePhase = ePhase;
            }
            switch (ePhase)
            {
            case ChessSharp.ChessLogicF.PgnParser.ParsingPhaseE.OpeningFile:
                break;

            case ChessSharp.ChessLogicF.PgnParser.ParsingPhaseE.ReadingFile:
                ctlPhase.Content = "Reading the file content into memory";
                break;

            case ChessSharp.ChessLogicF.PgnParser.ParsingPhaseE.RawParsing:
                ctlStep.Content = iGameDone.ToString() + " / " + iGameCount.ToString() + " mb";
                break;

            case ChessSharp.ChessLogicF.PgnParser.ParsingPhaseE.Finished:
                if (PgnParser.IsJobCancelled)
                {
                    DialogResult = false;
                }
                else
                {
                    DialogResult = m_bResult;
                }
                break;

            default:
                break;
            }
        }
コード例 #3
0
        /// <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, ChessSharp.ChessLogicF.PgnParser.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 });
        }