Beispiel #1
0
        /// <summary>
        /// Adds a PropertyGroup.
        /// This method will also check if a group already exists with the same name and link it to the parent.
        /// </summary>
        /// <param name="groupName">Name of the PropertyGroup to add</param>
        /// <returns>Returns <c>True</c> if a PropertyGroup with the passed in name was added, otherwise <c>False</c></returns>
        public override bool AddPropertyGroup(string groupName)
        {
            if (PropertyGroups.Any(x => x.Name == groupName))
            {
                return(false);
            }

            var propertyGroup = new PropertyGroup {
                Name = groupName, SortOrder = 0
            };

            if (CompositionPropertyGroups.Any(x => x.Name == groupName))
            {
                var firstGroup = CompositionPropertyGroups.First(x => x.Name == groupName && x.ParentId.HasValue == false);
                propertyGroup.SetLazyParentId(new Lazy <int?>(() => firstGroup.Id));
            }

            if (PropertyGroups.Any())
            {
                var last = PropertyGroups.Last();
                propertyGroup.SortOrder = last.SortOrder + 1;
            }

            PropertyGroups.Add(propertyGroup);
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Adds a PropertyType to a specific PropertyGroup
        /// </summary>
        /// <param name="propertyType"><see cref="PropertyType"/> to add</param>
        /// <param name="propertyGroupName">Name of the PropertyGroup to add the PropertyType to</param>
        /// <returns>Returns <c>True</c> if PropertyType was added, otherwise <c>False</c></returns>
        public override bool AddPropertyType(PropertyType propertyType, string propertyGroupName)
        {
            if (propertyType.HasIdentity == false)
            {
                propertyType.Key = Guid.NewGuid();
            }

            if (PropertyTypeExists(propertyType.Alias) == false)
            {
                if (PropertyGroups.Contains(propertyGroupName))
                {
                    propertyType.PropertyGroupId = new Lazy <int>(() => PropertyGroups[propertyGroupName].Id);
                    PropertyGroups[propertyGroupName].PropertyTypes.Add(propertyType);
                }
                else
                {
                    //If the PropertyGroup doesn't already exist we create a new one
                    var propertyTypes = new List <PropertyType> {
                        propertyType
                    };
                    var propertyGroup = new PropertyGroup(new PropertyTypeCollection(propertyTypes))
                    {
                        Name = propertyGroupName, SortOrder = 1
                    };
                    //and check if its an inherited PropertyGroup, which exists in the composition
                    if (CompositionPropertyGroups.Any(x => x.Name == propertyGroupName))
                    {
                        var parentPropertyGroup = CompositionPropertyGroups.First(x => x.Name == propertyGroupName && x.ParentId.HasValue == false);
                        propertyGroup.SortOrder = parentPropertyGroup.SortOrder;
                        //propertyGroup.ParentId = parentPropertyGroup.Id;
                        propertyGroup.SetLazyParentId(new Lazy <int?>(() => parentPropertyGroup.Id));
                    }

                    PropertyGroups.Add(propertyGroup);
                }

                return(true);
            }

            return(false);
        }
        private PropertyGroup AddAndReturnPropertyGroup(string name)
        {
            // ensure we don't have it already
            if (PropertyGroups.Any(x => x.Name == name))
            {
                return(null);
            }

            // create the new group
            var group = new PropertyGroup {
                Name = name, SortOrder = 0
            };

            // check if it is inherited - there might be more than 1 but we want the 1st, to
            // reuse its sort order - if there are more than 1 and they have different sort
            // orders... there isn't much we can do anyways
            var inheritGroup = CompositionPropertyGroups.FirstOrDefault(x => x.Name == name);

            if (inheritGroup == null)
            {
                // no, just local, set sort order
                var lastGroup = PropertyGroups.LastOrDefault();
                if (lastGroup != null)
                {
                    group.SortOrder = lastGroup.SortOrder + 1;
                }
            }
            else
            {
                // yes, inherited, re-use sort order
                group.SortOrder = inheritGroup.SortOrder;
            }

            // add
            PropertyGroups.Add(group);

            return(group);
        }