private static void UpdateExistingProperty(PropertyType propertyType, DocumentTypePropertyAttribute propertyAttribute, ContentType documentType) { SetPropertyTypeNameIfDifferent(propertyType, propertyAttribute.Name); SetPropertyTypeDescriptionIfDifferent(propertyType, propertyAttribute.Description); SetPropertyTypeMandatoryIfDifferent(propertyType, propertyAttribute.Mandatory); SetPropertyTypeValidationExpressionIfDifferent(propertyType, propertyAttribute.ValidationExpression); SetPropertyTypeSortOrderIfDifferent(propertyType, propertyAttribute.SortOrder); SetPropertyTypeTabIfDifferent(documentType, propertyType, propertyAttribute.Tab); }
private static bool CompareContentTypeProperties(Type uSiteBuilderDocType, IContentType contentType) { // Retrieve tab names and corresponding properties Dictionary <string, string> tabsWithProperties = new Dictionary <string, string>(); string tmpTabName; foreach (var tabItem in contentType.PropertyGroups) { tmpTabName = tabItem.Name; foreach (var propertyItem in tabItem.PropertyTypes) { tabsWithProperties.Add(propertyItem.Alias, tmpTabName); } } foreach (PropertyInfo propInfo in uSiteBuilderDocType.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { DocumentTypePropertyAttribute propAttr = Util.GetAttribute <DocumentTypePropertyAttribute>(propInfo); if (propAttr == null) { continue; // skip this property - not part of a document type } if (propAttr.DefaultValue != null) { _hasDefaultValues = true; } // getting name and alias string propertyName; string propertyAlias; DocumentTypeManager.ReadPropertyNameAndAlias(propInfo, propAttr, out propertyName, out propertyAlias); if (Util.GetAttribute <ObsoleteAttribute>(propInfo) != null) { // If it's marked as obsolete, but still exists, there's a change if (contentType.PropertyTypes.Any(p => p.Alias == propertyAlias)) { return(false); } // marked as obsolete and already deleted, skip rest of checks continue; } var dataTypeDefinition = ManagerBase.GetDataTypeDefinition(uSiteBuilderDocType, propAttr, propInfo); Umbraco.Core.Models.PropertyType property = contentType.PropertyTypes.FirstOrDefault(p => p.Alias == propertyAlias); if (property == null) { // new property return(false); } if (property.DataTypeDefinitionId != dataTypeDefinition.Id) { return(false); } string tabName = string.Empty; tabsWithProperties.TryGetValue(property.Alias, out tabName); if (tabName == null) { // For generics properties tab tabName = string.Empty; } if (propAttr.TabAsString != tabName) { return(false); } if (property.Name != propertyName) { return(false); } if (property.Mandatory != propAttr.Mandatory) { return(false); } if (property.ValidationRegExp != propAttr.ValidationRegExp) { return(false); } if (property.Description != propAttr.Description) { return(false); } } return(true); }
private static PropertyType CreateAndAddPropertyTypeToDocumentType(string propertyAlias, ContentType documentType, DocumentTypePropertyAttribute propertyAttribute) { var dataTypeDefinition = DataTypeDefinition.GetDataTypeDefinition(propertyAttribute.DataTypeId); if (dataTypeDefinition == null) { throw new DataTypeDefinitionUnknownException(propertyAttribute.DataTypeId); } var propertyType = documentType.AddPropertyType(dataTypeDefinition, propertyAlias, propertyAttribute.Name); SetPropertyTypeMandatoryIfDifferent(propertyType, propertyAttribute.Mandatory); SetPropertyTypeValidationExpressionIfDifferent(propertyType, propertyAttribute.ValidationExpression); SetPropertyTypeSortOrderIfDifferent(propertyType, propertyAttribute.SortOrder); SetPropertyTypeDescriptionIfDifferent(propertyType, propertyAttribute.Description); SetPropertyTypeTabIfDifferent(documentType, propertyType, propertyAttribute.Tab); return(propertyType); }