Esempio n. 1
0
        private static async Task <string> StoreEventImageInBlobStorage(
            Binder binder,
            TraceWriter log,
            Models.DownloadEventImage eventImageModel)
        {
            Uri uri      = new Uri(eventImageModel.ImageUrl);
            var filename = Path.GetFileName(uri.LocalPath);
            var downloadLocationForEventImage = $"eventimages/{eventImageModel.Id}/{filename}";

            using (var blobBinding = await binder.BindAsync <Stream>(
                       new BlobAttribute(downloadLocationForEventImage, FileAccess.Write)))
            {
                var webClient  = new WebClient();
                var imageBytes = await webClient.DownloadDataTaskAsync(uri);

                log.Verbose($"Writing event image for CFP `{eventImageModel.Id}` to location `{downloadLocationForEventImage}`.");
                await blobBinding.WriteAsync(imageBytes, 0, imageBytes.Length);

                return(downloadLocationForEventImage);
            }
        }
Esempio n. 2
0
        private static void UpdateRecordInTheCfpRepository(
            Models.DownloadEventImage eventImageModel,
            string relativeLocationOfStoredImage,
            TraceWriter log)
        {
            var storageAccountName    = ConfigurationManager.AppSettings["StorageAccountName"];
            var absoluteImageLocation = $"https://{storageAccountName}.blob.core.windows.net/{relativeLocationOfStoredImage}";

            var connectionstring = ConfigurationManager.AppSettings["CfpExchangeDb"];

            log.Info($"Updating the record `{eventImageModel.Id}` with the event image url to `{absoluteImageLocation}`.");
            using (var connection = new SqlConnection(connectionstring))
            {
                connection.Open();
                connection.Execute("UPDATE dbo.Cfps SET EventImage = @EventImage WHERE Id = @Id",
                                   new
                {
                    EventImage = absoluteImageLocation,
                    Id         = eventImageModel.Id.ToString("D")
                });
                log.Info($"Updated the record `{eventImageModel.Id}` with the event image url to `{absoluteImageLocation}`.");
            }
        }