Exemple #1
0
        protected override bool ShouldSkipObject(IConfigurable dataObject)
        {
            ADUser aduser = dataObject as ADUser;

            if (aduser == null)
            {
                return(true);
            }
            if (this.DeletedSiteMailbox)
            {
                return(!TeamMailbox.IsPendingDeleteSiteMailbox(aduser));
            }
            if (TeamMailbox.IsPendingDeleteSiteMailbox(aduser))
            {
                return(true);
            }
            if (!TeamMailbox.IsLocalTeamMailbox(aduser) && !TeamMailbox.IsRemoteTeamMailbox(aduser))
            {
                return(true);
            }
            if (base.ParameterSetName == "TeamMailboxIW")
            {
                TeamMailbox teamMailbox = TeamMailbox.FromDataObject((ADUser)dataObject);
                return(!teamMailbox.OwnersAndMembers.Contains(this.executingUserId));
            }
            return(false);
        }
        protected override TeamMailboxSyncInfo CreateOnCacheMiss(TeamMailboxSyncId key, ref bool shouldAdd)
        {
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(key.DomainController, true, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(key.OrgId), 105, "CreateOnCacheMiss", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\LinkedFolder\\TeamMailboxSyncInfoCache.cs");
            ADRecipient       adrecipient = tenantOrRootOrgRecipientSession.FindByExchangeGuid(key.MailboxGuid);
            ADUser            aduser      = adrecipient as ADUser;

            if (aduser == null)
            {
                return(null);
            }
            TeamMailboxLifecycleState teamMailboxLifecycleState = TeamMailboxLifecycleState.Active;

            if (TeamMailbox.IsPendingDeleteSiteMailbox(aduser))
            {
                teamMailboxLifecycleState = TeamMailboxLifecycleState.PendingDelete;
            }
            else if (aduser.SharePointUrl == null)
            {
                teamMailboxLifecycleState = TeamMailboxLifecycleState.Unlinked;
            }
            ExchangePrincipal exchangePrincipal = null;

            try
            {
                exchangePrincipal = ExchangePrincipal.FromMailboxGuid(ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(key.OrgId), key.MailboxGuid, key.DomainController);
            }
            catch (ObjectNotFoundException)
            {
                return(null);
            }
            TeamMailboxSyncInfo result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                MailboxSession    mailboxSession    = null;
                UserConfiguration userConfiguration = null;
                if (teamMailboxLifecycleState == TeamMailboxLifecycleState.Active)
                {
                    mailboxSession = MailboxSession.OpenAsAdmin(exchangePrincipal, CultureInfo.InvariantCulture, "Client=TeamMailbox;Action=CommitChanges;Interactive=False");
                    disposeGuard.Add <MailboxSession>(mailboxSession);
                    if (!string.Equals(mailboxSession.MailboxOwner.MailboxInfo.Location.ServerFqdn, TeamMailboxSyncInfoCache.LocalServerFqdn, StringComparison.OrdinalIgnoreCase))
                    {
                        throw new WrongServerException(new LocalizedString(string.Format("Non-local XSO MailboxSession not allowed for TeamMailboxSync. TeamMailbox Name: {0}, MailboxGuid {1}, ServerFqdn {2}", mailboxSession.MailboxOwner.MailboxInfo.DisplayName, mailboxSession.MailboxOwner.MailboxInfo.MailboxGuid, mailboxSession.MailboxOwner.MailboxInfo.Location.ServerFqdn)));
                    }
                    userConfiguration = UserConfigurationHelper.GetMailboxConfiguration(mailboxSession, this.syncLogConfigurationName, UserConfigurationTypes.Stream, true);
                    disposeGuard.Add <UserConfiguration>(userConfiguration);
                }
                TeamMailbox         teamMailbox         = TeamMailbox.FromDataObject(aduser);
                TeamMailboxSyncInfo teamMailboxSyncInfo = new TeamMailboxSyncInfo(key.MailboxGuid, teamMailboxLifecycleState, mailboxSession, exchangePrincipal, teamMailbox.DisplayName, teamMailbox.WebCollectionUrl, teamMailbox.WebId, (aduser.SharePointUrl != null) ? aduser.SharePointUrl.AbsoluteUri : null, (teamMailboxLifecycleState == TeamMailboxLifecycleState.Active) ? this.resourceMonitorFactory.Create(exchangePrincipal.MailboxInfo.MailboxDatabase.ObjectGuid) : null, userConfiguration);
                disposeGuard.Success();
                result = teamMailboxSyncInfo;
            }
            return(result);
        }