Example #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;
        }
Example #2
0
 /// <summary>
 /// Add a new Word/File pair to the Catalog
 /// </summary>
 public bool Add(string word, File infile, int position)
 {
     // ### Make sure the Word object is in the index ONCE only
     if (_Index.ContainsKey(word))
     {
         Word theword = (Word)_Index[word];	// add this file reference to the Word
         theword.Add(infile, position);
     }
     else
     {
         Word theword = new Word(word, infile, position);	// create a new Word object
         _Index.Add(word, theword);
     }
     _SerializePreparationDone = false;  // adding to the catalog invalidates 'serialization preparation'
     return true;
 }