Esempio n. 1
0
        /// <summary>
        /// Retrive a list of Content sharing the ContentType
        /// </summary>
        /// <param name="ct">The ContentType</param>
        /// <returns>A list of Content objects sharing the ContentType defined.</returns>
        public static Content[] getContentOfContentType(ContentType ct)
        {
            IRecordsReader dr = SqlHelper.ExecuteReader("Select nodeId from  cmsContent INNER JOIN umbracoNode ON cmsContent.nodeId = umbracoNode.id where ContentType = " + ct.Id + " ORDER BY umbracoNode.text ");
            System.Collections.ArrayList tmp = new System.Collections.ArrayList();

            while (dr.Read()) tmp.Add(dr.GetInt("nodeId"));
            dr.Close();

            Content[] retval = new Content[tmp.Count];
            for (int i = 0; i < tmp.Count; i++) retval[i] = new Content((int)tmp[i]);

            return retval;
        }
        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;
        }
Esempio n. 3
0
        /// <summary>
        /// We will need to first check if the document was loaded by Examine, if so we'll need to check if this property exists
        /// in the results, if it does not, then we'll have to revert to looking up in the db.
        /// </summary>
        /// <param name="dd"> </param>
        /// <param name="alias"></param>
        /// <returns></returns>
        private IPublishedProperty GetProperty(DictionaryPublishedContent dd, string alias)
        {
            if (dd.LoadedFromExamine)
            {
                //if this is from Examine, lets check if the alias does not exist on the document
                if (dd.Properties.All(x => x.PropertyTypeAlias != alias))
                {
                    //ok it doesn't exist, we might assume now that Examine didn't index this property because the index is not set up correctly
                    //so before we go loading this from the database, we can check if the alias exists on the content type at all, this information
                    //is cached so will be quicker to look up.
                    if (dd.Properties.Any(x => x.PropertyTypeAlias == UmbracoContentIndexer.NodeTypeAliasFieldName))
                    {
                        // so in dd.Properties, there is an IPublishedProperty with property type alias "__NodeTypeAlias" and
                        // that special property would contain the node type alias, which we use to get "aliases & names". That
                        // special property is going to be a PropertyResult (with Value == DataValue) and we
                        // want its value in the most simple way = it is OK to use DataValue here.
                        var aliasesAndNames = ContentType.GetAliasesAndNames(dd.Properties.First(x => x.PropertyTypeAlias.InvariantEquals(UmbracoContentIndexer.NodeTypeAliasFieldName)).DataValue.ToString());
                        if (aliasesAndNames != null)
                        {
                            if (!aliasesAndNames.ContainsKey(alias))
                            {
                                //Ok, now we know it doesn't exist on this content type anyways
                                return(null);
                            }
                        }
                    }

                    //if we've made it here, that means it does exist on the content type but not in examine, we'll need to query the db :(
                    var media = global::umbraco.library.GetMedia(dd.Id, true);
                    if (media != null && media.Current != null)
                    {
                        media.MoveNext();
                        var mediaDoc = ConvertFromXPathNavigator(media.Current);
                        return(mediaDoc.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias)));
                    }
                }
            }

            //We've made it here which means that the value is stored in the Examine index.
            //We are going to check for a special field however, that is because in some cases we store a 'Raw'
            //value in the index such as for xml/html.
            var rawValue = dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(UmbracoContentIndexer.RawFieldPrefix + alias));

            return(rawValue
                   ?? dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias)));
        }
        private void AddFieldsetTextboxForAll(Control rootProperties)
        {
            var allProperties = new ContentType(_contentTypeId).PropertyTypes.Where(c => c.ContentTypeId == _contentTypeId); // Skip masters -- NOTE err multiple controls same ID without this

            foreach (var property in allProperties)
            {
                PropertyType property1 = property;
                var propertyRootControl =
                    Utility.FindControl<Control>(
                        (Control c) =>
                        c.ClientID.EndsWith(string.Format("gpw_{0}_control", property1.Id)),
                        rootProperties);

                // If it's an inherited property there won't be a control for it
                if (propertyRootControl != null)
                    AddFieldsetTextbox(propertyRootControl, property1.Id + "_fieldset", false, DataHelper.GetFieldsetForProperty(property.Alias, _contentTypeId));
            }
        }
        public static IEnumerable<GenericPropertyElement> GetPropertiesForContentType(int contentTypeId)
        {
            var section = GetConfigSection();
            var contentTypeElement = section.ContentTypes.Cast<ContentTypeElement>().FirstOrDefault(c => c.Id == contentTypeId);

            IEnumerable<GenericPropertyElement> list = Enumerable.Empty<GenericPropertyElement>();

            var contentType = new ContentType(contentTypeId);

            // Check for master content types and return their configured properties as well
            // TODO: refactor this / clean up
            if (contentType.MasterContentType > 0)
            {
                var masterContentType = contentType;
                do
                {
                    masterContentType = new ContentType(masterContentType.MasterContentType);

                    var masterContentTypeElement =
                        section.ContentTypes.Cast<ContentTypeElement>().FirstOrDefault(c => c.Id == masterContentType.Id);

                    if (masterContentTypeElement != null)
                        list = list.Concat(masterContentTypeElement.GenericProperties.Cast<GenericPropertyElement>().AddSortOrder(masterContentType.Id).OrderByDescending(p => p.SortOrder));

                }
                while (masterContentType.MasterContentType > 0);
            }

            // We added the properties in reverse order (walking up the master tree) - Reverse to get the "correct" order
            list = list.Reverse();

            // Add the properties from the "actual" doctype AFTER the masters have been added
            if (contentTypeElement != null)
                list = list.Concat(contentTypeElement.GenericProperties.Cast<GenericPropertyElement>().AddSortOrder(contentTypeId).OrderBy(p => p.SortOrder));

            return list;
        }
        /// <summary>
        /// We will need to first check if the document was loaded by Examine, if so we'll need to check if this property exists
        /// in the results, if it does not, then we'll have to revert to looking up in the db.
        /// </summary>
        /// <param name="dd"> </param>
        /// <param name="alias"></param>
        /// <returns></returns>
        private IPublishedContentProperty GetProperty(DictionaryPublishedContent dd, string alias)
        {
            if (dd.LoadedFromExamine)
            {
                //if this is from Examine, lets check if the alias does not exist on the document
                if (dd.Properties.All(x => x.Alias != alias))
                {
                    //ok it doesn't exist, we might assume now that Examine didn't index this property because the index is not set up correctly
                    //so before we go loading this from the database, we can check if the alias exists on the content type at all, this information
                    //is cached so will be quicker to look up.
                    if (dd.Properties.Any(x => x.Alias == "__NodeTypeAlias"))
                    {
                        var aliasesAndNames = ContentType.GetAliasesAndNames(dd.Properties.First(x => x.Alias.InvariantEquals("__NodeTypeAlias")).Value.ToString());
                        if (aliasesAndNames != null)
                        {
                            if (!aliasesAndNames.ContainsKey(alias))
                            {
                                //Ok, now we know it doesn't exist on this content type anyways
                                return(null);
                            }
                        }
                    }

                    //if we've made it here, that means it does exist on the content type but not in examine, we'll need to query the db :(
                    var media = global::umbraco.library.GetMedia(dd.Id, true);
                    if (media != null && media.Current != null)
                    {
                        media.MoveNext();
                        var mediaDoc = ConvertFromXPathNavigator(media.Current);
                        return(mediaDoc.Properties.FirstOrDefault(x => x.Alias.InvariantEquals(alias)));
                    }
                }
            }

            return(dd.Properties.FirstOrDefault(x => x.Alias.InvariantEquals(alias)));
        }
 /// <summary>
 /// Returns true if any property has been removed or if any alias has changed
 /// </summary>
 /// <param name="contentType"></param>
 /// <returns></returns>
 public bool HasAnyPropertyAliasChanged(ContentType contentType)
 {                
     var newAliases = contentType.PropertyTypes.Select(x => x.Alias).ToArray();
     //if any have been removed, return true
     if (newAliases.Length < _originalPropertyAliases.Count())
     {
         return true;
     }
     //otherwise ensure that all of the original aliases are still existing
     return newAliases.ContainsAll(_originalPropertyAliases) == false;
 }
        /// <summary>
        /// Adds each property's Sort Order as defined in Umbraco to a list of GenericPropertyElements
        /// Does not take into account the master doctype properties
        /// </summary>
        /// <param name="properties">List of GenericPropertyElements to add the sort order to</param>
        /// <param name="contentTypeId">Content type where the properties exist</param>
        /// <returns>IEnumerable containing GenericPropertyElements with SortOrder populated</returns>
        private static IEnumerable<GenericPropertyElement> AddSortOrder(this IEnumerable<GenericPropertyElement> properties, int contentTypeId)
        {
            var umbracoProperties = new ContentType(contentTypeId).PropertyTypes.Where(p => p.ContentTypeId == contentTypeId).ToList();

            var _properties = properties.ToList();
            foreach (var property in _properties)
            {
                var umbracoProperty = umbracoProperties.FirstOrDefault(p => p.Alias == property.Alias);
                if (umbracoProperty != null)
                {
                    property.SortOrder = umbracoProperty.SortOrder;
                }
            }

            return properties;
        }
