Пример #1
0
        internal static PropertyDefinition GetPropertyDefinitionForSize(UserPhotoSize size)
        {
            switch (size)
            {
            case UserPhotoSize.HR48x48:
                return(UserPhotoSchema.UserPhotoHR48x48);

            case UserPhotoSize.HR64x64:
                return(UserPhotoSchema.UserPhotoHR64x64);

            case UserPhotoSize.HR96x96:
                return(UserPhotoSchema.UserPhotoHR96x96);

            case UserPhotoSize.HR120x120:
                return(UserPhotoSchema.UserPhotoHR120x120);

            case UserPhotoSize.HR240x240:
                return(UserPhotoSchema.UserPhotoHR240x240);

            case UserPhotoSize.HR360x360:
                return(UserPhotoSchema.UserPhotoHR360x360);

            case UserPhotoSize.HR432x432:
                return(UserPhotoSchema.UserPhotoHR432x432);

            case UserPhotoSize.HR504x504:
                return(UserPhotoSchema.UserPhotoHR504x504);

            case UserPhotoSize.HR648x648:
                return(UserPhotoSchema.UserPhotoHR648x648);

            default:
                throw new ArgumentNullException("size");
            }
        }
Пример #2
0
        private static UserPhotoSize NextSmallerSize(UserPhotoSize size)
        {
            switch (size)
            {
            case UserPhotoSize.HR64x64:
                return(UserPhotoSize.HR48x48);

            case UserPhotoSize.HR96x96:
                return(UserPhotoSize.HR64x64);

            case UserPhotoSize.HR120x120:
                return(UserPhotoSize.HR96x96);

            case UserPhotoSize.HR240x240:
                return(UserPhotoSize.HR120x120);

            case UserPhotoSize.HR360x360:
                return(UserPhotoSize.HR240x240);

            case UserPhotoSize.HR432x432:
                return(UserPhotoSize.HR360x360);

            case UserPhotoSize.HR504x504:
                return(UserPhotoSize.HR432x432);

            case UserPhotoSize.HR648x648:
                return(UserPhotoSize.HR504x504);
            }
            throw new ObjectNotFoundException(Strings.UserPhotoNotFound);
        }
Пример #3
0
        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());
            }
        }
Пример #4
0
        public static Size GetImageSize(UserPhotoSize size)
        {
            switch (size)
            {
            case UserPhotoSize.HR48x48:
                return(UserPhotoDimensions.HR48x48ImageSize);

            case UserPhotoSize.HR64x64:
                return(UserPhotoDimensions.HR64x64ImageSize);

            case UserPhotoSize.HR96x96:
                return(UserPhotoDimensions.HR96x96ImageSize);

            case UserPhotoSize.HR120x120:
                return(UserPhotoDimensions.HR120x120ImageSize);

            case UserPhotoSize.HR240x240:
                return(UserPhotoDimensions.HR240x240ImageSize);

            case UserPhotoSize.HR360x360:
                return(UserPhotoDimensions.HR360x360ImageSize);

            case UserPhotoSize.HR432x432:
                return(UserPhotoDimensions.HR432x432ImageSize);

            case UserPhotoSize.HR504x504:
                return(UserPhotoDimensions.HR504x504ImageSize);

            case UserPhotoSize.HR648x648:
                return(UserPhotoDimensions.HR648x648ImageSize);

            default:
                throw new EnumOutOfRangeException("size", size, "UserPhotoSize dimensions are unaccounted for.");
            }
        }
        // Token: 0x0600130E RID: 4878 RVA: 0x0004EF08 File Offset: 0x0004D108
        public static string Get(UserPhotoSize size)
        {
            switch (size)
            {
            case UserPhotoSize.HR48x48:
                return("size=HR48X48");

            case UserPhotoSize.HR64x64:
                return("size=HR64X64");

            case UserPhotoSize.HR96x96:
                return("size=HR96X96");

            case UserPhotoSize.HR120x120:
                return("size=HR120X120");

            case UserPhotoSize.HR240x240:
                return("size=HR240X240");

            case UserPhotoSize.HR360x360:
                return("size=HR360X360");

            case UserPhotoSize.HR432x432:
                return("size=HR432X432");

            case UserPhotoSize.HR504x504:
                return("size=HR504X504");

            case UserPhotoSize.HR648x648:
                return("size=HR648X648");

            default:
                throw new ArgumentOutOfRangeException("size");
            }
        }
