Пример #1
0
 private static void GetThumbnailPhotoCompleted(IAsyncResult result)
 {
     AirSyncPhotoRetriever.GetThumbnailPhotoFromMailboxDelegate getThumbnailPhotoFromMailboxDelegate = ((AsyncResult)result).AsyncDelegate as AirSyncPhotoRetriever.GetThumbnailPhotoFromMailboxDelegate;
     AirSyncPhotoRetriever.UserPhotoWithSize userPhotoWithSize = result.AsyncState as AirSyncPhotoRetriever.UserPhotoWithSize;
     try
     {
         byte[] userPhotoBytes = getThumbnailPhotoFromMailboxDelegate.EndInvoke(result);
         lock (AirSyncPhotoRetriever.lockObject)
         {
             List <AirSyncPhotoRetriever.UserPhotoWithSize> list;
             if (!AirSyncPhotoRetriever.userPhotosCache.ContainsKey(userPhotoWithSize.UserEmail))
             {
                 list = new List <AirSyncPhotoRetriever.UserPhotoWithSize>();
             }
             else
             {
                 list = AirSyncPhotoRetriever.userPhotosCache[userPhotoWithSize.UserEmail];
             }
             list.Add(new AirSyncPhotoRetriever.UserPhotoWithSize
             {
                 UserEmail      = userPhotoWithSize.UserEmail,
                 PhotoSize      = userPhotoWithSize.PhotoSize,
                 UserPhotoBytes = userPhotoBytes
             });
             AirSyncPhotoRetriever.userPhotosCache.Add(userPhotoWithSize.UserEmail, list);
         }
     }
     catch (AccessDeniedException arg)
     {
         AirSyncDiagnostics.TraceError <AccessDeniedException>(ExTraceGlobals.ProtocolTracer, "AirSyncPhotoRetriever::GetThumbnailPhotoCompleted- Access denied retrieving thumbnailPhoto via GetUserPhoto. TargetUser: {0}.  Exception: {1}", userPhotoWithSize.UserEmail, arg);
     }
 }
Пример #2
0
        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);
        }