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); } }
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 override bool UpdateItem(ContentItem item, System.Web.UI.Control editor) { string value = ((LinkEditorControl)editor).Value; item.SetDetail(Name, value, typeof(string)); return(true); }
public bool SetValue(ValueAccessorContext context, string propertyName, object value) { ContentItem item = (ContentItem)context.Instance; if (value != null) { item.SetDetail(propertyName, value, value.GetType()); } return(value != null); }
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"]; 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)) { object value = Parse(navigator.Value, type); if (value is string) value = PrepareStringDetail(item, name, value as string); 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; } } }
/// <summary> /// Rebases a single item. /// </summary> /// <param name="item"></param> /// <param name="fromUrl"></param> /// <param name="toUrl"></param> /// <returns></returns> public static IEnumerable <RebaseInfo> Rebase(ContentItem item, string fromUrl, string toUrl) { var rebasedLinks = new List <RebaseInfo>(); foreach (var pi in item.GetContentType().GetProperties()) { if (pi.CanRead == false || pi.CanWrite == false) { continue; } foreach (IRelativityTransformer transformer in pi.GetCustomAttributes(typeof(IRelativityTransformer), false)) { if (transformer.RelativeWhen != RelativityMode.Always && transformer.RelativeWhen != RelativityMode.Rebasing) { continue; } string original = item.GetDetail(pi.Name) as string; if (string.IsNullOrEmpty(original)) { continue; } string rebased = transformer.Rebase(original, fromUrl, toUrl); if (!string.Equals(original, rebased)) { item.SetDetail(pi.Name, rebased, typeof(string)); rebasedLinks.Add(new RebaseInfo { ItemID = item.ID, ItemTitle = item.Title, ItemPath = item.Path, PropertyName = pi.Name }); } } } return(rebasedLinks); }