Пример #1
0
        public static string GetIcon(this IPublishedContentType contentType, IContentTypeService contentTypeService = null)
        {
            if (contentType != null && ContentTypeCacheHelper.TryGetIcon(contentType.Alias, out var icon, contentTypeService) == true)
            {
                return(icon);
            }

            return(UmbConstants.Icons.DefaultIcon);
        }
Пример #2
0
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            DataTypeCacheRefresher.CacheUpdated += (sender, e) =>
            {
                if (e.MessageType != MessageType.RefreshByJson)
                {
                    return;
                }

                // NOTE: The properties for the JSON payload are available here: (Currently there isn't a public API to deserialize the payload)
                // https://github.com/umbraco/Umbraco-CMS/blob/release-7.7.0/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs#L66-L70
                var payload = JsonConvert.DeserializeAnonymousType((string)e.MessageObject, new[] { new { Id = default(int) } });
                if (payload == null)
                {
                    return;
                }

                foreach (var item in payload)
                {
                    applicationContext.ApplicationCache.RuntimeCache.ClearCacheItem(string.Format(InnerContentConstants.PreValuesCacheKey, item.Id));
                }
            };

            ContentTypeCacheRefresher.CacheUpdated += (sender, e) =>
            {
                if (e.MessageType != MessageType.RefreshByJson)
                {
                    return;
                }

                // NOTE: The properties for the JSON payload are available here: (Currently there isn't a public API to deserialize the payload)
                // https://github.com/umbraco/Umbraco-CMS/blob/release-7.7.0/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs#L91-L109
                var payload = JsonConvert.DeserializeAnonymousType((string)e.MessageObject, new[] { new { Id = default(int), AliasChanged = default(bool) } });
                if (payload == null)
                {
                    return;
                }

                // Only update if the content-type alias has changed.
                var ids = payload.Where(x => x.AliasChanged).Select(x => x.Id).ToArray();
                if (ids.Length == 0)
                {
                    return;
                }

                var contentTypes = applicationContext.Services.ContentTypeService.GetAllContentTypes(ids);
                foreach (var contentType in contentTypes)
                {
                    ContentTypeCacheHelper.TryRemove(contentType);
                    ContentTypeCacheHelper.TryAdd(contentType);
                }
            };
        }