Esempio n. 9
0
        /// <summary>
        /// Create and setup all of the controls child controls.
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            
            _prntpage = (UmbracoEnsuredPage)Page;
            int i = 0;
            Hashtable inTab = new Hashtable();

            // zb-00036 #29889 : load it only once
            if (_virtualTabs == null)
                _virtualTabs = _content.ContentType.getVirtualTabs.ToList();

            if(_contentType == null)
                _contentType = ContentType.GetContentType(_content.ContentType.Id);

            foreach (ContentType.TabI tab in _virtualTabs)
            {
                var tabPage = this.Panels[i] as TabPage;
                if (tabPage == null)
                {
                    throw new ArgumentException("Unable to load tab \"" + tab.Caption + "\"");
                }

                tabPage.Style.Add("text-align", "center");

                //Legacy vs New API loading of PropertyTypes
                if (_contentType.ContentTypeItem != null)
                {
                    LoadPropertyTypes(_contentType.ContentTypeItem, tabPage, inTab, tab.Id, tab.Caption);
                }
                else
                {
                    LoadPropertyTypes(tab, tabPage, inTab);
                }

                i++;
            }

            // Add property pane
            tpProp = NewTabPage(ui.Text("general", "properties", null));
            AddSaveAndPublishButtons(ref tpProp);
            tpProp.Controls.Add(
                new LiteralControl("<div id=\"errorPane_" + tpProp.ClientID +
                                   "\" style=\"display: none; text-align: left; color: red;width: 100%; border: 1px solid red; background-color: #FCDEDE\"><div><b>There were errors - data has not been saved!</b><br/></div></div>"));

            //if the property is not in a tab, add it to the general tab
            var props = _content.GenericProperties;
            foreach (Property p in props)
            {
                if (inTab[p.PropertyType.Id.ToString()] == null)
                    AddControlNew(p, tpProp, ui.Text("general", "properties", null));
            }

        }
