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: 0x060050C9 RID: 20681 RVA: 0x0012BB94 File Offset: 0x00129D94
        internal static ADRecipient UnMarshalObject(object rusResult, ADObject originalRecipient)
        {
            if (rusResult == null || !(rusResult is object[]))
            {
                return(null);
            }
            SortedList sortedList = new SortedList(new CaseInsensitiveComparer(CultureInfo.InvariantCulture));

            foreach (object[] array2 in (object[])rusResult)
            {
                string[] array3 = new string[array2.Length - 1];
                Array.Copy(array2, 1, array3, 0, array2.Length - 1);
                sortedList.Add(array2[0], array3);
            }
            string[] array4 = new string[sortedList.Count];
            sortedList.Keys.CopyTo(array4, 0);
            ADRecipient adrecipient          = new ADRecipient();
            List <ADPropertyDefinition> list = new List <ADPropertyDefinition>((ADPropertyDefinition[])RUSMarshal.LdapAttributesToPropertyDefinitions(RUSMarshal.SchemaInstance, array4));
            List <object> list2 = new List <object>(list.Count);

            for (int j = 0; j < list.Count; j++)
            {
                list2.Add(RUSMarshal.UnMarshalAttribute(list[j], (object[])sortedList[list[j].LdapDisplayName]));
            }
            int k = list.Count - 1;

            while (k >= 0)
            {
                if (list[k] != ADRecipientSchema.WindowsEmailAddress)
                {
                    goto IL_171;
                }
                SmtpAddress smtpAddress = (SmtpAddress)list2[k];
                if (((SmtpAddress)list2[k]).Length <= 256)
                {
                    goto IL_171;
                }
                list.RemoveAt(k);
                list2.RemoveAt(k);
                ExTraceGlobals.RecipientUpdateServiceTracer.TraceDebug <string>((long)adrecipient.GetHashCode(), "RecipientUpdateService:: A Windows Email Address exceeding 256 characters for recipient \"{0}\" is generated and discarded", adrecipient.ToString());
IL_286:
                k--;
                continue;
IL_171:
                if (!list[k].IsMultivalued)
                {
                    goto IL_286;
                }
                int  num  = (list2[k] == null) ? 0 : ((MultiValuedPropertyBase)list2[k]).Count;
                int  num2 = (originalRecipient[list[k]] == null) ? 0 : ((MultiValuedPropertyBase)originalRecipient[list[k]]).Count;
                bool flag = num != num2;
                if (!flag && num != 0)
                {
                    object[] array5 = (object[])RUSMarshal.MarshalAttribute(list[k], list2[k]);
                    object[] array6 = (object[])RUSMarshal.MarshalAttribute(list[k], originalRecipient[list[k]]);
                    for (int l = 1; l < array6.Length; l++)
                    {
                        if (-1 == Array.IndexOf <object>(array5, array6[l]))
                        {
                            flag = true;
                            break;
                        }
                    }
                }
                if (!flag)
                {
                    list.RemoveAt(k);
                    list2.RemoveAt(k);
                    ExTraceGlobals.RecipientUpdateServiceTracer.TraceDebug <string>((long)adrecipient.GetHashCode(), "RecipientUpdateService:: the value of 'msExchPoliciesIncluded' property of recipient \"{0}\" does NOT change at all.", adrecipient.ToString());
                    goto IL_286;
                }
                goto IL_286;
            }
            adrecipient.SetProperties(list.ToArray(), list2.ToArray());
            return(adrecipient);
        }