Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Unassigned values read over WebAPI fail to parse #219

Merged
merged 3 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
/// <inheritdoc />
public void Read(string value)
{
UpdateRead(bool.Parse(value));
if (bool.TryParse(value, out var val))
{
UpdateRead(val);
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md

using AXSharp.Connector.ValueTypes;
using Newtonsoft.Json.Linq;

namespace AXSharp.Connector.S71500.WebApi;

Expand Down Expand Up @@ -64,9 +65,12 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
}

/// <inheritdoc />
public void Read(string result)
public void Read(string value)
{
UpdateRead(byte.Parse(result));
if (byte.TryParse(value, out var val))
{
UpdateRead(val);
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
/// <inheritdoc />
public void Read(string value)
{
UpdateRead(char.Parse(value));
if (char.TryParse(value, out var val))
{
UpdateRead(val);
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
/// <inheritdoc />
public void Read(string value)
{
UpdateRead(int.Parse(value));
if (int.TryParse(value, out var val))
{
UpdateRead(val);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
/// <inheritdoc />
public void Read(string value)
{
UpdateRead(uint.Parse(value));
if (uint.TryParse(value, out var val))
{
UpdateRead(val);
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ public override async Task<DateOnly> GetAsync()

private DateOnly GetFromBinary(string value)
{
var val = long.Parse(value);
return GetFromBinary(val);
if (long.TryParse(value, out var val))
{
return GetFromBinary(val);
}

return DateOnly.MinValue;
}

private DateOnly GetFromBinary(long value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md

using AXSharp.Connector.ValueTypes;
using Newtonsoft.Json.Linq;

namespace AXSharp.Connector.S71500.WebApi;

Expand Down Expand Up @@ -75,9 +76,14 @@ public override async Task<DateTime> GetAsync()
return await _webApiConnector.ReadAsync<DateTime>(this);
}

private DateTime GetFromBinary(string val)
private DateTime GetFromBinary(string value)
{
return GetFromBinary(long.Parse(val));
if (long.TryParse(value, out var val))
{
return GetFromBinary(val);
}

return DateTime.MinValue;
}

private DateTime GetFromBinary(long val)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
/// <inheritdoc />
public void Read(string value)
{
UpdateRead(short.Parse(value));
if (short.TryParse(value, out var val))
{
UpdateRead(val);
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ public override async Task<DateOnly> GetAsync()

private DateOnly GetFromBinary(string value)
{
var val = long.Parse(value);
return GetFromBinary(val);
return long.TryParse(value, out var val) ? GetFromBinary(val) : DateOnly.MinValue;
}

private DateOnly GetFromBinary(long value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md

using AXSharp.Connector.ValueTypes;
using Newtonsoft.Json.Linq;

namespace AXSharp.Connector.S71500.WebApi;

Expand Down Expand Up @@ -75,9 +76,9 @@ public override async Task<DateTime> GetAsync()
return await _webApiConnector.ReadAsync<DateTime>(this);
}

private DateTime GetFromBinary(string val)
private DateTime GetFromBinary(string value)
{
return GetFromBinary(long.Parse(val));
return long.TryParse(value, out var val) ? GetFromBinary(val) : DateTime.MinValue;
}

private DateTime GetFromBinary(long val)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
/// <inheritdoc />
public void Read(string value)
{
UpdateRead(long.Parse(value));
if (long.TryParse(value, out var val))
{
UpdateRead(val);
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md

using AXSharp.Connector.ValueTypes;
using Newtonsoft.Json.Linq;

namespace AXSharp.Connector.S71500.WebApi;

Expand Down Expand Up @@ -65,9 +66,12 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
}

/// <inheritdoc />
public void Read(string result)
public void Read(string value)
{
UpdateRead(double.Parse(result));
if (double.TryParse(value, out var val))
{
UpdateRead(val);
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
}

/// <inheritdoc />
public void Read(string result)
public void Read(string value)
{
UpdateRead(TimeSpan.FromMilliseconds(ToMilliseconds(long.Parse(result))));
if (long.TryParse(value, out var val))
{
UpdateRead(TimeSpan.FromMilliseconds(ToMilliseconds(val)));
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
/// <inheritdoc />
public void Read(string value)
{
UpdateRead(TimeSpan.FromMilliseconds(long.Parse(value) / 1000000));
if (long.TryParse(value, out var val))
{
UpdateRead(TimeSpan.FromMilliseconds(val / 1000000));
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md

using AXSharp.Connector.ValueTypes;
using Newtonsoft.Json.Linq;

namespace AXSharp.Connector.S71500.WebApi;

Expand Down Expand Up @@ -65,9 +66,12 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
}

/// <inheritdoc />
public void Read(string result)
public void Read(string value)
{
UpdateRead(ulong.Parse(result));
if (ulong.TryParse(value, out var val))
{
UpdateRead(val);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md

using AXSharp.Connector.ValueTypes;
using Newtonsoft.Json.Linq;

namespace AXSharp.Connector.S71500.WebApi;

Expand Down Expand Up @@ -64,9 +65,12 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
}

/// <inheritdoc />
public void Read(string result)
public void Read(string value)
{
UpdateRead(float.Parse(result));
if (float.TryParse(value, out var val))
{
UpdateRead(val);
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md

using AXSharp.Connector.ValueTypes;
using Newtonsoft.Json.Linq;

namespace AXSharp.Connector.S71500.WebApi;

Expand Down Expand Up @@ -64,9 +65,12 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
}

/// <inheritdoc />
public void Read(string result)
public void Read(string value)
{
UpdateRead(sbyte.Parse(result));
if (sbyte.TryParse(value, out var val))
{
UpdateRead(val);
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md

using AXSharp.Connector.ValueTypes;
using Newtonsoft.Json.Linq;

namespace AXSharp.Connector.S71500.WebApi;

Expand Down Expand Up @@ -65,9 +66,12 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
}

/// <inheritdoc />
public void Read(string result)
public void Read(string value)
{
UpdateRead(TimeSpan.FromMilliseconds(ToMilliseconds(long.Parse(result))));
if (long.TryParse(value, out var val))
{
UpdateRead(TimeSpan.FromMilliseconds(ToMilliseconds(val)));
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System.Globalization;
using AXSharp.Connector.ValueTypes;
using Newtonsoft.Json.Linq;

namespace AXSharp.Connector.S71500.WebApi;

Expand Down Expand Up @@ -65,9 +66,12 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
}

/// <inheritdoc />
public void Read(string result)
public void Read(string value)
{
UpdateRead(TimeSpan.FromMilliseconds(long.Parse(result) / 1000000));
if (long.TryParse(value, out var val))
{
UpdateRead(TimeSpan.FromMilliseconds(val / 1000000));
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
/// <inheritdoc />
public void Read(string value)
{
UpdateRead(ushort.Parse(value));
if (ushort.TryParse(value, out var val))
{
UpdateRead(val);
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
/// <inheritdoc />
public void Read(string value)
{
UpdateRead(ulong.Parse(value));
if (ulong.TryParse(value, out var val))
{
UpdateRead(val);
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
/// <inheritdoc />
public void Read(string value)
{
UpdateRead(byte.Parse(value));
if (byte.TryParse(value, out var val))
{
UpdateRead(val);
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
/// <inheritdoc />
public void Read(string value)
{
UpdateRead(uint.Parse(value));
if (uint.TryParse(value, out var val))
{
UpdateRead(val);
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
/// <inheritdoc />
public void Read(string value)
{
UpdateRead(char.Parse(value));
if (char.TryParse(value, out var val))
{
UpdateRead(val);
}
}

/// <inheritdoc />
Expand Down
Loading