Example #1
0
        private PhotoResponse SavePhotosToFileSystem(PhotoRequest request, PhotoResponse response)
        {
            response.FileSystemUploadHandlerProcessed = true;
            this.tracer.TraceDebug <string>((long)this.GetHashCode(), "File system photo upload handler: saving photos of {0} to file system.", request.TargetPrimarySmtpAddress);
            FileSystemPhotoMap map = new FileSystemPhotoMap(this.photosRootDirectoryFullPath, this.upstreamTracer);

            foreach (UserPhotoSize size in this.sizesToCacheOnFileSystem)
            {
                this.SavePhotoToFileSystem(request, response, map, size);
            }
            return(response);
        }
Example #2
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);
        }
Example #3
0
        private static string NormalizeAndHash(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                return(s);
            }
            string s2 = s.ToLowerInvariant();
            string result;

            using (MessageDigestForNonCryptographicPurposes messageDigestForNonCryptographicPurposes = new MessageDigestForNonCryptographicPurposes())
            {
                byte[] bytes = messageDigestForNonCryptographicPurposes.ComputeHash(Encoding.UTF8.GetBytes(s2));
                result = FileSystemPhotoMap.ConvertToHexadecimalSequence(bytes);
            }
            return(result);
        }
Example #4
0
        private static string Escape(string part)
        {
            StringBuilder stringBuilder = new StringBuilder(part.Length);

            foreach (char c in part)
            {
                if (FileSystemPhotoMap.IsInvalidCharInPath(c))
                {
                    stringBuilder.Append('_');
                }
                else
                {
                    stringBuilder.Append(c);
                }
            }
            return(stringBuilder.ToString());
        }
Example #5
0
 private static string GetEscapedSmtpLocalWithHash(SmtpAddress smtpAddress)
 {
     return("_" + FileSystemPhotoMap.Escape(smtpAddress.Local.Substring(0, Math.Min(20, smtpAddress.Local.Length))) + "-" + FileSystemPhotoMap.NormalizeAndHash(smtpAddress.ToString()));
 }
Example #6
0
 private static string GetEscapedSmtpDomainWithHash(SmtpAddress smtpAddress)
 {
     return("_" + FileSystemPhotoMap.Escape(smtpAddress.Domain.Substring(0, Math.Min(30, smtpAddress.Domain.Length))) + "-" + FileSystemPhotoMap.NormalizeAndHash(smtpAddress.Domain));
 }
Example #7
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);
        }
Example #8
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);
            }
        }