Parcourir la source

Update

master
Dunja Stevanovic il y a 3 ans
Parent
révision
a0ed02b27e

+ 0
- 3
BlackRockReportFunction/BlackRockReportFunction.csproj Voir le fichier

@@ -38,7 +38,4 @@
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
<ItemGroup>
<Folder Include="Helpers\" />
</ItemGroup>
</Project>

+ 24
- 15
BlackRockReportFunction/ClockifyApiIntegrationFunction.cs Voir le fichier

@@ -9,6 +9,7 @@ using Newtonsoft.Json;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using BlackRockReportFunction.Exception;

namespace BlackRockReportFunction
{
@@ -39,12 +40,12 @@ namespace BlackRockReportFunction

[Function("ClockifyApiIntegrationFunction")]
[QueueOutput("queue1")]
public string Run([TimerTrigger("*/15 * * * * *" )] MyInfo myTimer) //TODO: Set on Friday at 20 o'clock "0 0 20 * * 5"
public string Run([TimerTrigger("*/15 * * * * *")] TimerInfo myTimer) //TODO: Set on Friday at 20 o'clock "0 0 20 * * 5"
{
InitializeClockifyIntegration(); // Clockify API Integration

var monday = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek + (int)DayOfWeek.Monday).ToString("yyyy-MM-dd");
var friday = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek + (int)DayOfWeek.Friday).ToString("yyyy-MM-dd"); // TO DO: Set end day of week
var friday = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek + (int)DayOfWeek.Friday).ToString("yyyy-MM-dd");

var json = "{\"dateRangeStart\":\""+monday+"T00:00:00.000\",\"dateRangeEnd\":\""+friday+"T23:59:59.000\",\"summaryFilter\":{\"groups\":[\"USER\",\"TIMEENTRY\"]},\"clients\":{\"ids\":[\"61488f8d9eb0753d0e40d761\"]},\"projects\":{\"ids\":[\"6242f015f6fe850b94cd0c64\"]},\"amountShown\":\"HIDE_AMOUNT\"}";

@@ -52,7 +53,7 @@ namespace BlackRockReportFunction

HttpResponseMessage response = client.PostAsync(client.BaseAddress + "/workspaces/5eb44340ef0f6c66fc88732a/reports/summary", httpContent).Result;
//TO DO: Clear code!!!
if (response.IsSuccessStatusCode)
{
@@ -63,26 +64,34 @@ namespace BlackRockReportFunction
}
else
{
return JsonConvert.SerializeObject(JsonConvert.DeserializeObject<object>(response.Content.ReadAsStringAsync().Result), Formatting.Indented);
_logger.LogInformation($"Request failed. Error status code: {(int)response.StatusCode}");
throw new HttpErrorStatusCodeException(response.StatusCode);

}

}
}

public class MyInfo
{
public MyScheduleStatus ScheduleStatus { get; set; }
//public class MyInfo
//{
// public MyScheduleStatus ScheduleStatus { get; set; }

public bool IsPastDue { get; set; }
}
// public bool IsPastDue { get; set; }
//}

public class MyScheduleStatus
{
public DateTime Last { get; set; }
//public class MyScheduleStatus
//{
// public DateTime Last { get; set; }

public DateTime Next { get; set; }
// public DateTime Next { get; set; }

// public DateTime LastUpdated { get; set; }



//}


public DateTime LastUpdated { get; set; }
}
}

+ 19
- 0
BlackRockReportFunction/Exception/HttpErrorStatusCodeException.cs Voir le fichier

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace BlackRockReportFunction.Exception
{
public class HttpErrorStatusCodeException : HttpRequestException
{
public HttpErrorStatusCodeException(HttpStatusCode errorStatusCode)
{
ErrorStatusCode = errorStatusCode;
}
public HttpStatusCode ErrorStatusCode { get; set; }
}
}

+ 3
- 4
BlackRockReportFunction/MailSenderFunction.cs Voir le fichier

@@ -41,7 +41,7 @@ namespace BlackRockReportFunction
var email = new MimeMessage();
email.From.Add(MailboxAddress.Parse("nikola.jovanovic@dilig.net"));
email.To.Add(MailboxAddress.Parse("greta.bartoletti@ethereal.email"));
//email.To.Add(MailboxAddress.Parse("greta.bartoletti@ethereal.email"));
email.Subject = "BlackRock Report";
var body = new TextPart(TextFormat.Html) { Text = string.Format("Here is yours report for last week. {0}", fileName) };

@@ -61,10 +61,9 @@ namespace BlackRockReportFunction
multipart.Add(attachment);
email.Body = multipart;

//using var smtp = new SmtpClient();
SmtpClient smtp = new SmtpClient();
smtp.Connect("smtp.ethereal.email", 587, SecureSocketOptions.StartTls);
//smtp.UseDefaultCredentials = true;
smtp.Connect("smtp.ethereal.email", 587, SecureSocketOptions.StartTls);
smtp.Authenticate("greta.bartoletti@ethereal.email", "ecsdGZxWHk4yfjZpD5"); //"shaniya.blick76@ethereal.email", "8pPsjCbwCFMrEeKNef"
smtp.Send(email);
smtp.Disconnect(true);

+ 1
- 2
BlackRockReportFunction/ReportGeneratorFunction.cs Voir le fichier

@@ -29,8 +29,7 @@ namespace BlackRockReportFunction
[BlobOutput("report-container/BlackRock_Report.xslx", Connection = "AzureWebJobsStorage")]
public async Task Run([QueueTrigger("queue1")] string myQueueItem)
{
//Console.WriteLine("Run function debugging");
//var reportObject = JsonConvert.DeserializeObject<ClockifyReport>(myQueueItem);
var reportObject = JsonConvert.DeserializeObject<Root>(myQueueItem);
var reportFile = ReportGenerator.GenerateReportContent(reportObject);


Chargement…
Annuler
Enregistrer