示例#1
0
        private void LoadComponentModelsFromComponentPresentationFactory(IPage page)
        {
            LoggerService.Debug(">>LoadComponentModelsFromComponentPresentationFactory ({0})", LoggingCategory.Performance, page.Id);

            foreach (DD4T.ContentModel.ComponentPresentation cp in page.ComponentPresentations)
            {
                if (cp.Component == null)
                {
                    continue;
                }

                // added by QS: only load DCPs from broker if they are in fact dynamic!
                if (cp.IsDynamic)
                {
                    try
                    {
                        ComponentPresentation dcp = (ComponentPresentation)ComponentPresentationFactory.GetComponentPresentation(cp.Component.Id, cp.ComponentTemplate.Id);
                        cp.Component         = dcp.Component;
                        cp.ComponentTemplate = dcp.ComponentTemplate;
                        cp.Conditions        = dcp.Conditions;
                    }
                    catch (ComponentPresentationNotFoundException)
                    {
                        LoggerService.Warning("dynamic component presentation {0} / {1} included on page {2} cannot be found; it may have been unpublished", LoggingCategory.Model, cp.Component.Id, cp.ComponentTemplate.Id, page.Id);
                        // DCPs can be unpublished while the page that they are embedded on remain published
                        // in this case, simply ignore the exception (the 'stub' component is still on the page)
                    }
                }
            }
            LoggerService.Debug("<<LoadComponentModelsFromComponentPresentationFactory ({0})", LoggingCategory.Performance, page.Id);
        }
        internal static IComponentPresentationFactory GetComponentPresentationFactory(Localization localization)
        {
            lock (_componentPresentationFactories)
            {
                IComponentPresentationFactory componentPresentationFactory;
                if (!_componentPresentationFactories.TryGetValue(localization.LocalizationId, out componentPresentationFactory))
                {
                    IPublicationResolver publicationResolver = new PublicationResolver(localization);
                    IProvidersCommonServices providersCommonServices = new ProvidersCommonServices(publicationResolver, _logger, _config);
                    IFactoryCommonServices factoryCommonServices = new FactoryCommonServices(publicationResolver, _logger, _config, CreateCacheAgent());
                    componentPresentationFactory = new ComponentPresentationFactory(
                        new TridionComponentPresentationProvider(providersCommonServices), 
                        factoryCommonServices);
                    _componentPresentationFactories.Add(localization.LocalizationId, componentPresentationFactory);
                }

                return componentPresentationFactory;
            }
        }
示例#3
0
        private void LoadComponentModelsFromComponentPresentationFactory(IPage page)
        {
            LoggerService.Debug(">>LoadComponentModelsFromComponentPresentationFactory ({0})", LoggingCategory.Performance, page.Id);

            foreach (DD4T.ContentModel.ComponentPresentation cp in page.ComponentPresentations)
            {
                if (cp.Component == null)
                {
                    continue;
                }

                // added by QS: only load DCPs from broker if they are in fact dynamic!
                if (cp.IsDynamic)
                {
                    try
                    {
                        ComponentPresentation dcp = (ComponentPresentation)ComponentPresentationFactory.GetComponentPresentation(cp.Component.Id, cp.ComponentTemplate.Id);
                        cp.Component = dcp.Component;
                        //Fix for backward compatibility. We keep using the template on the page as 1.x version of dd4t doesn't have the componenttemplate data in the dcp
                        //The title is mandatory in tridion, so it can't be null or empty when successful, the id will still be set by the factory
                        if (!String.IsNullOrEmpty(dcp.ComponentTemplate.Title))
                        {
                            cp.ComponentTemplate = dcp.ComponentTemplate;
                        }
                        cp.TargetGroupConditions = dcp.TargetGroupConditions;
                    }
                    catch (ComponentPresentationNotFoundException)
                    {
                        LoggerService.Warning("dynamic component presentation {0} / {1} included on page {2} cannot be found; it may have been unpublished", LoggingCategory.Model, cp.Component.Id, cp.ComponentTemplate.Id, page.Id);
                        // DCPs can be unpublished while the page that they are embedded on remain published
                        // in this case, simply ignore the exception (the 'stub' component is still on the page)
                    }
                }
            }
            LoggerService.Debug("<<LoadComponentModelsFromComponentPresentationFactory ({0})", LoggingCategory.Performance, page.Id);
        }