// Token: 0x06001094 RID: 4244 RVA: 0x000611B4 File Offset: 0x0005F3B4
        private bool GetMetricsForChangedGroups(GroupMetricsGeneratorTaskContext context)
        {
            string       text             = this.changedGroupListPath;
            TypedHashSet calculatedGroups = new TypedHashSet(20000);

            try
            {
                if (GroupMetricsUtility.Fault == GroupMetricsFault.UnreadableChangedGroupFile)
                {
                    text = this.tenantDirectory;
                }
                List <string> list = new List <string>();
                Dictionary <string, object> parentGroupDictionary           = new Dictionary <string, object>();
                IRecipientSession           tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(false, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(base.OrgId), 1316, "GetMetricsForChangedGroups", "f:\\15.00.1497\\sources\\dev\\MailboxAssistants\\src\\assistants\\DirectoryProcessor\\GroupMetricsGenerator\\GroupMetricsGenerator.cs");
                using (StreamReader streamReader = new StreamReader(text))
                {
                    string text2;
                    if (context.LastProcessedGroupDistinguishedName != null)
                    {
                        while ((text2 = streamReader.ReadLine()) != null && text2 != context.LastProcessedGroupDistinguishedName)
                        {
                        }
                    }
                    DateTime utcNow = DateTime.UtcNow;
                    while ((text2 = streamReader.ReadLine()) != null)
                    {
                        this.GetMetricsForSingleGroup(tenantOrRootOrgRecipientSession, text2, calculatedGroups, parentGroupDictionary, list);
                        context.LastProcessedGroupDistinguishedName = text2;
                        if ((Utilities.TestForceYieldChunk && this.groupsExpanded > 2) || DateTime.UtcNow - utcNow > this.OneChunkTimeLimit)
                        {
                            break;
                        }
                        base.RunData.ThrowIfShuttingDown();
                    }
                    if (text2 == null)
                    {
                        context.AllChunksFinished = true;
                    }
                }
                for (int i = 0; i < list.Count; i++)
                {
                    string text2 = list[i];
                    this.GetMetricsForSingleGroup(tenantOrRootOrgRecipientSession, text2, calculatedGroups, parentGroupDictionary, list);
                }
                return(true);
            }
            catch (FileNotFoundException)
            {
                context.AllChunksFinished = true;
                return(true);
            }
            catch (IOException ex)
            {
                GroupMetricsGenerator.EventLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_UnableToReadChangedGroupList, null, new object[]
                {
                    this.GetOrganizationIdString(),
                    text,
                    ex.GetType().FullName,
                    ex.Message
                });
            }
            catch (UnauthorizedAccessException ex2)
            {
                GroupMetricsGenerator.EventLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_UnableToReadChangedGroupList, null, new object[]
                {
                    this.GetOrganizationIdString(),
                    text,
                    ex2.GetType().FullName,
                    ex2.Message
                });
            }
            catch (SecurityException ex3)
            {
                GroupMetricsGenerator.EventLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_UnableToReadChangedGroupList, null, new object[]
                {
                    this.GetOrganizationIdString(),
                    text,
                    ex3.GetType().FullName,
                    ex3.Message
                });
            }
            return(false);
        }
        // Token: 0x0600108A RID: 4234 RVA: 0x00060890 File Offset: 0x0005EA90
        internal void GetMetricsForSingleGroup(IRecipientSession session, string groupDN, TypedHashSet calculatedGroups, Dictionary <string, object> parentGroupDictionary, IList <string> parentGroupList)
        {
            ADObjectId        id                = new ADObjectId(groupDN);
            ADRawEntry        group             = null;
            ADOperationResult adoperationResult = this.TryRunPerGroupADOperation(delegate
            {
                group = session.ReadADRawEntry(id, GroupMetricsGenerator.groupProperties);
            }, groupDN);

            if (!adoperationResult.Succeeded || group == null)
            {
                return;
            }
            ulong hash = GroupMetricsUtility.GetHash(group.Id.ObjectGuid);

            if (calculatedGroups.Contains(hash))
            {
                return;
            }
            int                  externalMemberCount = 0;
            HashSet <ulong>      allMemberHashes     = new HashSet <ulong>(2000);
            ADRecipientExpansion expander            = new ADRecipientExpansion(session, false);

            adoperationResult = this.TryRunPerGroupADOperation(delegate
            {
                if (GroupMetricsUtility.Fault == GroupMetricsFault.TransientExceptionInExpansion)
                {
                    throw new ADTransientException(new LocalizedString("Fault Injection"));
                }
                if (GroupMetricsUtility.Fault == GroupMetricsFault.InvalidCredentialExceptionInExpansion)
                {
                    throw new ADInvalidCredentialException(new LocalizedString("Fault Injection"));
                }
                if (GroupMetricsUtility.Fault == GroupMetricsFault.PermanentExceptionInExpansion)
                {
                    throw new DataSourceOperationException(new LocalizedString("Fault Injection"));
                }
                expander.Expand(group, delegate(ADRawEntry member, ExpansionType recipientExpansionType, ADRawEntry parent, ExpansionType parentExpansionType)
                {
                    this.RunData.ThrowIfShuttingDown();
                    if (recipientExpansionType == ExpansionType.GroupMembership)
                    {
                        return(ExpansionControl.Continue);
                    }
                    ulong hash2 = GroupMetricsUtility.GetHash(member.Id.ObjectGuid);
                    if (allMemberHashes.TryAdd(hash2) && this.IsExternal(member))
                    {
                        externalMemberCount++;
                    }
                    if (allMemberHashes.Count >= 1000)
                    {
                        return(ExpansionControl.Terminate);
                    }
                    if (recipientExpansionType != ExpansionType.None)
                    {
                        return(ExpansionControl.Skip);
                    }
                    return(ExpansionControl.Continue);
                }, (ExpansionFailure failure, ADRawEntry member, ExpansionType recipientExpansionType, ADRawEntry parent, ExpansionType parentExpansionType) => ExpansionControl.Continue);
            }, groupDN);
            if (!adoperationResult.Succeeded)
            {
                return;
            }
            MultiValuedProperty <ADObjectId> multiValuedProperty = group[ADRecipientSchema.MemberOfGroup] as MultiValuedProperty <ADObjectId>;

            foreach (ADObjectId adobjectId in multiValuedProperty)
            {
                string distinguishedName = adobjectId.DistinguishedName;
                if (!parentGroupDictionary.ContainsKey(distinguishedName))
                {
                    parentGroupDictionary.Add(distinguishedName, null);
                    parentGroupList.Add(distinguishedName);
                }
            }
            int count = allMemberHashes.Count;

            calculatedGroups.Add(hash);
            this.groupsExpanded++;
            int oldValue  = (int)group[ADGroupSchema.GroupMemberCount];
            int oldValue2 = (int)group[ADGroupSchema.GroupExternalMemberCount];

            if (this.ShouldSaveToAD(oldValue, count) || this.ShouldSaveToAD(oldValue2, externalMemberCount))
            {
                this.SaveGroupMetricsToAD(session, group, count, externalMemberCount);
            }
        }