private static SetDisplayPictureResult SaveToAD(UserContext userContext, bool isClearPicture)
        {
            if (userContext == null)
            {
                throw new ArgumentNullException("userContext");
            }
            SetDisplayPictureResult noError = SetDisplayPictureResult.NoError;

            byte[] array = null;
            if (!isClearPicture)
            {
                if (userContext.UploadedDisplayPicture == null)
                {
                    noError.SetErrorResult(SetDisplayPictureResultCode.SaveError, SanitizedHtmlString.GetNonEncoded(-1306631087));
                    return(noError);
                }
                array = userContext.UploadedDisplayPicture;
            }
            IRecipientSession recipientSession = Utilities.CreateADRecipientSession(false, ConsistencyMode.IgnoreInvalid, userContext);
            ADRecipient       adrecipient      = Utilities.CreateADRecipientFromProxyAddress(userContext.ExchangePrincipal.ObjectId, null, recipientSession);

            if (adrecipient == null)
            {
                noError.SetErrorResult(SetDisplayPictureResultCode.GeneralError, SanitizedHtmlString.GetNonEncoded(-1496582182));
                return(noError);
            }
            try
            {
                adrecipient.SetProperties(new PropertyDefinition[]
                {
                    ADRecipientSchema.ThumbnailPhoto
                }, new object[]
                {
                    array
                });
                recipientSession.Save(adrecipient);
            }
            catch (Exception ex)
            {
                noError.SetErrorResult(SetDisplayPictureResultCode.SaveError, SanitizedHtmlString.GetNonEncoded(-1496582182));
                ExTraceGlobals.CoreTracer.TraceDebug <string>(0L, "Failed to save display picture to AD  - {0}", ex.Message);
                return(noError);
            }
            userContext.UpdateDisplayPictureCanary();
            userContext.UploadedDisplayPicture = null;
            userContext.HasPicture             = new bool?(array != null);
            string stringHash = Utilities.GetStringHash(userContext.ExchangePrincipal.LegacyDn);

            if (isClearPicture)
            {
                DisplayPictureUtility.RecipientsNegativeCache[stringHash] = DateTime.UtcNow;
            }
            else if (DisplayPictureUtility.IsInRecipientsNegativeCache(stringHash))
            {
                DisplayPictureUtility.RecipientsNegativeCache.Remove(stringHash);
            }
            return(noError);
        }
        // Token: 0x06003113 RID: 12563 RVA: 0x00121434 File Offset: 0x0011F634
        public static SanitizedHtmlString GetDueByString(ExDateTime?dueDate)
        {
            SanitizedHtmlString result = null;

            if (dueDate != null)
            {
                int days = (dueDate.Value.Date - DateTimeUtilities.GetLocalTime().Date).Days;
                if (days == 0)
                {
                    result = SanitizedHtmlString.GetNonEncoded(2136131687);
                }
                else if (days == 1)
                {
                    result = SanitizedHtmlString.GetNonEncoded(-1763467067);
                }
                else if (days > 1 && days < 15)
                {
                    result = SanitizedHtmlString.Format(LocalizedStrings.GetNonEncoded(397195003), new object[]
                    {
                        days
                    });
                }
                else if (days == -1)
                {
                    result = SanitizedHtmlString.GetNonEncoded(-2069325904);
                }
                else if (days < -1 && days > -15)
                {
                    result = SanitizedHtmlString.Format(LocalizedStrings.GetNonEncoded(2142112873), new object[]
                    {
                        days * -1
                    });
                }
                else if (days < -14)
                {
                    result = SanitizedHtmlString.GetNonEncoded(2027934943);
                }
            }
            return(result);
        }
        public static SetDisplayPictureResult UploadDisplayPicture(HttpPostedFile file, UserContext userContext)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }
            if (userContext == null)
            {
                throw new ArgumentNullException("userContext");
            }
            SetDisplayPictureResult noError = SetDisplayPictureResult.NoError;

            if (file.ContentLength == 0)
            {
                noError.SetErrorResult(SetDisplayPictureResultCode.GeneralError, SanitizedHtmlString.GetNonEncoded(-1496582182));
                return(noError);
            }
            int num  = 20;
            int num2 = num * 1048576;

            if (file.ContentLength > num2)
            {
                noError.SetErrorResult(SetDisplayPictureResultCode.FileExceedsSizeLimit, SanitizedHtmlString.Format(LocalizedStrings.GetNonEncoded(1511892651), new object[]
                {
                    num
                }));
                return(noError);
            }
            byte[] uploadedDisplayPicture = DisplayPictureUtility.ProcessImage(file.InputStream, noError);
            if (noError.ResultCode != SetDisplayPictureResultCode.NoError)
            {
                return(noError);
            }
            userContext.UploadedDisplayPicture = uploadedDisplayPicture;
            return(noError);
        }
 private static byte[] ProcessImage(Stream stream, SetDisplayPictureResult result)
 {
     byte[] result2;
     try
     {
         Image image = Image.FromStream(stream);
         if (image == null)
         {
             result.SetErrorResult(SetDisplayPictureResultCode.FailedProcessImage, SanitizedHtmlString.GetNonEncoded(1235679903));
             result2 = null;
         }
         else
         {
             Size   imageScaledSize = DisplayPictureUtility.GetImageScaledSize(image.Size);
             Bitmap bitmap          = new Bitmap(imageScaledSize.Width, imageScaledSize.Height);
             using (Graphics graphics = Graphics.FromImage(bitmap))
             {
                 graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                 graphics.DrawImage(image, 0, 0, imageScaledSize.Width, imageScaledSize.Height);
             }
             PointF     imageCenterPosition = DisplayPictureUtility.GetImageCenterPosition((float)imageScaledSize.Width, (float)imageScaledSize.Height);
             RectangleF rect    = new RectangleF(imageCenterPosition, new SizeF((float)Math.Min(DisplayPictureUtility.maxImageSize, imageScaledSize.Width), (float)Math.Min(DisplayPictureUtility.maxImageSize, imageScaledSize.Height)));
             Bitmap     bitmap2 = bitmap.Clone(rect, bitmap.PixelFormat);
             byte[]     array   = null;
             using (Stream stream2 = new MemoryStream())
             {
                 bitmap2.Save(stream2, ImageFormat.Jpeg);
                 stream2.Position = 0L;
                 array            = DisplayPictureUtility.ReadFromStream(stream2);
             }
             result2 = array;
         }
     }
     catch (Exception ex)
     {
         result.SetErrorResult(SetDisplayPictureResultCode.FailedProcessImage, SanitizedHtmlString.GetNonEncoded(1235679903));
         ExTraceGlobals.CoreTracer.TraceDebug <string>(0L, "Failed to process image  - {0}", ex.Message);
         result2 = null;
     }
     return(result2);
 }