Esempio n. 10
0
        /// <summary>
        /// Sets up the ContentType property for this content item and sets the addition content properties manually.
        /// If the ContentType property is not already set, then this will get the ContentType from Cache.
        /// </summary>
        /// <param name="InitContentType"></param>
        /// <param name="InitVersion"></param>
        /// <param name="InitVersionDate"></param>
        /// <param name="InitContentTypeIcon"></param>
        protected void InitializeContent(int InitContentType, Guid InitVersion, DateTime InitVersionDate, string InitContentTypeIcon)
        {
            ClearLoadedProperties();

            if (_contentType == null)
                _contentType = ContentType.GetContentType(InitContentType);
            _version = InitVersion;
            _versionDate = InitVersionDate;
            _contentTypeIcon = InitContentTypeIcon;
        }
        // This isn't working after changing to Page.LoadComplete
        //void textbox_TextChanged(object sender, EventArgs e)
        //{
        //    var thisTextBox = (TextBox) sender;
        //    var related = thisTextBox.Attributes["relatedTextBox"];
        //    var alias = HttpContext.Current.Request.Form[related];
        //    // Don't update if save was pushed but the form wasn't filled out completely (no alias)
        //    if (!string.IsNullOrEmpty(alias))
        //        DataHelper.AddOrUpdateProperty(alias, ((TextBox)sender).Text, _contentTypeId);
        //}
        void SaveAll(Control rootProperties)
        {
            var allProperties = new ContentType(_contentTypeId).PropertyTypes.Where(p=>p.ContentTypeId == _contentTypeId); // Skip master properties

            var allKeys = HttpContext.Current.Request.Form.AllKeys;
            // Check for "New Property" - if Name, Alias, & Fieldset not empty, save
            var newPropertyName = HttpContext.Current.Request.Form[allKeys.Where(x => x.EndsWith("GenericPropertyNew_control$tbName")).FirstOrDefault()];
            var newPropertyAlias = HttpContext.Current.Request.Form[allKeys.Where(x => x.EndsWith("GenericPropertyNew_control$tbAlias")).FirstOrDefault()];
            var newPropertyFieldset = HttpContext.Current.Request.Form[allKeys.Where(x => x.EndsWith("GenericPropertyNew_control$new_fieldset")).FirstOrDefault()];
            if (!string.IsNullOrEmpty(newPropertyName) && !string.IsNullOrEmpty(newPropertyAlias) && !string.IsNullOrEmpty(newPropertyFieldset))
            {
                DataHelper.AddOrUpdateProperty(newPropertyAlias, newPropertyFieldset, _contentTypeId);
            }

            foreach (var property in allProperties.Where(p => p.Alias != newPropertyAlias)) // Skip the newly added property else we'll overwrite it
            {

                PropertyType property1 = property;
                var rootControl =
                    Utility.FindControl<Control>(
                        (Control c) =>
                        c.ClientID.EndsWith(string.Format("gpw_{0}_control", property1.Id)),
                        rootProperties);

                var aliasTextbox = Utility.FindControl<TextBox>((TextBox c) => c.ClientID.EndsWith("tbAlias"), rootControl);
                var alias = aliasTextbox.Text;

                if (string.IsNullOrEmpty(alias))
                    return;

                var requestKey =
                    HttpContext.Current.Request.Form.AllKeys.Where(k => k.EndsWith("_" + property.Id + "_fieldset")).FirstOrDefault();
                var newValue = HttpContext.Current.Request.Form[requestKey];
                var currentValue = DataHelper.GetFieldsetForProperty(aliasTextbox.Text, _contentTypeId);
                if (currentValue != newValue)
                    DataHelper.AddOrUpdateProperty(aliasTextbox.Text, newValue, _contentTypeId);
            }
        }
