/// <summary>
            /// Format the data for the editor
            /// </summary>
            /// <param name="property"></param>
            /// <param name="propertyType"></param>
            /// <param name="dataTypeService"></param>
            /// <returns></returns>
            public override object ConvertDbToEditor(Property property, PropertyType propertyType, IDataTypeService dataTypeService)
            {
                if (property.Value == null)
                    return null;

                var parsed = MacroTagParser.FormatRichTextPersistedDataForEditor(property.Value.ToString(), new Dictionary<string, string>());
                return parsed;
            }
            public override string ConvertDbToString(Property property, PropertyType propertyType, IDataTypeService dataTypeService)
            {
                if (property.Value == null || string.IsNullOrEmpty(property.Value.ToString()))
                {
                    return "";
                }

                return property.Value.ToString();
            }
            public override object ConvertDbToEditor(Property property, PropertyType propertyType, IDataTypeService dataTypeService)
            {
                if (property.Value == null || string.IsNullOrEmpty(property.Value.ToString()))
                {
                    return "";
                }

                return SecurityHelper.Decrypt(property.Value.ToString(), SecurityHelper.GetKey());
            }
 protected IDictionary<string, PreValue> GetPreValues(Property property)
 {
     var preVals = _dataTypeService.GetPreValuesCollectionByDataTypeId(property.PropertyType.DataTypeDefinitionId);
     if (preVals != null)
     {
         var dictionary = preVals.FormatAsDictionary();
         return dictionary;
     }
     return null;
 }
        /// <summary>
        /// when saving to the xml cache, if the value can be converted to xml then ensure it's not wrapped in CData
        /// </summary>
        /// <param name="property"></param>
        /// <param name="propertyType"></param>
        /// <param name="dataTypeService"></param>
        /// <returns></returns>
        public override XNode ConvertDbToXml(Property property, PropertyType propertyType, IDataTypeService dataTypeService)
        {
            string value = this.ConvertDbToString(property, propertyType, dataTypeService);

            try
            {
                return XElement.Parse(value);
            }
            catch
            {
                return new XCData(value);
            }
        }
Example #6
0
        /// <summary>
        /// Sets the property.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="value">The value.</param>
        /// <param name="config">The config.</param>
        /// <param name="context">The context.</param>
        public override void SetProperty(Umbraco.Core.Models.Property property, object value, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context)
        {
            throw new NotImplementedException();

            /* Image img = value as Image;
             * var item = field.Item;
             *
             * if (field == null) return;
             *
             * ImageField scImg = new ImageField(field);
             *
             * if (img == null)
             * {
             *   scImg.Clear();
             *   return;
             * }
             *
             * if (scImg.MediaID.Guid != img.MediaId)
             * {
             *   //this only handles empty guids, but do we need to remove the link before adding a new one?
             *   if (img.MediaId == Guid.Empty)
             *   {
             *       ItemLink link = new ItemLink(item.Database.Name, item.ID, scImg.InnerField.ID, scImg.MediaItem.Database.Name, scImg.MediaID, scImg.MediaItem.Paths.Path);
             *       scImg.RemoveLink(link);
             *   }
             *   else
             *   {
             *       ID newId = new ID(img.MediaId);
             *       Item target = item.Database.GetItem(newId);
             *       if (target != null)
             *       {
             *           scImg.MediaID = newId;
             *           ItemLink link = new ItemLink(item.Database.Name, item.ID, scImg.InnerField.ID, target.Database.Name, target.ID, target.Paths.FullPath);
             *           scImg.UpdateLink(link);
             *       }
             *       else throw new MapperException("No item with ID {0}. Can not update Media Item field".Formatted(newId));
             *   }
             * }
             *
             * scImg.Height = img.Height.ToString();
             * scImg.Width = img.Width.ToString();
             * scImg.HSpace = img.HSpace.ToString();
             * scImg.VSpace = img.VSpace.ToString();
             * scImg.Alt = img.Alt;
             * scImg.Border = img.Border;
             * scImg.Class = img.Class;*/
        }
        /// <summary>
        /// Need to lookup the pre-values and put the string version in cache, not the ID (which is what is stored in the db)
        /// </summary>
        /// <param name="property"></param>
        /// <param name="propertyType"></param>
        /// <param name="dataTypeService"></param>
        /// <returns></returns>
        public override string ConvertDbToString(Property property, PropertyType propertyType, IDataTypeService dataTypeService)
        {
            var idAttempt = property.Value.TryConvertTo<int>();
            if (idAttempt.Success)
            {
                var preValId = idAttempt.Result;
                var preVals = GetPreValues(property);
                if (preVals != null)
                {
                    if (preVals.Any(x => x.Value.Id == preValId))
                    {
                        return preVals.Single(x => x.Value.Id == preValId).Value.Value;
                    }

                    LogHelper.Warn<PublishValueValueEditor>("Could not find a pre value with ID " + preValId + " for property alias " + property.Alias);
                }
            }
            
            return base.ConvertDbToString(property, propertyType, dataTypeService);
        }
Example #8
0
        /// <summary>
        /// Gets the property.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="config">The config.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public override object GetProperty(Umbraco.Core.Models.Property property, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context)
        {
            if (property == null)
            {
                return(null);
            }

            var mediaService = new MediaService(new RepositoryFactory());
            int id;

            if (!int.TryParse(property.Value.ToString(), out id))
            {
                return(null);
            }

            var image = mediaService.GetById(id);

            if (image != null)
            {
                int width;
                int.TryParse(image.Properties["umbracoWidth"].Value.ToString(), out width);
                int height;
                int.TryParse(image.Properties["umbracoHeight"].Value.ToString(), out height);
                int bytes;
                int.TryParse(image.Properties["umbracoBytes"].Value.ToString(), out bytes);

                var img = new Image
                {
                    Id        = image.Id,
                    Alt       = image.Name,
                    Src       = image.Properties["umbracoFile"].Value.ToString(),
                    Width     = width,
                    Height    = height,
                    Extension = image.Properties["umbracoExtension"].Value.ToString(),
                    Size      = bytes
                };
                return(img);
            }

            return(null);
        }
Example #9
0
 public PagePublishedProperty(PublishedPropertyType propertyType, IPublishedContent content, Umbraco.Core.Models.Property property)
     : base(propertyType, PropertyCacheLevel.Unknown) // cache level is ignored
 {
     _sourceValue = property.GetValue();
     _content     = content;
 }
Example #10
0
 /// <summary>
 /// Creates the xml representation for the <see cref="Property"/> object
 /// </summary>
 /// <param name="property"><see cref="Property"/> to generate xml for</param>
 /// <returns>Xml of the property and its value</returns>
 public static XElement ToXml(this Property property)
 {
     return(property.ToXml(ApplicationContext.Current.Services.DataTypeService));
 }