public Type ResolveComponentTypeFor(Type ModelType, params Type[] AssignableFrom) { Type[] assignableFrom = new Type[] { typeof(IComponent) }; if (AssignableFrom?.Any() ?? false) { assignableFrom = AssignableFrom.Union(assignableFrom).Distinct().ToArray(); } return(ModelType is Type?ComponentMaps?.LastOrDefault(m => m.ModelType.IsAssignableFrom(ModelType) && assignableFrom.All(t => t.IsAssignableFrom(m.ComponentType)))?.ComponentType : null); }
public override void FillField(IDataMap map, ref Item newItem, object importRow) { var importValue = string.Join(Delimiter, map.GetFieldValues(ExistingDataNames, importRow)); if (string.IsNullOrEmpty(importValue)) { var path = importRow is Item ? ((Item)importRow).Paths.FullPath : "N/A"; Logger.Log($"There was no import value", path, LogType.MultilistToComponent); return; } var layoutField = newItem.Fields[FieldIDs.FinalLayoutField]; if (layoutField == null) { return; } var layout = LayoutDefinition.Parse(layoutField.Value); var deviceItem = layout.GetDevice(Device); var entries = importValue.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); var sitecoreMap = (SitecoreDataMap)map; var itemList = entries.Select(a => sitecoreMap.FromDB.GetItem(new ID(a))).Where(b => b != null).ToList(); foreach (var i in itemList) { var itemTemplate = i.TemplateID.ToString(); if (!ComponentMaps.ContainsKey(itemTemplate)) { Logger.Log($"There was no component mapping found", i.Paths.FullPath, LogType.MultilistToComponent, i.TemplateName, itemTemplate); continue; } var cm = ComponentMaps[itemTemplate]; var dsName = cm.DatasourcePath.Contains("/") ? cm.DatasourcePath.Substring(cm.DatasourcePath.LastIndexOf("/") + 1) : cm.DatasourcePath; if (!cm.OverwriteExisting) { var datasource = PresentationService.CreateDatasource(map, newItem, deviceItem, dsName, DatasourceFolder, cm.DatasourcePath, cm.Component, cm.OverwriteExisting); if (datasource == null) { Logger.Log($"There was no datasource created for matching device:{Device} - placeholder:{cm.Placeholder} - component:{cm.Component}", i.Paths.FullPath, LogType.MultilistToComponent, "device xml", deviceItem.ToXml()); continue; } SetFields(i, datasource, cm, sitecoreMap); PresentationService.AddComponent(newItem, datasource, cm.Placeholder, cm.Component, Device, cm.Parameters, IsSXA); } else { var rendering = PresentationService.FindRendering(deviceItem, cm.Placeholder, cm.Component); if (rendering == null) { Logger.Log($"There was no rendering matching device:{Device} - placeholder:{cm.Placeholder} - component:{cm.Component}", i.Paths.FullPath, LogType.MultilistToComponent, "device xml", deviceItem.ToXml()); continue; } var datasource = PresentationService.FindDatasourceByName(map, newItem, rendering, dsName); if (datasource == null) { Logger.Log($"There was no datasource found matching name:{dsName}", i.Paths.FullPath, LogType.MultilistToComponent, "rendering xml", rendering.ToXml()); continue; } SetFields(i, datasource, cm, sitecoreMap); } } }