Skip to content

Commit

Permalink
Upgrade to .NET 7
Browse files Browse the repository at this point in the history
  • Loading branch information
kbeaugrand committed Nov 28, 2022
1 parent 57a5d40 commit e1948ba
Show file tree
Hide file tree
Showing 38 changed files with 224 additions and 3,421 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: 7.0.x

- name: Restore Dotnet tools
run: dotnet tool restore
Expand All @@ -36,7 +36,7 @@ jobs:
working-directory: src/

- name: Generate Open API documentation
run: dotnet swagger tofile --output ./swagger.json AzureIoTHub.Portal.Server/bin/Debug/net6.0/AzureIoTHub.Portal.Server.dll v1
run: dotnet swagger tofile --output ./swagger.json AzureIoTHub.Portal.Server/bin/Debug/net7.0/AzureIoTHub.Portal.Server.dll v1
working-directory: src/

# Upload swagger docs to GitHub
Expand All @@ -47,7 +47,7 @@ jobs:
path: ./src/swagger.json

- name: Run unit tests
run: dotnet test --no-build --verbosity normal --logger trx --collect:"XPlat Code Coverage" /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura AzureIoTHub.Portal.Tests.Unit/AzureIoTHub.Portal.Tests.Unit.csproj
run: dotnet test --no-build --verbosity normal --logger trx --collect:"XPlat Code Coverage" AzureIoTHub.Portal.sln
working-directory: src/

# Upload test results as artifact
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: 7.0.x

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
48 changes: 15 additions & 33 deletions src/AzureIoTHub.Portal.Client/AzureIoTHub.Portal.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,63 +1,45 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>$(NoWarn)</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>$(NoWarn)</NoWarn>
</PropertyGroup>

<ItemGroup>
<TypeScriptCompile Remove="assets\script.ts" />
</ItemGroup>

<ItemGroup>
<Content Include="assets\src\index.ts" />
<Content Include="assets\webpack.config.js" />
</ItemGroup>

<ItemGroup>
<None Include="assets\src\index.ts" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ChartJs.Blazor.Fork" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.ClientAssets" Version="0.1.0-alpha.21528.2" />
<PackageReference Include="Blazored.LocalStorage" Version="4.2.0" />
<PackageReference Include="Blazored.Modal" Version="7.1.0" />
<PackageReference Include="FluentValidation" Version="11.3.0" />
<PackageReference Include="FluentValidation" Version="11.4.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web.Extensions" Version="5.0.0-preview9.20513.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="6.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.10" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.0-preview1.22518.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="4.8.4">
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="4.9.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MudBlazor" Version="6.1.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Net.Http.Json" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="System.Net.Http.Json" Version="7.0.0" />
<PackageReference Include="Tewr.Blazor.FileReader" Version="3.3.1.21360" />
<PackageReference Include="Microsoft.AspNetCore.Components.DataAnnotations.Validation" Version="3.2.0-rc1.20223.4" />

<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Toolbelt.Blazor.LoadingBar" Version="13.1.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AzureIoTHub.Portal.Shared\AzureIoTHub.Portal.Shared.csproj" />
</ItemGroup>

</Project>
214 changes: 100 additions & 114 deletions src/AzureIoTHub.Portal.Client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,119 +1,105 @@
// Copyright (c) CGI France. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace AzureIoTHub.Portal.Client
using System.Net.Http.Json;
using AzureIoTHub.Portal.Client;
using AzureIoTHub.Portal.Client.Handlers;
using AzureIoTHub.Portal.Client.Services;
using AzureIoTHub.Portal.Models.v10;
using AzureIoTHub.Portal.Settings;
using Blazored.LocalStorage;
using Blazored.Modal;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using MudBlazor;
using MudBlazor.Services;
using Tewr.Blazor.FileReader;
using Toolbelt.Blazor.Extensions.DependencyInjection;

var builder = WebAssemblyHostBuilder.CreateDefault(args);

builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

_ = builder.Services.AddTransient<ProblemDetailsHandler>();

_ = builder.Services.AddHttpClient("api", (sp, client) =>
{
using System;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
using Services;
using AzureIoTHub.Portal.Models.v10;
using Settings;
using Blazored.LocalStorage;
using Blazored.Modal;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Handlers;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using MudBlazor;
using MudBlazor.Services;
using Tewr.Blazor.FileReader;
using Toolbelt.Blazor.Extensions.DependencyInjection;

public static class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");

_ = builder.Services.AddTransient<ProblemDetailsHandler>();

_ = builder.Services.AddHttpClient("api", (sp, client) =>
{
client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress);
client.DefaultRequestHeaders.Add("X-Version", "1.0");
_ = client.EnableIntercept(sp);
}).AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>()
.AddHttpMessageHandler<ProblemDetailsHandler>();

_ = builder.Services.AddFileReaderService(o => o.UseWasmSharedBuffer = true);

// Supply HttpClient instances that include access tokens when making requests to the server project
_ = builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("api"))
.AddScoped<ClipboardService>();

