예제 #1
0
        static void Main(string[] args)
        {
            // Setup Storage
            var storageAccessor = new StorageAccessor(ConfigurationManager.AppSettings["StorageConnectionString"]);

            // Get Message Off the Queue
            AzureQueueService azureQueueService = new AzureQueueService(storageAccessor.CreateQueueClient(), "image-resize");
            var message = azureQueueService.GetMessage();
            var resizeImageMessage = JsonConvert.DeserializeObject<ResizeImageMessage>(message.AsString);

            // Download Image From Blob Storage
            var blobStorageService = new BlobStorageService(storageAccessor.CreateBlobClient(), "uploads");
            byte[] image = blobStorageService.DownloadImage(resizeImageMessage.BlobUrl);

            // Resize Image
            var imageManipulator = new ImageManipulator();
            byte[] thumbnail = imageManipulator.ResizeImage(image, 200);

            // Upload Thumbnail to Blob Storage
            var thumbnailUrl = GetThumbnailUrl(resizeImageMessage.BlobUrl);
            blobStorageService.UploadImage(thumbnail, thumbnailUrl);

            // Update User with Thumbnail
            TableStorageService tableStorageService = new TableStorageService(storageAccessor.CreateTableClient(), "Users");
            User user = tableStorageService.Find(resizeImageMessage.UserId, resizeImageMessage.UserEmail);
            user.SetAvatarUrl(thumbnailUrl);
            tableStorageService.Update(user);

            azureQueueService.DeleteMessage(message);

            Console.WriteLine("Finished Processing Image.");
            Console.Read();
        }