예제 #1
0
        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));
        }
        private bool IsAvailableFor(object input)
        {
            if (input == null)
            {
                return(true);
            }

            if (!_cmsContext.CanRender(input, _cmsContext.GetCurrentTheme()))
            {
                return(false);
            }

            var ensureExists = _container.GetAllInstances(typeof(IEnsureExists <>).MakeGenericType(input.GetType())).OfType <object>().ToList();

            var exists = ensureExists.All(x => (bool)x.GetType().GetMethod("Exists", new[] { input.GetType() }).Invoke(x, new[] { input }));

            if (!exists)
            {
                return(false);
            }

            var secureInterfaces = input.GetType()
                                   .GetInterfaces()
                                   .Where(x => x.GenericTypeArguments.Length == 1 && x.GenericTypeArguments[0].CanBeCastTo <ISubApplication>() && x.CanBeCastTo(typeof(IAmSecuredBy <>).MakeGenericType(x.GenericTypeArguments[0])))
                                   .ToList();

            return((from secureInterface in secureInterfaces
                    let authenticationContext = _serviceLocator.GetInstance(typeof(IAuthenticationService <>).MakeGenericType(secureInterface.GenericTypeArguments[0]))
                                                let user = (AuthenticationInformation)authenticationContext.GetType().GetMethod("GetUser").Invoke(authenticationContext, new object[0])
                                                           select _validateSecurity.IsAllowed(user, (SecuredBy)input
                                                                                              .GetType()
                                                                                              .GetMethod("GetSecuredBy", new[] { secureInterface.GenericTypeArguments[0] })
                                                                                              .Invoke(input, new[] { _serviceLocator.GetInstance(secureInterface.GenericTypeArguments[0]) })))
                   .All(x => x));
        }
예제 #3
0
        public virtual IRenderResult RenderTemplate(CmsTemplate template, IDictionary <string, object> settings, ICmsContext context, ITheme theme)
        {
            if (!context.CanRender(template, theme))
            {
                return(new RenderResult("text/plain", x => { }, new Dictionary <Guid, RequestContext>(), context));
            }

            var contexts = new Dictionary <Guid, RequestContext>();

            var result = ParseText($"<md>{template.Body}</md>", context, theme);

            return(new RenderResult(string.IsNullOrEmpty(template.ContentType) ? result.ContentType : template.ContentType, x => result.RenderTo(x), contexts, context));
        }