private static List <ContentComparison> PreviewDocTypes(Type parentDocType, string parentAlias) { var comparison = new List <ContentComparison>(); foreach (Type typeDocType in Util.GetFirstLevelSubTypes(parentDocType)) { string alias = DocumentTypeManager.GetDocumentTypeAlias(typeDocType); IContentType contentType = ContentTypeService.GetContentType(alias); if (contentType == null) { comparison.Add(new ContentComparison { Alias = alias, DocumentTypeStatus = Status.New, ParentAlias = parentAlias }); } else { #if DEBUG Stopwatch timer = new Stopwatch(); timer.Start(); #endif bool unchanged = IsUnchanged(typeDocType, parentDocType, contentType); #if DEBUG timer.Stop(); //StopwatchLogger.AddToLog(string.Format("Total elapsed time for method 'DocumentTypeComparer.PreviewDocTypes' - IsUnchanged: {0}ms.", timer.ElapsedMilliseconds)); timer.Restart(); #endif if (unchanged) { comparison.Add(new ContentComparison { Alias = alias, DocumentTypeStatus = Status.Same, ParentAlias = parentAlias, DocumentTypeId = contentType.Id }); } else { comparison.Add(new ContentComparison { Alias = alias, DocumentTypeStatus = Status.Changed, ParentAlias = parentAlias, DocumentTypeId = contentType.Id }); } } comparison.AddRange(PreviewDocTypes(typeDocType, alias)); } return(comparison); }
private static bool IsUnchanged(Type typeDocType, Type parentDocType, IContentType contentType) { DocumentTypeAttribute docTypeAttr = DocumentTypeManager.GetDocumentTypeAttribute(typeDocType); if (docTypeAttr.Mixins != null) { // update this document type since it depends on others return(false); } string docTypeName = String.IsNullOrEmpty(docTypeAttr.Name) ? typeDocType.Name : docTypeAttr.Name; string docTypeAlias = DocumentTypeManager.GetDocumentTypeAlias(typeDocType); if (contentType.Name != docTypeName) { return(false); } if (contentType.Alias != docTypeAlias) { return(false); } if (contentType.Icon != docTypeAttr.IconUrl) { return(false); } if (contentType.Thumbnail != docTypeAttr.Thumbnail) { return(false); } if (contentType.Description != docTypeAttr.Description) { return(false); } if (contentType.ParentId != -1) { if (parentDocType == typeof(DocumentTypeBase)) { return(false); } var existingParentDocumentType = ContentTypeService.GetContentType(contentType.ParentId); if (existingParentDocumentType.Alias != DocumentTypeManager.GetDocumentTypeAlias(parentDocType)) { return(false); } } else { if (parentDocType != typeof(DocumentTypeBase)) { return(false); } } #if DEBUG Stopwatch timer = new Stopwatch(); timer.Start(); #endif if (!CompareContentTypeProperties(typeDocType, contentType)) { return(false); } #if DEBUG timer.Stop(); //StopwatchLogger.AddToLog(string.Format("Total elapsed time for method 'DocumentTypeComparer.IsUnchanged' - CompareContentTypeProperties: {0}ms.", timer.ElapsedMilliseconds)); timer.Restart(); #endif if (!CompareAllowedTemplates(contentType, docTypeAttr, typeDocType)) { return(false); } if (contentType.AllowedAsRoot != docTypeAttr.AllowAtRoot) { return(false); } return(true); }