-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/1.0.4-upgrade-to-net-8-isolated' into master
- Loading branch information
Showing
26 changed files
with
429 additions
and
378 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action | ||
# More GitHub Actions for Azure: https://github.com/Azure/actions | ||
|
||
name: Build and deploy dotnet core app to Azure Function App - data-source-functions | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
workflow_dispatch: | ||
|
||
env: | ||
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root | ||
DOTNET_VERSION: '8.0.x' # set this to the dotnet version to use | ||
|
||
jobs: | ||
build-and-deploy: | ||
runs-on: windows-latest | ||
permissions: | ||
id-token: write #This is required for requesting the JWT | ||
|
||
steps: | ||
- name: 'Checkout GitHub Action' | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup DotNet ${{ env.DOTNET_VERSION }} Environment | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: ${{ env.DOTNET_VERSION }} | ||
|
||
- name: 'Resolve Project Dependencies Using Dotnet' | ||
shell: pwsh | ||
run: | | ||
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}' | ||
dotnet build --configuration Release --output ./output | ||
popd | ||
- name: Login to Azure | ||
uses: azure/login@v2 | ||
with: | ||
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_F1F0122F19484BB2858796558B0D19C9 }} | ||
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_2C4D4BECD44F46F5B6E6CA8ABD485841 }} | ||
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_29B57699ACA7440BB8E138E8DA7FB705 }} | ||
|
||
- name: 'Run Azure Functions Action' | ||
uses: Azure/functions-action@v1 | ||
id: fa | ||
with: | ||
app-name: 'data-source-functions' | ||
slot-name: 'Production' | ||
package: '${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Plumsail.DataSource | ||
{ | ||
class DebugRequestHandler : DelegatingHandler | ||
{ | ||
public DebugRequestHandler(HttpMessageHandler? innerHandler = null) | ||
{ | ||
InnerHandler = innerHandler ?? new HttpClientHandler(); | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
Console.WriteLine(""); | ||
Console.WriteLine(string.Format("Request: {0} {1}", request.Method, request.RequestUri)); | ||
Console.WriteLine("Request headers:"); | ||
foreach (var header in request.Headers) | ||
{ | ||
Console.WriteLine(string.Format("{0}: {1}", header.Key, string.Join(',', header.Value))); | ||
} | ||
if (request.Content is not null) | ||
{ | ||
Console.WriteLine(""); | ||
Console.WriteLine("Request body:"); | ||
var body = await request.Content.ReadAsStringAsync(); | ||
Console.WriteLine(body); | ||
} | ||
|
||
return await base.SendAsync(request, cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Plumsail.DataSource | ||
{ | ||
class DebugResponseHandler : DelegatingHandler | ||
{ | ||
public DebugResponseHandler(HttpMessageHandler? innerHandler = null) | ||
{ | ||
InnerHandler = innerHandler ?? new HttpClientHandler(); | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
var response = await base.SendAsync(request, cancellationToken); | ||
|
||
Console.WriteLine(""); | ||
Console.WriteLine("Response headers:"); | ||
foreach (var header in response.Headers) | ||
{ | ||
Console.WriteLine(string.Format("{0}: {1}", header.Key, string.Join(',', header.Value))); | ||
} | ||
if (response.Content is not null) | ||
{ | ||
Console.WriteLine(""); | ||
Console.WriteLine("Response body:"); | ||
var body = await response.Content.ReadAsStringAsync(); | ||
Console.WriteLine(body); | ||
} | ||
|
||
return response; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,48 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Azure.Functions.Worker; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.Http; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Logging; | ||
using Newtonsoft.Json; | ||
using Microsoft.Graph; | ||
using Microsoft.Identity.Client; | ||
using System.Net.Http.Headers; | ||
using Microsoft.Graph.Auth; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.Graph; | ||
using Microsoft.Graph.Beta; | ||
using Microsoft.Graph.Beta.Models; | ||
using Plumsail.DataSource.Dynamics365.BusinessCentral.Settings; | ||
using System.Text; | ||
using Microsoft.AspNetCore.Http.Extensions; | ||
using System.Net; | ||
using Plumsail.DataSource.Dynamics365.CRM; | ||
using System.Collections.Generic; | ||
using System.Text.Json.Nodes; | ||
using System.Threading.Tasks; | ||
|
||
namespace Plumsail.DataSource.Dynamics365.BusinessCentral | ||
{ | ||
public class Customers | ||
{ | ||
private readonly Settings.Customers _settings; | ||
private readonly GraphServiceClientProvider _graphProvider; | ||
private readonly HttpClientProvider _httpClientProvider; | ||
private readonly ILogger<Customers> _logger; | ||
|
||
public Customers(IOptions<AppSettings> settings, GraphServiceClientProvider graphProvider) | ||
public Customers(IOptions<AppSettings> settings, HttpClientProvider httpClientProvider, ILogger<Customers> logger) | ||
{ | ||
_settings = settings.Value.Customers; | ||
_graphProvider = graphProvider; | ||
_httpClientProvider = httpClientProvider; | ||
_logger = logger; | ||
} | ||
|
||
[FunctionName("D365-BC-Customers")] | ||
public async Task<IActionResult> Run( | ||
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, | ||
ILogger log) | ||
[Function("D365-BC-Customers")] | ||
public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req) | ||
{ | ||
log.LogInformation("Dynamics365-BusinessCentral-Customers is requested."); | ||
_logger.LogInformation("Dynamics365-BusinessCentral-Customers is requested."); | ||
|
||
var graph = await _graphProvider.Create(); | ||
var company = await graph.GetCompanyAsync(_settings.Company); | ||
if (company == null) | ||
var client = _httpClientProvider.Create(); | ||
var companyId = await client.GetCompanyIdAsync(_settings.Company); | ||
if (companyId == null) | ||
{ | ||
return new NotFoundResult(); | ||
} | ||
|
||
var customersPage = await graph.Financials.Companies[company.Id].Customers.Request().GetAsync(); | ||
var customers = new List<Customer>(customersPage); | ||
while (customersPage.NextPageRequest != null) | ||
{ | ||
customersPage = await customersPage.NextPageRequest.GetAsync(); | ||
customers.AddRange(customersPage); | ||
} | ||
|
||
return new OkObjectResult(customers); | ||
var customersJson = await client.GetStringAsync($"companies({companyId})/customers"); | ||
var customers = JsonValue.Parse(customersJson); | ||
return new OkObjectResult(customers?["value"]); | ||
} | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
FunctionApp/Dynamics365/BusinessCentral/GraphServiceClientExtensions.cs
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
FunctionApp/Dynamics365/BusinessCentral/GraphServiceClientProvider.cs
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
FunctionApp/Dynamics365/BusinessCentral/HttpClientExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Text.Json.Nodes; | ||
|
||
namespace Plumsail.DataSource.Dynamics365.BusinessCentral | ||
{ | ||
internal static class HttpClientExtensions | ||
{ | ||
internal static async System.Threading.Tasks.Task<string> GetCompanyIdAsync(this HttpClient client, string companyName) | ||
{ | ||
var companiesJson = await client.GetStringAsync("companies?$select=id,name"); | ||
var contacts = JsonValue.Parse(companiesJson)["value"].AsArray(); | ||
|
||
return contacts.FirstOrDefault(c => c["name"]?.GetValue<string>() == companyName)?["id"]?.GetValue<string>(); | ||
} | ||
} | ||
} |
Oops, something went wrong.