Black Rock Reporting Azure Function
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.IO;
  3. using System.Threading.Tasks;
  4. using Azure.Storage.Blobs;
  5. using BlackRockReportFunction.Bussines;
  6. using ClockifyReport.Models;
  7. using Microsoft.Azure.Functions.Worker;
  8. using Microsoft.Extensions.Logging;
  9. using Newtonsoft.Json;
  10. using Spire.Xls;
  11. //using Microsoft.Azure.WebJobs;
  12. namespace ClockifyReport
  13. {
  14. public class Function2
  15. {
  16. private readonly ILogger _logger;
  17. public Function2(ILoggerFactory loggerFactory)
  18. {
  19. _logger = loggerFactory.CreateLogger<Function2>();
  20. }
  21. [Function("Function2")]
  22. [BlobOutput("report-container", Connection = "AzureWebJobsStorage")]
  23. public async Task Run([QueueTrigger("clockify-queue", Connection = "AzureWebJobsStorage")]string myQueueItem)
  24. {
  25. var reportObject = JsonConvert.DeserializeObject<Root>(myQueueItem);
  26. var reportFile = ReportGenerator.GenerateReportContent(reportObject);
  27. string connection = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
  28. string containerName = "report-container";
  29. _logger.LogInformation(connection);
  30. var blobClient = new BlobContainerClient(connection, containerName);
  31. var blob = blobClient.GetBlobClient($"BlackRockReport_{DateTime.Now.ToString("f")}.xls");
  32. MemoryStream memoryStream = new MemoryStream();
  33. reportFile.SaveToStream(memoryStream);
  34. memoryStream.Position = 0;
  35. await blob.UploadAsync(memoryStream);
  36. _logger.LogInformation("File uploaded successfully!");
  37. }
  38. }
  39. }