protected override IConfigurable ConvertDataObjectToPresentationObject(IConfigurable dataObject)
        {
            if (dataObject == null)
            {
                return(null);
            }
            ADUser aduser = (ADUser)dataObject;
            MailboxAssociationReplicationStatePresentationObject mailboxAssociationReplicationStatePresentationObject = new MailboxAssociationReplicationStatePresentationObject
            {
                Identity = aduser.Identity
            };

            if (CmdletProxy.TryToProxyOutputObject(mailboxAssociationReplicationStatePresentationObject, base.CurrentTaskContext, aduser, this.Identity == null, this.ConfirmationMessage, CmdletProxy.AppendIdentityToProxyCmdlet(aduser)))
            {
                return(mailboxAssociationReplicationStatePresentationObject);
            }
            try
            {
                ExchangePrincipal mailboxOwner = ExchangePrincipal.FromADUser(aduser, null);
                using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(mailboxOwner, CultureInfo.InvariantCulture, "Client=Management;Action=Get-MailboxAssociationReplicationState"))
                {
                    mailboxSession.Mailbox.Load(GetMailboxAssociationReplicationState.MailboxProperties);
                    return(new MailboxAssociationReplicationStatePresentationObject
                    {
                        Identity = aduser.Identity,
                        NextReplicationTime = new ExDateTime?(mailboxSession.Mailbox.GetValueOrDefault <ExDateTime>(MailboxSchema.MailboxAssociationNextReplicationTime, ExDateTime.MinValue))
                    });
                }
            }
            catch (StorageTransientException exception)
            {
                base.WriteError(exception, ErrorCategory.ReadError, this.Identity);
            }
            catch (StoragePermanentException exception2)
            {
                base.WriteError(exception2, ErrorCategory.ReadError, this.Identity);
            }
            finally
            {
                TaskLogger.LogExit();
            }
            return(null);
        }
        protected override IConfigurable ConvertDataObjectToPresentationObject(IConfigurable dataObject)
        {
            if (dataObject == null)
            {
                return(null);
            }
            ADUser aduser = (ADUser)dataObject;
            UserPhotoConfiguration userPhotoConfiguration = new UserPhotoConfiguration(dataObject.Identity, Stream.Null, null);

            if (CmdletProxy.TryToProxyOutputObject(userPhotoConfiguration, base.CurrentTaskContext, aduser, this.Identity == null, this.ConfirmationMessage, CmdletProxy.AppendIdentityToProxyCmdlet(aduser)))
            {
                return(userPhotoConfiguration);
            }
            IConfigurable result;

            try
            {
                ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromADUser(aduser, null);
                using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(exchangePrincipal, CultureInfo.InvariantCulture, "Client=Management;Action=Get-UserPhoto"))
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        PhotoManagementRetrievalPipeline photoManagementRetrievalPipeline = new PhotoManagementRetrievalPipeline(GetUserPhoto.PhotosConfiguration, mailboxSession, (IRecipientSession)base.DataSession, this.tracer);
                        PhotoResponse  photoResponse = photoManagementRetrievalPipeline.Retrieve(this.CreateRetrievePhotoRequest(exchangePrincipal), memoryStream);
                        HttpStatusCode status        = photoResponse.Status;
                        if (status != HttpStatusCode.OK && status == HttpStatusCode.NotFound)
                        {
                            this.WriteError(new UserPhotoNotFoundException(this.Preview), ExchangeErrorCategory.Client, this.Identity, true);
                            throw new InvalidOperationException();
                        }
                        memoryStream.Seek(0L, SeekOrigin.Begin);
                        result = new UserPhotoConfiguration(dataObject.Identity, memoryStream, photoResponse.Thumbprint);
                    }
                }
            }
            catch (UserPhotoNotFoundException)
            {
                throw;
            }
            catch (Exception ex)
            {
                ExManagementApplicationLogger.LogEvent(ManagementEventLogConstants.Tuple_FailedToRetrievePhoto, new string[]
                {
                    dataObject.ToString(),
                    ((ADUser)dataObject).UserPrincipalName,
                    ex.ToString()
                });
                throw;
            }
            finally
            {
                this.tracer.Dump(new PhotoRequestLogWriter(GetUserPhoto.RequestLog, GetUserPhoto.GenerateRequestId()));
            }
            return(result);
        }
        protected override IConfigurable ConvertDataObjectToPresentationObject(IConfigurable dataObject)
        {
            if (dataObject == null)
            {
                return(null);
            }
            ADUser            aduser           = (ADUser)dataObject;
            IRecipientSession recipientSession = (IRecipientSession)base.DataSession;
            GroupMailbox      groupMailbox     = GroupMailbox.FromDataObject(aduser);

            if ((this.IncludeMemberSyncStatus || this.IncludePermissionsVersion) && CmdletProxy.TryToProxyOutputObject(groupMailbox, base.CurrentTaskContext, aduser, false, this.ConfirmationMessage, CmdletProxy.AppendIdentityToProxyCmdlet(aduser)))
            {
                return(groupMailbox);
            }
            ExchangePrincipal exchangePrincipal = null;

            if (this.IncludeMailboxUrls)
            {
                try
                {
                    exchangePrincipal = ExchangePrincipal.FromADUser(aduser, RemotingOptions.AllowCrossSite);
                    MailboxUrls mailboxUrls = new MailboxUrls(exchangePrincipal, false);
                    groupMailbox.InboxUrl    = this.SuppressPiiDataAsNeeded(mailboxUrls.InboxUrl);
                    groupMailbox.CalendarUrl = this.SuppressPiiDataAsNeeded(mailboxUrls.CalendarUrl);
                    groupMailbox.PeopleUrl   = this.SuppressPiiDataAsNeeded(mailboxUrls.PeopleUrl);
                    groupMailbox.PhotoUrl    = this.SuppressPiiDataAsNeeded(mailboxUrls.PhotoUrl);
                }
                catch (LocalizedException ex)
                {
                    base.WriteWarning("Unable to get mailbox principal due exception: " + ex.Message);
                }
            }
            IdentityDetails[] ownersDetails = this.GetOwnersDetails(recipientSession, aduser);
            if (ownersDetails != null)
            {
                groupMailbox.OwnersDetails = ownersDetails;
            }
            ADRawEntry[] array = null;
            if (this.IncludeMembers)
            {
                array = this.GetMemberRawEntriesFromAD(recipientSession, aduser);
                IdentityDetails[] identityDetails = this.GetIdentityDetails(array);
                groupMailbox.MembersDetails = identityDetails;
                groupMailbox.Members        = Array.ConvertAll <IdentityDetails, ADObjectId>(identityDetails, (IdentityDetails member) => member.Identity);
            }
            if (!this.IncludeMemberSyncStatus)
            {
                if (!this.IncludePermissionsVersion)
                {
                    return(groupMailbox);
                }
            }
            try
            {
                if (exchangePrincipal == null)
                {
                    exchangePrincipal = ExchangePrincipal.FromADUser(aduser, RemotingOptions.AllowCrossSite);
                }
                using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(exchangePrincipal, CultureInfo.InvariantCulture, "Client=Management;Action=Get-GroupMailbox"))
                {
                    if (this.IncludeMemberSyncStatus)
                    {
                        if (array == null)
                        {
                            array = this.GetMemberRawEntriesFromAD(recipientSession, aduser);
                        }
                        ADObjectId[] membersInAD        = Array.ConvertAll <ADRawEntry, ADObjectId>(array, (ADRawEntry member) => member.Id);
                        ADObjectId[] membersFromMailbox = this.GetMembersFromMailbox(recipientSession, aduser, mailboxSession);
                        groupMailbox.MembersSyncStatus = new GroupMailboxMembersSyncStatus(membersInAD, membersFromMailbox);
                        if (base.NeedSuppressingPiiData)
                        {
                            groupMailbox.MembersSyncStatus.MembersInADOnly      = SuppressingPiiData.Redact(groupMailbox.MembersSyncStatus.MembersInADOnly);
                            groupMailbox.MembersSyncStatus.MembersInMailboxOnly = SuppressingPiiData.Redact(groupMailbox.MembersSyncStatus.MembersInMailboxOnly);
                        }
                    }
                    if (this.IncludePermissionsVersion)
                    {
                        groupMailbox.PermissionsVersion = mailboxSession.Mailbox.GetValueOrDefault <int>(MailboxSchema.GroupMailboxPermissionsVersion, 0).ToString();
                    }
                }
            }
            catch (LocalizedException ex2)
            {
                base.WriteWarning("Unable to retrieve data from group mailbox due exception: " + ex2.Message);
            }
            return(groupMailbox);
        }
