浏览代码

- Json library from Newtonsoft

- bug in assets of service-worker.js
master
Flo Smilari 4 年前
父节点
当前提交
549d40bfd3

+ 2
- 6
Shared/Models/ReportResponse.cs 查看文件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Net;
namespace cwebplusApp.Shared.Models { namespace cwebplusApp.Shared.Models {
public class ReportResponse { public class ReportResponse {
public string GetDataAsFormattedList() { public string GetDataAsFormattedList() {
string result = ""; string result = "";
foreach(string s in Data) {
foreach (string s in Data) {
result += s + "\r\n"; result += s + "\r\n";
} }
return result; return result;

+ 8
- 14
Shared/Services/LFBicycleRest.cs 查看文件

using cwebplusApp.Shared.Models; using cwebplusApp.Shared.Models;
using Json.Net;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace cwebplusApp.Shared.Services { namespace cwebplusApp.Shared.Services {
HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format(subResourceUrl, VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format(subResourceUrl, VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName));
if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) {
ColorItem[] colors = JsonNet.Deserialize<ColorItem[]>(await httpResult.Content.ReadAsStringAsync());
ColorItem[] colors = JsonConvert.DeserializeObject<ColorItem[]>(await httpResult.Content.ReadAsStringAsync());
return new List<ColorItem>(colors); return new List<ColorItem>(colors);
} }
throw new HttpRequestException("HTTP error " + httpResult.StatusCode); throw new HttpRequestException("HTTP error " + httpResult.StatusCode);
HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format(subResourceUrl, VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format(subResourceUrl, VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName));
if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) {
BicycleType[] bicycleTypes = JsonNet.Deserialize<BicycleType[]>(await httpResult.Content.ReadAsStringAsync());
BicycleType[] bicycleTypes = JsonConvert.DeserializeObject<BicycleType[]>(await httpResult.Content.ReadAsStringAsync());
return new List<BicycleType>(bicycleTypes); return new List<BicycleType>(bicycleTypes);
} }
throw new HttpRequestException("HTTP error " + httpResult.StatusCode); throw new HttpRequestException("HTTP error " + httpResult.StatusCode);
HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format(subResourceUrl, VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format(subResourceUrl, VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName));
if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) {
Brand[] brands = JsonNet.Deserialize<Brand[]>(await httpResult.Content.ReadAsStringAsync());
Brand[] brands = JsonConvert.DeserializeObject<Brand[]>(await httpResult.Content.ReadAsStringAsync());
return new List<Brand>(brands); return new List<Brand>(brands);
} }
throw new HttpRequestException("HTTP error " + httpResult.StatusCode); throw new HttpRequestException("HTTP error " + httpResult.StatusCode);
if (httpClient != null) { if (httpClient != null) {
string subResourceUrl = Configuration.GetValue<string>("subresource_url_foundreport"); string subResourceUrl = Configuration.GetValue<string>("subresource_url_foundreport");
if (!String.IsNullOrEmpty(subResourceUrl)) { if (!String.IsNullOrEmpty(subResourceUrl)) {
string reportJson = JsonNet.Serialize(report);
string reportJson = JsonConvert.SerializeObject(report);
HttpContent content = new StringContent(reportJson, Encoding.UTF8, "application/json"); HttpContent content = new StringContent(reportJson, Encoding.UTF8, "application/json");
HttpResponseMessage httpResult = await httpClient.PostAsync(string.Format(subResourceUrl, VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName), content); HttpResponseMessage httpResult = await httpClient.PostAsync(string.Format(subResourceUrl, VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName), content);
string msg = await httpResult.Content.ReadAsStringAsync(); string msg = await httpResult.Content.ReadAsStringAsync();
ReportResponse response = JsonNet.Deserialize<ReportResponse>(msg);
ReportResponse response = JsonConvert.DeserializeObject<ReportResponse>(msg);
response.StatusCode = httpResult.StatusCode; response.StatusCode = httpResult.StatusCode;
//ReportResponse response = new();
//response.StatusCode = System.Net.HttpStatusCode.OK;
//Thread.Sleep(2000);
return response; return response;
} }
} }
if (httpClient != null) { if (httpClient != null) {
string subResourceUrl = Configuration.GetValue<string>("subresource_url_missingreport"); string subResourceUrl = Configuration.GetValue<string>("subresource_url_missingreport");
if (!String.IsNullOrEmpty(subResourceUrl)) { if (!String.IsNullOrEmpty(subResourceUrl)) {
string reportJson = JsonNet.Serialize(report);
string reportJson = JsonConvert.SerializeObject(report);
HttpContent content = new StringContent(reportJson, Encoding.UTF8, "application/json"); HttpContent content = new StringContent(reportJson, Encoding.UTF8, "application/json");
HttpResponseMessage httpResult = await httpClient.PostAsync(string.Format(subResourceUrl, VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName), content); HttpResponseMessage httpResult = await httpClient.PostAsync(string.Format(subResourceUrl, VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName), content);
if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) {
ReportResponse reponse = JsonNet.Deserialize<ReportResponse>(await httpResult.Content.ReadAsStringAsync());
ReportResponse reponse = JsonConvert.DeserializeObject<ReportResponse>(await httpResult.Content.ReadAsStringAsync());
return reponse; return reponse;
} }
throw new HttpRequestException("HTTP error " + httpResult.StatusCode); throw new HttpRequestException("HTTP error " + httpResult.StatusCode);

+ 7
- 7
Shared/Services/MasterDataService.cs 查看文件

using cwebplusApp.Shared.Models; using cwebplusApp.Shared.Models;
using cwebplusApp.Shared.ResourceFiles; using cwebplusApp.Shared.ResourceFiles;
using Json.Net;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using Microsoft.JSInterop; using Microsoft.JSInterop;
using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
if (String.IsNullOrEmpty(str)) { if (String.IsNullOrEmpty(str)) {
result = Array.Empty<ColorItem>(); result = Array.Empty<ColorItem>();
} else { } else {
result = JsonNet.Deserialize<ColorItem[]>(str) ?? Array.Empty<ColorItem>();
result = JsonConvert.DeserializeObject<ColorItem[]>(str) ?? Array.Empty<ColorItem>();
} }
return result; return result;
} }
if (String.IsNullOrEmpty(str)) { if (String.IsNullOrEmpty(str)) {
result = Array.Empty<BicycleType>(); result = Array.Empty<BicycleType>();
} else { } else {
result = JsonNet.Deserialize<BicycleType[]>(str) ?? Array.Empty<BicycleType>();
result = JsonConvert.DeserializeObject<BicycleType[]>(str) ?? Array.Empty<BicycleType>();
} }
return result; return result;
} }
if (String.IsNullOrEmpty(str)) { if (String.IsNullOrEmpty(str)) {
result = Array.Empty<Brand>(); result = Array.Empty<Brand>();
} else { } else {
result = JsonNet.Deserialize<Brand[]>(str) ?? Array.Empty<Brand>();
result = JsonConvert.DeserializeObject<Brand[]>(str) ?? Array.Empty<Brand>();
} }
return result; return result;
} }
private async Task SaveColorsToStorage(ColorItem[] colors) { private async Task SaveColorsToStorage(ColorItem[] colors) {
var json = JsonNet.Serialize(colors);
var json = JsonConvert.SerializeObject(colors);
await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameColors, json); await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameColors, json);
} }
private async Task SaveBcTypesToStorage(BicycleType[] bicycleTypes) { private async Task SaveBcTypesToStorage(BicycleType[] bicycleTypes) {
var json = JsonNet.Serialize(bicycleTypes);
var json = JsonConvert.SerializeObject(bicycleTypes);
await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBcTypes, json); await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBcTypes, json);
} }
private async Task SaveBrandsToStorage(Brand[] brands) { private async Task SaveBrandsToStorage(Brand[] brands) {
var json = JsonNet.Serialize(brands);
var json = JsonConvert.SerializeObject(brands);
await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBrands, json); await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBrands, json);
} }