Esempio n. 12
0
        /// <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);

            }
        }
Esempio n. 13
0
        /// <summary>
        /// Retrieve a list of all ContentTypes
        /// </summary>
        /// <returns>The list of all ContentTypes</returns>
        public ContentType[] GetAll()
        {
            var contentTypes = new List<ContentType>();

            using (IRecordsReader dr =
                SqlHelper.ExecuteReader(m_SQLOptimizedGetAll.Trim(), SqlHelper.CreateParameter("@nodeObjectType", base.nodeObjectType)))
            {
                while (dr.Read())
                {
                    //create the ContentType object without setting up
                    ContentType ct = new ContentType(dr.Get<int>("id"), true);
                    //populate it's CMSNode properties
                    ct.PopulateCMSNodeFromReader(dr);
                    //populate it's ContentType properties
                    ct.PopulateContentTypeNodeFromReader(dr);

                    contentTypes.Add(ct);
                }
            }

            return contentTypes.ToArray();

        }
Esempio n. 14
0
 /// <summary>
 /// If true, this instance uses default umbraco data only.
 /// </summary>
 /// <param name="ct">The ct.</param>
 /// <returns></returns>
 private static bool usesUmbracoDataOnly(ContentType ct)
 {
     bool retVal = true;
     foreach (PropertyType pt in ct.PropertyTypes)
     {
         if (!DataTypeDefinition.IsDefaultData(pt.DataTypeDefinition.DataType.Data))
         {
             retVal = false;
             break;
         }
     }
     return retVal;
 }
