public CategoryCached(Category category) { Id = category.Id; Name = category.Name; NameNormalized = category.NameNormalized; Title = category.Title; IsMaterialsContainer = category.IsMaterialsContainer; SubTitle = category.SubTitle; Icon = category.Icon; Header = category.Header; IsMaterialsNameEditable = category.IsMaterialsNameEditable; MaterialsSubTitleInputType = category.MaterialsSubTitleInputType; MaterialsPreviewGeneratorName = category.MaterialsPreviewGeneratorName; SettingsJson = SunJson.MakeJRow(category.SettingsJson); ParentId = category.ParentId; CacheSettingsId = category.CacheSettingsId; CacheSettings = category.CacheSettings; SortNumber = category.SortNumber; LayoutName = category.LayoutName; IsHidden = category.IsHidden; IsCacheContent = category.IsCacheContent; _subCategories = new List <CategoryCached>(); _allSubCategories = new List <CategoryCached>(); }
public CategoryCached(Category category) { Id = category.Id; Name = category.Name; NameNormalized = category.NameNormalized; Token = category.Token ?? category.Name.ToLower(); AppendTokenToSubCatsPath = category.AppendTokenToSubCatsPath; ShowInBreadcrumbs = category.ShowInBreadcrumbs; Title = category.Title; IsMaterialsContainer = category.IsMaterialsContainer; SubTitle = category.SubTitle; Icon = category.Icon; Header = category.Header; IsMaterialsNameEditable = category.IsMaterialsNameEditable; IsMaterialsSubTitleEditable = category.IsMaterialsSubTitleEditable; SettingsJson = SunJson.MakeJElement(category.SettingsJson); ParentId = category.ParentId; SortNumber = category.SortNumber; LayoutName = category.LayoutName; IsHidden = category.IsHidden; IsCacheContent = category.IsCacheContent; _subCategories = new List <CategoryCached>(); _allSubCategories = new List <CategoryCached>(); }
public static async Task Handler(HttpContext context) { context.Response.StatusCode = 500; context.Response.ContentType = "application/json"; var exceptionHandlerPathFeature = context.Features.Get <IExceptionHandlerPathFeature>(); switch (exceptionHandlerPathFeature.Error) { case null: return; case SunViewException sunViewException: await context.Response.WriteAsync(SunJson.Serialize(sunViewException.ErrorView)); break; default: ErrorView errorView = ErrorView.ServerError(exceptionHandlerPathFeature.Error); await context.Response.WriteAsync(SunJson.Serialize(errorView)); break; } }
protected async Task <IActionResult> CacheContentAsync <T>( CategoryCached category, string key, Func <Task <T> > dataLoader, int?page) { if (!cachePolicy.CanCache(category, new RequestOptions() { PageNumber = page })) { return(Json(await dataLoader())); } string json; if (!string.IsNullOrEmpty(json = contentCache.GetContent(key))) { return(JsonString(json)); } var content = await dataLoader(); json = SunJson.Serialize(content); contentCache.CacheContent(key, json); return(JsonString(json)); }
public async Task <IActionResult> CacheContentAsync <T>( ComponentServerCached component, IEnumerable <int> categoryIds, Func <Task <T> > dataLoader, int?page = null) { if (!cachePolicy.CanCache(component, page)) { return(Json(await dataLoader())); } var key = keyGenerator.ContentGenerateKey(component.Name, categoryIds, page); string json; if (!string.IsNullOrEmpty(json = contentCache.GetContent(key))) { return(JsonString(json)); } var content = await dataLoader(); json = SunJson.Serialize(content); contentCache.CacheContent(key, json); return(JsonString(json)); }
public SectionClientCached(Section section, Dictionary <string, Type> clientComponentTypes, IRolesCache rolesCache) { Id = section.Id; Name = section.Name; Type = section.Type; if (section.Roles != null) { Roles = section.Roles.Split(',') .Select(x => rolesCache.GetRole(x)) .ToDictionary(x => x.Id, x => x) .ToImmutableDictionary(); } else { Roles = new Dictionary <int, RoleCached>().ToImmutableDictionary(); } if (clientComponentTypes.TryGetValue(Type, out Type type)) { object clientData = JsonSerializer.Deserialize(section.Options, type); string clientJson = JsonSerializer.Serialize(clientData); Options = SunJson.MakeJElement(clientJson); } }
public ComponentClientCached(Component component, IReadOnlyDictionary <int, RoleCached> roles) { Id = component.Id; Name = component.Name; Type = component.Type; Settings = SunJson.MakeJRow(component.ClientSettingsJson); Roles = roles; }
public MenuItemCached(MenuItem menuItem, IReadOnlyDictionary <int, RoleCached> roles) { Id = menuItem.Id; ParentId = menuItem.ParentId; Name = menuItem.Name; Title = menuItem.Title; SubTitle = menuItem.SubTitle; RouteName = menuItem.RouteName; Exact = menuItem.Exact; CssClass = menuItem.CssClass; ExternalUrl = menuItem.ExternalUrl; IsSeparator = menuItem.IsSeparator; SortNumber = menuItem.SortNumber; Icon = menuItem.Icon; IsHidden = menuItem.IsHidden; RouteParamsJson = SunJson.MakeJRow(menuItem.RouteParamsJson); SettingsJson = SunJson.MakeJRow(menuItem.SettingsJson); Roles = roles; }
public async Task Invoke(HttpContext context) { try { await next(context); } catch (SunViewException e) { logger.LogError(e.ToString()); context.Response.StatusCode = 500; await context.Response.WriteAsync(SunJson.Serialize(e.ErrorView ?? ErrorView.ServerError())); } catch (Exception e) { logger.LogError(e.ToString()); context.Response.StatusCode = 500; ErrorView errorView = ErrorView.ServerError(e); await context.Response.WriteAsync(SunJson.Serialize(errorView)); } }
public bool CacheContent(string key, object content, out string convertedContent) { convertedContent = SunJson.Serialize(content); return(CacheContent(key, convertedContent)); }