0

Umbraco 用の Glass Mapper を使用しています。何かをモデル化しようとしているときに、次のようなクラスがあります。

[UmbracoType(AutoMap = true)]
    public class ImageWithLink : BaseUmbracoItem
    {
        public virtual Image Image { get; set; }
        public virtual ?? Link { get; set; }
        public virtual string Copy { get; set; }
    }

Sitecore の実装にあるような「リンク」データ タイプはないようです。この投稿 ( http://bluetubeinc.com/blog/2014/6/glass-mapper-and-umbraco-7 ) を見ましたが、「RelatedLink」データ型を使用していますが、存在しません (グラスでチェックインしましたリポジトリ)。

自分でモデル化する必要がありますか?

編集: これは関連リンク プロパティ タイプです。

4

2 に答える 2

0

I Found a (rather horrible) solution. Umbraco returns Json, so i had to de-serialize it. You could turn this into a mapper.

[UmbracoType(AutoMap = true)]
    public class BaseUmbracoItem : IUmbracoItem
    {
        public virtual string Links { get; set; }

        public List<UmbracoLink> TypedLink
        {
            get
            {
                return JsonConvert.DeserializeObject<List<UmbracoLink>>(Links);
            }
        }
    }
public class UmbracoLink
    {
        public string link { get; set; }
        public string type { get; set; }
        public string title { get; set; }
        public bool newWindow { get; set; }
        public bool isInternal { get; set; }
    }

Here is a mapper version:

public class UmbracoLinkMapper : AbstractDataMapper
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="UmbracoLinkMapper"/> class.
        /// </summary>
        public UmbracoLinkMapper()
        {
            ReadOnly = true;
        }

        /// <summary>
        /// Maps data from the .Net property value to the CMS value
        /// </summary>
        /// <param name="mappingContext">The mapping context.</param>
        /// <returns>The value to write</returns>
        /// <exception cref="System.NotSupportedException"></exception>
        public override void MapToCms(AbstractDataMappingContext mappingContext)
        {
            throw new NotSupportedException();
        }

        /// <summary>
        /// Maps data from the CMS value to the .Net property value
        /// </summary>
        /// <param name="mappingContext">The mapping context.</param>
        /// <returns>System.Object.</returns>
        public override object MapToProperty(AbstractDataMappingContext mappingContext)
        {
            var scContext = mappingContext as UmbracoDataMappingContext;
            var scConfig = Configuration as UmbracoLinkConfiguration;

            var properties = scContext.Content.Properties.Where(x => x.Alias == Configuration.PropertyInfo.Name.ToLower()).ToList();
            if (properties.Any())
            {
                var property = properties.First().Value as string;
                return JsonConvert.DeserializeObject<List<UmbracoLink>>(property).First();
            }
            return null;
        }

        /// <summary>
        /// Indicates that the data mapper will mapper to and from the property
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="context">The context.</param>
        /// <returns><c>true</c> if this instance can handle the specified configuration; otherwise, <c>false</c>.</returns>
        public override bool CanHandle(AbstractPropertyConfiguration configuration, Context context)
        {
            return configuration is UmbracoLinkConfiguration;
        }
    }

 public class UmbracoLinkConfiguration : AbstractPropertyConfiguration
    {
        public bool IsLazy { get; set; }
        public bool InferType { get; set; }
    }

public class UmbracoLinkAttribute : AbstractPropertyAttribute
    {
        public bool IsLazy { get; set; }
        public bool InferType { get; set; }

        public override AbstractPropertyConfiguration Configure(PropertyInfo propertyInfo)
        {
            var config = new UmbracoLinkConfiguration { IsLazy = IsLazy, InferType = InferType };
            Configure(propertyInfo, config);
            return config;
        }
    }
于 2015-02-13T17:28:29.480 に答える