|
1 | 1 | using System; |
| 2 | +using System.Diagnostics.CodeAnalysis; |
2 | 3 | using System.Globalization; |
3 | | -using System.Linq; |
4 | 4 | using System.Threading; |
5 | 5 | using System.Threading.Tasks; |
| 6 | +using Microsoft.AspNetCore.Components; |
6 | 7 | using Microsoft.AspNetCore.Components.WebAssembly.Hosting; |
7 | 8 | using Microsoft.Extensions.DependencyInjection; |
8 | 9 | using Microsoft.Extensions.Logging; |
9 | 10 | using NetEvent.Client.Services; |
10 | | -using NetEvent.Shared.Constants; |
| 11 | +using NetEvent.Shared.Config; |
11 | 12 |
|
12 | 13 | namespace NetEvent.Client.Extensions; |
13 | 14 |
|
14 | | -public static class WebAssemblyHostExtension |
| 15 | +[ExcludeFromCodeCoverage(Justification = "Ignore UI Extensions")] |
| 16 | +public static class DefaultCultureExtension |
15 | 17 | { |
16 | 18 | public static async Task SetDefaultCultureAsync(this WebAssemblyHost app) |
17 | 19 | { |
18 | | - var organizationDataService = app.Services.GetRequiredService<IOrganizationDataService>(); |
| 20 | + var organizationDataService = app.Services.GetRequiredService<ISystemSettingsDataService>(); |
19 | 21 | var logger = app.Services.GetRequiredService<ILogger<WebAssemblyHost>>(); |
20 | 22 |
|
21 | 23 | try |
22 | 24 | { |
23 | 25 | using var cancellationTokenSource = new CancellationTokenSource(); |
24 | 26 |
|
25 | | - var orgData = await organizationDataService.GetOrganizationDataAsync(cancellationTokenSource.Token).ConfigureAwait(false); |
26 | | - |
27 | | - var organizationCulture = orgData.FirstOrDefault(a => a.Key.Equals(OrganizationDataConstants.CultureKey)); |
| 27 | + var organizationCulture = await organizationDataService.GetSystemSettingAsync( |
| 28 | + SystemSettingGroup.OrganizationData, |
| 29 | + SystemSettings.DataCultureInfo, |
| 30 | + newCulture => |
| 31 | + { |
| 32 | + if (CultureInfo.DefaultThreadCurrentCulture?.Name.Equals(newCulture.Value, StringComparison.OrdinalIgnoreCase) != true) |
| 33 | + { |
| 34 | + var navigationManager = app.Services.GetRequiredService<NavigationManager>(); |
| 35 | + navigationManager.NavigateTo(navigationManager.Uri, true); |
| 36 | + } |
| 37 | + }, |
| 38 | + cancellationTokenSource.Token).ConfigureAwait(false); |
28 | 39 |
|
29 | 40 | if (organizationCulture == null) |
30 | 41 | { |
|
0 commit comments