diff --git a/uSync8.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs b/uSync8.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs index c2fa8313..a3bdfddb 100644 --- a/uSync8.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs +++ b/uSync8.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs @@ -117,16 +117,16 @@ protected XElement SerializeStructure(TObject item) var node = new XElement("Structure"); List> items = new List>(); - foreach (var allowedType in item.AllowedContentTypes) + foreach (var allowedType in item.AllowedContentTypes.OrderBy(x => x.SortOrder)) { var allowedItem = FindItem(allowedType.Id.Value); if (allowedItem != null) { - items.Add(new KeyValuePair(allowedItem.Key.ToString(), allowedItem.Alias)); + node.Add(new XElement(ItemType, + new XAttribute("Key", allowedItem.Key), + new XAttribute("SortOrder", allowedItem.SortOrder), allowedItem.Alias)); } } - if (items.Count > 0) - node.Add(items.OrderBy(x => x.Value).Select(x => new XElement(ItemType, new XAttribute("Key", x.Key), x.Value)).ToArray()); return node; } @@ -223,6 +223,8 @@ protected void DeserializeStructure(TObject item, XElement node) logger.Debug(serializerType, "Structure: {0}", key); + var itemSortOrder = baseNode.Attribute("SortOrder").ValueOrDefault(sortOrder); + IContentTypeBase baseItem = default(IContentTypeBase); if (key != Guid.Empty) @@ -244,9 +246,9 @@ protected void DeserializeStructure(TObject item, XElement node) logger.Debug(serializerType, "Structure Found {0}", baseItem.Alias); allowed.Add(new ContentTypeSort( - new Lazy(() => baseItem.Id), sortOrder, baseItem.Alias)); + new Lazy(() => baseItem.Id), itemSortOrder, baseItem.Alias)); - sortOrder++; + sortOrder = itemSortOrder + 1; } }