Exemple #1
0
        public async Task runQueue()
        {
            foreach (CloudQueueMessage message in cQueue.GetMessages(5))
            {
                //Deserialize
                MyImage img = JsonConvert.DeserializeObject <MyImage>(message.AsString);

                //Retrieve reference to a blob
                CloudBlockBlob blobImage = generateOriginalImageContainer().
                                           GetBlockBlobReference(FileNameCorrector.makeValidFileName(img.fileName));

                using (var st = new MemoryStream())
                {
                    //Download to stream
                    await blobImage.DownloadToStreamAsync(st);

                    //Resize image
                    Bitmap newImage = ImageResizeController.ResizeImage(Image.FromStream(st), Constants.imageWidth, Constants.imageHeight);

                    //Generate container for resized images
                    CloudBlobContainer resizedImageContainer = await generateResizedImageContainer();

                    //Retrieve reference to a blob
                    CloudBlockBlob blob = resizedImageContainer.GetBlockBlobReference(FileNameCorrector.makeValidFileName(img.fileName));

                    if (blob.Exists())
                    {
                        blob = resizedImageContainer.GetBlockBlobReference(FileNameCorrector.makeValidFileName(Path.GetFileNameWithoutExtension(img.fileName) + Guid.NewGuid().ToString() + Path.GetExtension(img.fileName)));
                    }

                    //Convert image to byte
                    byte[] data = ImageResizeController.ImageToByte(newImage);

                    await blob.UploadFromByteArrayAsync(data, 0, data.Length);

                    await cQueue.DeleteMessageAsync(message);
                }
            }
            await cQueue.ClearAsync();
        }
Exemple #2
0
        public void insertQueue(MyImage image)
        {
            CloudQueueMessage message = new CloudQueueMessage(JsonConvert.SerializeObject(image));

            cQueue.AddMessageAsync(message);
        }
 public void insertQueue(MyImage image)
 {
     CloudQueueMessage message = new CloudQueueMessage(JsonConvert.SerializeObject(image));
     cQueue.AddMessageAsync(message);
 }