diff --git a/src/Orchard/ContentManagement/ContentIdentity.cs b/src/Orchard/ContentManagement/ContentIdentity.cs index 99ce2f527..739b5a949 100644 --- a/src/Orchard/ContentManagement/ContentIdentity.cs +++ b/src/Orchard/ContentManagement/ContentIdentity.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; using System.Text; namespace Orchard.ContentManagement { @@ -9,6 +11,19 @@ namespace Orchard.ContentManagement { _dictionary = new Dictionary(); } + public ContentIdentity(string identity) { + _dictionary = new Dictionary(); + if (!String.IsNullOrEmpty(identity)) { + var identityEntries = identity.Split(new[] {"/"}, StringSplitOptions.RemoveEmptyEntries); + foreach (var token in identityEntries) { + var kv = token.Split(new[] {"="}, StringSplitOptions.None); + if (kv.Length == 2) { + _dictionary.Add(kv[0], kv[1]); + } + } + } + } + public void Add(string name, string value) { if (_dictionary.ContainsKey(name)) { _dictionary[name] = value; @@ -25,5 +40,19 @@ namespace Orchard.ContentManagement { } return stringBuilder.ToString(); } + + public class ContentIdentityEqualityComparer : IEqualityComparer { + public bool Equals(ContentIdentity contentIdentity1, ContentIdentity contentIdentity2) { + if (contentIdentity1._dictionary.Keys.Count != contentIdentity2._dictionary.Keys.Count) + return false; + + return contentIdentity1._dictionary.OrderBy(kvp => kvp.Key).SequenceEqual(contentIdentity2._dictionary.OrderBy(kvp => kvp.Key)); + } + + public int GetHashCode(ContentIdentity contentIdentity) { + return contentIdentity.ToString().GetHashCode(); + } + } + } } diff --git a/src/Orchard/ContentManagement/ImportContentSession.cs b/src/Orchard/ContentManagement/ImportContentSession.cs index 2a4e78a32..b46e47598 100644 --- a/src/Orchard/ContentManagement/ImportContentSession.cs +++ b/src/Orchard/ContentManagement/ImportContentSession.cs @@ -4,22 +4,22 @@ namespace Orchard.ContentManagement { public class ImportContentSession { private readonly IContentManager _contentManager; - // order of x500 elements. - private readonly Dictionary _dictionary; + private readonly Dictionary _dictionary; public ImportContentSession(IContentManager contentManager) { _contentManager = contentManager; - _dictionary = new Dictionary(); + _dictionary = new Dictionary(new ContentIdentity.ContentIdentityEqualityComparer()); } - // gets a content item for an identity string. public ContentItem Get(string id) { - if (_dictionary.ContainsKey(id)) - return _dictionary[id]; + var contentIdentity = new ContentIdentity(id); + + if (_dictionary.ContainsKey(contentIdentity)) + return _dictionary[contentIdentity]; foreach (var item in _contentManager.Query(VersionOptions.Published).List()) { - var identity = _contentManager.GetItemMetadata(item).Identity.ToString(); - if (identity == id) { + var identity = _contentManager.GetItemMetadata(item).Identity; + if (identity == contentIdentity) { _dictionary.Add(identity, item); return item; } @@ -29,7 +29,8 @@ namespace Orchard.ContentManagement { } public void Store(string id, ContentItem item) { - _dictionary.Add(id, item); + var contentIdentity = new ContentIdentity(id); + _dictionary.Add(contentIdentity, item); } }