protected override object FindParameterValue(Match match, ICmsRenderer cmsRenderer, ICmsContext context, ITheme theme, Func<string, string> recurse) { var templateNameGroup = match.Groups["templateName"]; if (templateNameGroup == null) return ""; var templateName = templateNameGroup.Value; var template = _templateStorage.Load(templateName, theme); if (template == null) return ""; var settings = new Dictionary<string, object>(); var settingsGroup = match.Groups["settings"]; if (settingsGroup != null && !string.IsNullOrEmpty(settingsGroup.Value)) { var settingsJson = settingsGroup.Value; if (!string.IsNullOrEmpty(settingsJson)) { var parsedSettings = JsonConvert.DeserializeObject<IDictionary<string, object>>(settingsJson); foreach (var item in parsedSettings) settings[item.Key] = item.Value; } } var renderResult = cmsRenderer.RenderTemplate(template, settings, context, theme); return renderResult.Read(); }
protected override object FindParameterValue(Match match, ICmsRenderer cmsRenderer, ICmsContext context, ITheme theme, Func<string, string> recurse) { var localizationNamespace = _findCurrentLocalizationNamespace.Find(); var key = !string.IsNullOrEmpty(localizationNamespace) ? string.Format("{0}:{1}", localizationNamespace, match.Groups["resource"].Value) : match.Groups["resource"].Value; var replacements = new Dictionary<string, string>(); var replacementsGroup = match.Groups["replacements"]; if (replacementsGroup != null && !string.IsNullOrEmpty(replacementsGroup.Value)) { var replacementsData = replacementsGroup .Value .Split(',') .Where(x => !string.IsNullOrEmpty(x)) .Select(x => x.Split(':')) .Where(x => x.Length > 1 && !string.IsNullOrEmpty(x[0]) && !string.IsNullOrEmpty(x[1])) .ToList(); foreach (var item in replacementsData) replacements[item[0]] = item[1]; } var localized = _localizeText.Localize(key, _findCultureForRequest.FindUiCulture()); localized = replacements.Aggregate(localized, (current, replacement) => current.Replace(string.Concat("{{", replacement.Key, "}}"), replacement.Value)); return recurse(localized); }
public string Parse(string text, ICmsRenderer cmsRenderer, ICmsContext context, ITheme theme, Func <string, string> recurse) { text = text ?? ""; text = GetRegexes().Aggregate(text, (current, regex) => regex.Replace(current, x => { var value = FindParameterValue(x, cmsRenderer, context, theme, recurse); if (value == null) { return(""); } var enumerableValue = value as IEnumerable; if (enumerableValue != null && !(value is string)) { var stringValues = enumerableValue.OfType <object>().Select(y => y.ToString()).ToList(); return(string.Join(SeperateListItemsWith, stringValues)); } return(value.ToString()); })); return(text); }
public virtual IRenderResult ParseText(string text, ICmsContext context, ITheme theme, ParseTextOptions options = null) { var parsers = _textParsers.ToList(); if (options != null && options.UseOnlyParsersTagged.Any()) { parsers = parsers.Where(x => options.UseOnlyParsersTagged.All(y => x.GetTags().Contains(y))).ToList(); } foreach (var textParser in parsers) { var useOptionsForNextLevel = options != null && !options.FilterOnlyFirstLevel; try { text = textParser.Parse(text, this, context, theme, x => ParseText(x, context, theme, useOptionsForNextLevel ? options : null).Read()); } catch (Exception) { //TODO:Log exception } } return(new RenderResult("text/html", x => x.Write(text), new Dictionary <Guid, RequestContext>(), context)); }
protected override object FindParameterValue(Match match, ICmsRenderer cmsRenderer, ICmsContext context, ITheme theme, Func<string, string> recurse) { var contextNameGroup = match.Groups["contextName"]; if (contextNameGroup == null || string.IsNullOrEmpty(contextNameGroup.Value)) return ""; var path = match.Groups["contextName"].Value; var parts = path.Split('.'); var contextName = parts.FirstOrDefault(); var requestContext = context.FindContext(contextName); if (requestContext == null) return null; var settingsName = parts.Skip(1).FirstOrDefault(); if (!requestContext.Data.ContainsKey(settingsName)) return null; var value = _findParameterValueFromModel.Find(path.Substring(string.Format("{0}.{1}.", contextName, settingsName).Length), requestContext.Data[settingsName]); var stringValue = value as string; return stringValue != null ? recurse(stringValue) : value; }
protected override object FindParameterValue(Match match, ICmsRenderer cmsRenderer, ICmsContext context, ITheme theme, Func<string, string> recurse) { var componentNameGroup = match.Groups["componentName"]; if (componentNameGroup == null) return ""; var componentName = componentNameGroup.Value; var component = context.Filter(_components.Where(x => x.GetType().Name == componentName), theme).FirstOrDefault(); if (component == null) return ""; var settings = component.GetDefaultSettings(); var settingsGroup = match.Groups["settings"]; if (!string.IsNullOrEmpty(settingsGroup?.Value)) { var settingsJson = settingsGroup.Value; if (!string.IsNullOrEmpty(settingsJson)) { var parsedSettings = JsonConvert.DeserializeObject<IDictionary<string, object>>(settingsJson); foreach (var item in parsedSettings) settings[item.Key] = item.Value; } } var renderResult = cmsRenderer.RenderComponent(component, settings, context, theme); return recurse(renderResult.Read()); }
protected MediaItemQuery(ICmsContext cmsContext) : base(cmsContext) { AddProperty(Properties.LibraryID); AddProperty(Properties.MediaType); AddProperty(Properties.Extensions).SetList(); }
public RenderResult(string contentType, Action <TextWriter> render, IDictionary <Guid, RequestContext> requestContexts, ICmsContext cmsContext) { ContentType = contentType; _render = render; _requestContexts = requestContexts; _cmsContext = cmsContext; }
public LibraryTypeQuery(ICmsContext cmsContext) : base(cmsContext) { _cmsContext = cmsContext; Sorting = new SortingInfo("Title", SortOrder.Descending); Paging = new PagerInfo(1, 20); SetQ(Properties.Title).SetIsLocalized(true); }
public WorkflowQuery(ICmsContext cmsContext) : base(cmsContext) { AddProperty(Properties.Statuses).SetList(); AddProperty(Properties.NotStatus); AddProperty(Properties.PublishedOn).SetOperator(QueryOperator.Between); AddProperty(Properties.ExpiresOn).SetOperator(QueryOperator.Between); SetValue(Properties.NotStatus, WorkflowStatus.Deleted.Value.ToString()); }
public static TSettings GetSettings <TSettings, TApplication>(this ICmsContext context) where TSettings : ApplicationSettings where TApplication : IApplication { var application = context.Applications.Single(x => x.GetType() == typeof(TApplication)); return((TSettings)application.GetSettings()); }
public RoleQuery(ICmsContext cmsContext) : base(cmsContext) { _cmsContext = cmsContext; Sorting = new SortingInfo(Properties.RoleName, SortOrder.Descending); Paging = new PagerInfo(1, Settings.General.PageSize); AddProperty(Properties.RoleName).SetIsLocalized(false).SetOperator(QueryOperator.StartsWith).SetList(); }
public ClassificationQuery(ICmsContext cmsContext) : base(cmsContext) { _cmsContext = cmsContext; Sorting = new SortingInfo("Name", SortOrder.Descending); Sorting = new SortingInfo("Alias", SortOrder.Descending); Paging = new PagerInfo(1, 20); AddProperty(Properties.ClassificationType); }
public static string GetLabelGroupFor(this ICmsContext context, Type entityType) { var application = context.Applications.SingleOrDefault(a => a.Types.Any(x => x.Type == entityType)); var res = application == null ? String.Empty : application.Types.Single(x => x.Type == entityType).LabelGroup; return(res); }
public LabelQuery(ICmsContext cmsContext) : base(cmsContext) { _cmsContext = cmsContext; Sorting = new SortingInfo("Ordinal", SortOrder.Ascending); Paging = new PagerInfo(1, 50); AddProperty(Properties.Classification); GetProperty(Properties.Name).SetOperator(QueryOperator.StartsWith); }
public override IRenderResult RenderComponent(ICmsComponent component, IDictionary<string, object> settings, ICmsContext context, ITheme theme) { var result = component.Render(context, settings) as TextRenderInformation; if(result == null) return new RenderResult("", ""); return new RenderResult(result.ContentType, result.Text); }
public DefaultMenuBuilder(IContainer container, IServiceLocator serviceLocator, IValidateSecurity validateSecurity, IEnumerable <IBuildMenuTree> buildMenuTrees, IFindBreadCrumbsFor findBreadCrumbsFor, ICmsContext cmsContext) { _container = container; _serviceLocator = serviceLocator; _validateSecurity = validateSecurity; _buildMenuTrees = buildMenuTrees; _findBreadCrumbsFor = findBreadCrumbsFor; _cmsContext = cmsContext; }
public DefaultMenuBuilder(IContainer container, IServiceLocator serviceLocator, IValidateSecurity validateSecurity, IEnumerable<IBuildMenuTree> buildMenuTrees, IFindBreadCrumbsFor findBreadCrumbsFor, ICmsContext cmsContext) { _container = container; _serviceLocator = serviceLocator; _validateSecurity = validateSecurity; _buildMenuTrees = buildMenuTrees; _findBreadCrumbsFor = findBreadCrumbsFor; _cmsContext = cmsContext; }
public KartaQuery(ICmsContext cmsContext) : base(cmsContext) { _cmsContext = cmsContext; Sorting = new SortingInfo("Title", SortOrder.Descending); SetQ(Properties.Title).SetIsLocalized(true); SetQ(Properties.Summary).SetIsLocalized(true); AddProperty(Properties.Category); Paging = new PagerInfo(1, 20); }
public PageQuery(ICmsContext cmsContext) : base(cmsContext) { Sorting = new SortingInfo("Title", SortOrder.Descending); Paging = new PagerInfo(1, 20); AddProperty(Properties.PageType); AddProperty(Properties.AllowAnonymous); AddProperty(Properties.RequireSSL); AddProperty(Properties.Navigable); GetProperty(Properties.Title).SetOperator(QueryOperator.StartsWith); GetProperty(Properties.MenuName).SetOperator(QueryOperator.StartsWith); }
public DocumentQuery(ICmsContext cmsContext) : base(cmsContext) { _cmsContext = cmsContext; Sorting = new SortingInfo("Ordinal", SortOrder.Ascending); Paging = new PagerInfo(1, Settings.General.PageSize); SetQ(Properties.Title).SetIsLocalized(true); AddProperty(Properties.Extension); AddProperty(Properties.FileName).SetOperator(QueryOperator.StartsWith); AddProperty(Properties.Category); }
public static IList <MetaDataPropertyDefinition> GetMetaDataFor(this ICmsContext context, Type entityType) { var application = context.Applications.SingleOrDefault(a => a.Types.Any(x => x.Type == entityType)) ?? context.Applications.SingleOrDefault(a => a.Types.Any(x => x.Type.IsAssignableFrom(entityType))); return(application == null ? new List <MetaDataPropertyDefinition>() : application.Types.Where(x => x.Type == entityType || x.Type.IsAssignableFrom(entityType)) .SelectMany(x => x.Properties).ToList()); }
public ArticleQuery(ICmsContext cmsContext) : base(cmsContext) { _cmsContext = cmsContext; Sorting = new SortingInfo("CreatedOn", SortOrder.Descending); Paging = new PagerInfo(1, Settings.General.PageSize); //Paging = new PagerInfo(1, Settings.General.PageSize); SetQ(Properties.Title).SetIsLocalized(true); SetQ(Properties.Summary).SetIsLocalized(true); SetQ(Properties.Content).SetIsLocalized(true); AddProperty(Properties.Category); }
public EventQuery(ICmsContext cmsContext) : base(cmsContext) { _cmsContext = cmsContext; Sorting = new SortingInfo("CreatedOn", SortOrder.Descending); Paging = new PagerInfo(1, 20); SetQ(Properties.Title).SetIsLocalized(true); AddProperty(Properties.StartsOn).SetOperator(QueryOperator.Between); AddProperty(Properties.EndsOn).SetOperator(QueryOperator.Between); AddProperty(Properties.Location); }
public string Parse(string text, ICmsRenderer cmsRenderer, ICmsContext context, ITheme theme, Func <string, string> recurse) { var hash = CalculateHash(text); var template = ParsedTemplates.Get(hash, x => Template.Parse(text)); var contexts = context .FindCurrentContexts() .ToDictionary(x => x.Name, x => (object)x.Data); return(template.Render(Hash.FromDictionary(contexts))); }
public string Parse(string text, ICmsRenderer cmsRenderer, ICmsContext context, ITheme theme, Func<string, string> recurse) { var hash = CalculateHash(text); var template = ParsedTemplates.Get(hash, x => Template.Parse(text)); var contexts = context .FindCurrentContexts() .ToDictionary(x => x.Name, x => (object)x.Data); return template.Render(Hash.FromDictionary(contexts)); }
public void Render(ViewRenderInformation information, ICmsContext context, ITheme theme, TextWriter renderTo) { var view = _viewEngines .Select(x => FindViewFrom(x, information.ViewName, information.Model, theme, information.Contexts, information.UseLayout)) .FirstOrDefault(x => x != null); if (view == null) { return; } view.Render(renderTo, information.ContentType); }
public static void SetPermissionsFor <TApplication>(this ICmsContext context, Permissions permissions) where TApplication : IApplication { var application = GetApplication <TApplication>(context) as ISecured; if (application == null) { throw new CmsException(String.Format( "Application {0} doesn't implement ISecured or is not registered.", typeof(TApplication).Name)); } application.Permissions = permissions; }
protected override object FindParameterValue(Match match, ICmsRenderer cmsRenderer, ICmsContext context, ITheme theme, Func<string, string> recurse) { var markdownParser = new Markdown(new MarkdownOptions { AutoNewLines = true }); var mardown = match.Groups[1].Value; if (string.IsNullOrEmpty(mardown)) return mardown; return markdownParser.Transform(mardown); }
public UserQuery(ICmsContext cmsContext) : base(cmsContext) { _cmsContext = cmsContext; Sorting = new SortingInfo(Properties.FirstName, SortOrder.Descending); Paging = new PagerInfo(1, Settings.General.PageSize); AddProperty(Properties.FirstName).SetIsLocalized(false).SetOperator(QueryOperator.StartsWith).SetList(); AddProperty(Properties.LastName).SetIsLocalized(false).SetOperator(QueryOperator.StartsWith).SetList(); AddProperty(Properties.Country).SetIsLocalized(false); AddProperty(Properties.FullName).SetIsLocalized(false); AddProperty(Properties.Locked); AddProperty(Properties.Deactived).SetDefaultValue("false"); AddProperty(Properties.Roles).SetList(); AddProperty(Properties.Email).SetIsLocalized(false); AddProperty(Properties.LabelAlias); }
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)); }
public string Parse(string text, ICmsRenderer cmsRenderer, ICmsContext context, ITheme theme, Func<string, string> recurse) { text = text ?? ""; text = GetRegexes().Aggregate(text, (current, regex) => regex.Replace(current, x => { var value = FindParameterValue(x, cmsRenderer, context, theme, recurse); if (value == null) return ""; var enumerableValue = value as IEnumerable; if (enumerableValue != null && !(value is string)) { var stringValues = enumerableValue.OfType<object>().Select(y => y.ToString()).ToList(); return string.Join(SeperateListItemsWith, stringValues); } return value.ToString(); })); return text; }
public Dependencies(IServiceProvider serviceProvider, ICmsContext cmsContext) { ServiceProvider = serviceProvider; CmsContext = cmsContext; }
public IRenderInformation Render(ICmsContext context, IDictionary<string, object> settings) { var text = string.Join(", ", settings.Select(x => $"{x.Key}={x.Value}")); return new TextRenderInformation(Enumerable.Empty<RequestContext>(), text, "text/plain"); }
protected override object FindParameterValue(Match match, ICmsRenderer cmsRenderer, ICmsContext context, ITheme theme, Func <string, string> recurse) { var localizationNamespace = _findCurrentLocalizationNamespace.Find(); var key = !string.IsNullOrEmpty(localizationNamespace) ? string.Format("{0}:{1}", localizationNamespace, match.Groups["resource"].Value) : match.Groups["resource"].Value; var replacements = new Dictionary <string, string>(); var replacementsGroup = match.Groups["replacements"]; if (replacementsGroup != null && !string.IsNullOrEmpty(replacementsGroup.Value)) { var replacementsData = replacementsGroup .Value .Split(',') .Where(x => !string.IsNullOrEmpty(x)) .Select(x => x.Split(new [] { ':' }, 2)) .Where(x => x.Length > 1 && !string.IsNullOrEmpty(x[0]) && !string.IsNullOrEmpty(x[1])) .ToList(); foreach (var item in replacementsData) { replacements[item[0]] = item[1]; } } var localized = _localizeText.Localize(key, _findCultureForRequest.FindUiCulture()); localized = replacements.Aggregate(localized, (current, replacement) => current.Replace(string.Concat("{{", replacement.Key, "}}"), replacement.Value)); return(recurse(localized)); }
public DefaultBreadCrumbsFinder(IFubuRequest fubuRequest, IServiceLocator serviceLocator, ICmsContext cmsContext) { _fubuRequest = fubuRequest; _serviceLocator = serviceLocator; _cmsContext = cmsContext; }
protected override object FindParameterValue(Match match, ICmsRenderer cmsRenderer, ICmsContext context, ITheme theme, Func <string, string> recurse) { var contextNameGroup = match.Groups["contextName"]; if (contextNameGroup == null || string.IsNullOrEmpty(contextNameGroup.Value)) { return(""); } var path = match.Groups["contextName"].Value; var parts = path.Split('.'); var contextName = parts.FirstOrDefault(); var requestContext = context.FindContext(contextName); if (requestContext == null) { return(null); } var settingsName = parts.Skip(1).FirstOrDefault(); if (!requestContext.Data.ContainsKey(settingsName)) { return(null); } var value = _findParameterValueFromModel.Find(path.Substring(string.Format("{0}.{1}.", contextName, settingsName).Length), requestContext.Data[settingsName]); var stringValue = value as string; return(stringValue != null?recurse(stringValue) : value); }
public override IRenderResult RenderComponent(ICmsComponent component, IDictionary <string, object> settings, ICmsContext context, ITheme theme) { var result = component.Render(context, settings) as TextRenderInformation; if (result == null) { return(new RenderResult("", "")); } return(new RenderResult(result.ContentType, result.Text)); }
public IRenderInformation Render(ICmsContext context, IDictionary <string, object> settings) { var text = string.Join(", ", settings.Select(x => $"{x.Key}={x.Value}")); return(new TextRenderInformation(Enumerable.Empty <RequestContext>(), text, "text/plain")); }
public CmsEndpointWriter(IOutputWriter writer, ICmsRenderer cmsRenderer, ICmsContext cmsContext) { _writer = writer; _cmsRenderer = cmsRenderer; _cmsContext = cmsContext; }
protected abstract object FindParameterValue(Match match, ICmsRenderer cmsRenderer, ICmsContext context, ITheme theme, Func<string, string> recurse);
public SecurityService(ICmsContext cmsContext, IRepository <TEntity> repository) { _cmsContext = cmsContext; _repository = repository; }