Example #1
0
        /// <summary>
        ///  does the basic deserialization, bascially the stuff in info
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        internal void DeserializeBase(IContentTypeBase item, XElement info)
        {
            var alias = info.Element("Alias").Value;

            if (item.Alias != alias)
            {
                item.Alias = alias;
            }

            var name = info.Element("Name").ValueOrDefault(string.Empty);

            if (!string.IsNullOrEmpty(name))
            {
                item.Name = name;
            }

            var icon = info.Element("Icon").ValueOrDefault("");

            if (item.Icon != icon)
            {
                item.Icon = icon;
            }

            var thumb = info.Element("Thumbnail").ValueOrDefault("");

            if (item.Thumbnail != thumb)
            {
                item.Thumbnail = thumb;
            }

            var desc = info.Element("Description").ValueOrDefault("");

            if (item.Description != desc)
            {
                item.Description = desc;
            }

            var allow = info.Element("AllowAtRoot").ValueOrDefault(false);

            if (item.AllowedAsRoot != allow)
            {
                item.AllowedAsRoot = allow;
            }

            var masterNode = info.Element("Master");

            if (masterNode != null)
            {
                var masterId = 0;

                var masterKey = masterNode.Attribute("Key").ValueOrDefault(Guid.Empty);
                if (masterKey != Guid.Empty)
                {
                    var masterEntity = ApplicationContext.Current.Services.EntityService.GetByKey(masterKey);
                    masterId = masterEntity.Id;
                }

                if (masterId == 0)
                {
                    // old school alias lookup
                    var master = default(IContentTypeBase);

                    LogHelper.Debug <Events>("Looking up Content Master by Alias");
                    var masterAlias = masterNode.Value;
                    master = LookupByAlias(masterAlias);
                    if (master != null)
                    {
                        masterId = master.Id;
                    }
                }

                if (masterId > 0)
                {
                    item.SetLazyParentId(new Lazy <int>(() => masterId));
                }
            }
        }