Пример #6
0
        private PhotoMetadata ReadPhotoOfSizeOrBestMatch(IItem photo, UserPhotoSize size, Stream output)
        {
            UserPhotoSize userPhotoSize = size;
            PhotoMetadata result;

            try
            {
IL_02:
                using (Stream stream = photo.OpenPropertyStream(MailboxPhotoReader.GetPropertyDefinitionForSize(userPhotoSize), PropertyOpenMode.ReadOnly))
                {
                    stream.CopyTo(output);
                    result = new PhotoMetadata
                    {
                        Length      = stream.Length,
                        ContentType = "image/jpeg"
                    };
                }
            }
            catch (ObjectNotFoundException)
            {
                this.tracer.TraceDebug <UserPhotoSize>((long)this.GetHashCode(), "Mailbox photo reader: photo of size {0} not found.", userPhotoSize);
                userPhotoSize = MailboxPhotoReader.NextSmallerSize(userPhotoSize);
                goto IL_02;
            }
            return(result);
        }
Пример #7
0
        private PhotoMetadata ReadPreview(IMailboxSession session, UserPhotoSize size, Stream output)
        {
            StoreId       storeId = this.FindPreviewItem(session);
            PhotoMetadata result;

            using (IItem item = Item.Bind((MailboxSession)session, storeId))
            {
                result = this.ReadPhotoOfSizeOrBestMatch(item, size, output);
            }
            return(result);
        }
Пример #8
0
        public string Map(string smtpAddress, UserPhotoSize size)
        {
            if (string.IsNullOrEmpty(smtpAddress))
            {
                throw new ArgumentNullException("smtpAddress");
            }
            SmtpAddress smtpAddress2 = FileSystemPhotoMap.ParseAndValidate(smtpAddress);
            string      text         = Path.Combine(this.photosRootDirectoryFullPath, FileSystemPhotoMap.GetEscapedSmtpDomainWithHash(smtpAddress2), FileSystemPhotoMap.MapUserPhotoSizeToFileSystemResolutionDirectory(size), FileSystemPhotoMap.GetEscapedSmtpLocalWithHash(smtpAddress2)) + ".jpg";

            this.tracer.TraceDebug <string, UserPhotoSize, string>((long)this.GetHashCode(), "File system photo map: mapped ({0}, {1}) to {2}", smtpAddress, size, text);
            return(text);
        }
Пример #9
0
 // Token: 0x0600121C RID: 4636 RVA: 0x0004CB24 File Offset: 0x0004AD24
 private void StorePhotoOfSpecificSize(IItem photoItem, UserPhotoSize size, PropertyDefinition specificSizeProperty, MemoryStream photo)
 {
     if (photo == null || photo.Length == 0L)
     {
         this.tracer.TraceDebug <UserPhotoSize>((long)this.GetHashCode(), "Mailbox photo writer: photo of size {0} not available and will not be stored onto preview item.", size);
         return;
     }
     using (Stream stream = photoItem.OpenPropertyStream(specificSizeProperty, PropertyOpenMode.Create))
     {
         photo.Seek(0L, SeekOrigin.Begin);
         photo.CopyTo(stream);
     }
 }
Пример #10
0
 public static bool TryMapStringToSize(string sizeString, out UserPhotoSize size)
 {
     if ("HR48X48".Equals(sizeString, StringComparison.OrdinalIgnoreCase))
     {
         size = UserPhotoSize.HR48x48;
         return(true);
     }
     if ("HR64X64".Equals(sizeString, StringComparison.OrdinalIgnoreCase))
     {
         size = UserPhotoSize.HR64x64;
         return(true);
     }
     if ("HR96X96".Equals(sizeString, StringComparison.OrdinalIgnoreCase))
     {
         size = UserPhotoSize.HR96x96;
         return(true);
     }
     if ("HR120X120".Equals(sizeString, StringComparison.OrdinalIgnoreCase))
     {
         size = UserPhotoSize.HR120x120;
         return(true);
     }
     if ("HR240X240".Equals(sizeString, StringComparison.OrdinalIgnoreCase))
     {
         size = UserPhotoSize.HR240x240;
         return(true);
     }
     if ("HR360X360".Equals(sizeString, StringComparison.OrdinalIgnoreCase))
     {
         size = UserPhotoSize.HR360x360;
         return(true);
     }
     if ("HR432X432".Equals(sizeString, StringComparison.OrdinalIgnoreCase))
     {
         size = UserPhotoSize.HR432x432;
         return(true);
     }
     if ("HR504X504".Equals(sizeString, StringComparison.OrdinalIgnoreCase))
     {
         size = UserPhotoSize.HR504x504;
         return(true);
     }
     if ("HR648X648".Equals(sizeString, StringComparison.OrdinalIgnoreCase))
     {
         size = UserPhotoSize.HR648x648;
         return(true);
     }
     size = UserPhotoSize.HR48x48;
     return(false);
 }
