| @page "/" | @page "/" | ||||
| @using cwebplusApp.Shared.Services; | @using cwebplusApp.Shared.Services; | ||||
| @using System.Threading; | @using System.Threading; | ||||
| @using Microsoft.Extensions.Configuration; | |||||
| @inject NavigationManager NavigationManager; | @inject NavigationManager NavigationManager; | ||||
| @inject AppState AppState; | @inject AppState AppState; | ||||
| @inject IStringLocalizer<Resources> i18n | @inject IStringLocalizer<Resources> i18n | ||||
| @inject PageHistoryManager PageHistoryManager | @inject PageHistoryManager PageHistoryManager | ||||
| @inject MasterDataService MasterDataService; | @inject MasterDataService MasterDataService; | ||||
| @inject Toaster Toaster; | @inject Toaster Toaster; | ||||
| @inject IConfiguration Configuration; | |||||
| @inject ILFBicycleRest iLFBicycleRest; | |||||
| <div class="row h-100 justify-content-center"> | <div class="row h-100 justify-content-center"> | ||||
| showProgressCircle = true; | showProgressCircle = true; | ||||
| StateHasChanged(); | StateHasChanged(); | ||||
| try { | try { | ||||
| iLFBicycleRest.Initialize(Configuration); | |||||
| await MasterDataService.SynchronizeMasterdata(); | await MasterDataService.SynchronizeMasterdata(); | ||||
| } catch (Exception) { | } catch (Exception) { | ||||
| Toaster.ShowWarning(i18n.GetString("Warning.Masterdata.Title"), i18n.GetString("Warning.Masterdata.Msg")); | Toaster.ShowWarning(i18n.GetString("Warning.Masterdata.Title"), i18n.GetString("Warning.Masterdata.Msg")); |
| using cwebplusApp.Shared.Models; | using cwebplusApp.Shared.Models; | ||||
| using Microsoft.Extensions.Configuration; | |||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| namespace cwebplusApp.Shared.Services { | namespace cwebplusApp.Shared.Services { | ||||
| public interface ILFBicycleRest { | public interface ILFBicycleRest { | ||||
| void Initialize(IConfiguration configuration); | |||||
| Task<List<ColorItem>> GetColors(); | Task<List<ColorItem>> GetColors(); | ||||
| Task<List<BicycleType>> GetBicycleTypes(); | Task<List<BicycleType>> GetBicycleTypes(); |
| using cwebplusApp.Shared.Models; | using cwebplusApp.Shared.Models; | ||||
| using Json.Net; | using Json.Net; | ||||
| using Microsoft.AspNetCore.Components; | |||||
| using Microsoft.Extensions.Configuration; | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Globalization; | using System.Globalization; | ||||
| private static readonly string VERSION = "v1"; | private static readonly string VERSION = "v1"; | ||||
| private readonly HttpClient httpClient; | |||||
| private HttpClient httpClient; | |||||
| [Inject] | |||||
| public IConfiguration Configuration { get; set; } | |||||
| public LFBicycleRest() { | |||||
| this.httpClient = new HttpClient { BaseAddress = new Uri("https://integrate.dynalias.net:9443/Fundvelo/") }; | |||||
| public void Initialize(IConfiguration configuration) { | |||||
| this.Configuration = configuration; | |||||
| string hostBaseUrl = Configuration.GetValue<string>("host_base_url"); | |||||
| Console.WriteLine("host_base_url: " + hostBaseUrl); | |||||
| if (!String.IsNullOrEmpty(hostBaseUrl)) { | |||||
| this.httpClient = new HttpClient { BaseAddress = new Uri(hostBaseUrl) }; | |||||
| } | |||||
| } | } | ||||
| public async Task<List<ColorItem>> GetColors() { | public async Task<List<ColorItem>> GetColors() { | ||||
| HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/colors", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); | |||||
| if (httpClient != null) { | |||||
| string subResourceUrl = Configuration.GetValue<string>("subresource_url_colors"); | |||||
| if (!String.IsNullOrEmpty(subResourceUrl)) { | |||||
| HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format(subResourceUrl, VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); | |||||
| if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { | |||||
| ColorItem[] colors = JsonNet.Deserialize<ColorItem[]>(await httpResult.Content.ReadAsStringAsync()); | |||||
| return new List<ColorItem>(colors); | |||||
| if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { | |||||
| ColorItem[] colors = JsonNet.Deserialize<ColorItem[]>(await httpResult.Content.ReadAsStringAsync()); | |||||
| return new List<ColorItem>(colors); | |||||
| } | |||||
| throw new HttpRequestException("HTTP error " + httpResult.StatusCode); | |||||
| } | |||||
| } | } | ||||
| throw new HttpRequestException("HTTP error " + httpResult.StatusCode); | |||||
| throw new HttpRequestException("HTTP client not initialized!"); | |||||
| } | } | ||||
| public async Task<List<BicycleType>> GetBicycleTypes() { | public async Task<List<BicycleType>> GetBicycleTypes() { | ||||
| HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/types", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); | |||||
| if (httpClient != null) { | |||||
| string subResourceUrl = Configuration.GetValue<string>("subresource_url_types"); | |||||
| if (!String.IsNullOrEmpty(subResourceUrl)) { | |||||
| HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format(subResourceUrl, VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); | |||||
| if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { | |||||
| BicycleType[] bicycleTypes = JsonNet.Deserialize<BicycleType[]>(await httpResult.Content.ReadAsStringAsync()); | |||||
| return new List<BicycleType>(bicycleTypes); | |||||
| if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { | |||||
| BicycleType[] bicycleTypes = JsonNet.Deserialize<BicycleType[]>(await httpResult.Content.ReadAsStringAsync()); | |||||
| return new List<BicycleType>(bicycleTypes); | |||||
| } | |||||
| throw new HttpRequestException("HTTP error " + httpResult.StatusCode); | |||||
| } | |||||
| } | } | ||||
| throw new HttpRequestException("HTTP error " + httpResult.StatusCode); | |||||
| throw new HttpRequestException("HTTP client not initialized!"); | |||||
| } | } | ||||
| public async Task<List<Brand>> GetBrands() { | public async Task<List<Brand>> GetBrands() { | ||||
| HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/brands", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); | |||||
| if (httpClient != null) { | |||||
| string subResourceUrl = Configuration.GetValue<string>("subresource_url_brands"); | |||||
| if (!String.IsNullOrEmpty(subResourceUrl)) { | |||||
| HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format(subResourceUrl, VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); | |||||
| if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { | |||||
| Brand[] brands = JsonNet.Deserialize<Brand[]>(await httpResult.Content.ReadAsStringAsync()); | |||||
| return new List<Brand>(brands); | |||||
| if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { | |||||
| Brand[] brands = JsonNet.Deserialize<Brand[]>(await httpResult.Content.ReadAsStringAsync()); | |||||
| return new List<Brand>(brands); | |||||
| } | |||||
| throw new HttpRequestException("HTTP error " + httpResult.StatusCode); | |||||
| } | |||||
| } | } | ||||
| throw new HttpRequestException("HTTP error " + httpResult.StatusCode); | |||||
| throw new HttpRequestException("HTTP client not initialized!"); | |||||
| } | } | ||||
| } | } |
| _brands = Defaults.GetBrandDefaults(_i18n).ToArray(); | _brands = Defaults.GetBrandDefaults(_i18n).ToArray(); | ||||
| _colors = Defaults.GetColorDefaults(_i18n).ToArray(); | _colors = Defaults.GetColorDefaults(_i18n).ToArray(); | ||||
| _bicycleTypes = Defaults.GetBicycleTypeDefaults(_i18n).ToArray(); | _bicycleTypes = Defaults.GetBicycleTypeDefaults(_i18n).ToArray(); | ||||
| Console.WriteLine("MasterDataService constructor / colors: " + _colors.Length); | |||||
| } | } | ||||
| public async Task SynchronizeMasterdata() { | public async Task SynchronizeMasterdata() { |
| <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.7" /> | <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.7" /> | ||||
| <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.7" PrivateAssets="all" /> | <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.7" PrivateAssets="all" /> | ||||
| <PackageReference Include="Microsoft.Extensions.Localization" Version="5.0.7" /> | <PackageReference Include="Microsoft.Extensions.Localization" Version="5.0.7" /> | ||||
| <PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" /> | |||||
| <PackageReference Include="System.Net.Http.Json" Version="5.0.0" /> | <PackageReference Include="System.Net.Http.Json" Version="5.0.0" /> | ||||
| </ItemGroup> | </ItemGroup> | ||||
| </PropertyGroup> | </PropertyGroup> | ||||
| <PropertyGroup> | <PropertyGroup> | ||||
| <ActiveDebugProfile>CaritasPWA</ActiveDebugProfile> | <ActiveDebugProfile>CaritasPWA</ActiveDebugProfile> | ||||
| <NameOfLastUsedPublishProfile>D:\Work\Caritas\CaritasPWA\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile> | |||||
| </PropertyGroup> | </PropertyGroup> | ||||
| </Project> | </Project> |
| { | |||||
| "host_base_url": "https://integrate.dynalias.net:9443/Fundvelo/", | |||||
| "subresource_url_colors": "api/{0}/{1}/fundvelo/colors", | |||||
| "subresource_url_brands": "api/{0}/{1}/fundvelo/brands", | |||||
| "subresource_url_types=": "api/{0}/{1}/fundvelo/types" | |||||
| } |
| .fv-osm-tile { | .fv-osm-tile { | ||||
| border: 1px solid rgb(0 0 0 /.38); | border: 1px solid rgb(0 0 0 /.38); | ||||
| height: 100%; | |||||
| border-radius: 20px; | border-radius: 20px; | ||||
| } | } | ||||
| // be reflected on the first load after each change). | // be reflected on the first load after each change). | ||||
| const staticCacheName = 'site-static-v1'; // IMPORTANT: CHANGE THE VERSION IN THIS NAME EVERY TIME THE APP IS DEPLOYED ON SERVER WITH CHANGES!!! | const staticCacheName = 'site-static-v1'; // IMPORTANT: CHANGE THE VERSION IN THIS NAME EVERY TIME THE APP IS DEPLOYED ON SERVER WITH CHANGES!!! | ||||
| const appsettings_url = 'appsettings.json'; | |||||
| const assets = [ | const assets = [ | ||||
| './', | './', | ||||
| '/index.html', | '/index.html', | ||||
| 'https://fonts.gstatic.com/s/roboto/v27/KFOlCnqEu92Fr1MmEU9fBBc4AMP6lQ.woff2', | 'https://fonts.gstatic.com/s/roboto/v27/KFOlCnqEu92Fr1MmEU9fBBc4AMP6lQ.woff2', | ||||
| 'https://fonts.gstatic.com/s/roboto/v27/KFOmCnqEu92Fr1Mu4mxKKTU1Kg.woff2', | 'https://fonts.gstatic.com/s/roboto/v27/KFOmCnqEu92Fr1Mu4mxKKTU1Kg.woff2', | ||||
| 'https://fonts.gstatic.com/s/materialicons/v85/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2', | 'https://fonts.gstatic.com/s/materialicons/v85/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2', | ||||
| 'appsettings.json', | |||||
| 'manifest.json' | 'manifest.json' | ||||
| ]; | ]; | ||||
| // install event | // install event | ||||
| self.addEventListener('install', evt => { | |||||
| evt.waitUntil( | |||||
| self.addEventListener('install', event => { | |||||
| event.waitUntil( | |||||
| caches.open(staticCacheName).then(cache => { | caches.open(staticCacheName).then(cache => { | ||||
| console.log('caching app assets'); | console.log('caching app assets'); | ||||
| cache.addAll(assets); | cache.addAll(assets); | ||||
| ); | ); | ||||
| }); | }); | ||||
| self.addEventListener('fetch', evt => { | |||||
| evt.respondWith( | |||||
| caches.match(evt.request).then(cacheRes => { | |||||
| return cacheRes || fetch(evt.request); | |||||
| }) | |||||
| ); | |||||
| }); | |||||
| // fetch events (appsettings are always first fetched from network) | |||||
| self.addEventListener('fetch', event => { | |||||
| if (event.request.url.endsWith(appsettings_url)) { | |||||
| fetch(event.request).then(function (response) { | |||||
| return caches.open(staticCacheName).then(function (cache) { | |||||
| console.log('update cache'); | |||||
| cache.put(event.request, response.clone()); | |||||
| return response; | |||||
| }); | |||||
| }); | |||||
| } else { | |||||
| event.respondWith( | |||||
| caches.match(event.request).then(cacheRes => { | |||||
| return cacheRes || fetch(event.request); | |||||
| }) | |||||
| ); | |||||
| } | |||||
| }); |