public static async System.Threading.Tasks.Task RunAsync( [QueueTrigger("podcast-to-be-added-to-weekly-activity", Connection = "AzureWebJobsStorage")] PodCast podCast, Binder binder, ILogger log) { var week = Week.FromDate(podCast.Created); var blobName = $"activity-weekly/{week.Year.ToString("0000")}/{week.WeekNumber.ToString("00")}.json"; log.LogInformation($"To save to {blobName}"); var attributes = new Attribute[] { new BlobAttribute(blobName), new StorageAccountAttribute("AzureWebJobsStorage") }; var blob = await binder.BindAsync <CloudBlockBlob>(attributes); using (var locker = new CloudBlockBlobLocker <Models.WeekActivity>(blob)) { var activity = locker.IsNew ? new Models.WeekActivity(week.Year, week.WeekNumber) : await locker.Download(); activity.AddPodCast(podCast); await locker.Upload(activity); } }
public async Task Run( [TimerTrigger("0 0 0 * * Mon")] TimerInfo myTimer, ILogger log, Binder binder) { var response = await _httpClient.GetAsync(AWSIpRangesUri); var data = await response.Content.ReadAsAsync <AwsIpRangesSummary>(); string blobPath = $"aws-ip-files/{data.SyncToken}.json"; var blobAttribute = new BlobAttribute(blobPath, FileAccess.Write); var blob = await binder.BindAsync <CloudBlockBlob>(blobAttribute); var exists = await blob.ExistsAsync(); if (exists) { log.LogInformation("AWS IP file {name} already exists, skipping save", blobPath); } else { log.LogInformation("New AWS IP file found, saving {name}", blobPath); await blob.UploadTextAsync(await response.Content.ReadAsStringAsync()); } }
public static async Task <long> CopyFileToBlob( [ActivityTrigger] string filePath, Binder binder, TraceWriter log) { long byteCount = new FileInfo(filePath).Length; // strip the drive letter prefix and convert to forward slashes string blobPath = filePath .Substring(Path.GetPathRoot(filePath).Length) .Replace('\\', '/'); string outputLocation = $"backups/{blobPath}"; log.Info($"Copying '{filePath}' to '{outputLocation}'. Total bytes = {byteCount}."); // copy the file contents into a blob using (Stream source = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) using (Stream destination = await binder.BindAsync <CloudBlobStream>( new BlobAttribute(outputLocation, FileAccess.Write))) { await source.CopyToAsync(destination); } return(byteCount); }
public async Task ChangeColdStorageFeedTrigger([CosmosDBTrigger( databaseName: "ContosoAuto", collectionName: "telemetry", ConnectionStringSetting = "CosmosDBConnection", LeaseCollectionName = "leases", LeaseCollectionPrefix = "cold", CreateLeaseCollectionIfNotExists = true, StartFromBeginning = true)] IReadOnlyList <Document> vehicleEvents, Binder binder, ILogger log) { log.LogInformation($"Saving {vehicleEvents.Count} events from Cosmos DB to cold storage."); if (vehicleEvents.Count > 0) { // Use imperative binding to Azure Storage, as opposed to declarative binding. // This allows us to compute the binding parameters and set the file path dynamically during runtime. var attributes = new Attribute[] { new BlobAttribute($"telemetry/custom/scenario1/{DateTime.UtcNow:yyyy/MM/dd/HH/mm/ss-fffffff}.json", FileAccess.ReadWrite), new StorageAccountAttribute("ColdStorageAccount") }; using (var fileOutput = await binder.BindAsync <TextWriter>(attributes)) { // Write the data to Azure Storage for cold storage and batch processing requirements. // Please note: Application Insights will log Dependency errors with a 404 result code for each write. // The error is harmless since the internal Storage SDK returns a 404 when it first checks if the file already exists. // Application Insights cannot distinguish between "good" and "bad" 404 responses for these calls. These errors can be ignored for now. // For more information, see https://github.com/Azure/azure-functions-durable-extension/issues/593 fileOutput.Write(JsonConvert.SerializeObject(vehicleEvents)); } } }
public async static Task <byte[]> ProducePdf([ActivityTrigger] string[] args, ILogger log, Binder binder) { log.LogInformation($"Generating pdf document..."); //add null checks here var html = args[0]; var fileName = args[1]; // convert string html into pdf var pdf = HtmlHelper.ConvertHtmlToPdf(html); var attributes = new Attribute[] { new BlobAttribute($"output/{fileName}", FileAccess.Write), new StorageAccountAttribute("AzureWebJobsStorage") }; using (var writer = await binder.BindAsync <Stream>(attributes)) { Stream stream = new MemoryStream(pdf); await stream.CopyToAsync(writer); } // return output log.LogInformation($"Generated pdf document."); return(pdf); }
public async Task Update(Action <Models.WeekActivity> action) { var blobName = $"activity-weekly/{_week.Year.ToString("0000")}/{_week.WeekNumber.ToString("00")}.json"; _log.LogInformation($"To save to {blobName}"); var attributes = new Attribute[] { new BlobAttribute(blobName), new StorageAccountAttribute("AzureWebJobsStorage") }; var blob = await _binder.BindAsync <CloudBlockBlob>(attributes); using (var locker = new CloudBlockBlobLocker <Models.WeekActivity>(blob)) { var activity = locker.IsNew ? new Models.WeekActivity(_week.Year, _week.WeekNumber) : await locker.Download(); action(activity); await locker.Upload(activity); } }
public static async Task <long> RequestApprovalAsync( [ActivityTrigger] DurableActivityContext context, Binder binder, ILogger log) { var application = context.GetInput <ApplicationEntity>(); if (application.Content == null) { throw new ArgumentNullException(nameof(application.Content), "A content input is required."); } var twitter = new TwitterClient(); var tweetId = await twitter.TweetAsync(application.Content); log.LogInformation($"{tweetId} をツイートしました。: {application.Content}"); application.TweetId = tweetId; application.Status = ApplicationStatus.Applying; var collector = await binder.BindAsync <IAsyncCollector <ApplicationEntity> >(new CosmosDBAttribute("ApprovalFlowSample", "Applications")); await collector.AddAsync(application); return(tweetId); }
public async static Task Run([ActivityTrigger] IDurableActivityContext context, Binder binder, ILogger log) { var activityToSave = context.GetInput <Models.WeekActivity>(); var blobName = $"activity-weekly/{activityToSave.Year.ToString("0000")}/{activityToSave.WeekNumber.ToString("00")}.json"; log.LogInformation($"Preparing to update ${blobName}"); var attributes = new Attribute[] { new BlobAttribute(blobName), new StorageAccountAttribute("AzureWebJobsStorage") }; var blob = await binder.BindAsync <CloudBlockBlob>(attributes); log.LogInformation("Locking blob"); using (var locker = new CloudBlockBlobLocker <Models.WeekActivity>(blob)) { if (locker.IsNew) { log.LogInformation("Uploading new blob"); await locker.Upload(activityToSave); } else { var mergedActivity = await locker.Download(); if (activityToSave.Blogs != null) { mergedActivity.Blogs = activityToSave.Blogs; } if (activityToSave.Clients != null) { mergedActivity.Clients = activityToSave.Clients; } if (activityToSave.Focus != null) { mergedActivity.Focus = activityToSave.Focus; } if (activityToSave.Pluralsight != null) { mergedActivity.Pluralsight = activityToSave.Pluralsight; } if (activityToSave.PodCasts != null) { mergedActivity.PodCasts = activityToSave.PodCasts; } if (activityToSave.Skills != null) { mergedActivity.Skills = activityToSave.Skills; } log.LogInformation("Uploading merged blob"); await locker.Upload(mergedActivity); } } }
private static async Task StoreResultInBlobAsync(Binder binder, string title, byte[] doc) { using (var stream = await binder.BindAsync <Stream>(new BlobAttribute($"printouts/{title}.pdf", FileAccess.Write))) { using (var writer = new BinaryWriter(stream)) { writer.Write(doc); } } }
private static async Task <string> UploadContentToBlob(HttpContent content, string blobFileName, Binder binder) { var blobPath = $"buildlogs/{blobFileName}"; using (var stream = await binder.BindAsync <Stream>(new BlobAttribute(blobPath, FileAccess.Write))) { await content.CopyToAsync(stream).ContinueWith(copyTask => { stream.Close(); }); } return(ConfigurationManager.AppSettings["DiagBlobUrl"] + "/" + blobPath); }
private static async Task DeleteQRCodeAsync(string vanityUrl, Binder binder) { StorageAccountAttribute storageAccountAttribute = new StorageAccountAttribute("AzureWebJobsStorage"); CloudStorageAccount storageAccount = await binder.BindAsync <CloudStorageAccount>(storageAccountAttribute); CloudBlobClient client = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = client.GetContainerReference(QRCODECONTAINER); CloudBlockBlob blob = container.GetBlockBlobReference($"{vanityUrl}.png"); await blob.DeleteIfExistsAsync(); }
public static async Task Run( [QueueTrigger("filemetadataproductionistest", Connection = "QueueStorage")] CloudQueueMessage myQueueItem, Binder binder, ILogger log) { //log.LogInformation($"C# Queue trigger function processed: {myQueueItem}"); var dto = JsonConvert.DeserializeObject <DocumentDto>(myQueueItem.AsString); var blobName = dto.AzureFileName; //todo get blob from storage (by guid from the queue) var attributes = new Attribute[] { new BlobAttribute("docstoragecontaineristest/" + blobName), new StorageAccountAttribute("AzureWebJobsStorage") }; CloudBlockBlob blob = await binder.BindAsync <CloudBlockBlob>(attributes); dto.DocumentContent = new byte[dto.DocumentContentLenght]; var result = blob.DownloadToByteArrayAsync(dto.DocumentContent, 0).Result; //dto.DocumentContent = ReadBlob("docstoragecontaineristest", blobName, dto.DocumentContentLenght); var connectionString = Environment.GetEnvironmentVariable("AdventureWorksDatabase"); var optionsBuilder = new DbContextOptionsBuilder <AdventureWorks2016Context>(); optionsBuilder.UseSqlServer(connectionString); using (var context = new AdventureWorks2016Context(optionsBuilder.Options)) { // add doc to the db //var owner = context.Employee.Where(x => x.BusinessEntityId == 1).FirstOrDefault(); var docId = context.GetNextDocId(); context.Document.Add(new Document() { ChangeNumber = 1, DocumentContent = dto.DocumentContent, DocumentNode = docId, DocumentSummary = dto.DocumentMetadata, FileExtension = Path.GetExtension(dto.FileName), FileName = dto.FileName, FolderFlag = false, ModifiedDate = DateTime.Now, Owner = 1, Revision = "", Rowguid = Guid.NewGuid(), Status = 1, Title = dto.DocumentName }); context.SaveChanges(); } }
public static async Task MarkRejectedAsync( [ActivityTrigger] DurableActivityContext context, Binder binder) { var application = context.GetInput <ApplicationEntity>(); application.Status = ApplicationStatus.Rejected; var collector = await binder.BindAsync <IAsyncCollector <ApplicationEntity> >(new CosmosDBAttribute("ApprovalFlowSample", "Applications")); await collector.AddAsync(application); }
private static async Task WriteImageToBlob(Binder binder, string identifier, byte[] bytes) { var attributes = new Attribute[] { new BlobAttribute($"raw-images/{identifier}", FileAccess.Write), new StorageAccountAttribute(Constants.StoreConnectionName) }; using (var writer = await binder.BindAsync <Stream>(attributes).ConfigureAwait(false)) { await writer.WriteAsync(bytes, 0, bytes.Length); } }
private static async Task WriteData(string data, Binder binder) { var account = "SCCMT_STORAGE"; var queue = "content"; var attributes = new Attribute[] { new QueueAttribute(queue), new StorageAccountAttribute(account) }; var output = await binder.BindAsync <CloudQueue>(attributes); await output.AddMessageAsync(new CloudQueueMessage(data)); }
public async Task Run([ActivityTrigger] BulkImportStatus myJobs, Binder binder, ILogger log) { var report = _reportService.CreateImportReport(myJobs); var attributes = new Attribute[] { new BlobAttribute($"{myJobs.Container}/Report/{myJobs.Name}.report.txt", FileAccess.Write), new StorageAccountAttribute("Storage") }; using (var writer = await binder.BindAsync <TextWriter>(attributes)) { await writer.WriteAsync(report); } }
public async static Task Initiate( [TimerTrigger("0 0/30 * * * *", RunOnStartup = true)] TimerInfo myTimer, [Queue("%TripDetectionQueue%")] ICollector <string> outgoingMessage, Binder binder, TraceWriter log) { using (var trackableContext = new TrackableContext(log)) { await trackableContext.ExecuteAsync(async() => { var logger = trackableContext.LoggerFactory.CreateLogger("PipelineExecuter"); logger.LogInformation("Running pipleine initiator at {0}", myTimer.ScheduleStatus.Last); // Load asset ids and configured trip detector var tripDetector = await trackableContext.TripDetectorFactory.Create(); var assetIds = (await trackableContext.AssetRepository.GetAllAsync()).Select(a => a.Id); logger.LogDebugSerialize("Loaded AssetIds {0}", assetIds); // Create a new message for each assetId foreach (var assetId in assetIds) { var blobPath = $"{ myTimer.ScheduleStatus.Last.ToString() }::{ assetId }"; var blobAttributes = new Attribute[] { new BlobAttribute($"{Utils.GetAppSetting("TripDetectionContainerName")}/{blobPath}", FileAccess.Write) }; using (var outStream = await binder.BindAsync <Stream>(blobAttributes)) { var formatter = new BinaryFormatter(); formatter.Serialize(outStream, new AzurePipelineState { TripDetectorType = (int)tripDetector.TripDetectorType, ModuleIndex = 0, Payload = assetId }); outStream.Close(); } logger.LogInformation("wrote blob for asset {0}", assetId); outgoingMessage.Add(blobPath); logger.LogInformation("wrote queue message for asset {0}", assetId); } }); } }
public static async Task Run( [TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, Binder binder, ILogger log) { log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}"); var outputContainerName = "mycontainer"; var outputBlobName = DateTime.UtcNow.ToString("yyyy-MM-dd-HH-mm-ss"); var outputBlobAttr = new BlobAttribute($"{outputContainerName}/{outputBlobName}", FileAccess.Write); using (var outputFile = await binder.BindAsync <TextWriter>(outputBlobAttr)) { await outputFile.WriteAsync($"processed at {DateTime.UtcNow.ToString("s")}"); } }
public static async Task RunAsync( [QueueTrigger("httpqueue", Connection = "OnSchedulingToMMMQueueTriggered:SourceQueueConnection")] Payload myQueueItem, [Blob("processed/{CorrelationId}", FileAccess.Write, Connection = "OnSchedulingToMMMQueueTriggered:ProcessedPayloadsConnectionString")] Stream processedPayload, Binder binder, //<--NOTE *Binder* not *IBinder* ILogger log) { log.LogInformation($"C# Queue trigger function processed: {myQueueItem.Body}"); var attributes = new Attribute[] { new BlobAttribute("success/{CorrelationId}"), new StorageAccountAttribute("MyStorageAccount") }; using (var writer = await binder.BindAsync <TextWriter>(attributes)) { writer.Write(JsonConvert.SerializeObject(myQueueItem.Body)); } }
private static async Task <IAsyncCollector <MinifiedUrl> > CreateOutputBinding(Binder binder) { var secret = new Secret(); var connectionString = await secret.Get("CosmosConnectionStringSecret"); ConfigurationManager.AppSettings["CosmosConnectionString"] = connectionString; var output = await binder.BindAsync <IAsyncCollector <MinifiedUrl> >( new DocumentDBAttribute("TablesDB", "minified-urls") { CreateIfNotExists = true, ConnectionStringSetting = "CosmosConnectionString", }); return(output); }
public async Task Run([BlobTrigger("import-person/{name}")] Stream myBlob, [DurableClient] IDurableOrchestrationClient starter, Binder binder, string name, ILogger log) { if (name.Contains(".report.txt") == false) { log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes"); string report; try { var importJobs = await _importPersonHandler.Handle(myBlob); importJobs.Id = Guid.NewGuid().ToString(); importJobs.Name = name; importJobs.Container = _container; report = _reportService.CreateImportReport(importJobs); if (importJobs.ImportFileIsValid) { string instanceId = await starter.StartNewAsync("MonitorBulkImport", importJobs.Id, importJobs); } myBlob.Close(); await _blobService.DeleteFile(name, _container); } catch (Exception ex) { report = $"Unable to import person CSV: {ex}"; log.LogError(report); throw; } var attributes = new Attribute[] { new BlobAttribute($"{_container}/Report/{name}.report.txt", FileAccess.Write), new StorageAccountAttribute("Storage") }; using (var writer = await binder.BindAsync <TextWriter>(attributes)) { await writer.WriteAsync(report); } } }
public static async Task ServiceBusBinderTest( string message, int numMessages, Binder binder) { var attribute = new ServiceBusAttribute(BinderQueueName) { EntityType = EntityType.Queue }; var collector = await binder.BindAsync <IAsyncCollector <string> >(attribute); for (int i = 0; i < numMessages; i++) { await collector.AddAsync(message + i); } await collector.FlushAsync(); }
public static async void Run([BlobTrigger("xmlfiles/{name}.xml", Connection = "BLOB_STORAGE")] CloudBlockBlob xmlData, string name, Binder binder, TraceWriter log) { string node = "ParseNode"; log.Info($"C# Blob trigger function Processed blob\n Name:{name}\n Node:{node}"); string path = $"{name}"; string json = ""; MemoryStream ms = new MemoryStream(); await xmlData.DownloadToStreamAsync(ms); ms.Seek(0, 0); XmlDocument doc = new XmlDocument(); doc.Load(ms); XmlNodeList nodes = doc.SelectNodes("node"); for (int i = 0; i < nodes.Count; i++) { json += JsonConvert.SerializeXmlNode(nodes[i], Newtonsoft.Json.Formatting.Indented, true); } byte[] b = Encoding.UTF8.GetBytes(json); /////// Save JSON /////////// var attributes = new System.Attribute[] { new BlobAttribute($"jsonfiles/{path}.json", FileAccess.Write), new StorageAccountAttribute("BLOB_STORAGE") }; using (var stream = await binder.BindAsync <Stream>(attributes)) { stream.Write(b, 0, b.Length); stream.Flush(); } await xmlData.DeleteIfExistsAsync(); }
public async static Task <string> Run([ActivityTrigger] object[] args, ILogger log, Binder binder) { log.LogInformation($"Replacing html content..."); //add null checks here string templateName = args[0].ToString(); dynamic json = args[1]; // retrieve the template from blob storage var html = await binder.BindAsync <string>(new BlobAttribute(templateName, FileAccess.Read)); //update the contents var replacedContents = HtmlHelper.InsertJsonIntoHtml(html, json); log.LogInformation($"Replaced html content."); // return output return(replacedContents); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log, Binder binder) { log.LogInformation("C# HTTP trigger function processed a request."); // var Token_url = Environment.GetEnvironmentVariable("Token_url_name"); var Token_url = "https://joetest.tokenstore.azure.net/services/dropbox/tokens/sampleToken"; // An implicit binding is used here to access the Token_service param from app settings TokenStoreInputBindingAttribute attribute = new TokenStoreInputBindingAttribute(Token_url, "tokenName", "aad"); // Initialize TokenStoreBinding var outputToken = await binder.BindAsync <string>(attribute); log.LogInformation($"The output token is: {outputToken}"); var filesList = new List <string>(); if (!string.IsNullOrEmpty(outputToken)) { using (var dbx = new DropboxClient(outputToken)) { var list = await dbx.Files.ListFolderAsync(string.Empty); // show folders then files foreach (var item in list.Entries.Where(i => i.IsFolder)) { filesList.Add($"{item.Name}/"); } foreach (var item in list.Entries.Where(i => i.IsFile)) { filesList.Add($"{item.Name} \n"); } } } System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach (var file in filesList) { sb.Append(file); } return((ActionResult) new OkObjectResult($"Files: \n {sb.ToString()}")); }
//[StorageAccount("sshack-blob-connection")] public static async Task Run( [QueueTrigger("request-queue")] BaseInfo info, Binder binder, ILogger log) { string fileName = $"{info.Command.FromTime.ToString("yyyyMMddHHmmss")}.json"; string outputLocation = $"{info.RequestID}/{fileName}"; if (info.RecordCount == 0) { info.RecordCount = 200000; } var records = populateData(info.RequestID, info.RecordCount); log.LogInformation($"[INFO] {fileName} Started : {DateTime.Now.ToString()}"); #region JsonSerialize and Create Blob //JsonSerializer js = new JsonSerializer(); //using (TextWriter blob = await binder.BindAsync<TextWriter>( // new BlobAttribute(outputLocation, FileAccess.Write))) //{ // js.Serialize(blob, records); //} #endregion using (Stream stream = SerializeToStream(records)) { stream.Position = 0; using (Stream destination = await binder.BindAsync <CloudBlobStream>( new BlobAttribute(outputLocation, FileAccess.Write))) { await stream.CopyToAsync(destination); } } //using (MemoryStream stream = SerializeToStream(records)) //{ // stream.Position = 0; // await CreateBlob(stream, info.RequestID, fileName); //} log.LogInformation($"[INFO] {fileName} Ended : {DateTime.Now.ToString()}"); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log, Binder binder) { // parse query parameter log.Info("Going to read the file."); var attributes = new Attribute[] { //new StorageAccountAttribute("MyStorageAccount"), new BlobAttribute("ilr-files/ILR-10006341-1718-20171107-113456-01.xml") }; Message message; var sw = new Stopwatch(); sw.Start(); var ilrText = await binder.BindAsync <string>(attributes); sw.Stop(); log.Info("Read the file-time it took: " + sw.Elapsed); sw.Restart(); // var stream = new FileStream(@"Files\ILR-10006341-1718-20171107-113456-01.xml", FileMode.Open); using (var reader = new StringReader(ilrText)) { var serializer = new XmlSerializer(typeof(Message)); message = serializer.Deserialize(reader) as Message; } sw.Stop(); log.Info("Deserailized the file-time it took: " + sw.Elapsed); log.Info("total learners:" + message.Learner.Length); IValidationService validationService = new ValidationService.Service.Implementation.RuleManagerValidationService(new RuleManager(ConfigureBuilder()), null); //var validationErrors = validationService.Validate(message); log.Info("C# HTTP trigger function processed a request."); return(req.CreateResponse(HttpStatusCode.OK, "Yay!Success")); }
public async Task Run([TimerTrigger("%Functions:DataMartImportSchedule%")] TimerInfo myTimer, [DurableClient] IDurableOrchestrationClient starter, Binder binder, ILogger log) { log.LogInformation($"Import Datamart data Timer function triggered, Schedule: {myTimer.Schedule.ToString()}"); await _configureDataModelHandler.ConfigureDataModel(_dataMartConfigs); string report; BulkImportStatus importJobsStatus; foreach (var dataMartConfig in _dataMartConfigs) { try { importJobsStatus = await _importDataMartHandler.Handle(dataMartConfig); importJobsStatus.Id = Guid.NewGuid().ToString(); importJobsStatus.Name = $"Data-Mart/{dataMartConfig.ObjectName}/Import-{DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture)}"; importJobsStatus.Container = _container; report = _reportService.CreateImportReport(importJobsStatus); string instanceId = await starter.StartNewAsync("MonitorBulkImport", importJobsStatus.Id, importJobsStatus); } catch (Exception ex) { report = $"Unable to import custom object {dataMartConfig.ObjectName}: {ex}"; log.LogError(report); throw; } var attributes = new Attribute[] { new BlobAttribute($"{_container}/Report/{importJobsStatus.Name}.report.txt", FileAccess.Write), new StorageAccountAttribute("Storage") }; using (var writer = await binder.BindAsync <TextWriter>(attributes)) { await writer.WriteAsync(report); } } }
public static async Task <IActionResult> GetQueueMessageCount( [HttpTrigger(AuthorizationLevel.Admin, "get", Route = "queue/{version}/{queueName}/count")] HttpRequest req, Binder binder, string version, string queueName, ILogger log) { log.LogInformation($"Retrieving '{queueName}' queue count."); var queue = await binder.BindAsync <CloudQueue>(new Attribute[] { new QueueAttribute(queueName) }); if (!await queue.ExistsAsync()) { return(new NotFoundObjectResult($"Queue '{queueName}' does not exist")); } await queue.FetchAttributesAsync(); return(new OkObjectResult(queue.ApproximateMessageCount)); }
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); } }