Пример #11
0
        private PhotoMetadata ReadActual(IMailboxSession session, UserPhotoSize size, Stream output, IPerformanceDataLogger perfLogger)
        {
            StoreId       photoId = this.FindActualItem(session, perfLogger);
            PhotoMetadata result;

            using (IItem item = MailboxPhotoReader.BindAndTrackPerformance(session, photoId, "MailboxPhotoReaderBindPhotoItem", perfLogger))
            {
                using (new StopwatchPerformanceTracker("MailboxPhotoReaderReadStream", perfLogger))
                {
                    using (new StorePerformanceTracker("MailboxPhotoReaderReadStream", perfLogger))
                    {
                        result = this.ReadPhotoOfSizeOrBestMatch(item, size, output);
                    }
                }
            }
            return(result);
        }
Пример #12
0
 public PhotoMetadata Read(IMailboxSession session, UserPhotoSize size, bool preview, Stream output, IPerformanceDataLogger perfLogger)
 {
     if (session == null)
     {
         throw new ArgumentNullException("session");
     }
     if (output == null)
     {
         throw new ArgumentNullException("output");
     }
     if (perfLogger == null)
     {
         throw new ArgumentNullException("perfLogger");
     }
     if (preview)
     {
         return(this.ReadPreview(session, size, output));
     }
     return(this.ReadActual(session, size, output, perfLogger));
 }
Пример #13
0
        internal void BeginGetThumbnailPhotoFromMailbox(List <string> targetPrimarySmtpAddresses, UserPhotoSize photoSize)
        {
            foreach (string text in targetPrimarySmtpAddresses)
            {
                if (AirSyncPhotoRetriever.userPhotosCache.ContainsKey(text))
                {
                    if ((from s in AirSyncPhotoRetriever.userPhotosCache[text]
                         where s.PhotoSize == photoSize
                         select s).Count <AirSyncPhotoRetriever.UserPhotoWithSize>() != 0)
                    {
                        goto IL_111;
                    }
                }
                if (!this.delegatesCollection.ContainsKey(text))
                {
                    AirSyncDiagnostics.TraceDebug <string, string, UserPhotoSize>(ExTraceGlobals.ProtocolTracer, null, "AirSyncPhotoRetriever::BeginGetThumbnailPhotoFromMailbox - {0} requesting photo for {1} , with photosize {2}", this.Context.User.ExchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString(), text, photoSize);
                    AirSyncPhotoRetriever.GetThumbnailPhotoFromMailboxDelegate getThumbnailPhotoFromMailboxDelegate = new AirSyncPhotoRetriever.GetThumbnailPhotoFromMailboxDelegate(AirSyncPhotoRetriever.GetThumbnailPhotoFromMailbox);
                    IAsyncResult value = getThumbnailPhotoFromMailboxDelegate.BeginInvoke(this.Context, text, photoSize, null, new AirSyncPhotoRetriever.UserPhotoWithSize
                    {
                        UserEmail = text,
                        PhotoSize = photoSize
                    });
                    this.delegatesCollection.TryAdd(text, value);
                    this.NumberOfPhotosRequested++;
                    continue;
                }
IL_111:
                this.NumberOfPhotosFromCache++;
            }
        }
Пример #14
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);
        }
