mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user