Exemple #1
0
 public Grouper AddGroupOwnerSource(IGroupOwnerSource ownerSource)
 {
     foreach (GroupStores store in ownerSource.GetSupportedGroupStores())
     {
         if (_ownerSources.ContainsKey(store))
         {
             throw new ArgumentException($"An owner source for {store} is already added.", nameof(ownerSource));
         }
         _ownerSources.Add(store, ownerSource);
     }
     return(this);
 }
Exemple #2
0
        public async Task <GroupMemberDiff> GetMemberDiffAsync(GrouperDocument document, bool includeUnchanged = false)
        {
            if (document is null)
            {
                throw new ArgumentNullException(nameof(document));
            }
            var currentMembers = await GetCurrentMembersAsync(document);

            var targetMembers = await GetTargetMembersAsync(document);

            IGroupOwnerSource ownerSource = GetOwnerSource(document);

            if (ownerSource != null)
            {
                if (document.Owner != GroupOwnerActions.MatchSource)
                {
                    var owners = new GroupMemberCollection();
                    await ownerSource.GetGroupOwnersAsync(owners, document.GroupId);

                    if (document.Owner == GroupOwnerActions.KeepExisting)
                    {
                        owners.IntersectWith(currentMembers);
                    }
                    targetMembers.Add(owners);
                }
            }
            if (!currentMembers.ContainsMatchingMemberType(targetMembers))
            {
                throw new InvalidOperationException("Member types does not match");
            }
            GroupMemberCollection unchangedMembers = new GroupMemberCollection();

            if (includeUnchanged)
            {
                unchangedMembers = currentMembers.Clone();
                unchangedMembers.IntersectWith(targetMembers);
            }
            int currentCount = currentMembers.Count;

            currentMembers.FilterUniqueMember(targetMembers);
            double changeRatio;

            if (currentCount == 0)
            {
                changeRatio = targetMembers.Count == 0 ? 1.0 : targetMembers.Count;
            }
            else
            {
                changeRatio = (currentCount - currentMembers.Count + targetMembers.Count) / (double)currentCount;
            }
            return(new GroupMemberDiff(document, targetMembers, currentMembers, unchangedMembers, changeRatio));
        }