1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 10:08:31 +00:00

Changed Json-Serializer to .NET Default

This commit is contained in:
Darth Affe 2020-11-12 17:13:19 +01:00
parent fdb5022197
commit 42456ad7bd
6 changed files with 24 additions and 21 deletions

View File

@ -1,10 +1,10 @@
using Newtonsoft.Json; using System.Text.Json.Serialization;
namespace RGB.NET.Devices.SteelSeries.API.Model namespace RGB.NET.Devices.SteelSeries.API.Model
{ {
internal class CoreProps internal class CoreProps
{ {
[JsonProperty(PropertyName = "address")] [JsonPropertyName("address")]
public string Address { get; set; } public string Address { get; set; }
} }
} }

View File

@ -1,5 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json; using System.Text.Json.Serialization;
namespace RGB.NET.Devices.SteelSeries.API.Model namespace RGB.NET.Devices.SteelSeries.API.Model
{ {
@ -7,13 +7,13 @@ namespace RGB.NET.Devices.SteelSeries.API.Model
{ {
#region Properties & Fields #region Properties & Fields
[JsonProperty("game")] [JsonPropertyName("game")]
public string Game { get; set; } public string Game { get; set; }
[JsonProperty("event")] [JsonPropertyName("event")]
public string Name { get; set; } public string Name { get; set; }
[JsonProperty("data")] [JsonPropertyName("data")]
public Dictionary<string, object> Data { get; } = new Dictionary<string, object>(); public Dictionary<string, object> Data { get; } = new Dictionary<string, object>();
#endregion #endregion

View File

@ -1,4 +1,4 @@
using Newtonsoft.Json; using System.Text.Json.Serialization;
namespace RGB.NET.Devices.SteelSeries.API.Model namespace RGB.NET.Devices.SteelSeries.API.Model
{ {
@ -6,10 +6,10 @@ namespace RGB.NET.Devices.SteelSeries.API.Model
{ {
#region Properties & Fields #region Properties & Fields
[JsonProperty("game")] [JsonPropertyName("game")]
public string Name { get; set; } public string Name { get; set; }
[JsonProperty("game_display_name")] [JsonPropertyName("game_display_name")]
public string DisplayName { get; set; } public string DisplayName { get; set; }
#endregion #endregion

View File

@ -1,4 +1,4 @@
using Newtonsoft.Json; using System.Text.Json.Serialization;
namespace RGB.NET.Devices.SteelSeries.API.Model namespace RGB.NET.Devices.SteelSeries.API.Model
{ {
@ -6,10 +6,10 @@ namespace RGB.NET.Devices.SteelSeries.API.Model
{ {
#region Properties & Fields #region Properties & Fields
[JsonProperty("game")] [JsonPropertyName("game")]
public string Game { get; set; } public string Game { get; set; }
[JsonProperty("golisp")] [JsonPropertyName("golisp")]
public string Handler { get; set; } public string Handler { get; set; }
#endregion #endregion

View File

@ -5,7 +5,8 @@ using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using Newtonsoft.Json; using System.Text.Json;
using System.Text.Json.Serialization;
using RGB.NET.Devices.SteelSeries.API.Model; using RGB.NET.Devices.SteelSeries.API.Model;
namespace RGB.NET.Devices.SteelSeries.API namespace RGB.NET.Devices.SteelSeries.API
@ -73,8 +74,10 @@ namespace RGB.NET.Devices.SteelSeries.API
string corePropsPath = GetCorePropsPath(); string corePropsPath = GetCorePropsPath();
if (!string.IsNullOrWhiteSpace(corePropsPath) && File.Exists(corePropsPath)) if (!string.IsNullOrWhiteSpace(corePropsPath) && File.Exists(corePropsPath))
{ {
CoreProps coreProps = JsonConvert.DeserializeObject<CoreProps>(File.ReadAllText(corePropsPath)); CoreProps coreProps = JsonSerializer.Deserialize<CoreProps>(File.ReadAllText(corePropsPath));
_baseUrl = coreProps.Address; _baseUrl = coreProps?.Address;
if (_baseUrl != null)
{
if (!_baseUrl.StartsWith("http://", StringComparison.Ordinal)) if (!_baseUrl.StartsWith("http://", StringComparison.Ordinal))
_baseUrl = "http://" + _baseUrl; _baseUrl = "http://" + _baseUrl;
@ -82,6 +85,7 @@ namespace RGB.NET.Devices.SteelSeries.API
RegisterGoLispHandler(new GoLispHandler(_game, HANDLER)); RegisterGoLispHandler(new GoLispHandler(_game, HANDLER));
} }
} }
}
catch catch
{ {
_baseUrl = null; _baseUrl = null;
@ -122,7 +126,7 @@ namespace RGB.NET.Devices.SteelSeries.API
private static string PostJson(string urlSuffix, object o) private static string PostJson(string urlSuffix, object o)
{ {
string payload = JsonConvert.SerializeObject(o); string payload = JsonSerializer.Serialize(o);
return _client.PostAsync(_baseUrl + urlSuffix, new StringContent(payload, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result; return _client.PostAsync(_baseUrl + urlSuffix, new StringContent(payload, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result;
} }

View File

@ -51,7 +51,6 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\RGB.NET.Core\RGB.NET.Core.csproj" /> <ProjectReference Include="..\RGB.NET.Core\RGB.NET.Core.csproj" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="HidSharp" Version="2.1.0" /> <PackageReference Include="HidSharp" Version="2.1.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>