public IReadOnlyCollection <IndexObject> AddFile(string path) { path = Path.GetFullPath(path); List <IndexObject> collisions = null; lock (this.byPath) { if (!this.byPath.ContainsKey(path)) { IndexObject created = new IndexObject(path); lock (this.byHash) { collisions = this.byHash .Where(x => this.comparer.Compare(x.Key, created.Hash)) .Select(x => x.Value) .ToList(); if (collisions.Count == 0) { this.byPath.Add(path, created); this.byHash.Add(created.Hash, created); } } } } return((IReadOnlyCollection <IndexObject>)collisions ?? new IndexObject[0]); }
public void RemoveFile(string path) { path = Path.GetFullPath(path); lock (this.byPath) { if (this.byPath.ContainsKey(path)) { lock (this.byHash) { IndexObject cache = this.byPath[path]; this.byHash.Remove(cache.Hash); lock (cache) { foreach (Category category in cache.Categories) { lock (category) { category.RemoveItem(cache); } } } } } } }
/// <summary> /// Adds the specified <see cref="IndexObject"/> <paramref name="item"/> to the category. /// </summary> /// <param name="item"> /// The <see cref="IndexObject"/> to add to this category. /// </param> public void AddItem(IndexObject item) { lock (this.innerItems) { if (!this.innerItems.Contains(item)) { this.innerItems.Add(item); } } }
/// <summary> /// Removes the specified <see cref="IndexObject"/> <paramref name="item"/> from the category, or throws <see cref="KeyNotFoundException"/> if the <see cref="IndexObject"/> was not in the category. /// </summary> /// <param name="item"></param> public void RemoveItem(IndexObject item) { lock (this.innerItems) { if (this.innerItems.Contains(item)) { this.innerItems.Remove(item); } else { throw new KeyNotFoundException( string.Format( CultureInfo.InvariantCulture, Properties.Resources.IndexObjectNotInCategory, this.Name, item.Hash)); } } }
/// <summary> /// Checks if the supplied <see cref="IndexObject"/>s have the same path and hash. /// </summary> /// <param name="left"> /// The first <see cref="IndexObject"/>. /// </param> /// <param name="right"> /// The second <see cref="IndexObject"/>. /// </param> /// <returns> /// True if the supplied <see cref="IndexObject"/>s have the same path and hash, and false otherwise. /// </returns> public static bool PathAndHashMatch(IndexObject left, IndexObject right) { return(left.Path == right.Path && left.Hash == right.Hash); }
/// <summary> /// Checks if the supplied <see cref="IndexObject"/> has the same path and hash as this <see cref="IndexObject"/>. /// </summary> /// <param name="item"> /// The <see cref="IndexObject"/> to compare the path and hash with. /// </param> /// <returns> /// True if the supplied <see cref="IndexObject"/> has the same path and hash, and false otherwise. /// </returns> public bool PathAndHashMatch(IndexObject item) { return(IndexObject.PathAndHashMatch(this, item)); }