static private GetComponentPresentationFactory ( Sdl.Web.Common.Configuration.Localization localization ) : IComponentPresentationFactory | ||
localization | Sdl.Web.Common.Configuration.Localization | |
Результат | IComponentPresentationFactory |
/// <summary> /// Gets an Entity Model for a given Entity Identifier. /// </summary> /// <param name="id">The Entity Identifier in format ComponentID-TemplateID.</param> /// <param name="localization">The context Localization.</param> /// <returns>The Entity Model.</returns> /// <exception cref="DxaItemNotFoundException">If no Entity Model exists for the given URL.</exception> /// <remarks> /// Since we can't obtain CT metadata for DCPs, we obtain the View Name from the CT Title. /// </remarks> public virtual EntityModel GetEntityModel(string id, Localization localization) { using (new Tracer(id, localization)) { string[] idParts = id.Split('-'); if (idParts.Length != 2) { throw new DxaException(String.Format("Invalid Entity Identifier '{0}'. Must be in format ComponentID-TemplateID.", id)); } string componentUri = string.Format("tcm:{0}-{1}", localization.LocalizationId, idParts[0]); string templateUri = string.Format("tcm:{0}-{1}-32", localization.LocalizationId, idParts[1]); IComponentPresentationFactory componentPresentationFactory = DD4TFactoryCache.GetComponentPresentationFactory(localization); IComponentPresentation dcp; if (!componentPresentationFactory.TryGetComponentPresentation(out dcp, componentUri, templateUri)) { throw new DxaItemNotFoundException(id, localization.LocalizationId); } EntityModel result = ModelBuilderPipeline.CreateEntityModel(dcp, localization); if (result.XpmMetadata != null) { // Entity Models requested through this method are per definition "query based" in XPM terminology. result.XpmMetadata["IsQueryBased"] = true; } return(result); } }
/// <summary> /// Gets an Entity Model for a given Entity Identifier. /// </summary> /// <param name="id">The Entity Identifier in format ComponentID-TemplateID.</param> /// <param name="localization">The context Localization.</param> /// <returns>The Entity Model.</returns> /// <exception cref="DxaItemNotFoundException">If no Entity Model exists for the given URL.</exception> /// <remarks> /// Since we can't obtain CT metadata for DCPs, we obtain the View Name from the CT Title. /// </remarks> public virtual EntityModel GetEntityModel(string id, Localization localization) { using (new Tracer(id, localization)) { string[] idParts = id.Split('-'); if (idParts.Length != 2) { throw new DxaException(String.Format("Invalid Entity Identifier '{0}'. Must be in format ComponentID-TemplateID.", id)); } string componentUri = localization.GetCmUri(idParts[0]); string templateUri = localization.GetCmUri(idParts[1], (int)ItemType.ComponentTemplate); IComponentPresentationFactory componentPresentationFactory = DD4TFactoryCache.GetComponentPresentationFactory(localization); IComponentPresentation dcp; if (!componentPresentationFactory.TryGetComponentPresentation(out dcp, componentUri, templateUri)) { throw new DxaItemNotFoundException(id, localization.Id); } EntityModel result; if (CacheRegions.IsViewModelCachingEnabled) { EntityModel cachedEntityModel = SiteConfiguration.CacheProvider.GetOrAdd( string.Format("{0}-{1}", id, localization.Id), // key CacheRegions.EntityModel, () => ModelBuilderPipeline.CreateEntityModel(dcp, localization), dependencies: new[] { componentUri } ); // Don't return the cached Entity Model itself, because we don't want dynamic logic to modify the cached state. result = (EntityModel)cachedEntityModel.DeepCopy(); } else { result = ModelBuilderPipeline.CreateEntityModel(dcp, localization); } if (result.XpmMetadata != null) { // Entity Models requested through this method are per definition "query based" in XPM terminology. result.XpmMetadata["IsQueryBased"] = true; } return(result); } }
/// <summary> /// Gets an Entity Model for a given Entity Identifier. /// </summary> /// <param name="id">The Entity Identifier in format ComponentID-TemplateID.</param> /// <param name="localization">The context Localization.</param> /// <returns>The Entity Model.</returns> /// <exception cref="DxaItemNotFoundException">If no Entity Model exists for the given URL.</exception> /// <remarks> /// Since we can't obtain CT metadata for DCPs, we obtain the View Name from the CT Title. /// </remarks> public virtual EntityModel GetEntityModel(string id, Localization localization) { using (new Tracer(id, localization)) { string[] idParts = id.Split('-'); if (idParts.Length != 2) { throw new DxaException(String.Format("Invalid Entity Identifier '{0}'. Must be in format ComponentID-TemplateID.", id)); } string componentUri = string.Format("tcm:{0}-{1}", localization.LocalizationId, idParts[0]); string templateUri = string.Format("tcm:{0}-{1}-32", localization.LocalizationId, idParts[1]); IComponentPresentationFactory componentPresentationFactory = DD4TFactoryCache.GetComponentPresentationFactory(localization); IComponentPresentation dcp; if (!componentPresentationFactory.TryGetComponentPresentation(out dcp, componentUri, templateUri)) { throw new DxaItemNotFoundException(id); } return(ModelBuilderPipeline.CreateEntityModel(dcp, localization)); } }