Exemplo n.º 1
0
 public string Get(Identifier identifier, PhotoCategory photoCategory)
 {
     var bucket = Math.Abs(identifier.Id.GetHashCode()) % 256;
     var imageIdStr = Encode(identifier.Id);
     var newFileName = String.Format("{0}.{1}", imageIdStr, "jpg");
     return String.Format("Images\\People\\{0}\\{1}\\{2}", photoCategory, bucket, newFileName);
 }
Exemplo n.º 2
0
        public void Save(Identifier identifier, Dictionary<PhotoCategory, byte[]> photos)
        {
            var listImage = photos[PhotoCategory.List];
            var thumbImage = photos[PhotoCategory.Thumb];
            var profileImage = photos[PhotoCategory.Profile];

            var listPath = fileSystemBasedImagePathProvider.GetImagePath(identifier.Id, identifier.ImageType, "list");
            var thumbPath = fileSystemBasedImagePathProvider.GetImagePath(identifier.Id, identifier.ImageType, "thumb");
            var profilePath = fileSystemBasedImagePathProvider.GetImagePath(identifier.Id, identifier.ImageType, null);

            // Get the directories and make sure they exist before saving the files.
            var listDirectory = listPath.Substring(0, listPath.LastIndexOf(@"\"));
            var thumbDirectory = thumbPath.Substring(0, thumbPath.LastIndexOf(@"\"));
            var profileDirectory = profilePath.Substring(0, profilePath.LastIndexOf(@"\"));

            if (!Directory.Exists(listDirectory))
            {
                Directory.CreateDirectory(listDirectory);
            }

            if (!Directory.Exists(thumbDirectory))
            {
                Directory.CreateDirectory(thumbDirectory);
            }

            if (!Directory.Exists(profileDirectory))
            {
                Directory.CreateDirectory(profileDirectory);
            }

            // Now that the directories are in place, save the images.
            if (listImage != null)
                File.WriteAllBytes(listPath, listImage);
            else
                File.Delete(listPath);

            if (thumbImage != null)
                File.WriteAllBytes(thumbPath, thumbImage);
            else
                File.Delete(thumbPath);

            if (profileImage != null)
                File.WriteAllBytes(profilePath, profileImage);
            else
                File.Delete(profilePath);
        }