| public const string DefaultFontName = "Calibri"; | public const string DefaultFontName = "Calibri"; | ||||
| public const int DefaultFontSize = 20; | public const int DefaultFontSize = 20; | ||||
| public static ExcelFile GenerateReportContent() | |||||
| public static ExcelFile GenerateReportContent(ClockifyReport reportObject) | |||||
| { | { | ||||
| string licenseKey = Environment.GetEnvironmentVariable("GemBoxLicenseKey"); | string licenseKey = Environment.GetEnvironmentVariable("GemBoxLicenseKey"); | ||||
| SpreadsheetInfo.SetLicense(licenseKey); | SpreadsheetInfo.SetLicense(licenseKey); | ||||
| var testObject = new ClockifyReport | |||||
| { | |||||
| reportName = "BlackRockReport_20220615", | |||||
| reportDescription = "Total (13/06/2022 - 15/06/2022)", | |||||
| reportPeople = new List<Person> | |||||
| { | |||||
| new Person | |||||
| { | |||||
| fullName = "Nikola Jovanovic", | |||||
| records = new List<ClockifyRecord> | |||||
| { | |||||
| new ClockifyRecord | |||||
| { | |||||
| recordDescription = "massa placerat duis ultricies lacus sed turpis tincidunt id aliquet risus feugiat in ante metus dictum at tempor commodo ullamcorper", | |||||
| recordTime = new TimeOnly(3,15,44), | |||||
| amount = 200 | |||||
| }, | |||||
| new ClockifyRecord | |||||
| { | |||||
| recordDescription = "et tortor at risus viverra adipiscing at in tellus integer feugiat scelerisque varius morbi enim nunc faucibus a pellentesque sit", | |||||
| recordTime = new TimeOnly(3,15,44), | |||||
| amount = 150 | |||||
| } | |||||
| } | |||||
| }, | |||||
| new Person | |||||
| { | |||||
| fullName = "Boris Stevanovic", | |||||
| records = new List<ClockifyRecord> | |||||
| { | |||||
| new ClockifyRecord | |||||
| { | |||||
| recordDescription = "iaculis urna id volutpat lacus laoreet non curabitur gravida arcu ac tortor dignissim convallis aenean et tortor at risus viverra", | |||||
| recordTime = new TimeOnly(3,15,44), | |||||
| amount = 300 | |||||
| }, | |||||
| new ClockifyRecord | |||||
| { | |||||
| recordDescription = "gravida arcu ac tortor dignissim convallis aenean et tortor at risus viverra adipiscing at in tellus integer feugiat scelerisque varius", | |||||
| recordTime = new TimeOnly(3,15,44), | |||||
| amount = 100 | |||||
| }, | |||||
| new ClockifyRecord | |||||
| { | |||||
| recordDescription = "sit amet massa vitae tortor condimentum lacinia quis vel eros donec ac odio tempor orci dapibus ultrices in iaculis nunc", | |||||
| recordTime = new TimeOnly(3,15,44), | |||||
| amount = 120 | |||||
| } | |||||
| } | |||||
| }, | |||||
| new Person | |||||
| { | |||||
| fullName = "Dunja Stevanovic", | |||||
| records = new List<ClockifyRecord> | |||||
| { | |||||
| new ClockifyRecord | |||||
| { | |||||
| recordDescription = "vulputate mi sit amet mauris commodo quis imperdiet massa tincidunt nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc", | |||||
| recordTime = new TimeOnly(3,15,44), | |||||
| amount = 50 | |||||
| }, | |||||
| new ClockifyRecord | |||||
| { | |||||
| recordDescription = "senectus et netus et malesuada fames ac turpis egestas maecenas pharetra convallis posuere morbi leo urna molestie at elementum eu", | |||||
| recordTime = new TimeOnly(3,15,44), | |||||
| amount = 500 | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| }; | |||||
| var excelFile = new ExcelFile(); | var excelFile = new ExcelFile(); | ||||
| var ws = excelFile.Worksheets.Add("Content"); | var ws = excelFile.Worksheets.Add("Content"); | ||||
| VerticalAlignment = VerticalAlignmentStyle.Center, | VerticalAlignment = VerticalAlignmentStyle.Center, | ||||
| }; | }; | ||||
| AddReportItems(testObject, ws, sectionStyle, mainDetailsStyle, normalDetailsStyle); | |||||
| AddReportItems(reportObject, ws, sectionStyle, mainDetailsStyle, normalDetailsStyle); | |||||
| // Autofit | // Autofit | ||||
| AutoFitReport(excelFile); | AutoFitReport(excelFile); |
| using BlackRockReportFunction.Bussines; | using BlackRockReportFunction.Bussines; | ||||
| using Microsoft.Azure.Functions.Worker; | using Microsoft.Azure.Functions.Worker; | ||||
| using Microsoft.Extensions.Logging; | using Microsoft.Extensions.Logging; | ||||
| using BlackRockReportFunction.Models; | |||||
| using Newtonsoft.Json; | |||||
| namespace BlackRockReportFunction | namespace BlackRockReportFunction | ||||
| { | { | ||||
| } | } | ||||
| [Function("ClockifyApiIntegrationFunction")] | [Function("ClockifyApiIntegrationFunction")] | ||||
| public void Run([TimerTrigger("* * * */5 * *")] MyInfo myTimer) | |||||
| [QueueOutput("queue1")] | |||||
| public string Run([TimerTrigger("*/15 * * * * *")] MyInfo myTimer) | |||||
| { | { | ||||
| ClockifyReports.InitializeClockifyIntegration(); | ClockifyReports.InitializeClockifyIntegration(); | ||||
| _logger.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}"); | |||||
| var testObject = new ClockifyReport | |||||
| { | |||||
| reportName = "BlackRockReport_20220615", | |||||
| reportDescription = "Total (13/06/2022 - 15/06/2022)", | |||||
| reportPeople = new List<Person> | |||||
| { | |||||
| new Person | |||||
| { | |||||
| fullName = "Nikola Jovanovic", | |||||
| records = new List<ClockifyRecord> | |||||
| { | |||||
| new ClockifyRecord | |||||
| { | |||||
| recordDescription = "massa placerat duis ultricies lacus sed turpis tincidunt id aliquet risus feugiat in ante metus dictum at tempor commodo ullamcorper", | |||||
| recordTime = new TimeOnly(3,15,44), | |||||
| amount = 200 | |||||
| }, | |||||
| new ClockifyRecord | |||||
| { | |||||
| recordDescription = "et tortor at risus viverra adipiscing at in tellus integer feugiat scelerisque varius morbi enim nunc faucibus a pellentesque sit", | |||||
| recordTime = new TimeOnly(3,15,44), | |||||
| amount = 150 | |||||
| } | |||||
| } | |||||
| }, | |||||
| new Person | |||||
| { | |||||
| fullName = "Boris Stevanovic", | |||||
| records = new List<ClockifyRecord> | |||||
| { | |||||
| new ClockifyRecord | |||||
| { | |||||
| recordDescription = "iaculis urna id volutpat lacus laoreet non curabitur gravida arcu ac tortor dignissim convallis aenean et tortor at risus viverra", | |||||
| recordTime = new TimeOnly(3,15,44), | |||||
| amount = 300 | |||||
| }, | |||||
| new ClockifyRecord | |||||
| { | |||||
| recordDescription = "gravida arcu ac tortor dignissim convallis aenean et tortor at risus viverra adipiscing at in tellus integer feugiat scelerisque varius", | |||||
| recordTime = new TimeOnly(3,15,44), | |||||
| amount = 100 | |||||
| }, | |||||
| new ClockifyRecord | |||||
| { | |||||
| recordDescription = "sit amet massa vitae tortor condimentum lacinia quis vel eros donec ac odio tempor orci dapibus ultrices in iaculis nunc", | |||||
| recordTime = new TimeOnly(3,15,44), | |||||
| amount = 120 | |||||
| } | |||||
| } | |||||
| }, | |||||
| new Person | |||||
| { | |||||
| fullName = "Dunja Stevanovic", | |||||
| records = new List<ClockifyRecord> | |||||
| { | |||||
| new ClockifyRecord | |||||
| { | |||||
| recordDescription = "vulputate mi sit amet mauris commodo quis imperdiet massa tincidunt nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc", | |||||
| recordTime = new TimeOnly(3,15,44), | |||||
| amount = 50 | |||||
| }, | |||||
| new ClockifyRecord | |||||
| { | |||||
| recordDescription = "senectus et netus et malesuada fames ac turpis egestas maecenas pharetra convallis posuere morbi leo urna molestie at elementum eu", | |||||
| recordTime = new TimeOnly(3,15,44), | |||||
| amount = 500 | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| }; | |||||
| _logger.LogInformation($"Data collection successfull!"); | |||||
| return JsonConvert.SerializeObject(testObject); | |||||
| } | } | ||||
| } | } | ||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Globalization; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| using Newtonsoft.Json; | |||||
| namespace BlackRockReportFunction.Helpers | |||||
| { | |||||
| public class TimeOnlyConverter : JsonConverter<TimeOnly> | |||||
| { | |||||
| private const string Format = "hh:mm:ss"; | |||||
| public override TimeOnly ReadJson(JsonReader reader, | |||||
| Type objectType, | |||||
| TimeOnly existingValue, | |||||
| bool hasExistingValue, | |||||
| JsonSerializer serializer) => | |||||
| TimeOnly.ParseExact((string)reader.Value, Format, CultureInfo.InvariantCulture); | |||||
| public override void WriteJson(JsonWriter writer, TimeOnly value, JsonSerializer serializer) => | |||||
| writer.WriteValue(value.ToString(Format, CultureInfo.InvariantCulture)); | |||||
| } | |||||
| } |
| { | { | ||||
| _logger = loggerFactory.CreateLogger<MailSenderFunction>(); | _logger = loggerFactory.CreateLogger<MailSenderFunction>(); | ||||
| } | } | ||||
| //http://127.0.0.1:10000/devstoreaccount1/report-container | |||||
| [Function("MailSenderFunction")] | [Function("MailSenderFunction")] | ||||
| public void Run([BlobTrigger("report-container/{name}", Connection = "AzureWebJobsStorage")] byte[] fileData) | public void Run([BlobTrigger("report-container/{name}", Connection = "AzureWebJobsStorage")] byte[] fileData) | ||||
| var email = new MimeMessage(); | var email = new MimeMessage(); | ||||
| email.From.Add(MailboxAddress.Parse("nikola.jovanovic@dilig.net")); | email.From.Add(MailboxAddress.Parse("nikola.jovanovic@dilig.net")); | ||||
| email.To.Add(MailboxAddress.Parse("justine.tromp31@ethereal.email")); | |||||
| email.To.Add(MailboxAddress.Parse("shaniya.blick76@ethereal.email")); | |||||
| email.Subject = "BlackRock Report"; | email.Subject = "BlackRock Report"; | ||||
| var body = new TextPart(TextFormat.Html) { Text = string.Format("Here is yours report for last week. {0}", fileName) }; | var body = new TextPart(TextFormat.Html) { Text = string.Format("Here is yours report for last week. {0}", fileName) }; | ||||
| using var smtp = new SmtpClient(); | using var smtp = new SmtpClient(); | ||||
| smtp.Connect("smtp.ethereal.email", 587, SecureSocketOptions.StartTls); | smtp.Connect("smtp.ethereal.email", 587, SecureSocketOptions.StartTls); | ||||
| smtp.Authenticate("justine.tromp31@ethereal.email", "ztbDPEp9gEfPetwZFY"); | |||||
| smtp.Authenticate("shaniya.blick76@ethereal.email", "8pPsjCbwCFMrEeKNef"); | |||||
| smtp.Send(email); | smtp.Send(email); | ||||
| smtp.Disconnect(true); | smtp.Disconnect(true); | ||||
| using System.Linq; | using System.Linq; | ||||
| using System.Text; | using System.Text; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using Newtonsoft.Json; | |||||
| using BlackRockReportFunction.Helpers; | |||||
| namespace BlackRockReportFunction.Models | namespace BlackRockReportFunction.Models | ||||
| { | { | ||||
| public class ClockifyRecord | public class ClockifyRecord | ||||
| { | { | ||||
| public string recordDescription { get; set; } | public string recordDescription { get; set; } | ||||
| [JsonConverter(typeof(TimeOnlyConverter))] | |||||
| public TimeOnly recordTime { get; set; } | public TimeOnly recordTime { get; set; } | ||||
| public decimal amount { get; set; } | public decimal amount { get; set; } | ||||
| } | } |
| using MimeKit.Text; | using MimeKit.Text; | ||||
| using MailKit.Net.Smtp; | using MailKit.Net.Smtp; | ||||
| using MailKit.Security; | using MailKit.Security; | ||||
| using Newtonsoft.Json; | |||||
| namespace BlackRockReportFunction | namespace BlackRockReportFunction | ||||
| { | { | ||||
| [BlobOutput("report-container/BlackRock_Report.xslx", Connection = "AzureWebJobsStorage")] | [BlobOutput("report-container/BlackRock_Report.xslx", Connection = "AzureWebJobsStorage")] | ||||
| public async Task Run([QueueTrigger("queue1")] string myQueueItem) | public async Task Run([QueueTrigger("queue1")] string myQueueItem) | ||||
| { | { | ||||
| _logger.LogInformation($"C# Queue trigger function processed: {myQueueItem}, gemboxKey: {"E0YU - JKLB - WFCE - N52P"}"); | |||||
| var reportFile = ReportGenerator.GenerateReportContent(); | |||||
| var reportObject = JsonConvert.DeserializeObject<ClockifyReport>(myQueueItem); | |||||
| var reportFile = ReportGenerator.GenerateReportContent(reportObject); | |||||
| string connection = Environment.GetEnvironmentVariable("AzureWebJobsStorage"); | string connection = Environment.GetEnvironmentVariable("AzureWebJobsStorage"); | ||||
| string containerName = "report-container"; | string containerName = "report-container"; |