using System; using System.Collections; using System.Collections.Generic; namespace Umbraco.Core.Deploy { /// /// Represents a collection of distinct . /// /// The collection cannot contain duplicates and modes are properly managed. public class ArtifactDependencyCollection : ICollection { private readonly Dictionary _dependencies = new Dictionary(); public IEnumerator GetEnumerator() { return _dependencies.Values.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public void Add(ArtifactDependency item) { if (_dependencies.ContainsKey(item.Udi)) { var exist = _dependencies[item.Udi]; if (item.Mode == ArtifactDependencyMode.Exist || item.Mode == exist.Mode) return; } _dependencies[item.Udi] = item; } public void Clear() { _dependencies.Clear(); } public bool Contains(ArtifactDependency item) { return _dependencies.ContainsKey(item.Udi) && (_dependencies[item.Udi].Mode == item.Mode || _dependencies[item.Udi].Mode == ArtifactDependencyMode.Match); } public void CopyTo(ArtifactDependency[] array, int arrayIndex) { _dependencies.Values.CopyTo(array, arrayIndex); } public bool Remove(ArtifactDependency item) { throw new NotSupportedException(); } public int Count { get { return _dependencies.Count; } } public bool IsReadOnly { get { return false; } } } }