+ 5
- 3
Shared/Services/OSM/NominatimService.cs 查看文件

using cwebplusApp.Shared.Models; using cwebplusApp.Shared.Models;
using Json.Net;
using Newtonsoft.Json;
//using Json.Net;
using System; using System;
using System.Globalization; using System.Globalization;
using System.Net.Http; using System.Net.Http;
namespace cwebplusApp.Shared.Services { namespace cwebplusApp.Shared.Services {
public class NominatimService { public class NominatimService {
public static async Task<NominatimReverseAddress> GetAddressForCoordinates(double latitude, double longitude) {
public static async ValueTask<NominatimReverseAddress> GetAddressForCoordinates(double latitude, double longitude) {
string lat = latitude.ToString("0.0000000000", CultureInfo.InvariantCulture); string lat = latitude.ToString("0.0000000000", CultureInfo.InvariantCulture);
string lng = longitude.ToString("0.0000000000", CultureInfo.InvariantCulture); string lng = longitude.ToString("0.0000000000", CultureInfo.InvariantCulture);
HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("reverse?format=json&accept-language={0}&lat={1}&lon={2}", HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("reverse?format=json&accept-language={0}&lat={1}&lon={2}",
CultureInfo.CurrentCulture.Name, lat, lng)); CultureInfo.CurrentCulture.Name, lat, lng));
if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) {
NominatimReverseAddress addressDto = JsonNet.Deserialize<NominatimReverseAddress>(await httpResult.Content.ReadAsStringAsync());
string contentStr = await httpResult.Content.ReadAsStringAsync();
NominatimReverseAddress addressDto = JsonConvert.DeserializeObject<NominatimReverseAddress>(contentStr);
return addressDto; return addressDto;
} }
return null; return null;

+ 3
- 2
Shared/Services/UserDataProvider.cs 查看文件

using cwebplusApp.Shared.Models; using cwebplusApp.Shared.Models;
using Microsoft.JSInterop; using Microsoft.JSInterop;
using Newtonsoft.Json;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
UserData result; UserData result;
var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyName); var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyName);
if (str != null) { if (str != null) {
result = System.Text.Json.JsonSerializer.Deserialize<UserData>(str) ?? new UserData();
result = JsonConvert.DeserializeObject<UserData>(str) ?? new UserData();
} else { } else {
result = new UserData(); result = new UserData();
} }
} }
public async Task Save(UserData _data) { public async Task Save(UserData _data) {
var json = System.Text.Json.JsonSerializer.Serialize(_data);
var json = JsonConvert.SerializeObject(_data);
await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyName, json); await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyName, json);
} }

