private static void SetCache (EntityCache scope) { m_contextCache.Store (Key, scope); }
private static ISitecoreDomainEntity ResolveEntity(Item item, IMap map, Type concreteType) { if (item == null) { return(null); } if (!map.SkipTemplateChecking && !item.DescendsFromTemplate(map.TemplatePath)) { Logger.LogWarningMessage(String.Format("Item ({0}, {1}) cannot be resolved to type ({2}) because it doesn't descend from template {3}", item.ID, item.Name, concreteType.FullName, map.TemplatePath)); return(null); } Logger.LogDebugMessage(String.Format("Resolving item ({0}, {1}) of type {2}", item.ID, item.Name, concreteType.FullName)); EntityCache entityCache = EntityCache.Current; if (entityCache.Contains(item.ID.Guid, concreteType)) { Logger.LogDebugMessage(String.Format("Resolving item from Cache: ({0}, {1}) of type {2}", item.ID, item.Name, concreteType.FullName)); DataAccessStatistics.IncrementResolveEntityFromCache(); return(entityCache.Get(item.ID.Guid, concreteType)); } var domainEntity = (ISitecoreDomainEntity)Activator.CreateInstance(concreteType); // write Id domainEntity.Id = item.ID.Guid; //Add the entity to the Resolver scope entityCache.Add(domainEntity); // write ParentId domainEntity.ParentId = item.ParentID.Guid; // write Url domainEntity.Url = GetItemUrl(item); // write properties foreach (MapEntry mapEntry in map.Mappings) { PropertyInfo property = mapEntry.MappedProperty; if (mapEntry.HasResolver) { object value = mapEntry.Resolver.Resolve(item); property.SetValue(domainEntity, value, null); } else { string rawValue = item[mapEntry.MappedTo]; if (rawValue.IsNullOrEmpty() && mapEntry.DontSetIfEmptyProperty) { continue; } object value = GetPropertyValueFromItem(item, mapEntry, property); property.SetValue(domainEntity, value, null); } } DataAccessStatistics.IncrementResolveEntity(); return(domainEntity); }
private static void SetCache(EntityCache scope) { m_contextCache.Store(Key, scope); }