private static int EnsureTab(ContentType documentType, Type tab) { if (!tab.IsSubclassOf(typeof(Tab))) throw new InvalidTabTypeException(tab); if (tab == typeof(DefaultTab)) return 0; var tabInstance = (Tab)Activator.CreateInstance(tab); var documentTab = documentType.getVirtualTabs.FirstOrDefault(t => t.GetRawCaption() == tabInstance.Name); if (documentTab == null) { var tabId = documentType.AddVirtualTab(tabInstance.Name); // This doesn't always return a tab, why? Any other way? documentType.ClearVirtualTabs(); documentTab = documentType.getVirtualTabs.FirstOrDefault(t => t.Id == tabId); } if (documentTab != null) { documentType.SetTabName(documentTab.Id, tabInstance.Name); documentType.SetTabSortOrder(documentTab.Id, tabInstance.SortOrder); } return documentTab == null ? 0 : documentTab.Id; }
/// <summary> /// Flushes the cache. /// </summary> /// <param name="id">The id.</param> public static void FlushFromCache(int id) { //Ensure that MediaTypes are reloaded from db by clearing cache InMemoryCacheProvider.Current.Clear(); var ct = new ContentType(id); ApplicationContext.Current.ApplicationCache.ClearCacheItem(string.Format("{0}{1}", CacheKeys.ContentTypeCacheKey, id)); ApplicationContext.Current.ApplicationCache.ClearCacheItem(ct.GetPropertiesCacheKey()); ct.ClearVirtualTabs(); //clear the content type from the property datatype cache used by razor RemoveFromDataTypeCache(ct.Alias); // clear anything that uses this as master content type //TODO: Update to load all content types //Should this include "ct.nodeObjectType == media.MediaType._objectType" ? if (ct.nodeObjectType == DocumentType._objectType) { //NOTE Changed from "DocumentType.GetAllAsList().FindAll(dt => dt.MasterContentType == id)" to loading master contenttypes directly from the db. //Related to http://issues.umbraco.org/issue/U4-1714 var dtos = ApplicationContext.Current.DatabaseContext.Database.Fetch<ContentType2ContentTypeDto>("WHERE parentContentTypeId = @Id", new { Id = id }); foreach (var dto in dtos) { FlushFromCache(dto.ChildId); } } }
/// <summary> /// Flushes the cache. /// </summary> /// <param name="Id">The id.</param> public static void FlushFromCache(int id) { ContentType ct = new ContentType(id); Cache.ClearCacheItem(string.Format("UmbracoContentType{0}", id)); Cache.ClearCacheItem(ct.GetPropertiesCacheKey()); ct.ClearVirtualTabs(); //clear the content type from the property datatype cache used by razor RemoveFromDataTypeCache(ct.Alias); // clear anything that uses this as master content type if (ct.nodeObjectType == DocumentType._objectType) { List<DocumentType> cacheToFlush = DocumentType.GetAllAsList().FindAll(dt => dt.MasterContentType == id); foreach (DocumentType dt in cacheToFlush) FlushFromCache(dt.Id); } }