internal static PublishedPropertyType CreateDummyPropertyType(this ArchetypePropertyModel prop)
 {
     return(new PublishedPropertyType(prop.HostContentType, new PropertyType(new DataTypeDefinition(-1, prop.PropertyEditorAlias)
     {
         Id = prop.DataTypeId
     })));
 }
        /// <summary>
        /// Creates dummy property type.
        /// </summary>
        /// <param name="prop">The property.</param>
        /// <returns></returns>
        internal static PublishedPropertyType CreateDummyPropertyType(this ArchetypePropertyModel prop)
        {
            // We need to check if `PropertyValueConvertersResolver` exists,
            // otherwise `PublishedPropertyType` will throw an exception outside of the Umbraco context.; e.g. unit-tests.
            if (!PropertyValueConvertersResolver.HasCurrent)
            {
                return(null);
            }

            return(new PublishedPropertyType(prop.HostContentType, new PropertyType(new DataTypeDefinition(-1, prop.PropertyEditorAlias)
            {
                Id = prop.DataTypeId
            })));
        }
        public ArchetypePublishedProperty(ArchetypePropertyModel property)
        {
            if (property == null)
                throw new ArgumentNullException("property");

            var preview = false;

            _property = property;
            _rawValue = property.Value;

            _propertyType = property.CreateDummyPropertyType();

            if (_propertyType != null)
            {
                _sourceValue = new Lazy<object>(() => _propertyType.ConvertDataToSource(_rawValue, preview));
                _objectValue = new Lazy<object>(() => _propertyType.ConvertSourceToObject(_sourceValue.Value, preview));
                _xpathValue = new Lazy<object>(() => _propertyType.ConvertSourceToXPath(_sourceValue.Value, preview));
            }
        }
示例#4
0
        private static object GetTypedValue(ArchetypePropertyModel archetypeProperty)
        {
            switch (archetypeProperty.PropertyEditorAlias)
            {
            case "Umbraco.ContentPickerAlias":
            case "Umbraco.MediaPicker":
                IPublishedContent v = archetypeProperty.GetValue <IPublishedContent>();
                if (v == null)
                {
                    return("");
                }
                return(v);

            //case "Umbraco.MultiNodeTreePicker":
            //    return archetypeProperty.GetValue<IEnumerable<IPublishedContent>>();
            default:
                return(archetypeProperty.Value);
            }
        }
示例#5
0
        /// <summary>
        /// Gets the typed value of the Archetype property
        /// </summary>
        /// <param name="mapper">Umbraco mapper</param>
        /// <param name="archetypeProperty">Archetype property</param>
        /// <returns>Object of the required type</returns>
        private static object GetTypedValue(IUmbracoMapper mapper, ArchetypePropertyModel archetypeProperty)
        {
            switch (archetypeProperty.PropertyEditorAlias)
            {
            case "Umbraco.ContentPickerAlias":
                return(archetypeProperty.GetValue <IPublishedContent>());

            case "Umbraco.MultiNodeTreePicker":
                return(archetypeProperty.GetValue <IEnumerable <IPublishedContent> >());

            case "Umbraco.TinyMCEv3":
                return(archetypeProperty.GetValue <IHtmlString>());

            case "Imulus.Archetype":
                return(GetArchetypeCollection(mapper, archetypeProperty.GetValue <ArchetypeModel>()));

            default:
                return(archetypeProperty.Value);
            }
        }
 public static bool IsArchetype(this ArchetypePropertyModel prop)
 {
     return(prop.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditorAlias));
 }