From 1d7a851cbb2865b3930a8a5f9408c09873f7cbed Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Tue, 19 Nov 2024 12:19:49 +0100 Subject: [PATCH] migration to dotnet-isolated --- .../Dynamics365/BusinessCentral/Authorize.cs | 12 +++---- .../Dynamics365/BusinessCentral/Customers.cs | 16 ++++----- .../Dynamics365/BusinessCentral/Items.cs | 15 ++++---- .../Dynamics365/BusinessCentral/Vendors.cs | 14 ++++---- FunctionApp/Dynamics365/CRM/Accounts.cs | 14 ++++---- FunctionApp/Dynamics365/CRM/Authorize.cs | 12 +++---- FunctionApp/Dynamics365/CRM/Contacts.cs | 14 ++++---- FunctionApp/FunctionApp.csproj | 11 +++++- FunctionApp/Program.cs | 34 +++++++++++++++++++ .../GraphServiceClientExtensions.cs | 2 +- FunctionApp/SharePoint/ListData.cs | 17 ++++++---- .../SharePoint/Settings/AppSettings.cs | 6 +--- FunctionApp/SharePoint/Settings/AzureApp.cs | 6 +--- FunctionApp/SharePoint/Settings/ListData.cs | 6 +--- FunctionApp/Startup.cs | 32 ----------------- 15 files changed, 107 insertions(+), 104 deletions(-) create mode 100644 FunctionApp/Program.cs delete mode 100644 FunctionApp/Startup.cs diff --git a/FunctionApp/Dynamics365/BusinessCentral/Authorize.cs b/FunctionApp/Dynamics365/BusinessCentral/Authorize.cs index e821f5c..f9daeda 100644 --- a/FunctionApp/Dynamics365/BusinessCentral/Authorize.cs +++ b/FunctionApp/Dynamics365/BusinessCentral/Authorize.cs @@ -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; @@ -17,16 +17,16 @@ namespace Plumsail.DataSource.Dynamics365.BusinessCentral public class Authorize { private readonly AzureApp _settings; + private readonly ILogger _logger; - public Authorize(IOptions settings) + public Authorize(IOptions settings, ILogger logger) { _settings = settings.Value.AzureApp; + _logger = logger; } - [FunctionName("D365-BC-Authorize")] - public async Task Run( - [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, - ILogger log) + [Function("D365-BC-Authorize")] + public async Task Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req) { var scopes = new string[] { "https://graph.microsoft.com/.default", "offline_access" }; diff --git a/FunctionApp/Dynamics365/BusinessCentral/Customers.cs b/FunctionApp/Dynamics365/BusinessCentral/Customers.cs index 10502cd..6171c43 100644 --- a/FunctionApp/Dynamics365/BusinessCentral/Customers.cs +++ b/FunctionApp/Dynamics365/BusinessCentral/Customers.cs @@ -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; @@ -16,19 +16,19 @@ public class Customers { private readonly Settings.Customers _settings; private readonly GraphServiceClientProvider _graphProvider; + private readonly ILogger _logger; - public Customers(IOptions settings, GraphServiceClientProvider graphProvider) + public Customers(IOptions settings, GraphServiceClientProvider graphProvider, ILogger logger) { _settings = settings.Value.Customers; _graphProvider = graphProvider; + _logger = logger; } - [FunctionName("D365-BC-Customers")] - public async Task Run( - [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, - ILogger log) + [Function("D365-BC-Customers")] + public async Task 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); diff --git a/FunctionApp/Dynamics365/BusinessCentral/Items.cs b/FunctionApp/Dynamics365/BusinessCentral/Items.cs index 1d73bae..4c28cd9 100644 --- a/FunctionApp/Dynamics365/BusinessCentral/Items.cs +++ b/FunctionApp/Dynamics365/BusinessCentral/Items.cs @@ -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; @@ -16,19 +16,20 @@ public class Items { private readonly Settings.Items _settings; private readonly GraphServiceClientProvider _graphProvider; + private readonly ILogger _logger; - public Items(IOptions settings, GraphServiceClientProvider graphProvider) + public Items(IOptions settings, GraphServiceClientProvider graphProvider, ILogger logger) { _settings = settings.Value.Items; _graphProvider = graphProvider; + _logger = logger; } - [FunctionName("D365-BC-Items")] + [Function("D365-BC-Items")] public async Task 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); diff --git a/FunctionApp/Dynamics365/BusinessCentral/Vendors.cs b/FunctionApp/Dynamics365/BusinessCentral/Vendors.cs index 23a536a..9116aad 100644 --- a/FunctionApp/Dynamics365/BusinessCentral/Vendors.cs +++ b/FunctionApp/Dynamics365/BusinessCentral/Vendors.cs @@ -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; @@ -16,19 +16,19 @@ public class Vendors { private readonly Settings.Vendors _settings; private readonly GraphServiceClientProvider _graphProvider; + private readonly ILogger _logger; - public Vendors(IOptions settings, GraphServiceClientProvider graphProvider) + public Vendors(IOptions settings, GraphServiceClientProvider graphProvider, ILogger logger) { _settings = settings.Value.Vendors; _graphProvider = graphProvider; + _logger = logger; } - [FunctionName("D365-BC-Vendors")] - public async Task Run( - [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, - ILogger log) + [Function("D365-BC-Vendors")] + public async Task 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); diff --git a/FunctionApp/Dynamics365/CRM/Accounts.cs b/FunctionApp/Dynamics365/CRM/Accounts.cs index 92846d7..5238489 100644 --- a/FunctionApp/Dynamics365/CRM/Accounts.cs +++ b/FunctionApp/Dynamics365/CRM/Accounts.cs @@ -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; @@ -11,18 +11,18 @@ namespace Plumsail.DataSource.Dynamics365.CRM public class Accounts { private readonly HttpClientProvider _httpClientProvider; + private readonly ILogger _logger; - public Accounts(HttpClientProvider httpClientProvider) + public Accounts(HttpClientProvider httpClientProvider, ILogger logger) { _httpClientProvider = httpClientProvider; + _logger = logger; } - [FunctionName("D365-CRM-Accounts")] - public async Task Run( - [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, - ILogger log) + [Function("D365-CRM-Accounts")] + public async Task 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"); diff --git a/FunctionApp/Dynamics365/CRM/Authorize.cs b/FunctionApp/Dynamics365/CRM/Authorize.cs index 382abd0..a5933c2 100644 --- a/FunctionApp/Dynamics365/CRM/Authorize.cs +++ b/FunctionApp/Dynamics365/CRM/Authorize.cs @@ -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; @@ -17,16 +17,16 @@ namespace Plumsail.DataSource.Dynamics365.CRM public class Authorize { private readonly AzureApp _settings; + private readonly ILogger _logger; - public Authorize(IOptions settings) + public Authorize(IOptions settings, ILogger logger) { _settings = settings.Value.AzureApp; + _logger = logger; } - [FunctionName("D365-CRM-Authorize")] - public async Task Run( - [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, - ILogger log) + [Function("D365-CRM-Authorize")] + public async Task Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req) { var scopes = new string[] { "https://admin.services.crm.dynamics.com/user_impersonation", "offline_access" }; diff --git a/FunctionApp/Dynamics365/CRM/Contacts.cs b/FunctionApp/Dynamics365/CRM/Contacts.cs index 0aa9b00..96caeec 100644 --- a/FunctionApp/Dynamics365/CRM/Contacts.cs +++ b/FunctionApp/Dynamics365/CRM/Contacts.cs @@ -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; @@ -11,18 +11,18 @@ namespace Plumsail.DataSource.Dynamics365.CRM public class Contacts { private readonly HttpClientProvider _httpClientProvider; + private readonly ILogger _logger; - public Contacts(HttpClientProvider httpClientProvider) + public Contacts(HttpClientProvider httpClientProvider, ILogger logger) { _httpClientProvider = httpClientProvider; + _logger = logger; } - [FunctionName("D365-CRM-Contacts")] - public async Task Run( - [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, - ILogger log) + [Function("D365-CRM-Contacts")] + public async Task 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"); diff --git a/FunctionApp/FunctionApp.csproj b/FunctionApp/FunctionApp.csproj index 37a083e..4cb4351 100644 --- a/FunctionApp/FunctionApp.csproj +++ b/FunctionApp/FunctionApp.csproj @@ -4,13 +4,19 @@ v4 Plumsail.DataSource.FunctionApp Plumsail.DataSource + Exe - + + + + + + @@ -21,4 +27,7 @@ Never + + + \ No newline at end of file diff --git a/FunctionApp/Program.cs b/FunctionApp/Program.cs new file mode 100644 index 0000000..925d2dd --- /dev/null +++ b/FunctionApp/Program.cs @@ -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(configuration.GetSection("Dynamics365.BusinessCentral")); + services.AddTransient(); + + services.Configure(configuration.GetSection("Dynamics365.CRM")); + services.AddTransient(); + + services.Configure(configuration.GetSection("SharePoint")); + services.AddTransient(); + }) + .Build(); + +host.Run(); \ No newline at end of file diff --git a/FunctionApp/SharePoint/GraphServiceClientExtensions.cs b/FunctionApp/SharePoint/GraphServiceClientExtensions.cs index c11ad5a..554c577 100644 --- a/FunctionApp/SharePoint/GraphServiceClientExtensions.cs +++ b/FunctionApp/SharePoint/GraphServiceClientExtensions.cs @@ -13,7 +13,7 @@ internal static async System.Threading.Tasks.Task 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); diff --git a/FunctionApp/SharePoint/ListData.cs b/FunctionApp/SharePoint/ListData.cs index 7d5c2d3..13dcc08 100644 --- a/FunctionApp/SharePoint/ListData.cs +++ b/FunctionApp/SharePoint/ListData.cs @@ -1,13 +1,14 @@ 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 { @@ -15,26 +16,28 @@ public class ListData { private readonly Settings.ListData _settings; private readonly GraphServiceClientProvider _graphProvider; + private readonly ILogger _logger; - public ListData(IOptions settings, GraphServiceClientProvider graphProvider) + public ListData(IOptions settings, GraphServiceClientProvider graphProvider, ILogger logger) { + _logger = logger; _settings = settings.Value.ListData; _graphProvider = graphProvider; } - [FunctionName("SharePoint-ListData")] + [Function("SharePoint-ListData")] public async Task 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(); diff --git a/FunctionApp/SharePoint/Settings/AppSettings.cs b/FunctionApp/SharePoint/Settings/AppSettings.cs index 6575e70..44b954b 100644 --- a/FunctionApp/SharePoint/Settings/AppSettings.cs +++ b/FunctionApp/SharePoint/Settings/AppSettings.cs @@ -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 { diff --git a/FunctionApp/SharePoint/Settings/AzureApp.cs b/FunctionApp/SharePoint/Settings/AzureApp.cs index 65b7090..7f0ace8 100644 --- a/FunctionApp/SharePoint/Settings/AzureApp.cs +++ b/FunctionApp/SharePoint/Settings/AzureApp.cs @@ -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 { diff --git a/FunctionApp/SharePoint/Settings/ListData.cs b/FunctionApp/SharePoint/Settings/ListData.cs index 23b1384..aed9f67 100644 --- a/FunctionApp/SharePoint/Settings/ListData.cs +++ b/FunctionApp/SharePoint/Settings/ListData.cs @@ -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 ListData { diff --git a/FunctionApp/Startup.cs b/FunctionApp/Startup.cs deleted file mode 100644 index 78bd947..0000000 --- a/FunctionApp/Startup.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.Azure.Functions.Extensions.DependencyInjection; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using System; -using D365_BC = Plumsail.DataSource.Dynamics365.BusinessCentral; -using D365_CRM = Plumsail.DataSource.Dynamics365.CRM; -using SP = Plumsail.DataSource.SharePoint; - -[assembly: FunctionsStartup(typeof(Plumsail.DataSource.FunctionApp.Startup))] -namespace Plumsail.DataSource.FunctionApp -{ - public class Startup : FunctionsStartup - { - public override void Configure(IFunctionsHostBuilder builder) - { - IConfigurationRoot configuration = new ConfigurationBuilder() - .SetBasePath(Environment.CurrentDirectory) - .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true) - .AddEnvironmentVariables() - .Build(); - - builder.Services.Configure(configuration.GetSection("Dynamics365.BusinessCentral")); - builder.Services.AddTransient(); - - builder.Services.Configure(configuration.GetSection("Dynamics365.CRM")); - builder.Services.AddTransient(); - - builder.Services.Configure(configuration.GetSection("SharePoint")); - builder.Services.AddTransient(); - } - } -}