public virtual IRenderResult RenderComponent(ICmsComponent component, IDictionary <string, object> settings, ICmsContext context, ITheme theme) { if (!context.CanRender(component, theme)) { return(new RenderResult("text/plain", x => { }, new Dictionary <Guid, RequestContext>(), context)); } var renderInformation = component.Render(context, settings); if (renderInformation == null) { return(new RenderResult("text/plain", x => { }, new Dictionary <Guid, RequestContext>(), context)); } var contexts = renderInformation.Contexts.ToDictionary(x => Guid.NewGuid(), x => x); contexts[Guid.NewGuid()] = ComponentSettingsContext.Build(settings); return(new RenderResult(renderInformation.ContentType, x => { var renderer = (IRenderer)context.Resolve(typeof(Renderer <>).MakeGenericType(renderInformation.GetType())); renderer.Render(renderInformation, context, theme, x); }, contexts, context)); }
public virtual IRenderResult RenderEndpoint <TInput>(TInput input, ICmsContext context, ITheme theme) where TInput : ICmsEndpointInput { var themeEndpoint = context .Filter(_themeEndpoints.OfType <ICmsEndpoint <TInput> >(), theme) .FirstOrDefault(); if (themeEndpoint == null) { return(new RenderResult("text/plain", x => { }, new Dictionary <Guid, RequestContext>(), context)); } var settings = themeEndpoint.GetDefaultSettings(); var endpointConfiguration = _endpointConfigurationStorage.Load(theme.GetName(), theme); if (endpointConfiguration != null) { foreach (var item in endpointConfiguration.Settings) { settings[item.Key] = item.Value; } } var renderInformation = themeEndpoint.Render(input, context, settings); if (renderInformation == null) { return(new RenderResult("text/plain", x => { }, new Dictionary <Guid, RequestContext>(), context)); } var contexts = renderInformation.Contexts.ToDictionary(x => Guid.NewGuid(), x => x); contexts[Guid.NewGuid()] = EndpointSettingsContext.Build(settings); return(new RenderResult(renderInformation.ContentType, x => { var renderer = (IRenderer)context.Resolve(typeof(Renderer <>).MakeGenericType(renderInformation.GetType())); renderer.Render(renderInformation, context, theme, x); }, contexts, context)); }