Exemple #4
0
        protected override IConfigurable ConvertDataObjectToPresentationObject(IConfigurable dataObject)
        {
            if (dataObject == null)
            {
                return(null);
            }
            ADUser aduser = (ADUser)dataObject;

            if (null != aduser.MasterAccountSid)
            {
                aduser.LinkedMasterAccount = SecurityPrincipalIdParameter.GetFriendlyUserName(aduser.MasterAccountSid, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
                aduser.ResetChangeTracking();
            }
            CASMailbox casmailbox = CASMailbox.FromDataObject(aduser);

            if ((this.GetPopProtocolLog || this.GetImapProtocolLog || this.ActiveSyncDebugLogging) && CmdletProxy.TryToProxyOutputObject(casmailbox, base.CurrentTaskContext, aduser, this.Identity == null, this.ConfirmationMessage, CmdletProxy.AppendIdentityToProxyCmdlet(aduser)))
            {
                return(casmailbox);
            }
            if (casmailbox.ActiveSyncMailboxPolicy == null && !casmailbox.ExchangeVersion.IsOlderThan(CASMailboxSchema.ActiveSyncMailboxPolicy.VersionAdded))
            {
                ADObjectId defaultPolicyId = base.GetDefaultPolicyId(aduser);
                if (defaultPolicyId != null)
                {
                    casmailbox.SetActiveSyncMailboxPolicyLocally(defaultPolicyId);
                    casmailbox.ActiveSyncMailboxPolicyIsDefaulted = true;
                }
            }
            if (this.GetPopProtocolLog || this.GetImapProtocolLog)
            {
                this.GetProtocolLogs(aduser);
            }
            if (this.ProtocolSettings)
            {
                this.PopulateProtocolSettings(casmailbox);
            }
            if (this.ActiveSyncDebugLogging)
            {
                casmailbox.ActiveSyncDebugLogging = this.GetActiveSyncLoggingEnabled(aduser);
            }
            return(casmailbox);
        }