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

            // Table Storage
            TableStorageService tableStorageService = new TableStorageService(storageAccessor.CreateTableClient(), "Users");
            User user = new User(Internet.Email(), Name.First(), Name.Last());
            tableStorageService.Add(user);

            // Blob Storage
            var blobStorageService = new BlobStorageService(storageAccessor.CreateBlobClient(), "uploads");
            var blobLocation = string.Format("{0}/{1}.jpg", user.Id, Guid.NewGuid().ToString("N"));
            Image avatar = Image.FromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Images\Avatar-AirBender.jpg"));
            blobStorageService.UploadImage(avatar, blobLocation);

            // Azure Queues
            AzureQueueService azureQueueService = new AzureQueueService(storageAccessor.CreateQueueClient(), "image-resize");
            azureQueueService.AddMessage(new ResizeImageMessage(user.Id, user.Email, blobLocation));

            Console.WriteLine("User Details");
            Console.WriteLine("Id : {0}", user.Id);
            Console.WriteLine("Email : {0}", user.Email);
            Console.WriteLine("First Name : {0}", user.FirstName);
            Console.WriteLine("Last Name : {0}", user.LastName);
            Console.WriteLine("Avatar Url : {0}", user.AvatarUrl);

            Console.WriteLine();
            Console.WriteLine("Blob Url : {0}", blobLocation);

            Console.Read();
        }
Beispiel #2
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();
        }