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: 0x06002C63 RID: 11363 RVA: 0x000F738C File Offset: 0x000F558C private Stream GetADPictureStream(string email, string routingType) { IRecipientSession recipientSession = Utilities.CreateADRecipientSession(ConsistencyMode.IgnoreInvalid, base.UserContext); byte[] array = null; bool flag = string.Equals(email, base.UserContext.ExchangePrincipal.LegacyDn, StringComparison.OrdinalIgnoreCase); string stringHash = Utilities.GetStringHash(email); bool flag2 = DisplayPictureUtility.IsInRecipientsNegativeCache(stringHash); if (!flag2 || flag) { ProxyAddress proxyAddress = null; try { if (string.Equals(routingType, "EX", StringComparison.Ordinal)) { proxyAddress = new CustomProxyAddress((CustomProxyAddressPrefix)ProxyAddressPrefix.LegacyDN, email, true); } else if (string.Equals(routingType, "SMTP", StringComparison.Ordinal)) { proxyAddress = new SmtpProxyAddress(email, true); } if (proxyAddress != null) { if (Globals.ArePerfCountersEnabled) { OwaSingleCounters.SenderPhotosTotalLDAPCalls.Increment(); } ADRawEntry adrawEntry = recipientSession.FindByProxyAddress(proxyAddress, new PropertyDefinition[] { ADRecipientSchema.ThumbnailPhoto }); if (adrawEntry != null) { array = (adrawEntry[ADRecipientSchema.ThumbnailPhoto] as byte[]); } } goto IL_10F; } catch (NonUniqueRecipientException ex) { ExTraceGlobals.CoreTracer.TraceDebug <string>(0L, "GetADPictureStream: NonUniqueRecipientException was thrown by FindByProxyAddress: {0}", ex.Message); throw new OwaEventHandlerException("Unable to retrieve recipient data.", LocalizedStrings.GetNonEncoded(-1953304495)); } } if (Globals.ArePerfCountersEnabled) { OwaSingleCounters.SenderPhotosDataFromNegativeCacheCount.Increment(); } IL_10F: bool flag3 = array != null && array.Length > 0; if (flag) { base.UserContext.HasPicture = new bool?(flag3); } if (flag3) { if (Globals.ArePerfCountersEnabled) { OwaSingleCounters.SenderPhotosTotalLDAPCallsWithPicture.Increment(); } if (flag2) { DisplayPictureUtility.RecipientsNegativeCache.Remove(stringHash); } return(new MemoryStream(array)); } if (!flag2) { int num = DisplayPictureUtility.RecipientsNegativeCache.AddAndCount(stringHash, DateTime.UtcNow); if (Globals.ArePerfCountersEnabled) { OwaSingleCounters.SenderPhotosNegativeCacheCount.RawValue = (long)num; } } return(new MemoryStream()); }