Cache for DD4T Factories; one for each Localization.
コード例 #1
0
        /// <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);
            }
        }
コード例 #2
0
        private static string GetLinkTitle(XmlElement linkElement, Localization localization)
        {
            string            componentUri     = linkElement.GetAttribute("xlink:href");
            IComponentFactory componentFactory = DD4TFactoryCache.GetComponentFactory(localization);
            IComponent        component        = componentFactory.GetComponent(componentUri);

            return((component == null) ? linkElement.GetAttribute("title") : component.Title);
        }
コード例 #3
0
 /// <summary>
 /// Ensures that the Component Fields of DCPs on the Page are populated.
 /// </summary>
 private static void FullyLoadDynamicComponentPresentations(IPage page, Localization localization)
 {
     using (new Tracer(page, localization))
     {
         foreach (ComponentPresentation dcp in page.ComponentPresentations.Where(cp => cp.IsDynamic).OfType <ComponentPresentation>())
         {
             IComponentFactory componentFactory = DD4TFactoryCache.GetComponentFactory(localization);
             dcp.Component = (Component)componentFactory.GetComponent(dcp.Component.Id, dcp.ComponentTemplate.Id);
         }
     }
 }
コード例 #4
0
        protected virtual IPage GetPage(string url, Localization localization)
        {
            string cmUrl = GetCmUrl(url);

            using (new Tracer(url, cmUrl))
            {
                IPageFactory pageFactory = DD4TFactoryCache.GetPageFactory(localization);
                IPage        result;
                pageFactory.TryFindPage(cmUrl, out result);
                return(result);
            }
        }
コード例 #5
0
        public virtual string GetPageContent(string urlPath, Localization localization)
        {
            string cmUrl = GetCmUrl(urlPath);

            using (new Tracer(urlPath, cmUrl))
            {
                IPageFactory pageFactory = DD4TFactoryCache.GetPageFactory(localization);
                string       result;
                pageFactory.TryFindPageContent(GetCmUrl(urlPath), out result);
                return(result);
            }
        }
コード例 #6
0
        /// <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);
            }
        }
コード例 #7
0
        /// <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));
            }
        }