Esempio n. 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Tab"/> class.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="caption">The caption.</param>
 /// <param name="sortOrder">The sort order.</param>
 /// <param name="cType">Type of the c.</param>
 public Tab(int id, string caption, int sortOrder, ContentType cType)
 {
     _id = id;
     _caption = caption;
     _sortOrder = sortOrder;
     _contenttype = cType;
 }
        private void SetAllowedChildren(ContentType documentType, Type[] allowedChildDocumentTypes)
        {
            if (documentType == null || allowedChildDocumentTypes == null || !allowedChildDocumentTypes.Any())
                return;

            documentType.AllowedChildContentTypeIDs = allowedChildDocumentTypes
                .Where(allowedChildDocumentType => _typeDocumentTypeIdMappings.ContainsKey(allowedChildDocumentType))
                .Select(allowedChildDocumentType => _typeDocumentTypeIdMappings[allowedChildDocumentType]).ToArray();
        }
        private static void SetDocumentTypeDescriptionIfDifferent(ContentType documentType, string description)
        {
            if (documentType.Description == description)
                return;

            documentType.Description = description ?? String.Empty;
        }
        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;
        }
        private static void SetDocumentTypeIconIfDifferent(ContentType documentType, string iconUrl)
        {
            if (documentType.IconUrl == iconUrl)
                return;

            documentType.IconUrl = iconUrl ?? String.Empty;
        }
 private static void SetDocumentTypeMasterIfDifferent(ContentType documentType, int masterDocumentTypeId)
 {
     if (documentType.MasterContentType == masterDocumentTypeId)
         return;
         documentType.MasterContentType = masterDocumentTypeId;
 }
        private static void SetDocumentTypeThumbnailIfDifferent(ContentType documentType, string thumbnailUrl)
        {
            if (documentType.Thumbnail == thumbnailUrl)
                return;

            documentType.Thumbnail = thumbnailUrl ?? String.Empty;
        }
Esempio n. 22
0
 /// <summary>
 /// Creates a new Content object from the ContentType.
 /// </summary>
 /// <param name="ct"></param>
 protected void CreateContent(ContentType ct)
 {
     SqlHelper.ExecuteNonQuery("insert into cmsContent (nodeId,ContentType) values (" + this.Id + "," + ct.Id + ")");
     createNewVersion(DateTime.Now);
 }
        private static void SetPropertyTypeTabIfDifferent(ContentType documentType, PropertyType propertyType, Type tab)
        {
            var propertyTabId = EnsureTab(documentType, tab);

            if (propertyType.TabId == propertyTabId)
                return;

            propertyType.TabId = propertyTabId;
        }
