Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 3
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));
        }