Exemple #1
0
        public void Merge(Provider other)
        {
            foreach (var kv in other.FullPathToEntry)
            {
                var theirs = other.Entries [kv.Value];
                int index;
                if (!FullPathToEntry.TryGetValue(kv.Key, out index))
                {
                    FullPathToEntry.Add(kv.Key, CurrentId);
                    Entries.Add(CurrentId, theirs);
                    CurrentId = CurrentId + 1;
                }
                else
                {
                    var ours = Entries [index];

                    // check to see if we've removed an entry, unless we recently
                    // updated the entry:
                    long maxFreq = Math.Max(theirs.Frequency, ours.Frequency);
                    if (!theirs.IsValid && theirs.LastAccessTime >= ours.LastAccessTime)
                    {
                        maxFreq = Entry.cInvalid;
                    }
                    else if (!ours.IsValid && ours.LastAccessTime >= theirs.LastAccessTime)
                    {
                        maxFreq = Entry.cInvalid;
                    }

                    Entries [index] = new Entry(ours.FullPath, maxFreq, Math.Max(theirs.LastAccessTimeUtc, ours.LastAccessTimeUtc), ours.IsLeaf);
                }
            }
        }
Exemple #2
0
        public bool Remove(string fullPath)
        {
            var fullPathLower = fullPath.ToLower().TrimEnd(new char[] { '\\', '/' });
            int id;

            if (!FullPathToEntry.TryGetValue(fullPathLower, out id))
            {
                return(false);
            }

            return(UpdateEntry(id, remove: true));
        }
Exemple #3
0
        public void Add(Entry e)
        {
            FullPathToEntry.Add(e.FullPath.ToLower(), CurrentId);
            Entries.Add(CurrentId, e);
            string    lastElement      = GetLastElement(e.FullPath);
            string    lastElementLower = lastElement.ToLower();
            LastEntry lastEntry;

            if (!LastEntries.TryGetValue(lastElementLower, out lastEntry))
            {
                lastEntry = new LastEntry {
                    Name = lastElement, Ids = new List <int>()
                };
                LastEntries.Add(lastElementLower, lastEntry);
            }
            lastEntry.Ids.Add(CurrentId);
            CurrentId = CurrentId + 1;
        }
Exemple #4
0
        public bool UpdateEntry(string fullPath, Predicate <string> checkIsLeaf = null)
        {
            int id;

            fullPath = fullPath.TrimEnd(new char[] { '\\', '/' });
            string fullPathLower = fullPath.ToLower();

            if (!FullPathToEntry.TryGetValue(fullPathLower, out id))
            {
                if (checkIsLeaf == null)
                {
                    return(false);
                }

                Add(new Entry(fullPath, 1, DateTime.Now.ToFileTimeUtc(), checkIsLeaf(fullPath)));
                return(true);
            }

            return(UpdateEntry(id));
        }