protected override IConfigurable PrepareDataObject() { IConfigurable configurable = base.PrepareDataObject(); CmdletProxy.ThrowExceptionIfProxyIsNeeded(base.CurrentTaskContext, (ADUser)configurable, false, this.ConfirmationMessage, null); return(configurable); }
protected override void InternalProcessRecord() { TaskLogger.LogEnter(); CmdletProxy.ThrowExceptionIfProxyIsNeeded(base.CurrentTaskContext, this.DataObject, false, this.ConfirmationMessage, null); try { using (MailboxSession mailboxSession = ContactLinkingBaseCmdLet.OpenMailboxSessionAsAdmin(this.DataObject, this.UserAgent)) { this.PerformanceTracker = new ContactLinkingPerformanceTracker(mailboxSession); if (this.OwnsPerformanceTrackerLifeCycle) { this.PerformanceTracker.Start(); } this.ContactLinkingOperation(mailboxSession); } } catch (Exception ex) { TaskLogger.LogError(ex); this.WriteError(ex, ErrorCategory.NotSpecified, this.Identity, true); } finally { if (this.OwnsPerformanceTrackerLifeCycle && this.PerformanceTracker != null) { this.PerformanceTracker.Stop(); } this.WritePerformanceData(); TaskLogger.LogExit(); } }
protected override void InternalProcessRecord() { TaskLogger.LogEnter(); CmdletProxy.ThrowExceptionIfProxyIsNeeded(base.CurrentTaskContext, base.DataObject, false, this.ConfirmationMessage, null); try { ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromADUser(base.DataObject, null); using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(exchangePrincipal, CultureInfo.InvariantCulture, "Client=Management;Action=Remove-UserPhoto")) { new PhotoRemovalPipeline(RemoveUserPhoto.PhotosConfiguration, mailboxSession, (IRecipientSession)base.DataSession, this.tracer).Upload(this.CreateRemovePhotoRequest(exchangePrincipal), Stream.Null); } } catch (WrongServerException ex) { this.LogFailedToRemovePhotoEvent(ex); this.WriteError(new CannotModifyPhotoBecauseMailboxIsInTransitException(ex), ExchangeErrorCategory.ServerTransient, base.DataObject, true); } catch (Exception e) { this.LogFailedToRemovePhotoEvent(e); throw; } finally { this.tracer.Dump(new PhotoRequestLogWriter(RemoveUserPhoto.RequestLog, RemoveUserPhoto.GenerateRequestId())); } TaskLogger.LogExit(); }
protected override void InternalStateReset() { base.InternalStateReset(); if (!TaskHelper.GetLocalServerFqdn(new Task.TaskWarningLoggingDelegate(this.WriteWarning)).StartsWith(this.Server, StringComparison.OrdinalIgnoreCase)) { string remoteServerFqdn = this.Server.ToString(); int e15MinVersion = Microsoft.Exchange.Data.Directory.SystemConfiguration.Server.E15MinVersion; CmdletProxy.ThrowExceptionIfProxyIsNeeded(base.CurrentTaskContext, remoteServerFqdn, e15MinVersion, false, this.ConfirmationMessage, 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 PrepareDataObject() { IConfigurable configurable = base.PrepareDataObject(); BackEndServer backEndServer = BackEndLocator.GetBackEndServer((ADUser)configurable); if (backEndServer != null && backEndServer.Version < Server.E15MinVersion) { CmdletProxy.ThrowExceptionIfProxyIsNeeded(base.CurrentTaskContext, (ADUser)configurable, false, this.ConfirmationMessage, null); } return(configurable); }
protected override IConfigurable PrepareDataObject() { IConfigurable configurable = base.PrepareDataObject(); CASMailbox casmailbox = (CASMailbox)this.GetDynamicParameters(); if (casmailbox.ActiveSyncDebugLoggingSpecified || this.ResetAutoBlockedDevices) { ADUser user = (ADUser)configurable; CmdletProxy.ThrowExceptionIfProxyIsNeeded(base.CurrentTaskContext, user, false, this.ConfirmationMessage, delegate(PropertyBag parameters) { if (parameters.Contains("Confirm")) { parameters.Remove("Confirm"); } }); } return(configurable); }
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 void InternalProcessRecord() { TaskLogger.LogEnter(); CmdletProxy.ThrowExceptionIfProxyIsNeeded(base.CurrentTaskContext, this.DataObject, false, this.ConfirmationMessage, null); try { ADUser dataObject = this.DataObject; if (dataObject == null) { base.WriteError(new ObjectNotFoundException(Strings.MailboxAssociationMailboxNotFound), ExchangeErrorCategory.Client, this.DataObject); } else { IRecipientSession adSession = (IRecipientSession)base.DataSession; MailboxAssociationContext mailboxAssociationContext = new MailboxAssociationContext(adSession, dataObject, "Set-MailboxAssociation", this.Identity, false); mailboxAssociationContext.Execute(new Action <MailboxAssociationFromStore, IAssociationAdaptor, ADUser, IExtensibleLogger>(this.UpdateMailboxAssociation)); } } catch (StorageTransientException exception) { base.WriteError(exception, ErrorCategory.ReadError, this.Identity.MailboxId); } catch (StoragePermanentException exception2) { base.WriteError(exception2, ErrorCategory.ReadError, this.Identity.MailboxId); } catch (AssociationNotFoundException exception3) { base.WriteError(exception3, ErrorCategory.ReadError, this.Identity.MailboxId); } catch (MailboxNotFoundException exception4) { base.WriteError(exception4, ErrorCategory.ReadError, this.Identity.MailboxId); } catch (RpcException exception5) { base.WriteError(exception5, ErrorCategory.ConnectionError, this.Identity.MailboxId); } finally { TaskLogger.LogExit(); } }
protected override IConfigurable PrepareDataObject() { this.DataObject = (ADUser)base.PrepareDataObject(); if (this.DataObject.IsChanged(MailboxSchema.WindowsLiveID) && this.DataObject.WindowsLiveID != SmtpAddress.Empty) { this.DataObject.EmailAddressPolicyEnabled = false; SmtpAddress value = (SmtpAddress)this.DataObject.GetOriginalObject()[MailboxSchema.WindowsLiveID]; if (value == SmtpAddress.Empty || value == this.DataObject.PrimarySmtpAddress) { this.DataObject.PrimarySmtpAddress = this.DataObject.WindowsLiveID; } } bool flag = false; ADUser dataObject = this.DataObject; if (this.needChangeMailboxSubtype) { if (this.originalRecipientTypeDetails == RecipientTypeDetails.UserMailbox || this.targetRecipientTypeDetails == RecipientTypeDetails.UserMailbox) { flag = true; } } else if (dataObject.IsChanged(ADRecipientSchema.MasterAccountSid)) { flag = true; } if (!flag && (this.RemoveManagedFolderAndPolicy || base.Fields.IsModified(ADUserSchema.SharingPolicy))) { flag = true; } if (flag) { CmdletProxy.ThrowExceptionIfProxyIsNeeded(base.CurrentTaskContext, dataObject, false, this.ConfirmationMessage, new CmdletProxyInfo.ChangeCmdletProxyParametersDelegate(CmdletProxy.AppendForceToProxyCmdlet)); } if ((dataObject.IsChanged(ADUserSchema.LitigationHoldEnabled) && dataObject.LitigationHoldEnabled) || (dataObject.IsChanged(ADRecipientSchema.InPlaceHoldsRaw) && dataObject.IsInLitigationHoldOrInplaceHold)) { RecoverableItemsQuotaHelper.IncreaseRecoverableItemsQuotaIfNeeded(dataObject); } return this.DataObject; }
protected override void WriteResult(IConfigurable dataObject) { TaskLogger.LogEnter(); try { ADUser aduser = (ADUser)dataObject; MailboxAssociationPresentationObject mailboxAssociationPresentationObject = new MailboxAssociationPresentationObject(); if (!CmdletProxy.TryToProxyOutputObject(mailboxAssociationPresentationObject, base.CurrentTaskContext, aduser, false, this.ConfirmationMessage, null)) { IRecipientSession adSession = (IRecipientSession)base.DataSession; MailboxAssociationContext mailboxAssociationContext = new MailboxAssociationContext(adSession, aduser, "Get-MailboxAssociation", this.Identity, this.IncludeNotPromotedProperties); mailboxAssociationContext.Execute(new Action <MailboxAssociationFromStore, IAssociationAdaptor, ADUser, IExtensibleLogger>(this.WriteMailboxAssociation)); } else { base.WriteResult(mailboxAssociationPresentationObject); } } catch (StorageTransientException exception) { base.WriteError(exception, ErrorCategory.ReadError, this.Identity.MailboxId); } catch (StoragePermanentException exception2) { base.WriteError(exception2, ErrorCategory.ReadError, this.Identity.MailboxId); } catch (AssociationNotFoundException exception3) { base.WriteError(exception3, ErrorCategory.ReadError, this.Identity.MailboxId); } catch (MailboxNotFoundException exception4) { base.WriteError(exception4, ErrorCategory.ReadError, this.Identity.MailboxId); } finally { TaskLogger.LogExit(); } }
protected override void InternalProcessRecord() { TaskLogger.LogEnter(); bool flag = false; this.summary = default(UpdateSafeList.SafeListSummary); CmdletProxy.ThrowExceptionIfProxyIsNeeded(base.CurrentTaskContext, (ADUser)this.DataObject, false, this.ConfirmationMessage, null); try { ADUser aduser = this.DataObject as ADUser; if (aduser == null || (aduser.RecipientType != RecipientType.UserMailbox && aduser.RecipientType != RecipientType.MailUser)) { base.WriteError(new RecipientTypeInvalidException(this.Identity.ToString()), ErrorCategory.InvalidData, aduser); } ExchangePrincipal mailboxOwner = ExchangePrincipal.FromADUser(base.SessionSettings, aduser); using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(mailboxOwner, CultureInfo.InvariantCulture, "Client=Management;Action=Update-SafeList")) { if (!mailboxSession.Capabilities.CanHaveJunkEmailRule) { base.WriteError(new MailboxNotJunkRuleCapableException(this.Identity.ToString()), ErrorCategory.InvalidData, aduser); } else if (this.EnsureJunkEmailRule) { this.CheckAndCreateJunkEmailRule(mailboxSession); } else { JunkEmailRule filteredJunkEmailRule = mailboxSession.FilteredJunkEmailRule; switch (this.Type) { case UpdateType.SafeSenders: case UpdateType.SafeRecipients: case UpdateType.BlockedSenders: flag = this.CheckAndUpdateHashes(filteredJunkEmailRule, this.Type); break; case UpdateType.Both: if (this.CheckAndUpdateHashes(filteredJunkEmailRule, UpdateType.SafeRecipients)) { flag = true; } if (this.CheckAndUpdateHashes(filteredJunkEmailRule, UpdateType.SafeSenders)) { flag = true; } break; case UpdateType.All: if (this.CheckAndUpdateHashes(filteredJunkEmailRule, UpdateType.SafeRecipients)) { flag = true; } if (this.CheckAndUpdateHashes(filteredJunkEmailRule, UpdateType.SafeSenders)) { flag = true; } if (this.CheckAndUpdateHashes(filteredJunkEmailRule, UpdateType.BlockedSenders)) { flag = true; } break; } if (flag) { base.InternalProcessRecord(); if ((this.Type == UpdateType.SafeSenders || this.Type == UpdateType.Both || this.Type == UpdateType.All) && (this.summary.SkippedContacts > 0 || this.summary.SkippedSafeSenderDomains > 0 || this.summary.SkippedSafeSenders > 0)) { this.WriteWarning(Strings.SafeSendersNotUpdated(this.summary.SkippedContacts, this.summary.SkippedSafeSenders, this.summary.SkippedSafeSenderDomains, this.Identity.ToString())); } if ((this.Type == UpdateType.SafeRecipients || this.Type == UpdateType.Both || this.Type == UpdateType.All) && (this.summary.SkippedSafeRecipientDomains > 0 || this.summary.SkippedSafeRecipients > 0)) { this.WriteWarning(Strings.SafeRecipientsNotUpdated(this.summary.SkippedSafeRecipients, this.summary.SkippedSafeRecipientDomains, this.Identity.ToString())); } if ((this.Type == UpdateType.BlockedSenders || this.Type == UpdateType.All) && (this.summary.SkippedBlockedSenderDomains > 0 || this.summary.SkippedBlockedSenders > 0)) { this.WriteWarning(Strings.BlockedSendersNotUpdated(this.summary.SkippedBlockedSenders, this.summary.SkippedBlockedSenderDomains, this.Identity.ToString())); } } if (flag || !filteredJunkEmailRule.AllRestrictionsLoaded) { filteredJunkEmailRule.Save(); } } } } catch (JunkEmailValidationException ex) { TaskLogger.LogError(ex); base.WriteError(ex, ErrorCategory.InvalidData, this.DataObject); } catch (StorageTransientException ex2) { TaskLogger.LogError(ex2); base.WriteError(ex2, ErrorCategory.ReadError, this.DataObject); } catch (StoragePermanentException ex3) { TaskLogger.LogError(ex3); base.WriteError(ex3, ErrorCategory.InvalidOperation, this.DataObject); } finally { TaskLogger.LogExit(); } }
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); }
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); }