Black Rock Reporting Azure Function
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ReportGeneratorFunction.cs 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.IO;
  3. using Microsoft.Azure.Functions.Worker;
  4. using Microsoft.Extensions.Logging;
  5. using Microsoft.Azure.WebJobs;
  6. using GemBox.Spreadsheet;
  7. using BlackRockReportFunction.Models;
  8. using BlackRockReportFunction.Helpers;
  9. using Azure.Storage.Blobs;
  10. using BlackRockReportFunction.Bussines;
  11. namespace BlackRockReportFunction
  12. {
  13. public class ReportGeneratorFunction
  14. {
  15. private readonly ILogger _logger;
  16. public ReportGeneratorFunction(ILoggerFactory loggerFactory)
  17. {
  18. _logger = loggerFactory.CreateLogger<ReportGeneratorFunction>();
  19. }
  20. [Function("ReportGeneratorFunction")]
  21. [BlobOutput("report-container/BlackRock_Report.xslx", Connection = "AzureWebJobsStorage")]
  22. public async Task Run([QueueTrigger("queue1")] string myQueueItem)
  23. {
  24. _logger.LogInformation($"C# Queue trigger function processed: {myQueueItem}, gemboxKey: {"E0YU - JKLB - WFCE - N52P"}");
  25. var reportFile = await ReportGenerator.GenerateReportContent();
  26. string connection = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
  27. string containerName = "report-container";
  28. _logger.LogInformation(connection);
  29. var blobClient = new BlobContainerClient(connection, containerName);
  30. var blob = blobClient.GetBlobClient($"BlackRockReport_{DateTime.Now.ToString("f")}.xlsx");
  31. Stream memoryStream = new MemoryStream();
  32. reportFile.Save(memoryStream, new XlsxSaveOptions
  33. {
  34. Type = XlsxType.Xlsx
  35. });
  36. memoryStream.Position = 0;
  37. await blob.UploadAsync(memoryStream);
  38. _logger.LogInformation("File uploaded successfully!");
  39. }
  40. }
  41. }