public SitecoreDataMap(Database db, Item importItem, LevelLogger logger) : base(db, importItem, logger) { //deal with sitecore properties if any Item Props = GetItemByTemplate(importItem, Utility.Constants.PropertiesFolderID); if (Props.IsNotNull()) { ChildList c = Props.GetChildren(); if (c.Any()) { foreach (Item child in c) { //create an item to get the class / assembly name from BaseMapping bm = new BaseMapping(child); if (!string.IsNullOrEmpty(bm.HandlerAssembly)) { if (!string.IsNullOrEmpty(bm.HandlerClass)) { //create the object from the class and cast as base field to add it to field definitions IBaseProperty bp = null; try { bp = (IBaseProperty)Sitecore.Reflection.ReflectionUtil.CreateObject(bm.HandlerAssembly, bm.HandlerClass, new object[] { child }); } catch (FileNotFoundException fnfe) { Logger.AddError("Error", string.Format("the property:{0} binary {1} specified could not be found", child.Name, bm.HandlerAssembly)); } if (bp != null) PropertyDefinitions.Add(bp); else Logger.AddError("Error", string.Format("the property: '{0}' class type {1} could not be instantiated", child.Name, bm.HandlerClass)); } else { Logger.AddError("Error", string.Format("the property: '{0}' Handler Class {1} is not defined", child.Name, bm.HandlerClass)); } } else { Logger.AddError("Error", string.Format("the property: '{0}' Handler Assembly {1} is not defined", child.Name, bm.HandlerAssembly)); } } } else { Logger.AddError("Warn", "there are no properties to import"); } } }
private IBaseField CreateFieldDefinition(Item fieldItem) { BaseMapping bm = new BaseMapping(fieldItem); if (!string.IsNullOrEmpty(bm.HandlerAssembly)) { if (!string.IsNullOrEmpty(bm.HandlerClass)) { //create the object from the class and cast as base field to add it to field definitions try { var bf = (IBaseField)Sitecore.Reflection.ReflectionUtil.CreateObject(bm.HandlerAssembly, bm.HandlerClass, new object[] { fieldItem }); if (bf != null) { return bf; } Logger.AddError("Error", String.Format("the field: '{0}' class type {1} could not be instantiated", fieldItem.Name, bm.HandlerClass)); } catch (FileNotFoundException fnfe) { Logger.AddError("Error", String.Format("the field:{0} binary {1} specified could not be found. Exception: {2}", fieldItem.Name, bm.HandlerAssembly, GetExceptionDebugInfo(fnfe))); } } else { Logger.AddError("Error", String.Format("the field: '{0}' Handler Class {1} is not defined", fieldItem.Name, bm.HandlerClass)); } } else { Logger.AddError("Error", String.Format("the field: '{0}' Handler Assembly {1} is not defined", fieldItem.Name, bm.HandlerAssembly)); } return null; }