Skip to content

Commit ad59b5d

Browse files
author
Dmitriy Kozlov
committed
monor refactoring, added deployment file
1 parent 5ad2f4b commit ad59b5d

11 files changed

Lines changed: 66 additions & 25 deletions

File tree

.deployment

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[config]
2+
project = Dynamics365/BusinessCentral/Dynamics365.BusinessCentral.csproj

Dynamics365/BusinessCentral/Authorize.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ namespace Plumsail.DataSource.Dynamics365.BusinessCentral
2323
{
2424
public class Authorize
2525
{
26-
private AppSettings _settings;
26+
private readonly AzureApp _settings;
2727

2828
public Authorize(IOptions<AppSettings> settings)
2929
{
30-
_settings = settings.Value;
30+
_settings = settings.Value.AzureApp;
3131
}
3232

3333
[FunctionName("Dynamics365-BusinessCentral-Authorize")]
@@ -43,9 +43,9 @@ public async Task<IActionResult> Run(
4343
{
4444
var code = queryParams["code"];
4545

46-
var app = ConfidentialClientApplicationBuilder.Create(_settings.AzureApp.ClientId)
47-
.WithClientSecret(_settings.AzureApp.ClientSecret)
48-
.WithTenantId(_settings.AzureApp.Tenant)
46+
var app = ConfidentialClientApplicationBuilder.Create(_settings.ClientId)
47+
.WithClientSecret(_settings.ClientSecret)
48+
.WithTenantId(_settings.Tenant)
4949
.WithRedirectUri(currentUrl)
5050
.Build();
5151

@@ -57,8 +57,8 @@ public async Task<IActionResult> Run(
5757
}
5858

5959
var url = new StringBuilder();
60-
url.Append($"https://login.microsoftonline.com/{_settings.AzureApp.Tenant}/oauth2/v2.0/authorize?");
61-
url.Append($"client_id={_settings.AzureApp.ClientId}&");
60+
url.Append($"https://login.microsoftonline.com/{_settings.Tenant}/oauth2/v2.0/authorize?");
61+
url.Append($"client_id={_settings.ClientId}&");
6262
url.Append($"response_type=code&");
6363
url.Append($"redirect_uri={WebUtility.UrlEncode(currentUrl)}&");
6464
url.Append($"response_mode=query&");

Dynamics365/BusinessCentral/Customers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ namespace Plumsail.DataSource.Dynamics365.BusinessCentral
2323
{
2424
public class Customers
2525
{
26-
private Settings.Customers _settings;
27-
private GraphServiceClientProvider _graphProvider;
26+
private readonly Settings.Customers _settings;
27+
private readonly GraphServiceClientProvider _graphProvider;
2828

2929
public Customers(IOptions<AppSettings> settings, GraphServiceClientProvider graphProvider)
3030
{

Dynamics365/BusinessCentral/GraphServiceClientProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Plumsail.DataSource.Dynamics365.BusinessCentral
1313
{
1414
public class GraphServiceClientProvider
1515
{
16-
private AzureApp _azureAppSettings;
16+
private readonly AzureApp _azureAppSettings;
1717

1818
public GraphServiceClientProvider(IOptions<AppSettings> settings)
1919
{

Dynamics365/BusinessCentral/Items.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ namespace Plumsail.DataSource.Dynamics365.BusinessCentral
2323
{
2424
public class Items
2525
{
26-
private Settings.Items _settings;
27-
private GraphServiceClientProvider _graphProvider;
26+
private readonly Settings.Items _settings;
27+
private readonly GraphServiceClientProvider _graphProvider;
2828

2929
public Items(IOptions<AppSettings> settings, GraphServiceClientProvider graphProvider)
3030
{

Dynamics365/BusinessCentral/Vendors.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ namespace Plumsail.DataSource.Dynamics365.BusinessCentral
2323
{
2424
public class Vendors
2525
{
26-
private Settings.Vendors _settings;
27-
private GraphServiceClientProvider _graphProvider;
26+
private readonly Settings.Vendors _settings;
27+
private readonly GraphServiceClientProvider _graphProvider;
2828

2929
public Vendors(IOptions<AppSettings> settings, GraphServiceClientProvider graphProvider)
3030
{
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharePoint", "SharePoint\Sh
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dynamics365.BusinessCentral", "Dynamics365\BusinessCentral\Dynamics365.BusinessCentral.csproj", "{B0CB2C8F-B264-4AA4-8CBE-35F32791E870}"
99
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionsApp", "FunctionsApp\FunctionsApp.csproj", "{EFCE1BCA-A1D8-46D5-8681-5D96C16FC760}"
11+
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1214
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
2123
{B0CB2C8F-B264-4AA4-8CBE-35F32791E870}.Debug|Any CPU.Build.0 = Debug|Any CPU
2224
{B0CB2C8F-B264-4AA4-8CBE-35F32791E870}.Release|Any CPU.ActiveCfg = Release|Any CPU
2325
{B0CB2C8F-B264-4AA4-8CBE-35F32791E870}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{EFCE1BCA-A1D8-46D5-8681-5D96C16FC760}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{EFCE1BCA-A1D8-46D5-8681-5D96C16FC760}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{EFCE1BCA-A1D8-46D5-8681-5D96C16FC760}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{EFCE1BCA-A1D8-46D5-8681-5D96C16FC760}.Release|Any CPU.Build.0 = Release|Any CPU
2430
EndGlobalSection
2531
GlobalSection(SolutionProperties) = preSolution
2632
HideSolutionNode = FALSE
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Microsoft.Extensions.Options;
2+
using Microsoft.Graph;
3+
using Microsoft.Graph.Auth;
4+
using Microsoft.Identity.Client;
5+
using Plumsail.DataSource.SharePoint.Settings;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Net.Http.Headers;
10+
using System.Text;
11+
using System.Threading.Tasks;
12+
13+
namespace Plumsail.DataSource.SharePoint
14+
{
15+
public class GraphServiceClientProvider
16+
{
17+
private readonly AzureApp _azureAppSettings;
18+
19+
public GraphServiceClientProvider(IOptions<AppSettings> settings)
20+
{
21+
_azureAppSettings = settings.Value.AzureApp;
22+
}
23+
24+
public GraphServiceClient Create()
25+
{
26+
var confidentialClientApplication = ConfidentialClientApplicationBuilder.Create(_azureAppSettings.ClientId)
27+
.WithClientSecret(_azureAppSettings.ClientSecret)
28+
.WithTenantId(_azureAppSettings.Tenant)
29+
.Build();
30+
31+
var authProvider = new ClientCredentialProvider(confidentialClientApplication);
32+
return new GraphServiceClient(authProvider);
33+
}
34+
}
35+
}

SharePoint/ListData.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ namespace Plumsail.DataSource.SharePoint
1919
{
2020
public class ListData
2121
{
22-
private Settings.AppSettings _settings;
22+
private readonly Settings.ListData _settings;
23+
private readonly GraphServiceClientProvider _graphProvider;
2324

24-
public ListData(IOptions<Settings.AppSettings> settings)
25+
public ListData(IOptions<Settings.AppSettings> settings, GraphServiceClientProvider graphProvider)
2526
{
26-
_settings = settings.Value;
27+
_settings = settings.Value.ListData;
28+
_graphProvider = graphProvider;
2729
}
2830

2931
[FunctionName("SharePoint-ListData")]
@@ -33,14 +35,8 @@ public async Task<IActionResult> Run(
3335
{
3436
log.LogInformation("ListData is requested.");
3537

36-
var confidentialClientApplication = ConfidentialClientApplicationBuilder.Create(_settings.AzureApp.ClientId)
37-
.WithClientSecret(_settings.AzureApp.ClientSecret)
38-
.WithTenantId(_settings.AzureApp.Tenant)
39-
.Build();
40-
41-
var authProvider = new ClientCredentialProvider(confidentialClientApplication);
42-
var graph = new GraphServiceClient(authProvider);
43-
var list = await graph.GetListAsync(_settings.ListData.SiteUrl, _settings.ListData.ListName);
38+
var graph = _graphProvider.Create();
39+
var list = await graph.GetListAsync(_settings.SiteUrl, _settings.ListName);
4440

4541
var queryOptions = new List<QueryOption>()
4642
{

SharePoint/SharePoint.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
55
<AssemblyName>Plumsail.DataSource.SharePoint</AssemblyName>
66
<RootNamespace>Plumsail.DataSource.SharePoint</RootNamespace>
7+
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
78
</PropertyGroup>
89
<ItemGroup>
910
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />

0 commit comments

Comments
 (0)