_ = builder.Services.AddBlazoredLocalStorage();
_ = builder.Services.AddBlazoredModal();
_ = builder.Services.AddMudServices(config =>
{
config.SnackbarConfiguration.PositionClass = Defaults.Classes.Position.BottomLeft;
config.SnackbarConfiguration.PreventDuplicates = false;
});

_ = builder.Services.AddScoped<ILayoutService, LayoutService>();
_ = builder.Services.AddScoped<IDashboardLayoutService, DashboardLayoutService>();
_ = builder.Services.AddSingleton<IDeviceLayoutService, DeviceLayoutService>();
_ = builder.Services.AddSingleton<IEdgeDeviceLayoutService, EdgeDeviceLayoutService>();

_ = builder.Services.AddScoped<IEdgeModelClientService, EdgeModelClientService>();
_ = builder.Services.AddScoped<IEdgeDeviceClientService, EdgeDeviceClientService>();
_ = builder.Services.AddScoped<IDashboardMetricsClientService, DashboardMetricsClientService>();
_ = builder.Services.AddScoped<IDeviceConfigurationsClientService, DeviceConfigurationsClientService>();
_ = builder.Services.AddScoped<IDeviceModelsClientService, DeviceModelsClientService>();
_ = builder.Services.AddScoped<IDeviceTagSettingsClientService, DeviceTagSettingsClientService>();
_ = builder.Services.AddScoped<ILoRaWanConcentratorClientService, LoRaWanConcentratorClientService>();
_ = builder.Services.AddScoped<IDeviceClientService, DeviceClientService>();
_ = builder.Services.AddScoped<ILoRaWanDeviceModelsClientService, LoRaWanDeviceModelsClientService>();
_ = builder.Services.AddScoped<ILoRaWanDeviceClientService, LoRaWanDeviceClientService>();
_ = builder.Services.AddScoped<IEdgeDeviceConfigurationsClientService, EdgeDeviceConfigurationsClientService>();
_ = builder.Services.AddScoped<IIdeaClientService, IdeaClientService>();

await ConfigureOidc(builder);
await ConfigurePortalSettings(builder);

// Enable loading bar
builder.Services.AddLoadingBar(options =>
{
options.LoadingBarColor = "#D3E24A";
});
_ = builder.UseLoadingBar();

await builder.Build().RunAsync();
}

private static async Task ConfigureOidc(WebAssemblyHostBuilder builder)
{
using var httpClient = new HttpClient() { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) };
var settings = await httpClient.GetFromJsonAsync<OIDCSettings>("api/settings/oidc");

_ = builder.Services.AddOidcAuthentication(options =>
{
options.ProviderOptions.Authority = settings.Authority;
options.ProviderOptions.MetadataUrl = settings.MetadataUrl.ToString();
options.ProviderOptions.ClientId = settings.ClientId;

options.ProviderOptions.DefaultScopes.Add(settings.Scope);
options.ProviderOptions.ResponseType = "code";
});

_ = builder.Services.Configure<OIDCSettings>(opts =>
{
opts.ClientId = settings.ClientId;
opts.MetadataUrl = settings.MetadataUrl;
opts.Authority = settings.Authority;
opts.Scope = settings.Scope;
});
}

private static async Task ConfigurePortalSettings(WebAssemblyHostBuilder builder)
{
using var httpClient = new HttpClient() { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) };
var settings = await httpClient.GetFromJsonAsync<PortalSettings>("api/settings/portal");

_ = builder.Services.AddSingleton(settings);
}

}
client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress);
client.DefaultRequestHeaders.Add("X-Version", "1.0");
}).AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>()
.AddHttpMessageHandler<ProblemDetailsHandler>();

_ = builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("api"));

using var httpClient = new HttpClient() { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) };
var settings = await httpClient.GetFromJsonAsync<OIDCSettings>("api/settings/oidc");

_ = builder.Services.Configure<OIDCSettings>(opts =>
{
opts.ClientId = settings.ClientId;
opts.MetadataUrl = settings.MetadataUrl;
opts.Authority = settings.Authority;
opts.Scope = settings.Scope;
});