+ 1
- 2
cwebplusApp.csproj 查看文件

<PackageReference Include="BlazorAnimate" Version="3.0.0" /> <PackageReference Include="BlazorAnimate" Version="3.0.0" />
<PackageReference Include="BlazorGeolocation" Version="0.1.1" /> <PackageReference Include="BlazorGeolocation" Version="0.1.1" />
<PackageReference Include="FisSst.BlazorMaps" Version="1.0.2" /> <PackageReference Include="FisSst.BlazorMaps" Version="1.0.2" />
<PackageReference Include="Json.Net" Version="1.0.33" />
<PackageReference Include="MatBlazor" Version="2.9.0-develop-042" /> <PackageReference Include="MatBlazor" Version="2.9.0-develop-042" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.8" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.8" PrivateAssets="all" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.8" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="5.0.8" /> <PackageReference Include="Microsoft.Extensions.Localization" Version="5.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" /> <PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

+ 1
- 1
wwwroot/service-worker.js 查看文件

'_content/blazoranimate/aos.css', '_content/blazoranimate/aos.css',
'_framework/blazor.webassembly.js', '_framework/blazor.webassembly.js',
'_framework/blazor.boot.json', '_framework/blazor.boot.json',
'_framework/dotnet.5.0.7.js',
'_framework/dotnet.5.0.8.js',
'https://fonts.googleapis.com/css?family=Roboto:300,400,500', 'https://fonts.googleapis.com/css?family=Roboto:300,400,500',
'https://fonts.googleapis.com/icon?family=Material+Icons', 'https://fonts.googleapis.com/icon?family=Material+Icons',
'https://fonts.googleapis.com/css2?family=Ubuntu:wght@400;700&display=swap', 'https://fonts.googleapis.com/css2?family=Ubuntu:wght@400;700&display=swap',

正在加载...
取消
保存