Переглянути джерело

- Json library from Newtonsoft

- bug in assets of service-worker.js
master
Flo Smilari 4 роки тому
джерело
коміт
549d40bfd3

+ 2
- 6
Shared/Models/ReportResponse.cs Переглянути файл

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Net;
namespace cwebplusApp.Shared.Models {
public class ReportResponse {
@@ -13,7 +9,7 @@ namespace cwebplusApp.Shared.Models {
public string GetDataAsFormattedList() {
string result = "";
foreach(string s in Data) {
foreach (string s in Data) {
result += s + "\r\n";
}
return result;

+ 8
- 14
Shared/Services/LFBicycleRest.cs Переглянути файл

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

+ 7
- 7
Shared/Services/MasterDataService.cs Переглянути файл

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

+ 5
- 3
Shared/Services/OSM/NominatimService.cs Переглянути файл

@@ -1,5 +1,6 @@
using cwebplusApp.Shared.Models;
using Json.Net;
using Newtonsoft.Json;
//using Json.Net;
using System;
using System.Globalization;
using System.Net.Http;
@@ -8,7 +9,7 @@ using System.Threading.Tasks;
namespace cwebplusApp.Shared.Services {
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 lng = longitude.ToString("0.0000000000", CultureInfo.InvariantCulture);
@@ -17,7 +18,8 @@ namespace cwebplusApp.Shared.Services {
HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("reverse?format=json&accept-language={0}&lat={1}&lon={2}",
CultureInfo.CurrentCulture.Name, lat, lng));
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 null;

+ 3
- 2
Shared/Services/UserDataProvider.cs Переглянути файл

@@ -1,5 +1,6 @@
using cwebplusApp.Shared.Models;
using Microsoft.JSInterop;
using Newtonsoft.Json;
using System;
using System.Threading.Tasks;
@@ -33,7 +34,7 @@ namespace cwebplusApp.Shared.Services {
UserData result;
var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyName);
if (str != null) {
result = System.Text.Json.JsonSerializer.Deserialize<UserData>(str) ?? new UserData();
result = JsonConvert.DeserializeObject<UserData>(str) ?? new UserData();
} else {
result = new UserData();
}
@@ -41,7 +42,7 @@ namespace cwebplusApp.Shared.Services {
}
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);
}

+ 1
- 2
cwebplusApp.csproj Переглянути файл

@@ -17,13 +17,12 @@
<PackageReference Include="BlazorAnimate" Version="3.0.0" />
<PackageReference Include="BlazorGeolocation" Version="0.1.1" />
<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="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.8" PrivateAssets="all" />
<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.Net.Http.Json" Version="5.0.0" />
</ItemGroup>
<ItemGroup>

+ 1
- 1
wwwroot/service-worker.js Переглянути файл

@@ -43,7 +43,7 @@ const assets = [
'_content/blazoranimate/aos.css',
'_framework/blazor.webassembly.js',
'_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/icon?family=Material+Icons',
'https://fonts.googleapis.com/css2?family=Ubuntu:wght@400;700&display=swap',

Завантаження…
Відмінити
Зберегти