private IList <ExchangePrincipal> GetSyncMailboxPrincipals(Guid mailboxDatabaseGuid, IDirectorySession configSession) { List <ExchangePrincipal> list = new List <ExchangePrincipal>(); ADObjectId id = new ADObjectId(mailboxDatabaseGuid); Result <MailboxDatabase>[] dataBases = null; ADOperationResult adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate() { dataBases = configSession.FindByADObjectIds <MailboxDatabase>(new ADObjectId[] { id }); }, 3); if (!adoperationResult.Succeeded) { this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Error, string.Format("GetSyncMailboxPrincipals: failed to find database {0} in active directory because of {1}", mailboxDatabaseGuid, adoperationResult.Exception), adoperationResult.Exception); } if (dataBases != null && dataBases.Length > 0) { PartitionId[] allAccountPartitionIds = ADAccountPartitionLocator.GetAllAccountPartitionIds(); for (int i = 0; i < allAccountPartitionIds.Length; i++) { PartitionId partitionId = allAccountPartitionIds[i]; IRecipientSession recipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 238, "GetSyncMailboxPrincipals", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\UnifiedPolicy\\NotificationLoader.cs"); ADUser[] arbMbxs = null; adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate() { arbMbxs = recipientSession.FindPaged <ADUser>(RecipientFilterHelper.DiscoveryMailboxFilterUnifiedPolicy(dataBases[0].Data.Id), null, true, null, 0).ToArray <ADUser>(); }, 3); if (!adoperationResult.Succeeded) { this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Error, string.Format("GetSyncMailboxPrincipals: failed to find sync mailboxes in database {0} in active directory because of {1}", mailboxDatabaseGuid, adoperationResult.Exception), adoperationResult.Exception); } if (arbMbxs != null && arbMbxs.Length > 0) { ADUser[] arbMbxs2 = arbMbxs; int j = 0; while (j < arbMbxs2.Length) { ADUser aduser = arbMbxs2[j]; this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Verbose, string.Format("GetSyncMailboxPrincipals: found sync mailbox {0} in database {1} in partition {2}", aduser.UserPrincipalName, mailboxDatabaseGuid, partitionId), null); ExchangePrincipal item = null; try { item = ExchangePrincipal.FromADUser(ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(aduser.OrganizationId), aduser, RemotingOptions.LocalConnectionsOnly); } catch (StoragePermanentException exception) { this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Error, string.Format("GetSyncMailboxPrincipals: sync mailbox {0} is skipped because of StoragePermanentException in ExchangePrincipal construction", aduser.UserPrincipalName), exception); goto IL_20F; } catch (StorageTransientException exception2) { this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Error, string.Format("GetSyncMailboxPrincipals: sync mailbox {0} is skipped because of StorageTransientException in ExchangePrincipal construction", aduser.UserPrincipalName), exception2); goto IL_20F; } goto IL_207; IL_20F: j++; continue; IL_207: list.Add(item); goto IL_20F; } } else { this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Verbose, string.Format("GetSyncMailboxPrincipals: there is no sync mailboxes in database {0} in active directory", mailboxDatabaseGuid), null); } } } return(list); }