Exemple #1
0
 protected override void InternalProcessRecord()
 {
     TaskLogger.LogEnter();
     try
     {
         ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromADUser(this.DataObject, null);
         using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(exchangePrincipal, CultureInfo.InvariantCulture, "Client=Management;Action=Set-UserPhoto"))
         {
             PhotoRequest        request             = this.CreateRequest(exchangePrincipal);
             PhotoUploadPipeline photoUploadPipeline = new PhotoUploadPipeline(SetUserPhoto.PhotosConfiguration, mailboxSession, (IRecipientSession)base.DataSession, this.tracer);
             photoUploadPipeline.Upload(request, Stream.Null);
             if (!this.Save && !this.Cancel && !this.Preview)
             {
                 photoUploadPipeline.Upload(this.CreateSavePreviewRequest(exchangePrincipal), Stream.Null);
             }
         }
     }
     catch (WrongServerException ex)
     {
         this.LogFailedToUploadPhotoEvent(ex);
         this.WriteError(new CannotModifyPhotoBecauseMailboxIsInTransitException(ex), ExchangeErrorCategory.ServerTransient, this.DataObject, true);
     }
     catch (Exception e)
     {
         this.LogFailedToUploadPhotoEvent(e);
         throw;
     }
     finally
     {
         this.tracer.Dump(new PhotoRequestLogWriter(SetUserPhoto.RequestLog, SetUserPhoto.GenerateRequestId()));
     }
     TaskLogger.LogExit();
 }
        private void InternalUploadPhoto()
        {
            PhotoUploadPipeline photoUploadPipeline = new PhotoUploadPipeline(new PhotosConfiguration(ExchangeSetupContext.InstallPath), this.mailboxSession, this.adSession, GroupMailboxDefaultPhotoUploader.Tracer);
            string text = this.group.DisplayName;

            if (string.IsNullOrWhiteSpace(text))
            {
                text = this.group.Name;
            }
            using (Stream stream = InitialsImageGenerator.GenerateAsStream(text, 1024))
            {
                PhotoRequest request = new PhotoRequest
                {
                    TargetPrimarySmtpAddress = this.group.PrimarySmtpAddress.ToString(),
                    UploadTo         = this.group.ObjectId,
                    Preview          = true,
                    RawUploadedPhoto = stream,
                    UploadCommand    = UploadCommand.Upload
                };
                photoUploadPipeline.Upload(request, Stream.Null);
                request = new PhotoRequest
                {
                    TargetPrimarySmtpAddress = this.group.PrimarySmtpAddress.ToString(),
                    UploadTo      = this.group.ObjectId,
                    Preview       = false,
                    UploadCommand = UploadCommand.Upload
                };
                photoUploadPipeline.Upload(request, Stream.Null);
            }
        }
        public static void ClearGroupPhoto(IRecipientSession adSession, IMailboxSession mailboxSession, ADUser group)
        {
            PhotoUploadPipeline photoUploadPipeline = new PhotoUploadPipeline(new PhotosConfiguration(ExchangeSetupContext.InstallPath), mailboxSession, adSession, GroupMailboxDefaultPhotoUploader.Tracer);
            PhotoRequest        request             = new PhotoRequest
            {
                TargetPrimarySmtpAddress = group.PrimarySmtpAddress.ToString(),
                UploadTo      = group.ObjectId,
                Preview       = true,
                UploadCommand = UploadCommand.Clear
            };

            photoUploadPipeline.Upload(request, Stream.Null);
            request = new PhotoRequest
            {
                TargetPrimarySmtpAddress = group.PrimarySmtpAddress.ToString(),
                UploadTo      = group.ObjectId,
                Preview       = false,
                UploadCommand = UploadCommand.Clear
            };
            photoUploadPipeline.Upload(request, Stream.Null);
        }