| <PackageReference Include="Azure.Storage.Queues" Version="12.10.0" /> | <PackageReference Include="Azure.Storage.Queues" Version="12.10.0" /> | ||||
| <PackageReference Include="GemBox.Spreadsheet" Version="37.3.30.1110" /> | <PackageReference Include="GemBox.Spreadsheet" Version="37.3.30.1110" /> | ||||
| <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" /> | <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" /> | ||||
| <PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" /> | |||||
| <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" /> | |||||
| <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="4.0.4" /> | <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="4.0.4" /> | ||||
| <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.1.0" /> | <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.1.0" /> | ||||
| <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" OutputItemType="Analyzer" /> | <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" OutputItemType="Analyzer" /> | ||||
| <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.6.0" /> | <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.6.0" /> | ||||
| <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.SendGrid" Version="3.0.2" /> | <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.SendGrid" Version="3.0.2" /> | ||||
| <PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.2.0" /> | |||||
| <PackageReference Include="System.Core" Version="3.5.21022.801" /> | <PackageReference Include="System.Core" Version="3.5.21022.801" /> | ||||
| <PackageReference Include="System.Drawing.Common" Version="6.0.0" /> | <PackageReference Include="System.Drawing.Common" Version="6.0.0" /> | ||||
| <PackageReference Include="System.IO.Packaging" Version="6.0.0" /> | <PackageReference Include="System.IO.Packaging" Version="6.0.0" /> |
| using System.Net; | using System.Net; | ||||
| using System.Net.Http; | using System.Net.Http; | ||||
| using System.Net.Http.Headers; | using System.Net.Http.Headers; | ||||
| using GemBox.Spreadsheet; | |||||
| using Microsoft.AspNetCore.Mvc; | |||||
| using Microsoft.AspNetCore.Http; | |||||
| using Microsoft.Build.Tasks.Deployment.Bootstrapper; | |||||
| namespace BlackRockReportFunction.Bussines | namespace BlackRockReportFunction.Bussines | ||||
| { | { | ||||
| public class ClockifyReports | public class ClockifyReports | ||||
| { | { | ||||
| public static string? clockifyApiKey = Environment.GetEnvironmentVariable("ClockifyApiKey"); | |||||
| static HttpClient client = new HttpClient(); | static HttpClient client = new HttpClient(); | ||||
| static void InitializeClockifyIntegration() | |||||
| public static async Task InitializeClockifyIntegration() | |||||
| { | { | ||||
| client.DefaultRequestHeaders.Add("X-API-Key", clockifyApiKey); | |||||
| client.BaseAddress = new Uri("https://reports.api.clockify.me/v1"); | client.BaseAddress = new Uri("https://reports.api.clockify.me/v1"); | ||||
| client.DefaultRequestHeaders.Accept.Clear(); | client.DefaultRequestHeaders.Accept.Clear(); | ||||
| .Add(new MediaTypeWithQualityHeaderValue("application/json")); | .Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||||
| } | } | ||||
| static async Task<Uri> CreateClockifyReport(ClockifyReport clockifyReport) | |||||
| public static async Task<Uri> CreateClockifyReport(ClockifyReport clockifyReport) | |||||
| { | { | ||||
| HttpResponseMessage httpResponseMessage = await client | HttpResponseMessage httpResponseMessage = await client | ||||
| .PostAsJsonAsync("api/clockifyreport", clockifyReport); | .PostAsJsonAsync("api/clockifyreport", clockifyReport); | ||||
| return httpResponseMessage.Headers.Location; | return httpResponseMessage.Headers.Location; | ||||
| } | } | ||||
| static async Task<ClockifyReport> GetClockifyReportAsync(string path) | |||||
| public static async Task<ClockifyReport> GetClockifyReportAsync(string path) | |||||
| { | { | ||||
| ClockifyReport clockifyReport = null; | ClockifyReport clockifyReport = null; | ||||
| HttpResponseMessage httpResponseMessage= await client.GetAsync(path); | HttpResponseMessage httpResponseMessage= await client.GetAsync(path); |
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| using GemBox.Spreadsheet; | |||||
| using GemBox.Spreadsheet; | |||||
| using BlackRockReportFunction.Models; | using BlackRockReportFunction.Models; | ||||
| using BlackRockReportFunction.Helpers; | using BlackRockReportFunction.Helpers; | ||||
| using System.Windows.Forms; | |||||
| namespace BlackRockReportFunction.Bussines | namespace BlackRockReportFunction.Bussines | ||||
| { | { |
| using System; | using System; | ||||
| using System.Net; | using System.Net; | ||||
| using System.Net.Http.Headers; | using System.Net.Http.Headers; | ||||
| using BlackRockReportFunction.Bussines; | |||||
| using Microsoft.Azure.Functions.Worker; | using Microsoft.Azure.Functions.Worker; | ||||
| using Microsoft.Extensions.Logging; | using Microsoft.Extensions.Logging; | ||||
| } | } | ||||
| [Function("ClockifyApiIntegrationFunction")] | [Function("ClockifyApiIntegrationFunction")] | ||||
| public void Run([TimerTrigger("* * * */5 * *")] MyInfo myTimer) | |||||
| public void Run([TimerTrigger("*/5 * * * * *")] MyInfo myTimer) | |||||
| { | { | ||||
| ClockifyReports.InitializeClockifyIntegration(); | |||||
| _logger.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}"); | _logger.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}"); | ||||
| } | } | ||||
| } | } |