示例#1
0
        public void Index(DirectoryInfoExtended die, SearchOption so = SearchOption.AllDirectories)
        {
            Parallel.ForEach(IndexExtensions.FindExtensionMatches(die), fi =>
            {
                if (fi.Length < TermOptions.ExcludeRules.MinimumSizeToIndexInB)
                {
                    return;
                }

                var indFile = new IndexedFile(fi);

                lock (IndexedFiles)
                {
                    IndexedFiles.Add(indFile);
                }

                foreach (var indTerm in indFile.IndexedStrings)
                {
                    int loc = 0;

                    lock (IndexedFiles)
                    {
                        loc = IndexedTerms.FindIndex(n => n.Term.Equals(indTerm, StringComparison.CurrentCultureIgnoreCase));
                    }

                    var ri = Main.RenameTrackerList.GetItem(indTerm);

                    if (loc < 0)
                    {
                        var newIndTerm = new IndexedTerm(indTerm);

                        if (ri == null || !ri.RequireTermAtStart || (ri.RequireTermAtStart && fi.Name.StartsWith(indTerm, StringComparison.CurrentCultureIgnoreCase) && indFile.IndexedStrings[0].Equals(indTerm, StringComparison.CurrentCultureIgnoreCase)))
                        {
                            newIndTerm.IndexedFiles.Add(fi);
                        }

                        lock (IndexedTerms)
                        {
                            IndexedTerms.Add(newIndTerm);
                        }
                    }
                    else
                    {
                        if (ri == null || !ri.RequireTermAtStart || (ri.RequireTermAtStart && fi.Name.StartsWith(indTerm, StringComparison.CurrentCultureIgnoreCase) && indFile.IndexedStrings[0].Equals(indTerm, StringComparison.CurrentCultureIgnoreCase)))
                        {
                            lock (IndexedTerms)
                            {
                                if (!IndexedTerms[loc].IndexedFiles.Contains(fi))
                                {
                                    IndexedTerms[loc].IndexedFiles.Add(fi);
                                }
                            }
                        }
                    }
                }
            });

            Sort();
        }
示例#2
0
        public List <FileInfo> FindExtensionMatches(DirectoryInfoExtended die)
        {
            var list = new List <FileInfo>();

            if (!die.DirectoryInfo.Exists)
            {
                return(list);
            }

            using (new TimeOperation("GetFiles Operation"))
            {
                list.AddRange(die.GetFiles(false).Where(n => this.Contains(n)));
            }

            return(list.Where(n => n != null).ToList());
        }