Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProductOptionWrapper"/> class.
        /// </summary>
        /// <param name="display">
        /// The display.
        /// </param>
        /// <param name="_parent">
        /// The parent content.
        /// </param>
        /// <param name="contentType">
        /// The content Type.
        /// </param>
        public ProductOptionWrapper(ProductOptionDisplay display, IPublishedContent _parent, PublishedContentType contentType = null)
        {
            _display = display;
            _contentType = contentType;

            Initialize(_parent);
        }
        /// <summary>
        /// The data values as published properties.
        /// </summary>
        /// <param name="container">
        /// The <see cref="ProductVariantDetachedContentDisplay"/>.
        /// </param>
        /// <param name="contentType">
        /// The content type.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{IPublishedProperty}"/>.
        /// </returns>
        public static IEnumerable<IPublishedProperty> DataValuesAsPublishedProperties(this IHaveDetachedDataValues container, PublishedContentType contentType)
        {
            var properties = new List<IPublishedProperty>();

            foreach (var dcv in container.DetachedDataValues)
            {
                var propType = contentType.GetPropertyType(dcv.Key);
                object valObj;
                try
                {
                    valObj = DetachedValuesConverter.Current.ConvertDbForContent(propType, dcv).Value;
                }
                catch
                {
                    valObj = dcv.Value;
                }

                if (propType != null)
                {
                    properties.Add(new DetachedPublishedProperty(propType, valObj));
                }
            }

            return properties;
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProductContentBase"/> class.
 /// </summary>
 /// <param name="productBase">
 /// The product base.
 /// </param>
 /// <param name="contentType">
 /// The content Type.
 /// </param>
 /// <param name="specificCulture">
 /// Specifically sets the culture
 /// </param>
 protected ProductContentBase(ProductDisplayBase productBase, PublishedContentType contentType, string specificCulture)
 {
     Mandate.ParameterNotNull(productBase, "productBase");
     _productBase = productBase;
     this.CultureName = specificCulture;
     _contentType = contentType;
     this.Initialize();
 }
 public DetachedPublishedContent(string name,
     PublishedContentType contentType,
     IEnumerable<IPublishedProperty> properties,
     bool isPreviewing = false)
 {
     _name = name;
     _contentType = contentType;
     _properties = properties;
     _isPreviewing = isPreviewing;
 }
        public PublishedPropertyType(PublishedContentType contentType, PropertyType propertyType)
        {
            // PropertyEditor [1:n] DataTypeDefinition [1:n] PropertyType

            ContentType = contentType;
            PropertyTypeAlias = propertyType.Alias;

            DataTypeId = propertyType.DataTypeDefinitionId;
            PropertyEditorAlias = propertyType.PropertyEditorAlias;

            InitializeConverters();
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProductContent"/> class.
        /// </summary>
        /// <param name="contentType">
        /// The content type.
        /// </param>
        /// <param name="display">
        /// The display.
        /// </param>
        /// <param name="parent">
        /// The parent <see cref="IPublishedContent"/>
        /// </param>
        /// <param name="specificCulture">
        /// The specific culture name
        /// </param>
        /// <param name="isPreviewing">
        /// The is previewing.
        /// </param>
        public ProductContent(
            PublishedContentType contentType,
            ProductDisplay display,           
            IPublishedContent parent = null,
            string specificCulture = "en-US",
            bool isPreviewing = false)
            : base(display, contentType, specificCulture)
        {
            this._display = display;
            this._parent = parent;
            this._isPreviewing = isPreviewing;

            this.Initialize();
        }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProductAttributeContent"/> class.
        /// </summary>
        /// <param name="contentType">
        /// The content type.
        /// </param>
        /// <param name="display">
        /// The display.
        /// </param>
        /// <param name="parent">
        /// The parent content - generally set to the <see cref="IProductContent"/> containing the option
        /// </param>
        /// <param name="isPreviewing">
        /// The is previewing.
        /// </param>
        public ProductAttributeContent(
            PublishedContentType contentType,
            ProductAttributeDisplay display,
            IPublishedContent parent = null,
            bool isPreviewing = false)
        {
            Mandate.ParameterNotNull(display, "display");
            _contentType = contentType;
            _display = display;
            _parent = parent;
            _isForPreview = isPreviewing;

            this.Initialize();
        }
Пример #8
0
        internal ArchetypeModel DeserializeJsonToArchetype(string sourceJson, int dataTypeId, PublishedContentType hostContentType = null)
        {
            try
            {
                var archetype = JsonConvert.DeserializeObject<ArchetypeModel>(sourceJson, _jsonSettings);

                try
                {
                    // Get list of configured properties and their types and map them to the deserialized archetype model
                    var preValue = GetArchetypePreValueFromDataTypeId(dataTypeId);
                    RetrieveAdditionalProperties(ref archetype, preValue, hostContentType);
                }
                catch (Exception ex)
                {
                }

                return archetype;
            }
            catch
            {
                return new ArchetypeModel();
            }
        }
        /// <summary>
        /// The data values as published properties.
        /// </summary>
        /// <param name="pvd">
        /// The <see cref="ProductVariantDetachedContentDisplay"/>.
        /// </param>
        /// <param name="contentType">
        /// The content type.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{IPublishedProperty}"/>.
        /// </returns>
        public static IEnumerable<IPublishedProperty> DataValuesAsPublishedProperties(this ProductVariantDetachedContentDisplay pvd, PublishedContentType contentType)
        {
            var properties = new List<IPublishedProperty>();
            foreach (var value in pvd.DetachedDataValues)
            {
                var propType = contentType.GetPropertyType(value.Key);
                object valObj;
                try
                {
                    valObj = JsonConvert.DeserializeObject<object>(value.Value);
                }
                catch
                {
                    valObj = value.Value.Substring(1, value.Value.Length - 1);
                }

                if (propType != null)
                {
                    properties.Add(new DetachedPublishedProperty(propType, valObj));
                }
            }

            return properties;
        }
        static SolidPublishedCaches CreatePublishedContent()
        {
            var caches = new SolidPublishedCaches();
            var cache = caches.ContentCache;

            var props = new[]
                    {
                        new PublishedPropertyType("prop1", 1, "?"), 
                    };

            var contentType1 = new PublishedContentType(1, "ContentType1", props);
            var contentType2 = new PublishedContentType(2, "ContentType2", props);
            var contentType2s = new PublishedContentType(3, "ContentType2Sub", props);

            cache.Add(new SolidPublishedContent(contentType1)
                {
                    Id = 1,
                    SortOrder = 0,
                    Name = "Content 1",
                    UrlName = "content-1",
                    Path = "/1",
                    Level = 1,
                    Url = "/content-1",
                    ParentId = -1,
                    ChildIds = new int[] {},
                    Properties = new Collection<IPublishedProperty>
                        {
                            new SolidPublishedProperty
                                {
                                    PropertyTypeAlias = "prop1",
                                    HasValue = true,
                                    Value = 1234,
                                    DataValue = "1234"
                                }
                        }
                });

            cache.Add(new SolidPublishedContent(contentType2)
                {
                    Id = 2,
                    SortOrder = 1,
                    Name = "Content 2",
                    UrlName = "content-2",
                    Path = "/2",
                    Level = 1,
                    Url = "/content-2",
                    ParentId = -1,
                    ChildIds = new int[] { },
                    Properties = new Collection<IPublishedProperty>
                            {
                                new SolidPublishedProperty
                                    {
                                        PropertyTypeAlias = "prop1",
                                        HasValue = true,
                                        Value = 1234,
                                        DataValue = "1234"
                                    }
                            }
                });

            cache.Add(new SolidPublishedContent(contentType2s)
            {
                Id = 3,
                SortOrder = 2,
                Name = "Content 2Sub",
                UrlName = "content-2sub",
                Path = "/3",
                Level = 1,
                Url = "/content-2sub",
                ParentId = -1,
                ChildIds = new int[] { },
                Properties = new Collection<IPublishedProperty>
                            {
                                new SolidPublishedProperty
                                    {
                                        PropertyTypeAlias = "prop1",
                                        HasValue = true,
                                        Value = 1234,
                                        DataValue = "1234"
                                    }
                            }
            });

            return caches;
        }
Пример #11
0
 /// <summary>
 /// Retrieves additional metadata that isn't available on the stored model of an Archetype
 /// </summary>
 /// <param name="archetype">The Archetype to add the additional metadata to</param>
 /// <param name="preValue">The configuration of the Archetype</param>
 private void RetrieveAdditionalProperties(ref ArchetypeModel archetype, ArchetypePreValue preValue, PublishedContentType hostContentType = null)
 {
     foreach (var fieldset in preValue.Fieldsets)
     {
         var fieldsetAlias = fieldset.Alias;
         foreach (var fieldsetInst in archetype.Fieldsets.Where(x => x.Alias == fieldsetAlias))
         {
             foreach (var property in fieldset.Properties)
             {
                 var propertyAlias = property.Alias;
                 foreach (var propertyInst in fieldsetInst.Properties.Where(x => x.Alias == propertyAlias))
                 {
                     propertyInst.DataTypeGuid = property.DataTypeGuid.ToString();
                     propertyInst.DataTypeId = GetDataTypeByGuid(property.DataTypeGuid).Id;
                     propertyInst.PropertyEditorAlias = property.PropertyEditorAlias;
                     propertyInst.HostContentType = hostContentType;
                 }
             }
         }
     }
 }
Пример #12
0
 /// <summary>
 /// This constructor is for tests and is not intended to be used directly from application code.
 /// </summary>
 /// <remarks>
 /// <para>Values are assumed to be consisted and are not checked.</para>
 /// <para>The new published property type belongs to the published content type.</para>
 /// </remarks>
 public PublishedPropertyType(PublishedContentType contentType, string propertyTypeAlias, int dataTypeId, bool isUserProperty, ContentVariation variations, PropertyValueConverterCollection propertyValueConverters, IPublishedModelFactory publishedModelFactory, IPublishedContentTypeFactory factory)
     : this(propertyTypeAlias, dataTypeId, isUserProperty, variations, propertyValueConverters, publishedModelFactory, factory)
 {
     ContentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
 }
Пример #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProductVariantContent"/> class.
 /// </summary>
 /// <param name="variant">
 /// The variant.
 /// </param>
 /// <param name="contentType">
 /// The content type.
 /// </param>
 /// <param name="cultureName">
 /// The culture name.
 /// </param>
 /// <param name="parent">
 /// The parent.
 /// </param>
 public ProductVariantContent(ProductVariantDisplay variant, PublishedContentType contentType, string cultureName = "en-US", IPublishedContent parent = null)
     : base(variant, contentType, cultureName)
 {
     _variant = variant;
     _parent = parent;
 }
Пример #14
0
            public PagePublishedContent(IContent inner)
            {
                if (inner == null)
                    throw new NullReferenceException("content");

                _inner = inner;
                _id = _inner.Id;

                _creatorName = _inner.GetCreatorProfile().Name;
                _writerName = _inner.GetWriterProfile().Name;

                _contentType = new PublishedContentType(_inner.ContentType);

                _properties = _contentType.PropertyTypes
                    .Select(x =>
                    {
                        var p = _inner.Properties.SingleOrDefault(xx => xx.Alias == x.PropertyTypeAlias);
                        return p == null ? new PagePublishedProperty(x, this) : new PagePublishedProperty(x, this, p);
                    })
                    .Cast<IPublishedProperty>()
                    .ToArray();

                _parent = new PagePublishedContent(_inner.ParentId);
            }
        public SolidPublishedContent(PublishedContentType contentType)
        {
            // initialize boring stuff
            TemplateId = 0;
            WriterName = CreatorName = string.Empty;
            WriterId = CreatorId = 0;
            CreateDate = UpdateDate = DateTime.Now;
            Version = Guid.Empty;
            IsDraft = false;

            ContentType = contentType;
            DocumentTypeAlias = contentType.Alias;
            DocumentTypeId = contentType.Id;
        }
 public PublishedContent(PublishedContentType contentType, PublishedProperty[] properties)
 {
     _contentType = contentType;
     _properties = properties;
 }
Пример #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProductVariantContent"/> class.
 /// </summary>
 /// <param name="variant">
 /// The variant.
 /// </param>
 /// <param name="contentType">
 /// The content type.
 /// </param>
 /// <param name="optionContentTypes">
 /// The option Content Types.
 /// </param>
 /// <param name="cultureName">
 /// The culture name.
 /// </param>
 /// <param name="parent">
 /// The parent.
 /// </param>
 public ProductVariantContent(ProductVariantDisplay variant, PublishedContentType contentType, IDictionary<Guid, PublishedContentType> optionContentTypes, string cultureName = "en-US", IPublishedContent parent = null)
     : base(variant, contentType, optionContentTypes, cultureName)
 {
     _variant = variant;
     _parent = parent;
 }
        private object ConvertProperty(IPublishedProperty property, IPublishedContent owner, PublishedContentType contentType)
        {
            string editorAlias = contentType.GetPropertyType(property.PropertyTypeAlias).PropertyEditorAlias;
            
            // Property converter exist
            if (PropertyConverters.ContainsKey(editorAlias))
            {
                return PropertyConverters[editorAlias].Convert(property, owner);
            }

            return property.Value;
        }
Пример #19
0
		private void Initialize()
		{
		    if (_xmlNode == null) return;

		    if (_xmlNode.Attributes != null)
		    {
		        _id = int.Parse(_xmlNode.Attributes.GetNamedItem("id").Value);
		        if (_xmlNode.Attributes.GetNamedItem("template") != null)
		            _template = int.Parse(_xmlNode.Attributes.GetNamedItem("template").Value);
		        if (_xmlNode.Attributes.GetNamedItem("sortOrder") != null)
		            _sortOrder = int.Parse(_xmlNode.Attributes.GetNamedItem("sortOrder").Value);
		        if (_xmlNode.Attributes.GetNamedItem("nodeName") != null)
		            _name = _xmlNode.Attributes.GetNamedItem("nodeName").Value;
		        if (_xmlNode.Attributes.GetNamedItem("writerName") != null)
		            _writerName = _xmlNode.Attributes.GetNamedItem("writerName").Value;
		        if (_xmlNode.Attributes.GetNamedItem("urlName") != null)
		            _urlName = _xmlNode.Attributes.GetNamedItem("urlName").Value;
		        // Creatorname is new in 2.1, so published xml might not have it!
		        try
		        {
		            _creatorName = _xmlNode.Attributes.GetNamedItem("creatorName").Value;
		        }
		        catch
		        {
		            _creatorName = _writerName;
		        }

		        //Added the actual userID, as a user cannot be looked up via full name only... 
		        if (_xmlNode.Attributes.GetNamedItem("creatorID") != null)
		            _creatorId = int.Parse(_xmlNode.Attributes.GetNamedItem("creatorID").Value);
		        if (_xmlNode.Attributes.GetNamedItem("writerID") != null)
		            _writerId = int.Parse(_xmlNode.Attributes.GetNamedItem("writerID").Value);

                if (UmbracoConfig.For.UmbracoSettings().Content.UseLegacyXmlSchema)
		        {
		            if (_xmlNode.Attributes.GetNamedItem("nodeTypeAlias") != null)
		                _docTypeAlias = _xmlNode.Attributes.GetNamedItem("nodeTypeAlias").Value;
		        }
		        else
		        {
		            _docTypeAlias = _xmlNode.Name;
		        }

		        if (_xmlNode.Attributes.GetNamedItem("nodeType") != null)
		            _docTypeId = int.Parse(_xmlNode.Attributes.GetNamedItem("nodeType").Value);
		        if (_xmlNode.Attributes.GetNamedItem("path") != null)
		            _path = _xmlNode.Attributes.GetNamedItem("path").Value;
		        if (_xmlNode.Attributes.GetNamedItem("version") != null)
		            _version = new Guid(_xmlNode.Attributes.GetNamedItem("version").Value);
		        if (_xmlNode.Attributes.GetNamedItem("createDate") != null)
		            _createDate = DateTime.Parse(_xmlNode.Attributes.GetNamedItem("createDate").Value);
		        if (_xmlNode.Attributes.GetNamedItem("updateDate") != null)
		            _updateDate = DateTime.Parse(_xmlNode.Attributes.GetNamedItem("updateDate").Value);
		        if (_xmlNode.Attributes.GetNamedItem("level") != null)
		            _level = int.Parse(_xmlNode.Attributes.GetNamedItem("level").Value);

                _isDraft = (_xmlNode.Attributes.GetNamedItem("isDraft") != null);
            }

		    // load data
            var dataXPath = UmbracoConfig.For.UmbracoSettings().Content.UseLegacyXmlSchema ? "data" : "* [not(@isDoc)]";
		    var nodes = _xmlNode.SelectNodes(dataXPath);

		    _contentType = PublishedContentType.Get(PublishedItemType.Content, _docTypeAlias);

		    var propertyNodes = new Dictionary<string, XmlNode>();
            if (nodes != null)
                foreach (XmlNode n in nodes)
                {
                    var alias = UmbracoConfig.For.UmbracoSettings().Content.UseLegacyXmlSchema
                        ? n.Attributes.GetNamedItem("alias").Value
                        : n.Name;
                    propertyNodes[alias.ToLowerInvariant()] = n;
                }

            _properties = _contentType.PropertyTypes.Select(p =>
		        {
                    XmlNode n;
                    return propertyNodes.TryGetValue(p.PropertyTypeAlias.ToLowerInvariant(), out n)
                        ? new XmlPublishedProperty(p, _isPreviewing, n)
                        : new XmlPublishedProperty(p, _isPreviewing);		        
		        }).Cast<IPublishedProperty>().ToArray();

            // warn: this is not thread-safe...
            _initialized = true;
		}
Пример #20
0
 /// <summary>
 /// Initialize a new instance of the <see cref="PublishedPropertyType"/> class with a property type.
 /// </summary>
 /// <remarks>
 /// <para>The new published property type belongs to the published content type.</para>
 /// </remarks>
 public PublishedPropertyType(PublishedContentType contentType, PropertyType propertyType, PropertyValueConverterCollection propertyValueConverters, IPublishedModelFactory publishedModelFactory, IPublishedContentTypeFactory factory)
     : this(propertyType.Alias, propertyType.DataTypeId, true, propertyType.Variations, propertyValueConverters, publishedModelFactory, factory)
 {
     ContentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
 }