private static string MapUserPhotoSizeToFileSystemResolutionDirectory(UserPhotoSize size) { switch (size) { case UserPhotoSize.HR48x48: return("HR48x48"); case UserPhotoSize.HR64x64: return("HR64x64"); case UserPhotoSize.HR96x96: return("HR96x96"); case UserPhotoSize.HR120x120: return("HR120x120"); case UserPhotoSize.HR240x240: return("HR240x240"); case UserPhotoSize.HR360x360: return("HR360x360"); case UserPhotoSize.HR432x432: return("HR432x432"); case UserPhotoSize.HR504x504: return("HR504x504"); case UserPhotoSize.HR648x648: return("HR648x648"); default: return(size.ToString()); } }
internal byte[] EndGetThumbnailPhotoFromMailbox(string targetPrimarySmtpAddress, TimeSpan waitTime, UserPhotoSize photoSize) { AirSyncPhotoRetriever.UserPhotoWithSize userPhotoWithSize = null; if ((!AirSyncPhotoRetriever.userPhotosCache.ContainsKey(targetPrimarySmtpAddress) || (from s in AirSyncPhotoRetriever.userPhotosCache[targetPrimarySmtpAddress] where s.PhotoSize == photoSize select s).Count <AirSyncPhotoRetriever.UserPhotoWithSize>() == 0) && waitTime.TotalMilliseconds > 0.0) { AirSyncDiagnostics.TraceDebug <string, double>(ExTraceGlobals.ProtocolTracer, "AirSyncPhotoRetriever::EndGetThumbnailPhotoFromMailbox - user photo not available in cache. TargetUser: {0}, PhotoSize: {1}, waittime:{2}", targetPrimarySmtpAddress, photoSize.ToString(), waitTime.TotalMilliseconds); IAsyncResult asyncResult; if (this.delegatesCollection.TryRemove(targetPrimarySmtpAddress, out asyncResult) && asyncResult.AsyncWaitHandle.WaitOne(waitTime)) { AirSyncPhotoRetriever.GetThumbnailPhotoCompleted(asyncResult); this.NumberOfPhotosSuccess++; AirSyncDiagnostics.TraceDebug <int>(ExTraceGlobals.ProtocolTracer, "AirSyncPhotoRetriever::EndGetThumbnailPhotoFromMailbox - user photo successfully retrieved. user:{0}, numberofPhotosSuccess:{1}", targetPrimarySmtpAddress, this.NumberOfPhotosSuccess); } else { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.ProtocolTracer, null, "AirSyncPhotoRetriever::EndGetThumbnailPhotoFromMailbox - user photo failed to retrieve."); } } else { AirSyncDiagnostics.TraceDebug <int>(ExTraceGlobals.ProtocolTracer, null, "AirSyncPhotoRetriever::EndGetThumbnailPhotoFromMailbox - photo retrieved from cache. number of photos from cache:{0}", this.NumberOfPhotosFromCache); } List <AirSyncPhotoRetriever.UserPhotoWithSize> source; if (this.VerifyUserPermissions(this.Context.User.ExchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString(), this.Context.User.OrganizationId, targetPrimarySmtpAddress) && AirSyncPhotoRetriever.userPhotosCache.TryGetValue(targetPrimarySmtpAddress, out source)) { userPhotoWithSize = (from s in source where s.PhotoSize == photoSize select s).FirstOrDefault <AirSyncPhotoRetriever.UserPhotoWithSize>(); } if (userPhotoWithSize == null) { return(null); } return(userPhotoWithSize.UserPhotoBytes); }