Make ContentIdentity the key for the ImportContentSession table. This will make the order in which the tokens appear in the x.500 ids irrelevant, which is desired.

--HG--
branch : dev
This commit is contained in:
Suha Can
2011-03-15 17:46:03 -07:00
parent 3c2cfa471b
commit d38ccab883
2 changed files with 40 additions and 10 deletions

View File

@@ -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<string, string>();
}
public ContentIdentity(string identity) {
_dictionary = new Dictionary<string, string>();
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<ContentIdentity> {
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();
}
}
}
}

View File

@@ -4,22 +4,22 @@ namespace Orchard.ContentManagement {
public class ImportContentSession {
private readonly IContentManager _contentManager;
// order of x500 elements.
private readonly Dictionary<string, ContentItem> _dictionary;
private readonly Dictionary<ContentIdentity, ContentItem> _dictionary;
public ImportContentSession(IContentManager contentManager) {
_contentManager = contentManager;
_dictionary = new Dictionary<string, ContentItem>();
_dictionary = new Dictionary<ContentIdentity, ContentItem>(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);
}
}