| @@ -9,83 +9,11 @@ namespace BlackRockReportFunction.Bussines | |||
| public const string DefaultFontName = "Calibri"; | |||
| public const int DefaultFontSize = 20; | |||
| public static ExcelFile GenerateReportContent() | |||
| public static ExcelFile GenerateReportContent(ClockifyReport reportObject) | |||
| { | |||
| string licenseKey = Environment.GetEnvironmentVariable("GemBoxLicenseKey"); | |||
| 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 ws = excelFile.Worksheets.Add("Content"); | |||
| @@ -124,7 +52,7 @@ namespace BlackRockReportFunction.Bussines | |||
| VerticalAlignment = VerticalAlignmentStyle.Center, | |||
| }; | |||
| AddReportItems(testObject, ws, sectionStyle, mainDetailsStyle, normalDetailsStyle); | |||
| AddReportItems(reportObject, ws, sectionStyle, mainDetailsStyle, normalDetailsStyle); | |||
| // Autofit | |||
| AutoFitReport(excelFile); | |||
| @@ -4,6 +4,8 @@ using System.Net.Http.Headers; | |||
| using BlackRockReportFunction.Bussines; | |||
| using Microsoft.Azure.Functions.Worker; | |||
| using Microsoft.Extensions.Logging; | |||
| using BlackRockReportFunction.Models; | |||
| using Newtonsoft.Json; | |||
| namespace BlackRockReportFunction | |||
| { | |||
| @@ -17,11 +19,86 @@ namespace BlackRockReportFunction | |||
| } | |||
| [Function("ClockifyApiIntegrationFunction")] | |||
| public void Run([TimerTrigger("* * * */5 * *")] MyInfo myTimer) | |||
| [QueueOutput("queue1")] | |||
| public string Run([TimerTrigger("*/15 * * * * *")] MyInfo myTimer) | |||
| { | |||
| 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); | |||
| } | |||
| } | |||
| @@ -0,0 +1,25 @@ | |||
| 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)); | |||
| } | |||
| } | |||
| @@ -21,7 +21,6 @@ namespace BlackRockReportFunction | |||
| { | |||
| _logger = loggerFactory.CreateLogger<MailSenderFunction>(); | |||
| } | |||
| //http://127.0.0.1:10000/devstoreaccount1/report-container | |||
| [Function("MailSenderFunction")] | |||
| public void Run([BlobTrigger("report-container/{name}", Connection = "AzureWebJobsStorage")] byte[] fileData) | |||
| @@ -41,7 +40,7 @@ namespace BlackRockReportFunction | |||
| var email = new MimeMessage(); | |||
| 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"; | |||
| var body = new TextPart(TextFormat.Html) { Text = string.Format("Here is yours report for last week. {0}", fileName) }; | |||
| @@ -63,7 +62,7 @@ namespace BlackRockReportFunction | |||
| using var smtp = new SmtpClient(); | |||
| 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.Disconnect(true); | |||
| @@ -3,12 +3,15 @@ using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| using Newtonsoft.Json; | |||
| using BlackRockReportFunction.Helpers; | |||
| namespace BlackRockReportFunction.Models | |||
| { | |||
| public class ClockifyRecord | |||
| { | |||
| public string recordDescription { get; set; } | |||
| [JsonConverter(typeof(TimeOnlyConverter))] | |||
| public TimeOnly recordTime { get; set; } | |||
| public decimal amount { get; set; } | |||
| } | |||
| @@ -13,6 +13,7 @@ using MimeKit; | |||
| using MimeKit.Text; | |||
| using MailKit.Net.Smtp; | |||
| using MailKit.Security; | |||
| using Newtonsoft.Json; | |||
| namespace BlackRockReportFunction | |||
| { | |||
| @@ -29,9 +30,8 @@ namespace BlackRockReportFunction | |||
| [BlobOutput("report-container/BlackRock_Report.xslx", Connection = "AzureWebJobsStorage")] | |||
| 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 containerName = "report-container"; | |||