| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System;
- using System.IO;
- using Microsoft.Azure.Functions.Worker;
- using Microsoft.Extensions.Logging;
- using Microsoft.Azure.WebJobs;
- using GemBox.Spreadsheet;
- using BlackRockReportFunction.Models;
- using BlackRockReportFunction.Helpers;
- using Azure.Storage.Blobs;
- using BlackRockReportFunction.Bussines;
- using MailKit;
- using MimeKit;
- using MimeKit.Text;
- using MailKit.Net.Smtp;
- using MailKit.Security;
- using Newtonsoft.Json;
-
- namespace BlackRockReportFunction
- {
- public class ReportGeneratorFunction
- {
- private readonly ILogger _logger;
-
- public ReportGeneratorFunction(ILoggerFactory loggerFactory)
- {
- _logger = loggerFactory.CreateLogger<ReportGeneratorFunction>();
- }
-
- [Function("ReportGeneratorFunction")]
- [BlobOutput("report-container/BlackRock_Report.xslx", Connection = "AzureWebJobsStorage")]
- public async Task Run([QueueTrigger("queue1")] string myQueueItem)
- {
- var reportObject = JsonConvert.DeserializeObject<ClockifyReport>(myQueueItem);
- var reportFile = ReportGenerator.GenerateReportContent(reportObject);
-
- string connection = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
- string containerName = "report-container";
-
- _logger.LogInformation(connection);
-
- var blobClient = new BlobContainerClient(connection, containerName);
- var blob = blobClient.GetBlobClient($"BlackRockReport_{DateTime.Now.ToString("f")}.xlsx");
-
- Stream memoryStream = new MemoryStream();
- reportFile.Save(memoryStream, new XlsxSaveOptions
- {
- Type = XlsxType.Xlsx
- });
-
- memoryStream.Position = 0;
- await blob.UploadAsync(memoryStream);
-
- _logger.LogInformation("File uploaded successfully!");
- }
- }
- }
|