Esempio n. 1
0
        /// <summary>
        /// Ensures the groups specified in this instance's <see cref="AttributeDefinitions"/> are contained in the local collection
        /// of groups.
        /// </summary>
        /// <remarks></remarks>
        private void EnsureGroupsPopulated()
        {
            using (new WriteLockDisposable(_groupLocker))
            {
                if (_groupPopulationValid)
                {
                    return;
                }

                // Get the groups from the attribute definitions. For those that have an ID (i.e. exist), ensure
                // our copy is distinct.
                var groupsFromDefs = GetGroupsFromDefsDistinctByAlias(); //<-- changed to distinct by alias not Id

                var groupsWithId    = GetGroupsWithId(groupsFromDefs);
                var groupsWithoutId = GetGroupsWithoutId(groupsFromDefs);
                var union           = UnionGroups(groupsWithoutId, groupsWithId);

                // Get the groups from the above selection that we don't already have
                var compoundAdd = GroupsNotPresent(union);

                // Add them to our local collection where they don't already exist in our local collection with a valid id
                compoundAdd.Where(x => !_attributeGroups.Any(y => !y.Id.IsNullValueOrEmpty() && y.Id == x.Id))
                .ForEach(x => _attributeGroups.Add(x));

                // After adding, check if we have any with matching aliases and remove those with a null ID
                _attributeGroups.RemoveAll(nullGroup => nullGroup.Id.IsNullValueOrEmpty() && _attributeGroups.Any(y => y.Alias == nullGroup.Alias && !y.Id.IsNullValueOrEmpty()));

                // Ensure we have distinct groups based on alias
                _attributeGroups.RemoveAll(existing => !_attributeGroups.DistinctBy(x => x.Alias).Contains(existing));

                _groupPopulationValid = true;
            }
        }