Пример #1
0
        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 (!string.IsNullOrEmpty(meta))
                {
                    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));
            }
        }
Пример #2
0
        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)));
            }
        }