builder.Services.AddOidcAuthentication(options =>
{
options.ProviderOptions.Authority = settings.Authority;
options.ProviderOptions.MetadataUrl = settings.MetadataUrl.ToString();
options.ProviderOptions.ClientId = settings.ClientId;
options.ProviderOptions.ResponseType = "code";

options.ProviderOptions.DefaultScopes.Add(settings.Scope);
});

builder.Services.AddApiAuthorization();

_ = builder.Services.AddFileReaderService(o => o.UseWasmSharedBuffer = true);

_ = builder.Services.AddBlazoredLocalStorage();
_ = builder.Services.AddBlazoredModal();
_ = builder.Services.AddMudServices(config =>
{
config.SnackbarConfiguration.PositionClass = Defaults.Classes.Position.BottomLeft;
config.SnackbarConfiguration.PreventDuplicates = false;
});

_ = builder.Services.AddScoped<ILayoutService, LayoutService>();
_ = builder.Services.AddScoped<IDashboardLayoutService, DashboardLayoutService>();
_ = builder.Services.AddSingleton<IDeviceLayoutService, DeviceLayoutService>();
_ = builder.Services.AddSingleton<IEdgeDeviceLayoutService, EdgeDeviceLayoutService>();

_ = builder.Services.AddScoped<IEdgeModelClientService, EdgeModelClientService>();
_ = builder.Services.AddScoped<IEdgeDeviceClientService, EdgeDeviceClientService>();
_ = builder.Services.AddScoped<IDashboardMetricsClientService, DashboardMetricsClientService>();
_ = builder.Services.AddScoped<IDeviceConfigurationsClientService, DeviceConfigurationsClientService>();
_ = builder.Services.AddScoped<IDeviceModelsClientService, DeviceModelsClientService>();
_ = builder.Services.AddScoped<IDeviceTagSettingsClientService, DeviceTagSettingsClientService>();
_ = builder.Services.AddScoped<ILoRaWanConcentratorClientService, LoRaWanConcentratorClientService>();
_ = builder.Services.AddScoped<IDeviceClientService, DeviceClientService>();
_ = builder.Services.AddScoped<ILoRaWanDeviceModelsClientService, LoRaWanDeviceModelsClientService>();
_ = builder.Services.AddScoped<ILoRaWanDeviceClientService, LoRaWanDeviceClientService>();
_ = builder.Services.AddScoped<IEdgeDeviceConfigurationsClientService, EdgeDeviceConfigurationsClientService>();
_ = builder.Services.AddScoped<IIdeaClientService, IdeaClientService>();
_ = builder.Services.AddScoped<ClipboardService>();

await ConfigurePortalSettings(builder);

// Enable loading bar
builder.Services.AddLoadingBar(options =>
{
options.LoadingBarColor = "#D3E24A";
});
_ = builder.UseLoadingBar();

await builder.Build().RunAsync();

static async Task ConfigurePortalSettings(WebAssemblyHostBuilder builder)
{
using var httpClient = new HttpClient() { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) };
var settings = await httpClient.GetFromJsonAsync<PortalSettings>("api/settings/portal");

_ = builder.Services.AddSingleton(settings);
}
3 changes: 1 addition & 2 deletions src/AzureIoTHub.Portal.Client/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@inherits LayoutComponentBase

@using AzureIoTHub.Portal.Models.v10
@using Microsoft.AspNetCore.Components.Web.Extensions.Head

@inject PortalSettings Portal
@inject ILayoutService LayoutService
Expand All @@ -12,7 +11,7 @@
<MudDialogProvider />
<MudSnackbarProvider />

<Title value="@Portal.PortalName" />
<PageTitle>@Portal.PortalName</PageTitle>

<MudLayout>

Expand Down
8 changes: 7 additions & 1 deletion src/AzureIoTHub.Portal.Client/Shared/RedirectToLogin.razor
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
@inject NavigationManager Navigation
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using Microsoft.Extensions.Options;

@inject IOptionsSnapshot<RemoteAuthenticationOptions<ApiAuthorizationProviderOptions>> Options

@code {
protected override void OnInitialized()
{
Navigation.NavigateTo($"authentication/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}");
Navigation.NavigateToLogin(Options.Get(
Microsoft.Extensions.Options.Options.DefaultName)
.AuthenticationPaths.LogInPath);
}
}
8 changes: 0 additions & 8 deletions src/AzureIoTHub.Portal.Client/assets/babel.config.json

This file was deleted.

Loading

0 comments on commit e1948ba

Please sign in to comment.