Пример #1
0
        /// <summary>
        /// Creates a new property on the ContentType under the correct tab
        /// </summary>
        /// <param name="newContentType"></param>
        /// <param name="tabName"></param>
        /// <param name="dataTypeService"></param>
        /// <param name="atTabGeneric"></param>
        /// <param name="item"></param>
        private static void CreateProperty(IContentType newContentType, string tabName, IDataTypeService dataTypeService, bool atTabGeneric, PropertyInfo item)
        {
            UmbracoPropertyAttribute attribute = item.GetCustomAttribute <UmbracoPropertyAttribute>();

            IDataTypeDefinition dataTypeDef;

            if (string.IsNullOrEmpty(attribute.DataTypeInstanceName))
            {
                dataTypeDef = dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(attribute.DataType).FirstOrDefault();
            }
            else
            {
                dataTypeDef = dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(attribute.DataType).FirstOrDefault(x => x.Name == attribute.DataTypeInstanceName);
            }

            if (dataTypeDef != null)
            {
                PropertyType propertyType = new PropertyType(dataTypeDef);
                propertyType.Name        = attribute.Name;
                propertyType.Alias       = (atTabGeneric ? attribute.Alias : UmbracoCodeFirstExtensions.HyphenToUnderscore(UmbracoCodeFirstExtensions.ParseUrl(attribute.Alias + "_" + tabName, false)));
                propertyType.Description = attribute.Description;
                propertyType.Mandatory   = attribute.Mandatory;

                if (atTabGeneric)
                {
                    newContentType.AddPropertyType(propertyType);
                }
                else
                {
                    newContentType.AddPropertyType(propertyType, tabName);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Gets the config data stored in the property editor prevalues
        /// </summary>
        /// <returns></returns>
        public object GetPrevalues()
        {
            IDataTypeDefinition dataType = _dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(Alias).First();

            if (dataType == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            IEnumerable <string> prevalues = _dataTypeService.GetPreValuesByDataTypeId(dataType.Id);

            return(new { prevalues });
        }
Пример #3
0
        private IDataTypeDefinition GetDataTypeDefinition(XElement property)
        {
            var dataTypeDefinitionId = new Guid(property.Element("Definition").Value);
            var dataTypeDefinition   = dataTypeService.GetDataTypeDefinitionById(dataTypeDefinitionId);

            var legacyPropertyEditorId = Guid.Empty;

            Guid.TryParse(property.Element("Type").Value, out legacyPropertyEditorId);
            var propertyEditorAlias = property.Element("Type").Value.Trim();

            if (dataTypeDefinition == null)
            {
                var dataTypeDefinitions = dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(propertyEditorAlias);
                if (dataTypeDefinitions != null && dataTypeDefinitions.Any())
                {
                    dataTypeDefinition = dataTypeDefinitions.FirstOrDefault();
                }
            }
            else
            {
#pragma warning disable CS0618 // Type or member is obsolete
                if (legacyPropertyEditorId != Guid.Empty && dataTypeDefinition.ControlId != legacyPropertyEditorId)
#pragma warning restore CS0618 // Type or member is obsolete
                {
#pragma warning disable CS0618 // Type or member is obsolete
                    var dataTypeDefinitions2 = dataTypeService.GetDataTypeDefinitionByControlId(legacyPropertyEditorId);
#pragma warning restore CS0618 // Type or member is obsolete
                    if (dataTypeDefinitions2 != null && dataTypeDefinitions2.Any())
                    {
                        dataTypeDefinition = dataTypeDefinitions2.FirstOrDefault();
                    }
                }
                else
                {
                    if (dataTypeDefinition.PropertyEditorAlias != propertyEditorAlias)
                    {
                        var dataTypeDefinitions3 = dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(propertyEditorAlias);
                        if (dataTypeDefinitions3 != null && dataTypeDefinitions3.Any())
                        {
                            dataTypeDefinition = dataTypeDefinitions3.FirstOrDefault();
                        }
                    }
                }
            }

            if (dataTypeDefinition == null)
            {
                dataTypeDefinition = dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias("Umbraco.NoEdit").FirstOrDefault();
            }
            return(dataTypeDefinition);
        }
Пример #4
0
        private static string VerifyExistingProperty(IContentType contentType, string tabName, IDataTypeService dataTypeService, PropertyInfo item, bool atGenericTab = false)
        {
            UmbracoPropertyAttribute attribute = item.GetCustomAttribute <UmbracoPropertyAttribute>();
            IDataTypeDefinition      dataTypeDef;

            if (string.IsNullOrEmpty(attribute.DataTypeInstanceName))
            {
                dataTypeDef = dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(attribute.DataType).FirstOrDefault();
            }
            else
            {
                dataTypeDef = dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(attribute.DataType).FirstOrDefault(x => x.Name == attribute.DataTypeInstanceName);
            }

            if (dataTypeDef != null)
            {
                PropertyType property;
                bool         alreadyExisted = contentType.PropertyTypeExists(attribute.Alias);
                // TODO: Added attribute.Tab != null after Generic Properties add, is this bulletproof?
                if (alreadyExisted && attribute.Tab != null)
                {
                    property = contentType.PropertyTypes.FirstOrDefault(x => x.Alias == attribute.Alias);
                }
                else
                {
                    property = new PropertyType(dataTypeDef);
                }

                property.Name = attribute.Name;
                //TODO: correct name?
                property.Alias       = (atGenericTab ? attribute.Alias : UmbracoCodeFirstExtensions.HyphenToUnderscore(UmbracoCodeFirstExtensions.ParseUrl(attribute.Alias + "_" + tabName, false)));
                property.Description = attribute.Description;
                property.Mandatory   = attribute.Mandatory;

                if (!alreadyExisted)
                {
                    if (atGenericTab)
                    {
                        contentType.AddPropertyType(property);
                    }
                    else
                    {
                        contentType.AddPropertyType(property, tabName);
                    }
                }

                return(property.Alias);
            }
            return(null);
        }
        private string GetMailChimpApiKeyValue()
        {
            var dataType  = _dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias("SiteOcean.MailChimp.ListPicker").First();
            var prevalues = _dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id);

            return(prevalues.PreValuesAsDictionary["apiKey"].Value);
        }
Пример #6
0
        private IEnumerable <int> NestedContentAliasWithContentType(string alias)
        {
            var nestedContents = _dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(NestedContentAlias);

            foreach (var dataType in nestedContents)
            {
                var preValues    = _dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id).FormatAsDictionary();
                var contentTypes = JsonConvert.DeserializeObject <NestedContentPreValue[]>(preValues["contentTypes"].Value, _serializerSettings);
                if (contentTypes.Any(n => n.NcAlias.Equals(alias, StringComparison.CurrentCultureIgnoreCase)))
                {
                    yield return(dataType.Id);
                }
            }
        }
        public IEnumerable <Crop> GetAllCrops()
        {
            var allCrops = new List <Crop>();
            var imageCropperDataTypes = _dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(ApplicationConstants.ImageCropperPropertyEditorAlias);

            foreach (var dataType in imageCropperDataTypes)
            {
                var crops = _dataTypeService.GetPreValuesByDataTypeId(dataType.Id).ToList();
                if (!crops.HasAny())
                {
                    continue;
                }

                var cropsFromDb = JsonConvert.DeserializeObject <IEnumerable <Crop> >(crops.First());
                allCrops.AddRange(cropsFromDb);
            }

            return(allCrops);
        }
        /// <summary>
        ///  Adds a property to the contenttype item.
        /// </summary>
        public void AddProperty(IContentTypeBase item, string alias, string name, string tab, string editorAlias,
                                string description)
        {
            // return if the property already exists.
            if (item.PropertyTypes.Any(x => x.Alias == alias))
            {
                return;
            }

            var dataTypeDef = _dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(editorAlias)
                              .FirstOrDefault();

            if (dataTypeDef != null)
            {
                // add a property
                var propertyType = new PropertyType(dataTypeDef, alias);

                propertyType.Name        = name;
                propertyType.Description = description;
                item.AddPropertyType(propertyType, tab);
            }
        }
Пример #9
0
        public static void ImportRemoveMissingProps(this IContentType item, XElement node)
        {
            // don't do this if the setting is set to false
            if (!uSyncSettings.docTypeSettings.DeletePropertyValues)
            {
                return;
            }

            List <string> propertiesToRemove             = new List <string>();
            Dictionary <string, string> propertiesToMove = new Dictionary <string, string>();

            // go through the properties in the item
            foreach (var property in item.PropertyTypes)
            {
                // is this property in the xml ?
                XElement propertyNode = node.Element("GenericProperties")
                                        .Elements("GenericProperty")
                                        .Where(x => x.Element("Alias").Value == property.Alias)
                                        .SingleOrDefault();

                if (propertyNode == null)
                {
                    LogHelper.Info <uSync>("Removing {0} from {1}", () => property.Alias, () => item.Name);
                    propertiesToRemove.Add(property.Alias);
                }
                else
                {
                    // at this point we write our properties over those
                    // in the db - because the import doesn't do this
                    // for existing items.
                    LogHelper.Debug <uSync>("Updating prop {0} for {1}", () => property.Alias, () => item.Alias);



                    var legacyEditorId = Guid.Empty;
                    var editorAlias    = string.Empty;
                    Guid.TryParse(propertyNode.Element("Type").Value, out legacyEditorId);
                    if (legacyEditorId == Guid.Empty)
                    {
                        // new style id...?
                    }

                    var dataTypeDefinitionId          = new Guid(propertyNode.Element("Definition").Value);
                    IDataTypeService _dataTypeService = ApplicationContext.Current.Services.DataTypeService;

                    IDataTypeDefinition dataTypeDefinition = null;
                    try
                    {
                        dataTypeDefinition = _dataTypeService.GetDataTypeDefinitionById(dataTypeDefinitionId);
                        if (dataTypeDefinition == null)
                        {
                            editorAlias = propertyNode.Element("Type").Value;
                            // try to match on guid as alias is not unique
                            dataTypeDefinition =
                                _dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(editorAlias).Any(x => x.Key == dataTypeDefinitionId)
                                    ? _dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(editorAlias).First(x => x.Key == dataTypeDefinitionId)
                                    : _dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(editorAlias).FirstOrDefault();
                        }

                        if (dataTypeDefinition != null &&
                            dataTypeDefinition.Key == dataTypeDefinitionId)
                        {
                            // all good, we are here..
                        }
                        else
                        {
                            // we need to do even more looking...
                            var dataTypeDefinitions = _dataTypeService.GetDataTypeDefinitionByControlId(legacyEditorId);

                            if (dataTypeDefinition != null && dataTypeDefinitions.Any())
                            {
                                dataTypeDefinition = dataTypeDefinitions.First();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        // getDataTypeDefinition can throw exceptions - when you have issues with legacy ids'
                        // so we capture them, so we can carry on.
                        LogHelper.Info <SyncDocType>("Error looking for the datatype {0}, you might be missing a package?", () => dataTypeDefinitionId);
                    }

                    if (dataTypeDefinition != null)
                    {
                        // now we set it in the DB
                        // property.DataTypeDefinitionId = dataTypeDefinition.Id;
                        // we can set both the id and alias, but we can't directly change the
                        // underling database type, not sure if you can to be honest.
                        if (property.DataTypeDefinitionId != dataTypeDefinition.Id)
                        {
                            LogHelper.Info <SyncDocType>("Updating the datatype Definition");
                            property.DataTypeDefinitionId = dataTypeDefinition.Id;
                            property.PropertyEditorAlias  = dataTypeDefinition.PropertyEditorAlias;
                        }


                        // TODO: make changes to the datatype import/export properly.
                    }

                    property.Name             = propertyNode.Element("Name").Value;
                    property.Description      = propertyNode.Element("Description").Value;
                    property.Mandatory        = propertyNode.Element("Mandatory").Value.ToLowerInvariant().Equals("true");
                    property.ValidationRegExp = propertyNode.Element("Validation").Value;

                    XElement sortOrder = propertyNode.Element("SortOrder");
                    if (sortOrder != null)
                    {
                        property.SortOrder = int.Parse(sortOrder.Value);
                    }

                    var tab = propertyNode.Element("Tab").Value;
                    if (!string.IsNullOrEmpty(tab))
                    {
                        var propGroup = item.PropertyGroups.First(x => x.Name == tab);

                        if (!propGroup.PropertyTypes.Any(x => x.Alias == property.Alias))
                        {
                            // if it's not in this prop group - we can move it it into it
                            LogHelper.Info <uSync>("Moving {0} in {1} to {2}",
                                                   () => property.Alias, () => item.Name, () => tab);
                            propertiesToMove.Add(property.Alias, tab);
                        }
                    }
                }
            }

            foreach (string alias in propertiesToRemove)
            {
                LogHelper.Debug <uSync>("Removing {0}", () => alias);
                item.RemovePropertyType(alias);

                // if slow - save after every remove
                // on big sites, this increases the chances of your SQL server completing the operation in time...
                //

                /*
                 * if (uSyncSettings.SlowUpdate)
                 * {
                 *  LogHelper.Debug<uSync>("SlowMode: saving now {0}", () => item.Name);
                 *  _contentTypeService.Save(item);
                 * }
                 */
            }

            foreach (KeyValuePair <string, string> movePair in propertiesToMove)
            {
                item.MovePropertyType(movePair.Key, movePair.Value);
            }

            if (propertiesToRemove.Count > 0 || propertiesToMove.Count > 0)
            {
                LogHelper.Debug <uSync>("Saving {0}", () => item.Name);
                _contentTypeService.Save(item);
            }
        }
        private static string VerifyExistingProperty(IContentType contentType, string tabName, IDataTypeService dataTypeService, PropertyInfo item, bool atGenericTab = false)
        {
            UmbracoPropertyAttribute attribute = item.GetCustomAttribute<UmbracoPropertyAttribute>();
            IDataTypeDefinition dataTypeDef;
            if (string.IsNullOrEmpty(attribute.DataTypeInstanceName))
            {
                dataTypeDef = dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(attribute.DataType).FirstOrDefault();
            }
            else
            {
                dataTypeDef = dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(attribute.DataType).FirstOrDefault(x => x.Name == attribute.DataTypeInstanceName);
            }

            if (dataTypeDef != null)
            {
                PropertyType property;
                bool alreadyExisted = contentType.PropertyTypeExists(attribute.Alias);
                // TODO: Added attribute.Tab != null after Generic Properties add, is this bulletproof?
                if (alreadyExisted && attribute.Tab != null)
                {
                    property = contentType.PropertyTypes.FirstOrDefault(x => x.Alias == attribute.Alias);
                }
                else
                {
                    property = new PropertyType(dataTypeDef);
                }

                property.Name = attribute.Name;
                //TODO: correct name?
                property.Alias = (atGenericTab ? attribute.Alias : UmbracoCodeFirstExtensions.HyphenToUnderscore(UmbracoCodeFirstExtensions.ParseUrl(attribute.Alias + "_" + tabName, false)));
                property.Description = attribute.Description;
                property.Mandatory = attribute.Mandatory;

                if (!alreadyExisted)
                {
                    if (atGenericTab)
                    {
                        contentType.AddPropertyType(property);
                    }
                    else
                    {
                        contentType.AddPropertyType(property, tabName);
                    }

                }

                return property.Alias;
            }
            return null;
        }
        /// <summary>
        /// Creates a new property on the ContentType under the correct tab
        /// </summary>
        /// <param name="newContentType"></param>
        /// <param name="tabName"></param>
        /// <param name="dataTypeService"></param>
        /// <param name="atTabGeneric"></param>
        /// <param name="item"></param>
        private static void CreateProperty(IContentType newContentType, string tabName, IDataTypeService dataTypeService, bool atTabGeneric, PropertyInfo item)
        {
            UmbracoPropertyAttribute attribute = item.GetCustomAttribute<UmbracoPropertyAttribute>();

            IDataTypeDefinition dataTypeDef;
            if (string.IsNullOrEmpty(attribute.DataTypeInstanceName))
            {
                dataTypeDef = dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(attribute.DataType).FirstOrDefault();
            }
            else
            {
                dataTypeDef = dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(attribute.DataType).FirstOrDefault(x => x.Name == attribute.DataTypeInstanceName);
            }

            if (dataTypeDef != null)
            {
                PropertyType propertyType = new PropertyType(dataTypeDef);
                propertyType.Name = attribute.Name;
                propertyType.Alias = (atTabGeneric ? attribute.Alias : UmbracoCodeFirstExtensions.HyphenToUnderscore(UmbracoCodeFirstExtensions.ParseUrl(attribute.Alias + "_" + tabName, false)));
                propertyType.Description = attribute.Description;
                propertyType.Mandatory = attribute.Mandatory;

                if (atTabGeneric)
                {
                    newContentType.AddPropertyType(propertyType);
                }
                else
                {
                    newContentType.AddPropertyType(propertyType, tabName);
                }

            }
        }
        public static void ImportRemoveMissingProps(this IContentType item, XElement node)
        {
            // don't do this if the setting is set to false
            if (!uSyncSettings.docTypeSettings.DeletePropertyValues)
            {
                return;
            }

            List <string> propertiesToRemove             = new List <string>();
            Dictionary <string, string> propertiesToMove = new Dictionary <string, string>();

            // go through the properties in the item
            foreach (var property in item.PropertyTypes)
            {
                // is this property in the xml ?
                XElement propertyNode = node.Element("GenericProperties")
                                        .Elements("GenericProperty")
                                        .Where(x => x.Element("Alias").Value == property.Alias)
                                        .SingleOrDefault();

                if (propertyNode == null)
                {
                    LogHelper.Info <uSync>("Removing {0} from {1}", () => property.Alias, () => item.Name);
                    propertiesToRemove.Add(property.Alias);
                }
                else
                {
                    // at this point we write our properties over those
                    // in the db - because the import doesn't do this
                    // for existing items.
                    LogHelper.Debug <uSync>("Updating prop {0} for {1}", () => property.Alias, () => item.Alias);


                    /* not sure we need to do this, we just call EditorAlias - it will find it ? */

                    /*
                     * var legacyEditorId = Guid.Empty;
                     * Guid.TryParse(propertyNode.Element("Type").Value, out legacyEditorId);
                     *
                     *
                     * if ( legacyEditorId == Guid.Empty)
                     * {
                     *  // new style id...?
                     * }
                     *
                     * var dataTypeDefinitionId = new Guid(propertyNode.Element("Definition").Value);
                     * IDataTypeService _dataTypeService = ApplicationContext.Current.Services.DataTypeService;
                     *
                     * var dataTypeDefinition = _dataTypeService.GetDataTypeDefinitionById(dataTypeDefinitionId);
                     */
                    var editorAlias = propertyNode.Element("Type").Value;

                    IDataTypeService _dataTypeService = ApplicationContext.Current.Services.DataTypeService;
                    var dataTypeDefinition            = _dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(editorAlias).FirstOrDefault();

                    /*
                     * if ( dataTypeDefinition != null &&
                     *   dataTypeDefinition.Key == dataTypeDefinitionId  )
                     * {
                     *  // all good, we are here..
                     * }
                     * else
                     * {
                     *  // we need to do even more looking...
                     *  var dataTypeDefinitions = _dataTypeService.GetDataTypeDefinitionByControlId(legacyEditorId);
                     *
                     *  if ( dataTypeDefinition != null && dataTypeDefinitions.Any())
                     *  {
                     *      dataTypeDefinition = dataTypeDefinitions.First();
                     *  }
                     * }
                     */

                    /*
                     * if ( dataTypeDefinition != null)
                     * {
                     *  // phew we have found what we are looking for.
                     *
                     *  // now we set it in the DB
                     *  // property.DataTypeDefinitionId = dataTypeDefinition.Id;
                     *
                     *  // this is wrong, because you can't
                     *  // actually change the DataTypeId and that prob
                     *  // matters when changing a type.
                     *
                     *  // TODO: make changes to the datatype import/export properly.
                     * }
                     */

                    property.Name             = propertyNode.Element("Name").Value;
                    property.Description      = propertyNode.Element("Description").Value;
                    property.Mandatory        = propertyNode.Element("Mandatory").Value.ToLowerInvariant().Equals("true");
                    property.ValidationRegExp = propertyNode.Element("Validation").Value;

                    XElement sortOrder = propertyNode.Element("SortOrder");
                    if (sortOrder != null)
                    {
                        property.SortOrder = int.Parse(sortOrder.Value);
                    }

                    var tab = propertyNode.Element("Tab").Value;
                    if (!string.IsNullOrEmpty(tab))
                    {
                        var propGroup = item.PropertyGroups.First(x => x.Name == tab);

                        if (!propGroup.PropertyTypes.Any(x => x.Alias == property.Alias))
                        {
                            // if it's not in this prop group - we can move it it into it
                            LogHelper.Info <uSync>("Moving {0} in {1} to {2}",
                                                   () => property.Alias, () => item.Name, () => tab);
                            propertiesToMove.Add(property.Alias, tab);
                        }
                    }
                }
            }

            foreach (string alias in propertiesToRemove)
            {
                LogHelper.Debug <uSync>("Removing {0}", () => alias);
                item.RemovePropertyType(alias);
            }

            foreach (KeyValuePair <string, string> movePair in propertiesToMove)
            {
                item.MovePropertyType(movePair.Key, movePair.Value);
            }

            if (propertiesToRemove.Count > 0 || propertiesToMove.Count > 0)
            {
                LogHelper.Debug <uSync>("Saving {0}", () => item.Name);
                _contentTypeService.Save(item);
            }
        }
Пример #13
0
        internal void DeserializeProperties(IContentTypeBase item, XElement node)
        {
            List <string> propertiesToRemove = new List <string>();
            Dictionary <string, string>        propertiesToMove = new Dictionary <string, string>();
            Dictionary <PropertyGroup, string> tabsToBlank      = new Dictionary <PropertyGroup, string>();

            var genericPropertyNode = node.Element("GenericProperties");

            if (genericPropertyNode != null)
            {
                // add or update properties
                foreach (var propertyNode in genericPropertyNode.Elements("GenericProperty"))
                {
                    bool newProperty = false;

                    var property = default(PropertyType);
                    var propKey  = propertyNode.Element("Key").ValueOrDefault(Guid.Empty);
                    if (propKey != Guid.Empty)
                    {
                        property = item.PropertyTypes.SingleOrDefault(x => x.Key == propKey);
                    }

                    var alias = propertyNode.Element("Alias").ValueOrDefault(string.Empty);

                    if (property == null)
                    {
                        // look up via alias?
                        property = item.PropertyTypes.SingleOrDefault(x => x.Alias == alias);
                    }

                    // we need to get element stuff now before we can create or update

                    var defGuid            = propertyNode.Element("Definition").ValueOrDefault(Guid.Empty);
                    var dataTypeDefinition = _dataTypeService.GetDataTypeDefinitionById(defGuid);

                    if (dataTypeDefinition == null)
                    {
                        var propEditorAlias = propertyNode.Element("Type").ValueOrDefault(string.Empty);
                        if (!string.IsNullOrEmpty(propEditorAlias))
                        {
                            dataTypeDefinition = _dataTypeService
                                                 .GetDataTypeDefinitionByPropertyEditorAlias(propEditorAlias)
                                                 .FirstOrDefault();
                        }
                    }

                    if (dataTypeDefinition == null)
                    {
                        LogHelper.Warn <Events>("Failed to get Definition for property type");
                        continue;
                    }

                    if (property == null)
                    {
                        // create the property
                        LogHelper.Debug <Events>("Creating new Property: {0} {1}", () => item.Alias, () => alias);
                        property    = new PropertyType(dataTypeDefinition, alias);
                        newProperty = true;
                    }

                    if (property != null)
                    {
                        LogHelper.Debug <Events>("Updating Property :{0} {1}", () => item.Alias, () => alias);

                        var key = propertyNode.Element("Key").ValueOrDefault(Guid.Empty);
                        if (key != Guid.Empty)
                        {
                            LogHelper.Debug <Events>("Setting Key :{0}", () => key);
                            property.Key = key;
                        }

                        LogHelper.Debug <Events>("Item Key    :{0}", () => property.Key);

                        // update settings.
                        property.Name = propertyNode.Element("Name").ValueOrDefault("unnamed" + DateTime.Now.ToString("yyyyMMdd_HHmmss"));

                        if (property.Alias != alias)
                        {
                            property.Alias = alias;
                        }

                        if (propertyNode.Element("Description") != null)
                        {
                            property.Description = propertyNode.Element("Description").Value;
                        }

                        if (propertyNode.Element("Mandatory") != null)
                        {
                            property.Mandatory = propertyNode.Element("Mandatory").Value.ToLowerInvariant().Equals("true");
                        }

                        if (propertyNode.Element("Validation") != null)
                        {
                            property.ValidationRegExp = propertyNode.Element("Validation").Value;
                        }

                        if (propertyNode.Element("SortOrder") != null)
                        {
                            property.SortOrder = int.Parse(propertyNode.Element("SortOrder").Value);
                        }

                        if (propertyNode.Element("Type") != null)
                        {
                            LogHelper.Debug <Events>("Setting Property Type : {0}", () => propertyNode.Element("Type").Value);
                            property.PropertyEditorAlias = propertyNode.Element("Type").Value;
                        }

                        if (property.DataTypeDefinitionId != dataTypeDefinition.Id)
                        {
                            property.DataTypeDefinitionId = dataTypeDefinition.Id;
                        }

                        var tabName = propertyNode.Element("Tab").ValueOrDefault(string.Empty);

                        if (_itemType == "MemberType")
                        {
                            ((IMemberType)item).SetMemberCanEditProperty(alias,
                                                                         propertyNode.Element("CanEdit").ValueOrDefault(false));

                            ((IMemberType)item).SetMemberCanViewProperty(alias,
                                                                         propertyNode.Element("CanView").ValueOrDefault(false));
                        }

                        if (!newProperty)
                        {
                            if (!string.IsNullOrEmpty(tabName))
                            {
                                var propGroup = item.PropertyGroups.FirstOrDefault(x => x.Name == tabName);
                                if (propGroup != null)
                                {
                                    if (!propGroup.PropertyTypes.Any(x => x.Alias == property.Alias))
                                    {
                                        // this tab currently doesn't contain this property, to we have to
                                        // move it (later)
                                        propertiesToMove.Add(property.Alias, tabName);
                                    }
                                }
                            }
                            else
                            {
                                // this property isn't in a tab (now!)
                                if (!newProperty)
                                {
                                    var existingTab = item.PropertyGroups.FirstOrDefault(x => x.PropertyTypes.Contains(property));
                                    if (existingTab != null)
                                    {
                                        // this item is now not in a tab (when it was)
                                        // so we have to remove it from tabs (later)
                                        tabsToBlank.Add(existingTab, property.Alias);
                                    }
                                }
                            }
                        }
                        else
                        {
                            // new propert needs to be added to content type..
                            if (string.IsNullOrEmpty(tabName))
                            {
                                item.AddPropertyType(property);
                            }
                            else
                            {
                                item.AddPropertyType(property, tabName);
                            }

                            // setting the key before here doesn't seem to work for new types.
                            if (key != Guid.Empty)
                            {
                                property.Key = key;
                            }
                        }
                    }
                } // end foreach property
            }     // end generic properties


            // look at what properties we need to remove.
            var propertyNodes = node.Elements("GenericProperties").Elements("GenericProperty");

            foreach (var property in item.PropertyTypes)
            {
                XElement propertyNode = propertyNodes
                                        .FirstOrDefault(x => x.Element("key") != null && x.Element("Key").Value == property.Key.ToString());

                if (propertyNode == null)
                {
                    LogHelper.Debug <uSync.Core.Events>("Looking up property type by alias {0}", () => property.Alias);
                    propertyNode = propertyNodes
                                   .SingleOrDefault(x => x.Element("Alias").Value == property.Alias);
                }

                if (propertyNode == null)
                {
                    propertiesToRemove.Add(property.Alias);
                }
            }


            // now we have gone through all the properties, we can do the moves and removes from the groups
            if (propertiesToMove.Any())
            {
                foreach (var move in propertiesToMove)
                {
                    LogHelper.Debug <Events>("Moving Property: {0} {1}", () => move.Key, () => move.Value);
                    item.MovePropertyType(move.Key, move.Value);
                }
            }

            if (propertiesToRemove.Any())
            {
                // removing properties can cause timeouts on installs with lots of content...
                foreach (var delete in propertiesToRemove)
                {
                    LogHelper.Debug <Events>("Removing Property: {0}", () => delete);
                    item.RemovePropertyType(delete);
                }
            }

            if (tabsToBlank.Any())
            {
                foreach (var blank in tabsToBlank)
                {
                    // there might be a bug here, we need to do some cheking of if this is
                    // possible with the public api

                    // blank.Key.PropertyTypes.Remove(blank.Value);
                }
            }
        }