public virtual TProjection Create <TProjection>(IPageContent pageContent, IContent content, IList <IOptionValue> options,
                                                        IEnumerable <ChildContentProjection> childContentProjections, IEnumerable <PageContentProjection> childRegionContentProjections,
                                                        Func <IPageContent, IContent, IContentAccessor, IEnumerable <ChildContentProjection>, IEnumerable <PageContentProjection>, TProjection> createProjectionDelegate)
            where TProjection : PageContentProjection
        {
            IContentAccessor contentAccessor = GetAccessorForType(content, options);

            if (contentAccessor == null)
            {
                Log.Error(string.Format("A content accessor was not found for the content type {0} with id={1}.", content.GetType().FullName, content.Id));

                contentAccessor = new EmptyContentAccessor(string.Format("<i style=\"color:red;\">{0}</i>", RootGlobalization.Message_FailedToRenderContent));
            }

            TProjection pageContentProjection = createProjectionDelegate.Invoke(pageContent, content, contentAccessor, childContentProjections, childRegionContentProjections);

            return(pageContentProjection);
        }
Пример #2
0
        public TProjection Create <TProjection>(IPageContent pageContent, IContent content, IList <IOptionValue> options,
                                                IEnumerable <ChildContentProjection> childContentProjections,
                                                Func <IPageContent, IContent, IContentAccessor, IEnumerable <ChildContentProjection>, TProjection> createProjectionDelegate)
            where TProjection : PageContentProjection
        {
            IContentAccessor contentAccessor = null;
            Type             contentType;

            if (content is IProxy)
            {
                contentType = content.GetType().BaseType;
            }
            else
            {
                contentType = content.GetType();
            }

            string key = "CONTENTRENDERER-" + contentType.Name.ToUpperInvariant();

            if (containerProvider.CurrentScope.IsRegisteredWithKey <IContentAccessor>(key))
            {
                contentAccessor = containerProvider.CurrentScope
                                  .ResolveKeyed <IContentAccessor>(key, new Parameter[]
                {
                    new PositionalParameter(0, content),
                    new PositionalParameter(1, options)
                });
            }

            if (contentAccessor == null)
            {
                Log.Error(string.Format("A content accessor was not found for the content type {0} with id={1}.", content.GetType().FullName, content.Id));

                contentAccessor = new EmptyContentAccessor(string.Format("<i style=\"color:red;\">{0}</i>", RootGlobalization.Message_FailedToRenderContent));
            }

            TProjection pageContentProjection = createProjectionDelegate.Invoke(pageContent, content, contentAccessor, childContentProjections);

            return(pageContentProjection);
        }
        public PageContentProjection Create(IPageContent pageContent, IContent content, IList<IOption> options)
        {
            IContentAccessor contentAccessor = null;
            Type contentType;

            if (content is IProxy)
            {
                contentType = content.GetType().BaseType;
            }
            else
            {
                contentType = content.GetType();
            }

            string key = "CONTENTRENDERER-" + contentType.Name.ToUpperInvariant();

            if (containerProvider.CurrentScope.IsRegisteredWithKey<IContentAccessor>(key))
            {
                contentAccessor = containerProvider.CurrentScope
                    .ResolveKeyed<IContentAccessor>(key, new Parameter[]
                                                             {
                                                                 new PositionalParameter(0, content),
                                                                 new PositionalParameter(1, options)
                                                             });
            }

            if (contentAccessor == null)
            {
                Log.Error(string.Format("A content accessor was not found for the content type {0} with id={1}.", content.GetType().FullName, content.Id));

                contentAccessor = new EmptyContentAccessor(string.Format("<i style=\"color:red;\">{0}</i>", RootGlobalization.Message_FailedToRenderContent));
            }

            PageContentProjection pageContentProjection = new PageContentProjection(pageContent, content, contentAccessor);

            return pageContentProjection;
        }