Пример #15
0
        private static byte[] GetThumbnailPhotoFromMailbox(IAirSyncContext context, string targetPrimarySmtpAddress, UserPhotoSize photoSize = UserPhotoSize.HR48x48)
        {
            byte[]        array         = null;
            ClientContext clientContext = ClientContext.Create(context.User.ClientSecurityContextWrapper.ClientSecurityContext, context.User.ExchangePrincipal.MailboxInfo.OrganizationId, null, null, CultureInfo.InvariantCulture, Guid.NewGuid().ToString());

            clientContext.RequestSchemaVersion = ExchangeVersionType.Exchange2012;
            if (!SmtpAddress.IsValidSmtpAddress(targetPrimarySmtpAddress))
            {
                AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.ProtocolTracer, null, "Target SMTP address is not valid: {0}", targetPrimarySmtpAddress);
                return(array);
            }
            GetUserPhotoQuery getUserPhotoQuery = new GetUserPhotoQuery(clientContext, new PhotoRequest
            {
                Requestor = new PhotoPrincipal
                {
                    EmailAddresses = new string[]
                    {
                        context.User.ExchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString().ToString()
                    },
                    OrganizationId = context.User.ExchangePrincipal.MailboxInfo.OrganizationId
                },
                Size = photoSize,
                TargetSmtpAddress = targetPrimarySmtpAddress,
                Trace             = ExTraceGlobals.ProtocolTracer.IsTraceEnabled(TraceType.DebugTrace),
                HostOwnedTargetMailboxSessionGetter = new Func <ExchangePrincipal, IMailboxSession>(AirSyncPhotoRetriever.GetCachedMailboxSessionForPhotoRequest)
            }, null, false, AirSyncPhotoRetriever.PhotosConfiguration, ExTraceGlobals.ProtocolTracer);

            try
            {
                array = getUserPhotoQuery.Execute();
                if (array == null || array.Length == 0)
                {
                    AirSyncDiagnostics.TraceError(ExTraceGlobals.ProtocolTracer, "Unable to retrieve thumbnailPhoto via GetUserPhoto for {0}", targetPrimarySmtpAddress);
                    return(null);
                }
                return(array);
            }
            catch (AccessDeniedException arg)
            {
                AirSyncDiagnostics.TraceError <AccessDeniedException>(ExTraceGlobals.ProtocolTracer, "Access denied retrieving thumbnailPhoto via GetUserPhoto for {0}.  Exception: {1}", targetPrimarySmtpAddress, arg);
            }
            return(null);
        }
Пример #16
0
        private void SavePhotoToFileSystem(PhotoRequest request, PhotoResponse response, FileSystemPhotoMap map, UserPhotoSize size)
        {
            byte[] uploadedPhotoOfSize = this.GetUploadedPhotoOfSize(response.UploadedPhotos, size);
            if (uploadedPhotoOfSize == null || uploadedPhotoOfSize.Length == 0)
            {
                this.tracer.TraceError <UserPhotoSize>((long)this.GetHashCode(), "File system photo upload handler: photo of size {0} NOT available and will NOT be saved to file system.", size);
                return;
            }
            string text = map.Map(request.TargetPrimarySmtpAddress, size);

            using (MemoryStream memoryStream = new MemoryStream(uploadedPhotoOfSize))
            {
                this.tracer.TraceDebug <string>((long)this.GetHashCode(), "File system photo upload handler: writing photo at {0}", text);
                this.DeleteThenWritePhoto(text, response.Thumbprint.Value, memoryStream);
            }
        }
Пример #17
0
 private byte[] GetUploadedPhotoOfSize(IDictionary <UserPhotoSize, byte[]> uploadedPhotos, UserPhotoSize size)
 {
     if (uploadedPhotos == null)
     {
         return(null);
     }
     byte[] result;
     if (!uploadedPhotos.TryGetValue(size, out result))
     {
         return(null);
     }
     return(result);
 }
 private bool IsSizeCacheable(UserPhotoSize size)
 {
     return(this.sizesToCacheOnFileSystem.Contains(size));
 }
Пример #19
0
        private void ClearPhotoFromFileSystem(PhotoRequest request, PhotoResponse response, FileSystemPhotoMap map, UserPhotoSize size)
        {
            int    num  = PhotoThumbprinter.Default.GenerateThumbprintForNegativeCache();
            string text = map.Map(request.TargetPrimarySmtpAddress, size);

            this.tracer.TraceDebug <string, int>((long)this.GetHashCode(), "File system photo upload handler: clearing photo at {0}.  Replacing it with NEGATIVE caching photo with thumbprint = {1:X8}", text, num);
            this.DeleteThenWritePhoto(text, num, Stream.Null);
        }
Пример #20
0
 private static Image GetImageOfSize(Image originalImage, UserPhotoSize size)
 {
     Util.ThrowOnNullArgument(originalImage, "originalImage");
     EnumValidator.ThrowIfInvalid <UserPhotoSize>(size, "size");
     return(UserPhotoUtilities.GetScaledAndCroppedImage(originalImage, UserPhotoDimensions.GetImageSize(size)));
 }