protected static void SetLinkedItem(string value, ReadingJournal journal, Action<ContentItem> setter, string versionKey = null) { int referencedItemID = int.Parse(value); if (referencedItemID != 0) { ContentItem referencedItem = journal.Find(referencedItemID); if (referencedItem != null) { setter(referencedItem); } else { journal.Register(referencedItemID, setter, relationType: "link"); } } else if (!string.IsNullOrEmpty(versionKey)) { ContentItem referencedItem = journal.Find(versionKey); if (referencedItem != null) { setter(referencedItem); } else { journal.Register(versionKey, setter); } } }
private void ReadProperty(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { Dictionary <string, string> attributes = GetAttributes(navigator); string name = attributes["name"]; if (!attributes.ContainsKey("typeName")) { item[name] = null; return; } Type type = Utility.TypeFromName(attributes["typeName"]); if (type == typeof(ContentItem)) { SetLinkedItem(navigator.Value, journal, (referencedItem) => item[name] = referencedItem, attributes.GetValueOrDefault("versionKey")); } else if (type.IsContentItemEnumeration()) { SetLinkedItems(navigator, journal, item, name); } else { item[name] = Parse(navigator.Value, type); } }
protected static void SetLinkedItem(string value, ReadingJournal journal, Action <ContentItem> setter, string versionKey = null) { int referencedItemID = int.Parse(value); if (referencedItemID != 0) { ContentItem referencedItem = journal.Find(referencedItemID); if (referencedItem != null) { setter(referencedItem); } else { journal.Register(referencedItemID, setter); } } else if (!string.IsNullOrEmpty(versionKey)) { ContentItem referencedItem = journal.Find(versionKey); if (referencedItem != null) { setter(referencedItem); } else { journal.Register(versionKey, setter); } } }
internal ContentDetail ReadMultipleValue(XPathNavigator navigator, ContentItem item, ReadingJournal journal, string name) { var multiDetail = ContentDetail.Multi(name); foreach (XPathNavigator valueElement in EnumerateChildren(navigator)) { switch (valueElement.GetAttribute("key", "")) { case ContentDetail.TypeKeys.BoolType: multiDetail.BoolValue = (bool)Parse(valueElement.Value, typeof(bool)); break; case ContentDetail.TypeKeys.DateTimeType: multiDetail.DateTimeValue = (DateTime)Parse(valueElement.Value, typeof(DateTime)); break; case ContentDetail.TypeKeys.DoubleType: multiDetail.DoubleValue = (double)Parse(valueElement.Value, typeof(double)); break; case ContentDetail.TypeKeys.IntType: multiDetail.IntValue = (int)Parse(valueElement.Value, typeof(int)); break; case ContentDetail.TypeKeys.LinkType: SetLinkedItem(valueElement.Value, journal, (referencedItem) => multiDetail.LinkedItem = referencedItem); break; case ContentDetail.TypeKeys.MultiType: journal.Error(new InvalidOperationException("Nested multi types not supported")); break; case ContentDetail.TypeKeys.ObjectType: multiDetail.ObjectValue = Parse(valueElement.Value, typeof(object)); break; case ContentDetail.TypeKeys.StringType: multiDetail.StringValue = (string)PrepareStringDetail(item, name, valueElement.Value); break; } } return multiDetail; }
public void Read(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { foreach (XPathNavigator detailCollectionElement in EnumerateChildren(navigator)) { ReadDetailCollection(detailCollectionElement, item, journal); } }
protected virtual void ReadDetail(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { Dictionary<string, string> attributes = GetAttributes(navigator); Type type = Utility.TypeFromName(attributes["typeName"]); string name = attributes["name"]; if (type == typeof(ContentItem)) { SetLinkedItem(navigator.Value, journal, (referencedItem) => item[name] = referencedItem, attributes.GetValueOrDefault("versionKey")); } else if(type == typeof(IMultipleValue)) { var multiDetail = ReadMultipleValue(navigator, item, journal, name); multiDetail.AddTo(item); } else { object value = Parse(navigator.Value, type); if (value is string) value = PrepareStringDetail(item, name, value as string, attributes.ContainsKey("encoded") && Convert.ToBoolean(attributes["encoded"])); item.SetDetail(name, value, type); } }
public void Read(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { foreach (XPathNavigator detailCollectionElement in EnumerateChildren(navigator)) { ReadDetailCollection(detailCollectionElement, item, journal); } }
public virtual IImportRecord Read(XPathNavigator navigator) { if (navigator == null) { throw new ArgumentNullException("navigator"); } ReadingJournal journal = new ReadingJournal(); foreach (XPathNavigator itemElement in EnumerateChildren(navigator)) { try { ContentItem item = ReadSingleItem(itemElement, journal); journal.Report(item); } catch (DefinitionNotFoundException ex) { journal.Error(ex); if (!_ignoreMissingTypes) { throw; } } } return(journal); }
public void Read(System.Xml.XPath.XPathNavigator navigator, ContentItem item, ReadingJournal journal) { foreach (XPathNavigator detailElement in EnumerateChildren(navigator)) { ReadProperty(detailElement, item, journal); } }
private static void Handle(ContentItem item, ReadingJournal journal, int id) { var child = journal.Find(id); if (child != null) child.AddTo(item); else journal.Register(id, (ci) => ci.AddTo(item), isChild: true); }
public void Read(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { foreach (XPathNavigator authorizationElement in EnumerateChildren(navigator)) { string role = authorizationElement.Value; item.AuthorizedRoles.Add(new AuthorizedRole(item, role)); } }
public void Read(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { foreach (XPathNavigator authorizationElement in EnumerateChildren(navigator)) { string role = authorizationElement.Value; item.AuthorizedRoles.Add(new AuthorizedRole(item, role)); } }
private void Handle(ContentItem item, ReadingJournal journal, string versionKey) { var child = journal.Find(versionKey); if (child != null) child.AddTo(item); else journal.Register(versionKey, (ci) => ci.AddTo(item), isChild: true); }
protected virtual void HandleParentRelation(ContentItem item, string parent, ReadingJournal journal) { if (!string.IsNullOrEmpty(parent)) { int parentID = int.Parse(parent); ContentItem parentItem = journal.Find(parentID); item.AddTo(parentItem); } }
protected void ReadDetailCollection(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { Dictionary<string, string> attributes = GetAttributes(navigator); string name = attributes["name"]; foreach (XPathNavigator detailElement in EnumerateChildren(navigator)) { ReadDetail(detailElement, item.GetDetailCollection(name, true), journal); } }
protected virtual void ReadDetail(XPathNavigator navigator, DetailCollection collection, ReadingJournal journal) { Dictionary<string, string> attributes = GetAttributes(navigator); Type type = Utility.TypeFromName(attributes["typeName"]); string meta = attributes.ContainsKey("meta") ? attributes["meta"] : null; if (type == typeof(ContentItem)) { int referencedItemID = int.Parse(navigator.Value); ContentItem referencedItem = journal.Find(referencedItemID); if (referencedItem != null) { collection.Add(ContentDetail.New( collection.EnclosingItem, attributes["name"], referencedItem, meta)); } else { journal.Register(referencedItemID, (item) => { collection.Add(ContentDetail.New( collection.EnclosingItem, attributes["name"], item, meta)); }, relationType: "collectionlink"); } } else if (type == typeof(Enum)) { if (meta != null) { collection.Add(ContentDetail.New( collection.EnclosingItem, attributes["name"], Parse(navigator.Value, Type.GetType(meta)))); } } else if (type == typeof(IMultipleValue)) { var detail = detailReader.ReadMultipleValue(navigator, collection.EnclosingItem, journal, collection.Name); detail.Meta = meta; detail.AddTo(collection); } else { object value = Parse(navigator.Value, type); if (value is string) value = detailReader.PrepareStringDetail(collection.EnclosingItem, collection.Name, value as string, attributes.ContainsKey("encoded") && Convert.ToBoolean(attributes["encoded"])); collection.Add(ContentDetail.New(collection.EnclosingItem, attributes["name"], value, meta)); } }
private void ReadProperty(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { Dictionary<string, string> attributes = GetAttributes(navigator); Type type = Utility.TypeFromName(attributes["typeName"]); string name = attributes["name"]; if(type == typeof(ContentItem)) SetLinkedItem(navigator.Value, journal, (referencedItem) => item[name] = referencedItem); else item[name] = Parse(navigator.Value, type); }
protected static void SetLinkedItem(string value, ReadingJournal journal, Action<ContentItem> setter) { int referencedItemID = int.Parse(value); ContentItem referencedItem = journal.Find(referencedItemID); if (referencedItem != null) { setter(referencedItem); } else { journal.Register(referencedItemID, setter); } }
private static void Handle(ContentItem item, ReadingJournal journal, int id) { var child = journal.Find(id); if (child != null) { child.AddTo(item); } else { journal.Register(id, (ci) => ci.AddTo(item), isChild: true); } }
private void Handle(ContentItem item, ReadingJournal journal, string versionKey) { var child = journal.Find(versionKey); if (child != null) { child.AddTo(item); } else { journal.Register(versionKey, (ci) => ci.AddTo(item), isChild: true); } }
protected virtual void ReadDetail(XPathNavigator navigator, DetailCollection collection, ReadingJournal journal) { Dictionary<string, string> attributes = GetAttributes(navigator); Type type = Utility.TypeFromName(attributes["typeName"]); if (type == typeof(ContentItem)) { int referencedItemID = int.Parse(navigator.Value); ContentItem referencedItem = journal.Find(referencedItemID); if (referencedItem != null) { collection.Add(ContentDetail.New( collection.EnclosingItem, attributes["name"], referencedItem)); } else { journal.Register(referencedItemID, (item) => { collection.Add(ContentDetail.New( collection.EnclosingItem, attributes["name"], item)); }); } } else if (type == typeof(Enum)) { if (attributes.ContainsKey("meta")) { collection.Add(ContentDetail.New( collection.EnclosingItem, attributes["name"], Parse(navigator.Value, Type.GetType(attributes["meta"])))); } } else if (type == typeof(IMultipleValue)) { detailReader.ReadMultipleValue(navigator, collection.EnclosingItem, journal, collection.Name).AddTo(collection); } else { collection.Add(ContentDetail.New( collection.EnclosingItem, attributes["name"], Parse(navigator.Value, type))); } }
protected virtual void ReadDetail(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { Dictionary<string, string> attributes = GetAttributes(navigator); Type type = Utility.TypeFromName(attributes["typeName"]); string name = attributes["name"]; string meta = attributes.ContainsKey("meta") ? attributes["meta"] : null; if (type == typeof(System.Enum)) { // we're going to need to do better- we saved a more specific type in 'meta' try { type = Utility.TypeFromName(meta); } catch (Exception ex) { // This is really bad because it means the enum type has gone away. logger.Warn(ex); // Also, another exception is going to be thrown later because the enum won't be able to be decoded. So we'll just load the value // as a string and hope that someone eventually deals with it. This may automatically happen if the ContentItem used the regular // GetDetail that returns a System.Object. This is the most robust approach because it is the only way the page MIGHT NOT crash // when this exception is encountered. type = typeof(String); } } if (type == typeof(ContentItem)) { SetLinkedItem(navigator.Value, journal, (referencedItem) => item[name] = referencedItem, attributes.GetValueOrDefault("versionKey")); } else if(type == typeof(IMultipleValue)) { var multiDetail = ReadMultipleValue(navigator, item, journal, name); multiDetail.Meta = meta; multiDetail.AddTo(item); } else { object value = Parse(navigator.Value, type); if (value is string) value = PrepareStringDetail(item, name, value as string, attributes.ContainsKey("encoded") && Convert.ToBoolean(attributes["encoded"])); item.SetDetail(name, value, type); } }
public virtual ContentItem ReadSingleItem(XPathNavigator navigator, ReadingJournal journal) { if (navigator.LocalName != "item") throw new DeserializationException("Expected element 'item' but was '" + navigator.LocalName + "'"); Dictionary<string, string> attributes = GetAttributes(navigator); ContentItem item = CreateInstance(attributes); ReadDefaultAttributes(attributes, item, journal); foreach(XPathNavigator current in EnumerateChildren(navigator)) { if(readers.ContainsKey(current.LocalName)) readers[current.LocalName].Read(current, item, journal); } return item; }
private void ReadProperty(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { Dictionary <string, string> attributes = GetAttributes(navigator); Type type = Utility.TypeFromName(attributes["typeName"]); string name = attributes["name"]; if (type == typeof(ContentItem)) { SetLinkedItem(navigator.Value, journal, (referencedItem) => item[name] = referencedItem); } else { item[name] = Parse(navigator.Value, type); } }
private void SetLinkedItems(XPathNavigator navigator, ReadingJournal journal, ContentItem item, string name) { var items = new ItemList(); foreach (XPathNavigator itemElement in EnumerateChildren(navigator)) { SetLinkedItem(itemElement.Value, journal, (foundItem) => { items.Add(foundItem); var property = item.GetContentType().GetProperty(name); if (property != null) item[name] = items.ConvertTo(property.PropertyType, name); else item[name] = items; }, itemElement.GetAttribute("versionKey", "")); } }
public void Read(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { IDictionary<string, IAttachmentHandler> attachments = explorer.Map<IAttachmentHandler>(item.GetContentType()); foreach(XPathNavigator attachmentElement in EnumerateChildren(navigator)) { string name = attachmentElement.GetAttribute("name", string.Empty); if(attachments.ContainsKey(name)) { XPathNavigator attachmentContents = navigator.CreateNavigator(); attachmentContents.MoveToFirstChild(); Attachment a = attachments[name].Read(attachmentContents, item); if(a != null) journal.Report(a); } } }
private static void Method(ContentItem item, ReadingJournal journal, object id, dynamic child) { if (child != null) child.AddTo(item); else { if (id is string) { journal.Register(id.ToString(), (ci) => ci.AddTo(item), isChild: true); } else if (id is int) { journal.Register(int.Parse(id.ToString()), (ci) => ci.AddTo(item), isChild: true); } } }
public void Read(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { IDictionary<string, IAttachmentHandler> attachments = _explorer.Map<IAttachmentHandler>(item.GetContentType()); foreach(XPathNavigator attachmentElement in EnumerateChildren(navigator)) { string name = attachmentElement.GetAttribute("name", string.Empty); if(attachments.ContainsKey(name)) { XPathNavigator attachmentContents = navigator.CreateNavigator(); attachmentContents.MoveToFirstChild(); Attachment a = attachments[name].Read(attachmentContents, item); if(a != null) journal.Report(a); } } }
protected virtual void ReadDefaultAttributes(Dictionary<string, string> attributes, ContentItem item, ReadingJournal journal) { item.Created = ToNullableDateTime(attributes["created"]).Value; item.Expires = ToNullableDateTime(attributes["expires"]); item.ID = Convert.ToInt32(attributes["id"]); item.Name = attributes["name"]; if (item.ID.ToString() == item.Name) item.Name = null; item.Published = ToNullableDateTime(attributes["published"]); item.SavedBy = attributes["savedBy"]; item.SortOrder = Convert.ToInt32(attributes["sortOrder"]); item.Title = attributes["title"]; item.Updated = ToNullableDateTime(attributes["updated"]).Value; item.Visible = Convert.ToBoolean(attributes["visible"]); if (!string.IsNullOrEmpty(attributes["zoneName"])) item.ZoneName = attributes["zoneName"]; if (attributes.ContainsKey("templateKey") && !string.IsNullOrEmpty(attributes["templateKey"])) item.TemplateKey = attributes["templateKey"]; if (attributes.ContainsKey("translationKey") && !string.IsNullOrEmpty(attributes["translationKey"])) item.TranslationKey = Convert.ToInt32(attributes["translationKey"]); if (attributes.ContainsKey("ancestralTrail")) item.AncestralTrail = attributes["ancestralTrail"]; if (attributes.ContainsKey("alteredPermissions")) item.AlteredPermissions = (Permission)Convert.ToInt32(attributes["alteredPermissions"]); if (attributes.ContainsKey("childState")) item.ChildState = (Collections.CollectionState)Convert.ToInt32(attributes["childState"]); if (attributes.ContainsKey("versionIndex")) item.VersionIndex = Convert.ToInt32(attributes["versionIndex"]); if (attributes.ContainsKey("versionOf")) { item.VersionOf.ID = Convert.ToInt32(attributes["versionOf"]); item.VersionOf.ValueAccessor = repository.Get; } if (attributes.ContainsKey("parent")) { var parentVersionKey = attributes.ContainsKey("parentVersionKey") ? attributes["parentVersionKey"] : null; HandleParentRelation(item, attributes["parent"], parentVersionKey, journal); } if (attributes.ContainsKey("state") && !string.IsNullOrEmpty(attributes["state"])) item.State = (ContentState)Convert.ToInt32(attributes["state"]); else item.State = SerializationUtility.RecaulculateState(item); }
protected virtual void ReadDetail(XPathNavigator navigator, DetailCollection collection, ReadingJournal journal) { Dictionary<string, string> attributes = GetAttributes(navigator); Type type = Utility.TypeFromName(attributes["typeName"]); if (type == typeof(ContentItem)) { int referencedItemID = int.Parse(navigator.Value); ContentItem referencedItem = journal.Find(referencedItemID); if (referencedItem != null) { collection.Add(ContentDetail.New( collection.EnclosingItem, attributes["name"], referencedItem)); } else { journal.ItemAdded += delegate(object sender, ItemEventArgs e) { if (e.AffectedItem.ID == referencedItemID) { collection.Add(ContentDetail.New( collection.EnclosingItem, attributes["name"], e.AffectedItem)); } }; } } else if (type == typeof(IMultipleValue)) { detailReader.ReadMultipleValue(navigator, collection.EnclosingItem, journal, collection.Name).AddTo(collection); } else { collection.Add(ContentDetail.New( collection.EnclosingItem, attributes["name"], Parse(navigator.Value, type))); } }
public void Read(System.Xml.XPath.XPathNavigator navigator, ContentItem item, ReadingJournal journal) { foreach (XPathNavigator childElement in EnumerateChildren(navigator)) { var attributes = GetAttributes(childElement); int id; if (attributes.ContainsKey("id") && int.TryParse(attributes["id"], out id) && id != 0) { Handle(item, journal, id); } if (attributes.ContainsKey("versionOf") && int.TryParse(attributes["versionOf"], out id) && id != 0) { Handle(item, journal, id); } else if (attributes.ContainsKey("versionKey")) { Handle(item, journal, attributes["versionKey"]); } } }
public virtual IImportRecord Read(XPathNavigator navigator) { if (navigator == null) throw new ArgumentNullException("navigator"); ReadingJournal journal = new ReadingJournal(); foreach (XPathNavigator itemElement in EnumerateChildren(navigator)) { try { ContentItem item = ReadSingleItem(itemElement, journal); journal.Report(item); } catch (DefinitionNotFoundException ex) { journal.Error(ex); if (!ignoreMissingTypes) throw; } } return journal; }
private void SetLinkedItems(XPathNavigator navigator, ReadingJournal journal, ContentItem item, string name) { var items = new ItemList(); foreach (XPathNavigator itemElement in EnumerateChildren(navigator)) { SetLinkedItem(itemElement.Value, journal, (foundItem) => { items.Add(foundItem); var property = item.GetContentType().GetProperty(name); if (property != null) { item[name] = items.ConvertTo(property.PropertyType, name); } else { item[name] = items; } }, itemElement.GetAttribute("versionKey", "")); } }
protected virtual void ReadDetail(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { Dictionary<string, string> attributes = GetAttributes(navigator); Type type = Utility.TypeFromName(attributes["typeName"]); string name = attributes["name"]; if (type != typeof(ContentItem)) { object value = Parse(navigator.Value, type); if (value is string) value = PrepareStringDetail(item, name, value as string); item[name] = value; //item.SetDetail(name, value, type); } else { int referencedItemID = int.Parse(navigator.Value); ContentItem referencedItem = journal.Find(referencedItemID); if (referencedItem != null) { item[name] = referencedItem; } else { EventHandler<ItemEventArgs> handler = null; handler = delegate(object sender, ItemEventArgs e) { if (e.AffectedItem.ID == referencedItemID) { item[name] = e.AffectedItem; journal.ItemAdded -= handler; } }; journal.ItemAdded += handler; } } }
public virtual ContentItem ReadSingleItem(XPathNavigator navigator, ReadingJournal journal) { if (navigator.LocalName != "item") { throw new DeserializationException("Expected element 'item' but was '" + navigator.LocalName + "'"); } Dictionary <string, string> attributes = GetAttributes(navigator); ContentItem item = CreateInstance(attributes); ReadDefaultAttributes(attributes, item, journal); foreach (XPathNavigator current in EnumerateChildren(navigator)) { if (readers.ContainsKey(current.LocalName)) { readers[current.LocalName].Read(current, item, journal); } } return(item); }
internal ContentDetail ReadMultipleValue(XPathNavigator navigator, ContentItem item, ReadingJournal journal, string name) { var multiDetail = ContentDetail.Multi(name); foreach (XPathNavigator valueElement in EnumerateChildren(navigator)) { switch (valueElement.GetAttribute("key", "")) { case ContentDetail.TypeKeys.BoolType: multiDetail.BoolValue = (bool)Parse(valueElement.Value, typeof(bool)); break; case ContentDetail.TypeKeys.DateTimeType: multiDetail.DateTimeValue = (DateTime)Parse(valueElement.Value, typeof(DateTime)); break; case ContentDetail.TypeKeys.DoubleType: multiDetail.DoubleValue = (double)Parse(valueElement.Value, typeof(double)); break; case ContentDetail.TypeKeys.IntType: multiDetail.IntValue = (int)Parse(valueElement.Value, typeof(int)); break; case ContentDetail.TypeKeys.LinkType: SetLinkedItem(valueElement.Value, journal, (referencedItem) => multiDetail.LinkedItem = referencedItem, valueElement.GetAttribute("versionKey", "")); break; case ContentDetail.TypeKeys.MultiType: journal.Error(new InvalidOperationException("Nested multi types not supported")); break; case ContentDetail.TypeKeys.ObjectType: multiDetail.ObjectValue = Parse(valueElement.Value, typeof(object)); break; case ContentDetail.TypeKeys.EnumType: /* TODO: May need special treatment here as well (see other TODO). */ case ContentDetail.TypeKeys.StringType: Dictionary<string, string> attributes = GetAttributes(navigator); multiDetail.StringValue = PrepareStringDetail(item, name, valueElement.Value, attributes.ContainsKey("encoded") && Convert.ToBoolean(attributes["encoded"])); break; default: throw new Exception("Failed to read MultipleValue"); } } return multiDetail; }
protected static void SetLinkedItem(string value, ReadingJournal journal, Action<ContentItem> setter) { int referencedItemID = int.Parse(value); ContentItem referencedItem = journal.Find(referencedItemID); if (referencedItem != null) { setter(referencedItem); } else { EventHandler<ItemEventArgs> handler = null; handler = delegate(object sender, ItemEventArgs e) { if (e.AffectedItem.ID == referencedItemID) { setter(e.AffectedItem); journal.ItemAdded -= handler; } }; journal.ItemAdded += handler; } }
private static void SetLinkedItem(string value, ReadingJournal journal, Action <ContentItem> setter) { int referencedItemID = int.Parse(value); ContentItem referencedItem = journal.Find(referencedItemID); if (referencedItem != null) { setter(referencedItem); } else { EventHandler <ItemEventArgs> handler = null; handler = delegate(object sender, ItemEventArgs e) { if (e.AffectedItem.ID == referencedItemID) { setter(e.AffectedItem); journal.ItemAdded -= handler; } }; journal.ItemAdded += handler; } }
private void ReadProperty(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { Dictionary<string, string> attributes = GetAttributes(navigator); string name = attributes["name"]; if (!attributes.ContainsKey("typeName")) { item[name] = null; return; } Type type = Utility.TypeFromName(attributes["typeName"]); if (type == typeof(ContentItem)) { SetLinkedItem(navigator.Value, journal, (referencedItem) => item[name] = referencedItem, attributes.GetValueOrDefault("versionKey")); } else if (type.IsContentItemEnumeration()) { SetLinkedItems(navigator, journal, item, name); } else item[name] = Parse(navigator.Value, type); }
public void Read(System.Xml.XPath.XPathNavigator navigator, ContentItem item, ReadingJournal journal) { foreach (XPathNavigator detailElement in EnumerateChildren(navigator)) { ReadProperty(detailElement, item, journal); } }
private static IImportRecord CreateRecord(ContentItem item) { ReadingJournal rj = new ReadingJournal(); rj.Report(item); return rj; }
protected virtual void HandleParentRelation(ContentItem item, string parent, string parentVersionKey, ReadingJournal journal) { int parentID = 0; if (int.TryParse(parent, out parentID) && parentID != 0) { ContentItem parentItem = journal.Find(parentID); if (parentItem != null) { item.AddTo(parentItem); } else { journal.Register(parentID, (laterParent) => item.AddTo(laterParent), isChild: true); } } if (!string.IsNullOrEmpty(parentVersionKey)) { ContentItem parentItem = journal.Find(parentVersionKey); if (parentItem != null) { item.AddTo(parentItem); } else { journal.Register(parentVersionKey, (laterParent) => item.AddTo(laterParent), isChild: true); } } }
protected virtual void ReadDetail(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { Dictionary <string, string> attributes = GetAttributes(navigator); Type type = Utility.TypeFromName(attributes["typeName"]); string name = attributes["name"]; string meta = attributes.ContainsKey("meta") ? attributes["meta"] : null; if (type == typeof(System.Enum)) { // we're going to need to do better- we saved a more specific type in 'meta' try { type = Utility.TypeFromName(meta); } catch (Exception ex) { // This is really bad because it means the enum type has gone away. logger.Warn(ex); // Also, another exception is going to be thrown later because the enum won't be able to be decoded. So we'll just load the value // as a string and hope that someone eventually deals with it. This may automatically happen if the ContentItem used the regular // GetDetail that returns a System.Object. This is the most robust approach because it is the only way the page MIGHT NOT crash // when this exception is encountered. type = typeof(String); } } if (type == typeof(ContentItem)) { SetLinkedItem(navigator.Value, journal, (referencedItem) => item[name] = referencedItem, attributes.GetValueOrDefault("versionKey")); } else if (type == typeof(IMultipleValue)) { var multiDetail = ReadMultipleValue(navigator, item, journal, name); multiDetail.Meta = meta; multiDetail.AddTo(item); } else { object value = Parse(navigator.Value, type); if (value is string) { value = PrepareStringDetail(item, name, value as string, attributes.ContainsKey("encoded") && Convert.ToBoolean(attributes["encoded"])); } item.SetDetail(name, value, type); } }
protected virtual void ReadDetail(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { Dictionary <string, string> attributes = GetAttributes(navigator); Type type = Utility.TypeFromName(attributes["typeName"]); string name = attributes["name"]; if (type == typeof(ContentItem)) { SetLinkedItem(navigator.Value, journal, (referencedItem) => item[name] = referencedItem); } else if (type == typeof(IMultipleValue)) { var multiDetail = ReadMultipleValue(navigator, item, journal, name); multiDetail.AddTo(item); } else { object value = Parse(navigator.Value, type); if (value is string) { value = PrepareStringDetail(item, name, value as string, attributes.ContainsKey("encoded") && Convert.ToBoolean(attributes["encoded"])); } item[name] = value; //item.SetDetail(name, value, type); } }
protected virtual void ReadDefaultAttributes(Dictionary <string, string> attributes, ContentItem item, ReadingJournal journal) { item.Created = ToNullableDateTime(attributes["created"]).Value; item.Expires = ToNullableDateTime(attributes["expires"]); item.ID = Convert.ToInt32(attributes["id"]); item.Name = attributes["name"]; if (item.ID.ToString() == item.Name) { item.Name = null; } item.Published = ToNullableDateTime(attributes["published"]); item.SavedBy = attributes["savedBy"]; item.SortOrder = Convert.ToInt32(attributes["sortOrder"]); item.Title = attributes["title"]; item.Updated = ToNullableDateTime(attributes["updated"]).Value; item.Visible = Convert.ToBoolean(attributes["visible"]); if (!string.IsNullOrEmpty(attributes["zoneName"])) { item.ZoneName = attributes["zoneName"]; } if (attributes.ContainsKey("templateKey") && !string.IsNullOrEmpty(attributes["templateKey"])) { item.TemplateKey = attributes["templateKey"]; } if (attributes.ContainsKey("translationKey") && !string.IsNullOrEmpty(attributes["translationKey"])) { item.TranslationKey = Convert.ToInt32(attributes["translationKey"]); } if (attributes.ContainsKey("ancestralTrail")) { item.AncestralTrail = attributes["ancestralTrail"]; } if (attributes.ContainsKey("alteredPermissions")) { item.AlteredPermissions = (Permission)Convert.ToInt32(attributes["alteredPermissions"]); } if (attributes.ContainsKey("childState")) { item.ChildState = (Collections.CollectionState)Convert.ToInt32(attributes["childState"]); } if (attributes.ContainsKey("versionIndex")) { item.VersionIndex = Convert.ToInt32(attributes["versionIndex"]); } if (attributes.ContainsKey("versionOf")) { item.VersionOf.ID = Convert.ToInt32(attributes["versionOf"]); item.VersionOf.ValueAccessor = repository.Get; } if (attributes.ContainsKey("parent")) { var parentVersionKey = attributes.ContainsKey("parentVersionKey") ? attributes["parentVersionKey"] : null; HandleParentRelation(item, attributes["parent"], parentVersionKey, journal); } if (attributes.ContainsKey("state") && !string.IsNullOrEmpty(attributes["state"])) { item.State = (ContentState)Convert.ToInt32(attributes["state"]); } else { item.State = SerializationUtility.RecaulculateState(item); } }
protected virtual void ReadDefaultAttributes(Dictionary<string, string> attributes, ContentItem item, ReadingJournal journal) { item.Created = ToNullableDateTime(attributes["created"]).Value; item.Expires = ToNullableDateTime(attributes["expires"]); item.ID = Convert.ToInt32(attributes["id"]); item.Name = attributes["name"]; if (item.ID.ToString() == item.Name) item.Name = null; item.Published = ToNullableDateTime(attributes["published"]); item.SavedBy = attributes["savedBy"]; item.SortOrder = Convert.ToInt32(attributes["sortOrder"]); item.Title = attributes["title"]; item.Updated = ToNullableDateTime(attributes["updated"]).Value; item.Visible = Convert.ToBoolean(attributes["visible"]); if (!string.IsNullOrEmpty(attributes["zoneName"])) item.ZoneName = attributes["zoneName"]; if (attributes.ContainsKey("templateKey") && !string.IsNullOrEmpty(attributes["templateKey"])) item.TemplateKey = attributes["templateKey"]; if (attributes.ContainsKey("translationKey") && !string.IsNullOrEmpty(attributes["translationKey"])) item.TranslationKey = Convert.ToInt32(attributes["translationKey"]); if (attributes.ContainsKey("state") && !string.IsNullOrEmpty(attributes["state"])) item.State = (ContentState)Convert.ToInt32(attributes["state"]); HandleParentRelation(item, attributes["parent"], journal); }
protected virtual void ReadDetail(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { Dictionary <string, string> attributes = GetAttributes(navigator); Type type = Utility.TypeFromName(attributes["typeName"]); string name = attributes["name"]; if (type != typeof(ContentItem)) { object value = Parse(navigator.Value, type); if (value is string) { value = PrepareStringDetail(item, name, value as string); } item[name] = value; //item.SetDetail(name, value, type); } else { int referencedItemID = int.Parse(navigator.Value); ContentItem referencedItem = journal.Find(referencedItemID); if (referencedItem != null) { item[name] = referencedItem; } else { EventHandler <ItemEventArgs> handler = null; handler = delegate(object sender, ItemEventArgs e) { if (e.AffectedItem.ID == referencedItemID) { item[name] = e.AffectedItem; journal.ItemAdded -= handler; } }; journal.ItemAdded += handler; } } }
public void Read(System.Xml.XPath.XPathNavigator navigator, ContentItem item, ReadingJournal journal) { foreach (XPathNavigator childElement in EnumerateChildren(navigator)) { var attributes = GetAttributes(childElement); int id; if (attributes.ContainsKey("id") && int.TryParse(attributes["id"], out id) && id != 0) { Handle(item, journal, id); } if (attributes.ContainsKey("versionOf") && int.TryParse(attributes["versionOf"], out id) && id != 0) { Handle(item, journal, id); } else if (attributes.ContainsKey("versionKey")) { Handle(item, journal, attributes["versionKey"]); } } }
protected virtual void ReadDefaultAttributes(Dictionary <string, string> attributes, ContentItem item, ReadingJournal journal) { item.Created = ToNullableDateTime(attributes["created"]).Value; item.Expires = ToNullableDateTime(attributes["expires"]); item.ID = Convert.ToInt32(attributes["id"]); item.Name = attributes["name"]; if (item.ID.ToString() == item.Name) { item.Name = null; } item.Published = ToNullableDateTime(attributes["published"]); item.SavedBy = attributes["savedBy"]; item.SortOrder = Convert.ToInt32(attributes["sortOrder"]); item.Title = attributes["title"]; item.Updated = ToNullableDateTime(attributes["updated"]).Value; item.Visible = Convert.ToBoolean(attributes["visible"]); if (!string.IsNullOrEmpty(attributes["zoneName"])) { item.ZoneName = attributes["zoneName"]; } if (!string.IsNullOrEmpty(attributes["templateKey"])) { item.TemplateKey = attributes["templateKey"]; } HandleParentRelation(item, attributes["parent"], journal); }
protected virtual void ReadDetail(XPathNavigator navigator, DetailCollection collection, ReadingJournal journal) { Dictionary <string, string> attributes = GetAttributes(navigator); Type type = Utility.TypeFromName(attributes["typeName"]); if (type == typeof(ContentItem)) { int referencedItemID = int.Parse(navigator.Value); ContentItem referencedItem = journal.Find(referencedItemID); if (referencedItem != null) { collection.Add(ContentDetail.New( collection.EnclosingItem, attributes["name"], referencedItem)); } else { journal.ItemAdded += delegate(object sender, ItemEventArgs e) { if (e.AffectedItem.ID == referencedItemID) { collection.Add(ContentDetail.New( collection.EnclosingItem, attributes["name"], e.AffectedItem)); } }; } } else if (type == typeof(IMultipleValue)) { detailReader.ReadMultipleValue(navigator, collection.EnclosingItem, journal, collection.Name).AddTo(collection); } else { collection.Add(ContentDetail.New( collection.EnclosingItem, attributes["name"], Parse(navigator.Value, type))); } }
protected virtual void HandleParentRelation(ContentItem item, string parent, string parentVersionKey, ReadingJournal journal) { int parentID = 0; if (int.TryParse(parent, out parentID) && parentID != 0) { ContentItem parentItem = journal.Find(parentID); if (parentItem != null) item.AddTo(parentItem); else journal.Register(parentID, (laterParent) => item.AddTo(laterParent), isChild: true); } if (!string.IsNullOrEmpty(parentVersionKey)) { ContentItem parentItem = journal.Find(parentVersionKey); if (parentItem != null) item.AddTo(parentItem); else journal.Register(parentVersionKey, (laterParent) => item.AddTo(laterParent), isChild: true); } }
protected void ReadDetailCollection(XPathNavigator navigator, ContentItem item, ReadingJournal journal) { Dictionary <string, string> attributes = GetAttributes(navigator); string name = attributes["name"]; foreach (XPathNavigator detailElement in EnumerateChildren(navigator)) { ReadDetail(detailElement, item.GetDetailCollection(name, true), journal); } }
protected virtual void ReadDetail(XPathNavigator navigator, DetailCollection collection, ReadingJournal journal) { Dictionary <string, string> attributes = GetAttributes(navigator); Type type = Utility.TypeFromName(attributes["typeName"]); if (type == typeof(ContentItem)) { int referencedItemID = int.Parse(navigator.Value); ContentItem referencedItem = journal.Find(referencedItemID); if (referencedItem != null) { collection.Add(ContentDetail.New( collection.EnclosingItem, attributes["name"], referencedItem)); } else { journal.Register(referencedItemID, (item) => { collection.Add(ContentDetail.New( collection.EnclosingItem, attributes["name"], item)); }); } } else if (type == typeof(Enum)) { if (attributes.ContainsKey("meta")) { collection.Add(ContentDetail.New( collection.EnclosingItem, attributes["name"], Parse(navigator.Value, Type.GetType(attributes["meta"])))); } } else if (type == typeof(IMultipleValue)) { detailReader.ReadMultipleValue(navigator, collection.EnclosingItem, journal, collection.Name).AddTo(collection); } else { object value = Parse(navigator.Value, type); if (value is string) { value = detailReader.PrepareStringDetail(collection.EnclosingItem, collection.Name, value as string, attributes.ContainsKey("encoded") && Convert.ToBoolean(attributes["encoded"])); } collection.Add(ContentDetail.New(collection.EnclosingItem, attributes["name"], value)); } }
internal ContentDetail ReadMultipleValue(XPathNavigator navigator, ContentItem item, ReadingJournal journal, string name) { var multiDetail = ContentDetail.Multi(name); foreach (XPathNavigator valueElement in EnumerateChildren(navigator)) { switch (valueElement.GetAttribute("key", "")) { case ContentDetail.TypeKeys.BoolType: multiDetail.BoolValue = (bool)Parse(valueElement.Value, typeof(bool)); break; case ContentDetail.TypeKeys.DateTimeType: multiDetail.DateTimeValue = (DateTime)Parse(valueElement.Value, typeof(DateTime)); break; case ContentDetail.TypeKeys.DoubleType: multiDetail.DoubleValue = (double)Parse(valueElement.Value, typeof(double)); break; case ContentDetail.TypeKeys.IntType: multiDetail.IntValue = (int)Parse(valueElement.Value, typeof(int)); break; case ContentDetail.TypeKeys.LinkType: SetLinkedItem(valueElement.Value, journal, (referencedItem) => multiDetail.LinkedItem = referencedItem); break; case ContentDetail.TypeKeys.MultiType: journal.Error(new InvalidOperationException("Nested multi types not supported")); break; case ContentDetail.TypeKeys.ObjectType: multiDetail.ObjectValue = Parse(valueElement.Value, typeof(object)); break; case ContentDetail.TypeKeys.StringType: Dictionary <string, string> attributes = GetAttributes(navigator); multiDetail.StringValue = PrepareStringDetail(item, name, valueElement.Value, attributes.ContainsKey("encoded") && Convert.ToBoolean(attributes["encoded"])); break; } } return(multiDetail); }
protected virtual void HandleParentRelation(ContentItem item, string parent, ReadingJournal journal) { if (!string.IsNullOrEmpty(parent)) { int parentID = int.Parse(parent); ContentItem parentItem = journal.Find(parentID); item.AddTo(parentItem); } }
protected virtual void ReadDefaultAttributes(Dictionary <string, string> attributes, ContentItem item, ReadingJournal journal) { item.Created = ToDateTime(attributes["created"]); item.Expires = attributes.ContainsKey("expires") ? ToNullableDateTime(attributes["expires"]) : null; item.ID = Convert.ToInt32(attributes["id"]); item.Name = GetStringOrNull(attributes, "name"); if (item.ID.ToString() == item.Name) { item.Name = null; } item.Published = attributes.ContainsKey("published") ? ToNullableDateTime(attributes["published"]) : null; item.SavedBy = attributes.ContainsKey("savedBy") ? attributes["savedBy"] : null; item.SortOrder = Convert.ToInt32(attributes["sortOrder"]); item.Title = attributes.ContainsKey("title") ? attributes["title"] : ""; item.Updated = ToDateTime(attributes["updated"]); item.Visible = Convert.ToBoolean(attributes["visible"]); item.ZoneName = GetStringOrNull(attributes, "zoneName"); // empty string must get converted to null for code to work, see PersistentContentItemList<T>.FindPages() item.TemplateKey = GetStringOrNull(attributes, "templateKey"); if (attributes.ContainsKey("translationKey") && !string.IsNullOrEmpty(attributes["translationKey"])) { item.TranslationKey = Convert.ToInt32(attributes["translationKey"]); } if (attributes.ContainsKey("ancestralTrail")) { item.AncestralTrail = attributes["ancestralTrail"]; } if (attributes.ContainsKey("alteredPermissions")) { item.AlteredPermissions = (Permission)Convert.ToInt32(attributes["alteredPermissions"]); } if (attributes.ContainsKey("childState")) { item.ChildState = (Collections.CollectionState)Convert.ToInt32(attributes["childState"]); } if (attributes.ContainsKey("versionIndex")) { item.VersionIndex = Convert.ToInt32(attributes["versionIndex"]); } if (attributes.ContainsKey("versionOf")) { item.VersionOf.ID = Convert.ToInt32(attributes["versionOf"]); if (repository != null) { item.VersionOf.ValueAccessor = repository.Get; } } if (attributes.ContainsKey("parent")) { var parentVersionKey = attributes.ContainsKey("parentVersionKey") ? attributes["parentVersionKey"] : null; HandleParentRelation(item, attributes["parent"], parentVersionKey, journal); } if (attributes.ContainsKey("state") && !string.IsNullOrEmpty(attributes["state"])) { // be tolerant to read both old numeric and new textual state var val = attributes["state"]; int intval; ContentState newstate; if (int.TryParse(val, out intval)) { newstate = (ContentState)intval; } else if (!Enum.TryParse(val, true, out newstate)) { newstate = SerializationUtility.RecaulculateState(item); } item.State = newstate; } else // TODO: dangerous migration code { item.State = SerializationUtility.RecaulculateState(item); } }