Пример #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
        public void FactoryMethod_String()
        {
            var detail = ContentDetail.New(null, "Hello", "World");

            Assert.That(detail, Is.InstanceOf <ContentDetail>());
            Assert.That(detail.StringValue, Is.EqualTo("World"));
            Assert.That(detail.Value, Is.EqualTo("World"));
            Assert.That(detail.ValueType, Is.EqualTo(typeof(string)));
            Assert.That(detail.ValueTypeKey, Is.EqualTo(ContentDetail.TypeKeys.StringType));
        }
Пример #3
0
        public void FactoryMethod_Int()
        {
            var detail = ContentDetail.New(null, "Hello", 234);

            Assert.That(detail, Is.InstanceOf <ContentDetail>());
            Assert.That(detail.IntValue, Is.EqualTo(234));
            Assert.That(detail.Value, Is.EqualTo(234));
            Assert.That(detail.ValueType, Is.EqualTo(typeof(int)));
            Assert.That(detail.ValueTypeKey, Is.EqualTo(ContentDetail.TypeKeys.IntType));
        }
Пример #4
0
        public void FactoryMethod_Object()
        {
            var detail = ContentDetail.New(null, "Hello", new[] { "World" });

            Assert.That(detail, Is.InstanceOf <ContentDetail>());
            Assert.That(detail.Value, Is.InstanceOf <string[]>());
            Assert.That(((string[])detail.Value)[0], Is.EqualTo("World"));
            Assert.That(detail.ValueType, Is.EqualTo(typeof(object)));
            Assert.That(detail.ValueTypeKey, Is.EqualTo(ContentDetail.TypeKeys.ObjectType));
        }
Пример #5
0
        public void FactoryMethod_Double()
        {
            var detail = ContentDetail.New(null, "Hello", 123.456);

            Assert.That(detail, Is.InstanceOf <ContentDetail>());
            Assert.That(detail.DoubleValue, Is.EqualTo(123.456));
            Assert.That(detail.Value, Is.EqualTo(123.456));
            Assert.That(detail.ValueType, Is.EqualTo(typeof(double)));
            Assert.That(detail.ValueTypeKey, Is.EqualTo(ContentDetail.TypeKeys.DoubleType));
        }
Пример #6
0
        public void FactoryMethod_DateTime()
        {
            var detail = ContentDetail.New(null, "Hello", new DateTime(2010, 06, 16));

            Assert.That(detail, Is.InstanceOf <ContentDetail>());
            Assert.That(detail.DateTimeValue, Is.EqualTo(new DateTime(2010, 06, 16)));
            Assert.That(detail.Value, Is.EqualTo(new DateTime(2010, 06, 16)));
            Assert.That(detail.ValueType, Is.EqualTo(typeof(DateTime)));
            Assert.That(detail.ValueTypeKey, Is.EqualTo(ContentDetail.TypeKeys.DateTimeType));
        }
Пример #7
0
        public void FactoryMethod_Bool()
        {
            var detail = ContentDetail.New(null, "Hello", true);

            Assert.That(detail, Is.InstanceOf <ContentDetail>());
            Assert.That(detail.BoolValue, Is.True);
            Assert.That(detail.Value, Is.EqualTo(true));
            Assert.That(detail.ValueType, Is.EqualTo(typeof(bool)));
            Assert.That(detail.ValueTypeKey, Is.EqualTo(ContentDetail.TypeKeys.BoolType));
        }
Пример #8
0
		public void FactoryMethod_Link()
		{
			var item = new Definitions.Definitions.SideshowItem { ID = 123 };
			var detail = ContentDetail.New(null, "Hello", item);

			Assert.That(detail, Is.InstanceOf<ContentDetail>());
			Assert.That(detail.LinkedItem, Is.EqualTo(item));
			Assert.That(detail.Value, Is.EqualTo(item));
			Assert.That(detail.ValueType, Is.EqualTo(typeof(ContentItem)));
			Assert.That(detail.ValueTypeKey, Is.EqualTo(ContentDetail.TypeKeys.LinkType));
		}
Пример #9
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)));
            }
        }
Пример #10
0
        private static void SetDetail(ContentItem item, DetailCollection collection, string key, object value)
        {
            ContentDetail cd = collection.Details.FirstOrDefault(d => d.Name == key);

            if (value != null)
            {
                if (cd == null)
                {
                    cd = ContentDetail.New(key, value);
                    cd.EnclosingItem       = item;
                    cd.EnclosingCollection = collection;
                    collection.Details.Add(cd);
                }
                else
                {
                    cd.Value = value;
                }
            }
            else if (cd != null)
            {
                collection.Details.Remove(cd);
            }
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var values = serializer.Deserialize <Dictionary <string, object> >(reader);

            return(new ContentList <ContentDetail>(values.Select(kvp => ContentDetail.New(kvp.Key, kvp.Value))));
        }