Esempio n. 24
0
        /// <summary>
        /// Create and setup all of the controls child controls.
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();


            _prntpage = (UmbracoEnsuredPage)Page;
            int       i     = 0;
            Hashtable inTab = new Hashtable();

            // zb-00036 #29889 : load it only once
            if (_virtualTabs == null)
            {
                _virtualTabs = _content.ContentType.getVirtualTabs.ToList();
            }

            if (_contentType == null)
            {
                _contentType = ContentType.GetContentType(_content.ContentType.Id);
            }

            foreach (ContentType.TabI tab in _virtualTabs)
            {
                var tabPage = this.Panels[i] as TabPage;
                if (tabPage == null)
                {
                    throw new ArgumentException("Unable to load tab \"" + tab.Caption + "\"");
                }

                tabPage.Style.Add("text-align", "center");

                //Legacy vs New API loading of PropertyTypes
                if (_contentType.ContentTypeItem != null)
                {
                    LoadPropertyTypes(_contentType.ContentTypeItem, tabPage, inTab, tab.Id, tab.Caption);
                }
                else
                {
                    LoadPropertyTypes(tab, tabPage, inTab);
                }

                i++;
            }

            // Add property pane
            tpProp = NewTabPage(ui.Text("general", "properties", null));
            AddSaveAndPublishButtons(ref tpProp);
            tpProp.Controls.Add(
                new LiteralControl("<div id=\"errorPane_" + tpProp.ClientID +
                                   "\" style=\"display: none; text-align: left; color: red;width: 100%; border: 1px solid red; background-color: #FCDEDE\"><div><b>There were errors - data has not been saved!</b><br/></div></div>"));

            //if the property is not in a tab, add it to the general tab
            var props = _content.GenericProperties;

            foreach (Property p in props)
            {
                if (inTab[p.PropertyType.Id.ToString()] == null)
                {
                    AddControlNew(p, tpProp, ui.Text("general", "properties", null));
                }
            }
        }
        private static void SynchronizePropertiesForType(ContentType documentType, Type type)
        {
            if (documentType == null || type == null)
                return;

            var synchronizableProperties = GetPropertiesWithAttributes(type);
            foreach (var property in synchronizableProperties)
            {
                SynchronizeProperty(documentType, property);
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Loades PropertyTypes by Tab using the Legacy API.
        /// </summary>
        /// <param name="tab"></param>
        /// <param name="tabPage"></param>
        /// <param name="inTab"></param>
        private void LoadPropertyTypes(ContentType.TabI tab, TabPage tabPage, Hashtable inTab)
        {
            // Iterate through the property types and add them to the tab
            // zb-00036 #29889 : fix property types getter to get the right set of properties
            // ge : had a bit of a corrupt db and got weird NRE errors so rewrote this to catch the error and rethrow with detail
            var propertyTypes = tab.GetPropertyTypes(_content.ContentType.Id);
            foreach (var propertyType in propertyTypes.OrderBy(x => x.SortOrder))
            {
                var property = _content.getProperty(propertyType);
                if (property != null && tabPage != null)
                {
                    AddControlNew(property, tabPage, tab.Caption);

                    // adding this check, as we occasionally get an already in dictionary error, though not sure why
                    if (!inTab.ContainsKey(propertyType.Id.ToString(CultureInfo.InvariantCulture)))
                        inTab.Add(propertyType.Id.ToString(CultureInfo.InvariantCulture), true);
                }
                else
                {
                    throw new ArgumentNullException(
                        string.Format(
                            "Property {0} ({1}) on Content Type {2} could not be retrieved for Document {3} on Tab Page {4}. To fix this problem, delete the property and recreate it.",
                            propertyType.Alias, propertyType.Id, _content.ContentType.Alias, _content.Id, tab.Caption));
                }
            }
        }
        private static void SynchronizeProperty(ContentType documentType, KeyValuePair<PropertyInfo, DocumentTypePropertyAttribute> property)
        {
            if (documentType == null)
                return;

            var propertyAlias = Utility.FormatPropertyAlias(property.Key.Name);
            var propertyType = documentType.getPropertyType(propertyAlias);
            var propertyAttribute = property.Value;

            if (propertyType == null)
                propertyType = CreateAndAddPropertyTypeToDocumentType(propertyAlias, documentType, propertyAttribute);
            else
                UpdateExistingProperty(propertyType, propertyAttribute, documentType);

            propertyType.Save();
        }
 private bool DoesPropertyTypeAliasExist(GenericProperty gpData)
 {
     bool hasAlias = _contentType.getPropertyType(Casing.SafeAliasWithForcingCheck(gpData.Alias.Trim())) != null;
     ContentType ct = _contentType;
     while (ct.MasterContentType > 0)
     {
         ct = new ContentType(ct.MasterContentType);
         hasAlias = ct.getPropertyType(Casing.SafeAliasWithForcingCheck(gpData.Alias.Trim())) != null;
     }
     return !hasAlias;
 }
 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 void LoadContentType(int docTypeId)
 {
     //Fairly hacky code to load the ContentType as the real type instead of its base type, so it can be properly saved.
     if (Request.Path.ToLowerInvariant().Contains("editnodetypenew.aspx"))
     {
         _contentType = new DocumentType(docTypeId);
     }
     else if (Request.Path.ToLowerInvariant().Contains("editmediatype.aspx"))
     {
         _contentType = new cms.businesslogic.media.MediaType(docTypeId);
     }
     else if (Request.Path.ToLowerInvariant().Contains("editmembertype.aspx"))
     {
         _contentType = new cms.businesslogic.member.MemberType(docTypeId);
     }
     else
     {
         _contentType = new ContentType(docTypeId);
     }
 }
        /// <summary>
        /// Adds each property's Sort Order as defined in Umbraco to a list of GenericPropertyElements
        /// Does not take into account the master doctype properties
        /// </summary>
        /// <param name="properties">List of GenericPropertyElements to add the sort order to</param>
        /// <param name="contentTypeId">Content type where the properties exist</param>
        /// <returns>IEnumerable containing GenericPropertyElements with SortOrder populated</returns>
        private static IEnumerable<GenericPropertyElement> AddSortOrder(this IEnumerable<GenericPropertyElement> properties, int contentTypeId)
        {
            var umbracoProperties = new ContentType(contentTypeId).PropertyTypes.Where(p => p.ContentTypeId == contentTypeId).ToList();

            // By default properties have a 0 sortorder until manually sorted - check for this situation
            var arePropertiesSorted = umbracoProperties.Any(p => p.SortOrder > 0);

            var _properties = properties.ToList();
            foreach (var property in _properties)
            {
                var umbracoProperty = umbracoProperties.FirstOrDefault(p => p.Alias == property.Alias);
                if (umbracoProperty != null)
                {
                    property.SortOrder = arePropertiesSorted ? umbracoProperty.SortOrder : umbracoProperties.IndexOf(umbracoProperty);
                }
            }

            return properties;
        }