I'm having trouble creating a custom data handler using Umbraco Glass Mapper. I'm trying to go off the sitecore tutorial
. I'm trying to convert a MNTP into an object that contains a list of objects that will be created form the MNTP. Right now the Model field is just returning null.
public class RotatingBannerTest
{
public IEnumerable<RotatingBannerItem> RotatingBannerList { get; set; }
public RotatingBannerTest(IEnumerable<RotatingBannerItem> rotatingBannerItemList)
{
this.RotatingBannerList = rotatingBannerItemList;
}
}
My Data Handler is
public class RotatingBannerDataHandler : Glass.Mapper.Umb.DataMappers.AbstractUmbracoPropertyMapper
{
public RotatingBannerDataHandler()
: base(typeof(RotatingBannerTest))
{
}
public override object GetPropertyValue(object propertyValue, Glass.Mapper.Umb.Configuration.UmbracoPropertyConfiguration config, Glass.Mapper.Umb.UmbracoDataMappingContext context)
{ // Assuming it returns back xml string
if (string.IsNullOrWhiteSpace(propertyValue.ToString()))
{
return null;
}
try
{
RotatingBannerTest rotatingBanner = null;
DynamicXml dynamicRotatingBannerItems = new DynamicXml(propertyValue.ToString());
List<RotatingBannerItem> items = GetDynamicItemList<RotatingBannerItem>(dynamicRotatingBannerItems, context);
rotatingBanner = new RotatingBannerTest(items);
return rotatingBanner;
}
catch(Exception ex)
{
return null;
}
}
public List<Type> GetDynamicItemList<Type>(DynamicXml dynamicXmlItems, Glass.Mapper.Umb.UmbracoDataMappingContext context)
{
List<Type> dynamicItemList = new List<Type>();
if (dynamicXmlItems.BaseElement != null)
{
foreach (dynamic item in dynamicXmlItems)
{
dynamicItemList.Add(context.Service.GetItem<Type>(int.Parse(item.InnerText)));
}
}
return dynamicItemList;
}
public override object SetPropertyValue(object value, Glass.Mapper.Umb.Configuration.UmbracoPropertyConfiguration config, Glass.Mapper.Umb.UmbracoDataMappingContext context)
{
throw new NotImplementedException();
}
}
The model using the object model is
public class Home : SitePage
{
[UmbracoProperty]
public virtual string Content { get; set; }
[UmbracoProperty]
public virtual RotatingBannerTest RotatingBannerTest { get; set; }
}
The GlassMapperUmbCustomer where I register my Data handler is
container.Register(
Component.For<IContentService>().ImplementedBy<ContentService>().LifestyleTransient(),
Component.For<IUmbracoService>().ImplementedBy<UmbracoService>().LifestyleTransient(),
Component.For<Glass.Mapper.AbstractDataMapper>().ImplementedBy<RotatingBannerDataHandler>().LifeStyle.Transient
);
I put break points inside my data handler but the only thing that ever gets hit is the constructor. Does anyone have any idea what I might be doing wrong or at least have a suggestion in how I can debug this?
Thanks in advance!