static public ImageProcessingResult Process(string imageName, IBinaryRepository binaryRepository) { var log = new EventLog("Application") { Source = "Tadmap" }; log.WriteEntry("Processing image:" + imageName, EventLogEntryType.Information); Stream binary = binaryRepository.GetBinary(imageName); if (binary == null) { log.WriteEntry("No binary found:" + imageName, EventLogEntryType.Warning); return new ImageProcessingResult { Key = imageName, Result = ImageProcessingResult.ResultType.Failed }; // Image not available in the queue yet. } // If I have an image I should renew the message. IImageSet imageSet = new ImageSet1(imageName); int zoomLevels; int tileSize; imageSet.Create(binary, binaryRepository, out zoomLevels, out tileSize); log.WriteEntry("Processing finished.", EventLogEntryType.Information); return new ImageProcessingResult { Key = imageName, Result = ImageProcessingResult.ResultType.Complete, ZoomLevel = zoomLevels, TileSize = tileSize }; }
public UserImagesController(IImageRepository imageRepository, IBinaryRepository binaryRepository) { ActionInvoker = new ActionInvokers.ActionInvoker(); ImageRepository = imageRepository; BinaryRepository = binaryRepository; }
public void Create( System.IO.Stream stream, IBinaryRepository binaryRepository, out int zoomLevels, out int tileSize ) { using (System.Drawing.Bitmap oImage = Bitmap.FromStream(stream, true, true) as Bitmap) { using (System.Drawing.Image oSquare = ImageManipulator.ResizeAndCrop(oImage, 80, 80)) { using (MemoryStream oMemoryStream = new MemoryStream()) { oSquare.Save(oMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); oMemoryStream.Position = 0; binaryRepository.Add(oMemoryStream, Square, "image/jpeg"); } } using (System.Drawing.Image oThumb = ImageManipulator.FitToRectangle(oImage, 100, 100)) { using (MemoryStream oMemoryStream = new MemoryStream()) { oThumb.Save(oMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); oMemoryStream.Position = 0; binaryRepository.Add(oMemoryStream, Thumb, "image/jpeg"); } } using (System.Drawing.Image oLargeThumb = ImageManipulator.FitToRectangle(oImage, 200, 200)) { using (MemoryStream oMemoryStream = new MemoryStream()) { oLargeThumb.Save(oMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); oMemoryStream.Position = 0; binaryRepository.Add(oMemoryStream, LargeThumb, "image/jpeg"); } } using (System.Drawing.Image oLargeThumb = ImageManipulator.FitToRectangle(oImage, 560, 560)) { using (MemoryStream oMemoryStream = new MemoryStream()) { oLargeThumb.Save(oMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); oMemoryStream.Position = 0; binaryRepository.Add(oMemoryStream, Preview, "image/jpeg"); } } CreateTileSet(binaryRepository, oImage, Key, out zoomLevels, out tileSize); } stream.Position = 0; }
public void ConstructController() { _binaryStorage = new List<BinaryRepository.Data>(); _binaryRepository = new BinaryRepository(_binaryStorage); _imageRepository = new ImageRepository(); _queue = new MessageQueue(); _controller = new UploadController(_imageRepository, _binaryRepository, _queue, MockRepository.GenerateMock<FileUploaderAdapter>()); }
public ImageService( IBinaryRepository binaryRepository, [Dependency("images")] IMessageQueue imageQueue, [Dependency("complete")] IMessageQueue completeQueue ) { _binaryRepository = binaryRepository; _imageQueue = imageQueue; _completeQueue = completeQueue; InitializeComponent(); }
public UploadController( IImageRepository imageRepository, IBinaryRepository binaryRepository, [Dependency("Image")] IMessageQueue messageQueue, FileUploaderAdapter adapter ) { ActionInvoker = new ActionInvokers.ActionInvoker(); _imageRepository = imageRepository; _binaryRepository = binaryRepository; _messageQueue = messageQueue; _adapter = adapter; }
public void Create(System.IO.Stream stream, IBinaryRepository binaryRepository) { using (System.Drawing.Bitmap oImage = Bitmap.FromStream(stream, true, true) as Bitmap) { using (System.Drawing.Image oSquare = ImageManipulator.ResizeAndCrop(oImage, 80, 80)) { using (MemoryStream oMemoryStream = new MemoryStream()) { oSquare.Save(oMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); oMemoryStream.Position = 0; binaryRepository.Add(oMemoryStream, Square, "image/jpeg"); } } using (System.Drawing.Image oThumb = ImageManipulator.FitToRectangle(oImage, 100, 100)) { using (MemoryStream oMemoryStream = new MemoryStream()) { oThumb.Save(oMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); oMemoryStream.Position = 0; binaryRepository.Add(oMemoryStream, Thumb, "image/jpeg"); } } using (System.Drawing.Image oLargeThumb = ImageManipulator.FitToRectangle(oImage, 200, 200)) { using (MemoryStream oMemoryStream = new MemoryStream()) { oLargeThumb.Save(oMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); oMemoryStream.Position = 0; binaryRepository.Add(oMemoryStream, LargeThumb, "image/jpeg"); } } using (System.Drawing.Image oLargeThumb = ImageManipulator.FitToRectangle(oImage, 560, 560)) { using (MemoryStream oMemoryStream = new MemoryStream()) { oLargeThumb.Save(oMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); oMemoryStream.Position = 0; binaryRepository.Add(oMemoryStream, Preview, "image/jpeg"); } } } stream.Position = 0; binaryRepository.Add(stream, Original, ThreeSharpUtils.ConvertExtensionToMimeType(Path.GetExtension(Key))); }
public IQueryable<TadmapImage> GetAllImages(IBinaryRepository binaryRepository) { TadmapDb db = new TadmapDb(); return from i in db.UserImages select new TadmapImage(binaryRepository) { Id = i.Id, Title = i.Title, Description = i.Description, Key = i.Key, IsPublic = i.Privacy == 1, IsOffensive = i.OffensiveCount > 0, OwnerName = i.User.UserOpenIds.Single().OpenIdUrl, ImageSet = new ImageSet1(i.Key) }; }
public ImageRepository(IBinaryRepository binaryRepository) { _images = new List<TadmapImage>(); for (int i = 0; i < 10; i++) _images.Add( new TadmapImage(binaryRepository) { Id = new Guid("16b4d816-2e1e-4d54-9b66-78ef0fb7cbf" + i), Description = "description", Key = "Key", Title = "Title " + i, IsPublic = i < 5, OwnerName = "the owner", ImageSet = new ImageSet1("Key") } ); _images[0].IsOffensive = true; _images[9].IsOffensive = true; }
public TadmapImage( Guid id, string title, string description, string key, bool isPublic, bool isOffensive, Guid userId, IImageRepository imageRepository, IBinaryRepository binaryRepository ) { _imageRepository = imageRepository; _binaryRepository = binaryRepository; Id = id; Title = title; Description = description; Key = key; IsPublic = isPublic; IsOffensive = isOffensive; UserId = userId; }
public void CreateTileSet( IBinaryRepository binaryRepository, System.Drawing.Bitmap image, string key, out int zoomLevels, out int tileSize ) { double iZoomLevel = 0; double iMaxDimension = Math.Max(image.Width, image.Height); int iTileSize = Convert.ToInt32(iMaxDimension); while (iTileSize > 359) { iZoomLevel++; iTileSize = Convert.ToInt32(iMaxDimension / Math.Pow(2, iZoomLevel)); } zoomLevels = Convert.ToInt32(iZoomLevel); tileSize = iTileSize; int iImageSize = Convert.ToInt32(iMaxDimension); Bitmap oBaseImage = ImageManipulator.CenterImage(image, iImageSize, iImageSize); while (iZoomLevel >= 0) { iImageSize = Convert.ToInt32(iTileSize * Math.Pow(2, iZoomLevel)); using (Bitmap oZoomedImage = ImageManipulator.Resize(oBaseImage, iImageSize, iImageSize)) { List<List<Bitmap>> oTiles = ImageManipulator.CreateTiles(oZoomedImage, iTileSize); for (int i = 0; i < oTiles.Count; i++) { for (int j = 0; j < oTiles[i].Count; j++) { bool bUploaded = false; int tryCount = 0; while (bUploaded == false && tryCount < 3) { try { using (MemoryStream oStream = new MemoryStream()) { oTiles[i][j].Save(oStream, System.Drawing.Imaging.ImageFormat.Png); oStream.Position = 0; binaryRepository.Add( oStream, string.Format(CultureInfo.InvariantCulture, "Tile_{0}_{1}_{2}_{3}", j, i, iZoomLevel, key), "image.jpeg" ); bUploaded = true; } } catch (BinaryRepositoryException oException) { tryCount++; if (tryCount > 3) { throw new BinaryRepositoryException("Failed to add tile on third attempt.", oException); } } } } } } iZoomLevel--; } }
public TadmapImage(IBinaryRepository binaryRepository) { _binaryRepository = binaryRepository; }
public TadmapImage() { _imageRepository = new SqlImageRepository(); _binaryRepository = new S3BinaryRepository(); }
public HomeController(IImageRepository imageRepository, IBinaryRepository binaryRepository) { ImageRepository = imageRepository; BinaryRepository = binaryRepository; }
public void Create(System.IO.Stream stream, IBinaryRepository binaryRepository) { throw new NotImplementedException(); }
public UserImagesController(IImageRepository imageRepository, IBinaryRepository binaryRepository) { ImageRepository = imageRepository; BinaryRepository = binaryRepository; }
public ImageController(IImageRepository imageRepository, IBinaryRepository binaryRepository) { _imageRepository = imageRepository; _binaryRepository = binaryRepository; }
public IQueryable<TadmapImage> GetAllImages(IBinaryRepository binaryRepository) { return _images.AsQueryable(); }
public UploadController(IImageRepository imageRepository, IBinaryRepository binaryRepository) { ActionInvoker = new ActionInvokers.ActionInvoker(); _imageRepository = imageRepository; _binaryRepository = binaryRepository; }
public ImageController() { ActionInvoker = new ActionInvokers.ActionInvoker(); _imageRepository = new SqlImageRepository(); _binaryRepository = new S3BinaryRepository(); }