コード例 #1
0
        /// <summary>
        /// Property helper for Files &amp; WordFiles, ensures the data retrieved
        /// from those two properties is 'in sync'
        /// </summary>
        private void PrepareForSerialization()
        {
            if (_SerializePreparationDone)
            {
                return;
            }

            _FileList      = new List <File>();
            _WordfileArray = new CatalogWordFile[_Index.Count];
            Word[] wordArray = new Word[_Index.Count];
            _Index.Values.CopyTo(wordArray, 0);

            // go through all the words
            for (int i = 0; i < wordArray.Length; i++)
            {
                // first, add all files to the 'flist' collection
                foreach (File f in wordArray[i].Files)
                {
                    if (!_FileList.Contains(f))
                    {
                        _FileList.Add(f);
                    }
                }
                // now go through again and use the indexes
                CatalogWordFile wf = new CatalogWordFile();
                wf.Text = wordArray[i].Text;
                foreach (File f in wordArray[i].Files)
                {
                    wf.FileIds.Add(_FileList.IndexOf(f));
                }
                _WordfileArray[i] = wf;
            }
            _SerializePreparationDone = true;
        }
        /// <summary>
        /// Property helper for Files &amp; CatalogWordFiles, ensures the data retrieved
        /// from those two properties is 'in sync'
        /// </summary>
        private void PrepareForSerialization()
        {
            if (_SerializePreparationDone)
            {
                return;
            }
            // Create the list of 'Files' (ie. pages indexed) [v7]
            _FileList = new List <File>();
            foreach (File f in _FileIndex.Keys)
            {
                _FileList.Add(f);
                _Cache.SetIndexId(f.Url, f.IndexId);
            }

            _WordfileArray = new CatalogWordFile[_Index.Count];
            Word[] wordArray = new Word[_Index.Count];
            _Index.Values.CopyTo(wordArray, 0);

            // go through all the words
            for (int i = 0; i < wordArray.Length; i++)
            {
                CatalogWordFile wf = new CatalogWordFile();
                wf.Text = wordArray[i].Text;

                foreach (File f in wordArray[i].Files)
                {   // for each File, append the File.IndexId AND the List<int> of positions
                    wf.FileIdsWithPosition.Add(f.IndexId, wordArray[i].InFilesWithPosition()[f]);
                }

                _WordfileArray[i] = wf;
            }
            _SerializePreparationDone = true;
        }