Ejemplo n.º 1
0
        public UploadThumb GetThumb(UploadedFile file, int width)
        {
            if (disposed) throw new ObjectDisposedException("UploadThumbGenerator");

            if (!_thumbs.ContainsKey(file.TempKey))
                _thumbs.Add(file.TempKey, new Dictionary<int, UploadThumb>());

            var fileThumbs = _thumbs[file.TempKey];

            if (fileThumbs.ContainsKey(width))
                return (fileThumbs[width]);

            var thumb = new UploadThumb();
            try
            {
                using (var image = Image.FromFile(file.TempFilePathAbsolute))
                using (var resized = image.Width <= width
                                     	? image
                                     	: ImageUtils.ResizeImage(image, width, false))
                    resized.Save(thumb.ThumbPathAbsolute, ImageFormat.Png);
                fileThumbs.Add(width, thumb);
                return thumb;
            }
            catch (OutOfMemoryException)
            {
                throw;
            }
            catch (Exception)
            {
                DeleteThumb(thumb);
                return null;
            }
        }
Ejemplo n.º 2
0
 public UploadedFile HandleFile(HttpPostedFile postedFile)
 {
     var uploadedFile = new UploadedFile {Name = postedFile.FileName};
     uploadedFile.TempFilePathAbsolute.EnsureDirectoryExists();
     postedFile.SaveAs(uploadedFile.TempFilePathAbsolute);
     Files.Add(uploadedFile);
     return uploadedFile;
 }
Ejemplo n.º 3
0
        public void DeleteThumbs(UploadedFile file)
        {
            if (!_thumbs.ContainsKey(file.TempKey))
                return;

            var fileThumbs = _thumbs[file.TempKey];
            foreach (var thumb in fileThumbs.Values)
                DeleteThumb(thumb);

            _thumbs.Remove(file.TempKey);
        }
Ejemplo n.º 4
0
        public void RemoveFile(UploadedFile file)
        {
            if(!Files.Contains(file))
                throw new ArgumentException("The file to be removed is not managed by this UploadManager");

            DeleteFile(file);
            Files.Remove(file);

            ThumbGenerator.DeleteThumbs(file);
        }
Ejemplo n.º 5
0
 private void DeleteFile(UploadedFile file)
 {
     File.Delete(file.TempFilePathAbsolute);
 }