/// <summary>
        /// Note: you can call this more than once, in order to change the search language id
        /// </summary>
        public virtual void LoadIndex(string searchLanguageId)
        {
            if (_imageIndexReader == null)
            {
                LoadLanguageChoices();
            }

            _indexOfWordsToRelativePath           = new Dictionary <string, List <string> >();
            _indexOfRelativeFilePathToKeywordsCsv = new Dictionary <string, string>();

            using (var f = File.OpenText(FindIndexFileInFolder(FolderPath)))
            {
                //skip header line, which was already read to make the index layout above
                f.ReadLine();
                while (!f.EndOfStream)
                {
                    var line          = f.ReadLine();
                    var fields        = line.Split(new char[] { '\t' });
                    var relativePath  = _imageIndexReader.GetImageRelativePath(fields);
                    var csvOfKeywords = _imageIndexReader.GetCSVOfKeywordsOrEmpty(searchLanguageId, fields);
                    if (String.IsNullOrWhiteSpace(csvOfKeywords))
                    {
                        continue;
                    }
                    lock (_padlock)
                        _indexOfRelativeFilePathToKeywordsCsv.Add(relativePath, csvOfKeywords.Replace(",", ", "));
                    var keys = csvOfKeywords.SplitTrimmed(',');
                    foreach (var key in keys)
                    {
                        lock (_padlock)
                            _indexOfWordsToRelativePath.GetOrCreate(key.ToLowerInvariant()).Add(relativePath);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Note: you can call this more than once, in order to change the search language id
        /// </summary>
        public virtual void LoadIndex(string searchLanguageId)
        {
            if (_imageIndexReader == null)
            {
                LoadLanguageChoices();
            }

            _indexOfWordsToRelativePath           = new Dictionary <string, List <string> >();
            _indexOfRelativeFilePathToKeywordsCsv = new Dictionary <string, string>();

            var indexPath = FindIndexFileInFolder(FolderPath);

            using (var f = File.OpenText(indexPath))
            {
                //skip header line, which was already read to make the index layout above
                f.ReadLine();
                while (!f.EndOfStream)
                {
                    var line          = f.ReadLine();
                    var fields        = line.Split(new char[] { '\t' });
                    var relativePath  = _imageIndexReader.GetImageRelativePath(fields);
                    var csvOfKeywords = _imageIndexReader.GetCSVOfKeywordsOrEmpty(searchLanguageId, fields);
                    if (String.IsNullOrWhiteSpace(csvOfKeywords))
                    {
                        continue;
                    }
                    lock (_padlock)
                    {
                        try
                        {
                            _indexOfRelativeFilePathToKeywordsCsv.Add(relativePath, csvOfKeywords.Replace(",", ", "));
                        }
                        catch (System.ArgumentException)
                        {
                            if (_indexOfRelativeFilePathToKeywordsCsv.ContainsKey(relativePath))
                            {
                                throw new ApplicationException(
                                          $"{indexPath} has more than one row describing a file name '{relativePath}'. This is not allowed. You can use 'conditional formatting' with the condition 'duplicate' in a spreadsheet program to find duplicates.");
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                    var keys = csvOfKeywords.SplitTrimmed(',');
                    foreach (var key in keys)
                    {
                        lock (_padlock)
                            _indexOfWordsToRelativePath.GetOrCreate(key.ToLowerInvariant()).Add(relativePath);
                    }
                }
            }
        }