Skip to content

Commit

Permalink
migration to dotnet-isolated
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Kozlov committed Nov 19, 2024
1 parent dad7b21 commit 1d7a851
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 104 deletions.
12 changes: 6 additions & 6 deletions FunctionApp/Dynamics365/BusinessCentral/Authorize.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Identity.Client;
Expand All @@ -17,16 +17,16 @@ namespace Plumsail.DataSource.Dynamics365.BusinessCentral
public class Authorize
{
private readonly AzureApp _settings;
private readonly ILogger<Authorize> _logger;

public Authorize(IOptions<AppSettings> settings)
public Authorize(IOptions<AppSettings> settings, ILogger<Authorize> logger)
{
_settings = settings.Value.AzureApp;
_logger = logger;
}

[FunctionName("D365-BC-Authorize")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
[Function("D365-BC-Authorize")]
public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req)
{
var scopes = new string[] { "https://graph.microsoft.com/.default", "offline_access" };

Expand Down
16 changes: 8 additions & 8 deletions FunctionApp/Dynamics365/BusinessCentral/Customers.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Graph.Beta.Models;
using Microsoft.Graph;
using Microsoft.Graph.Beta.Models;
using Plumsail.DataSource.Dynamics365.BusinessCentral.Settings;
using System.Collections.Generic;
using System.Threading.Tasks;
Expand All @@ -16,19 +16,19 @@ public class Customers
{
private readonly Settings.Customers _settings;
private readonly GraphServiceClientProvider _graphProvider;
private readonly ILogger<Customers> _logger;

public Customers(IOptions<AppSettings> settings, GraphServiceClientProvider graphProvider)
public Customers(IOptions<AppSettings> settings, GraphServiceClientProvider graphProvider, ILogger<Customers> logger)
{
_settings = settings.Value.Customers;
_graphProvider = graphProvider;
_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);
Expand Down
15 changes: 8 additions & 7 deletions FunctionApp/Dynamics365/BusinessCentral/Items.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Graph.Beta.Models;
using Microsoft.Graph;
using Microsoft.Graph.Beta.Models;
using Plumsail.DataSource.Dynamics365.BusinessCentral.Settings;
using System.Collections.Generic;
using System.Threading.Tasks;
Expand All @@ -16,19 +16,20 @@ public class Items
{
private readonly Settings.Items _settings;
private readonly GraphServiceClientProvider _graphProvider;
private readonly ILogger<Items> _logger;

public Items(IOptions<AppSettings> settings, GraphServiceClientProvider graphProvider)
public Items(IOptions<AppSettings> settings, GraphServiceClientProvider graphProvider, ILogger<Items> logger)
{
_settings = settings.Value.Items;
_graphProvider = graphProvider;
_logger = logger;
}

[FunctionName("D365-BC-Items")]
[Function("D365-BC-Items")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
ILogger log)
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req)
{
log.LogInformation("Dynamics365-BusinessCentral-Vendors is requested.");
_logger.LogInformation("Dynamics365-BusinessCentral-Vendors is requested.");

var graph = await _graphProvider.Create();
var company = await graph.GetCompanyAsync(_settings.Company);
Expand Down
14 changes: 7 additions & 7 deletions FunctionApp/Dynamics365/BusinessCentral/Vendors.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Graph;
Expand All @@ -16,19 +16,19 @@ public class Vendors
{
private readonly Settings.Vendors _settings;
private readonly GraphServiceClientProvider _graphProvider;
private readonly ILogger<Vendors> _logger;

public Vendors(IOptions<AppSettings> settings, GraphServiceClientProvider graphProvider)
public Vendors(IOptions<AppSettings> settings, GraphServiceClientProvider graphProvider, ILogger<Vendors> logger)
{
_settings = settings.Value.Vendors;
_graphProvider = graphProvider;
_logger = logger;
}

[FunctionName("D365-BC-Vendors")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
ILogger log)
[Function("D365-BC-Vendors")]
public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req)
{
log.LogInformation("Dynamics365-BusinessCentral-Vendors is requested.");
_logger.LogInformation("Dynamics365-BusinessCentral-Vendors is requested.");

var graph = await _graphProvider.Create();
var company = await graph.GetCompanyAsync(_settings.Company);
Expand Down
14 changes: 7 additions & 7 deletions FunctionApp/Dynamics365/CRM/Accounts.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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.Extensions.Logging;
using Newtonsoft.Json.Linq;
using System.Threading.Tasks;
Expand All @@ -11,18 +11,18 @@ namespace Plumsail.DataSource.Dynamics365.CRM
public class Accounts
{
private readonly HttpClientProvider _httpClientProvider;
private readonly ILogger<Accounts> _logger;

public Accounts(HttpClientProvider httpClientProvider)
public Accounts(HttpClientProvider httpClientProvider, ILogger<Accounts> logger)
{
_httpClientProvider = httpClientProvider;
_logger = logger;
}

[FunctionName("D365-CRM-Accounts")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
ILogger log)
[Function("D365-CRM-Accounts")]
public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req)
{
log.LogInformation("Dynamics365-CRM-Accounts is requested.");
_logger.LogInformation("Dynamics365-CRM-Accounts is requested.");

var client = _httpClientProvider.Create();
var contactsJson = await client.GetStringAsync("accounts");
Expand Down
12 changes: 6 additions & 6 deletions FunctionApp/Dynamics365/CRM/Authorize.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Identity.Client;
Expand All @@ -17,16 +17,16 @@ namespace Plumsail.DataSource.Dynamics365.CRM
public class Authorize
{
private readonly AzureApp _settings;
private readonly ILogger<Authorize> _logger;

public Authorize(IOptions<AppSettings> settings)
public Authorize(IOptions<AppSettings> settings, ILogger<Authorize> logger)
{
_settings = settings.Value.AzureApp;
_logger = logger;
}

[FunctionName("D365-CRM-Authorize")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
[Function("D365-CRM-Authorize")]
public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req)
{
var scopes = new string[] { "https://admin.services.crm.dynamics.com/user_impersonation", "offline_access" };

Expand Down
14 changes: 7 additions & 7 deletions FunctionApp/Dynamics365/CRM/Contacts.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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.Extensions.Logging;
using Newtonsoft.Json.Linq;
using System.Threading.Tasks;
Expand All @@ -11,18 +11,18 @@ namespace Plumsail.DataSource.Dynamics365.CRM
public class Contacts
{
private readonly HttpClientProvider _httpClientProvider;
private readonly ILogger<Contacts> _logger;

public Contacts(HttpClientProvider httpClientProvider)
public Contacts(HttpClientProvider httpClientProvider, ILogger<Contacts> logger)
{
_httpClientProvider = httpClientProvider;
_logger = logger;
}

[FunctionName("D365-CRM-Contacts")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
ILogger log)
[Function("D365-CRM-Contacts")]
public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req)
{
log.LogInformation("Dynamics365-CRM-Contacts is requested.");
_logger.LogInformation("Dynamics365-CRM-Contacts is requested.");

var client = _httpClientProvider.Create();
var contactsJson = await client.GetStringAsync("contacts");
Expand Down
11 changes: 10 additions & 1 deletion FunctionApp/FunctionApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<AssemblyName>Plumsail.DataSource.FunctionApp</AssemblyName>
<RootNamespace>Plumsail.DataSource</RootNamespace>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.13.1" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Graph" Version="5.62.0" />
<PackageReference Include="Microsoft.Graph.Beta" Version="5.86.0-preview" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.6.0" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
Expand All @@ -21,4 +27,7 @@
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
</Project>
34 changes: 34 additions & 0 deletions FunctionApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using D365_BC = Plumsail.DataSource.Dynamics365.BusinessCentral;
using D365_CRM = Plumsail.DataSource.Dynamics365.CRM;
using SP = Plumsail.DataSource.SharePoint;

var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureAppConfiguration((context, builder) => {
builder.SetBasePath(Environment.CurrentDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
})
.ConfigureServices((context, services) => {
var configuration = context.Configuration;

services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();

services.Configure<D365_BC.Settings.AppSettings>(configuration.GetSection("Dynamics365.BusinessCentral"));
services.AddTransient<D365_BC.GraphServiceClientProvider>();

services.Configure<D365_CRM.Settings.AppSettings>(configuration.GetSection("Dynamics365.CRM"));
services.AddTransient<D365_CRM.HttpClientProvider>();

services.Configure<SP.Settings.AppSettings>(configuration.GetSection("SharePoint"));
services.AddTransient<SP.GraphServiceClientProvider>();
})
.Build();

host.Run();
2 changes: 1 addition & 1 deletion FunctionApp/SharePoint/GraphServiceClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal static async System.Threading.Tasks.Task<ListItemRequestBuilder> GetLis
var site = await graph.Sites[$"{url.Host}:{url.AbsolutePath}"].GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Select = ["id"];
requestConfiguration.QueryParameters.Expand = ["lists(select=id,name)"];
requestConfiguration.QueryParameters.Expand = ["lists($select=id,name)"];
});

var list = site.Lists.FirstOrDefault(list => list.Name == listName);
Expand Down
17 changes: 10 additions & 7 deletions FunctionApp/SharePoint/ListData.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
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.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Graph;
using Microsoft.Graph.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace Plumsail.DataSource.SharePoint
{
public class ListData
{
private readonly Settings.ListData _settings;
private readonly GraphServiceClientProvider _graphProvider;
private readonly ILogger<ListData> _logger;

public ListData(IOptions<Settings.AppSettings> settings, GraphServiceClientProvider graphProvider)
public ListData(IOptions<Settings.AppSettings> settings, GraphServiceClientProvider graphProvider, ILogger<ListData> logger)
{
_logger = logger;
_settings = settings.Value.ListData;
_graphProvider = graphProvider;
}

[FunctionName("SharePoint-ListData")]
[Function("SharePoint-ListData")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
ILogger log)
[HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req)
{
log.LogInformation("ListData is requested.");
_logger.LogInformation("ListData is requested.");

var graph = _graphProvider.Create();
var list = await graph.GetListAsync(_settings.SiteUrl, _settings.ListName);
var itemsPage = await list.Items.GetAsync(requestConfiguration =>
{
//requestConfiguration.QueryParameters.Filter = "fields/Title eq 'item 1'";
requestConfiguration.QueryParameters.Select = ["id"];
requestConfiguration.QueryParameters.Expand = ["fields(select=Title,Author)"];
requestConfiguration.QueryParameters.Expand = ["fields($select=Title,Author)"];
});

var items = new List<ListItem>();
Expand Down
6 changes: 1 addition & 5 deletions FunctionApp/SharePoint/Settings/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Plumsail.DataSource.SharePoint.Settings
namespace Plumsail.DataSource.SharePoint.Settings
{
public class AppSettings
{
Expand Down
6 changes: 1 addition & 5 deletions FunctionApp/SharePoint/Settings/AzureApp.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Plumsail.DataSource.SharePoint.Settings
namespace Plumsail.DataSource.SharePoint.Settings
{
public class AzureApp
{
Expand Down
Loading

0 comments on commit 1d7a851

Please sign in to comment.