1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-14 01:42:55 +00:00

Added some extra checks

This commit is contained in:
Jan Korf
2019-05-28 09:38:05 +02:00
parent 4ec4159455
commit 4e4ce047b4
4 changed files with 64 additions and 13 deletions
+29
View File
@@ -1,11 +1,15 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Security;
using System.Threading;
using System.Threading.Tasks;
using CryptoExchange.Net.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace CryptoExchange.Net
{
@@ -127,5 +131,30 @@ namespace CryptoExchange.Net
{
return handle.WaitOneAsync((int)timeout.TotalMilliseconds, CancellationToken.None);
}
public static JToken ToJToken(this string stringData, Log log = null)
{
if (string.IsNullOrEmpty(stringData))
return null;
try
{
return JToken.Parse(stringData);
}
catch (JsonReaderException jre)
{
var info = $"Deserialize JsonReaderException: {jre.Message}, Path: {jre.Path}, LineNumber: {jre.LineNumber}, LinePosition: {jre.LinePosition}. Data: {stringData}";
log?.Write(LogVerbosity.Error, info);
if (log == null) Debug.WriteLine(LogVerbosity.Error, info);
return null;
}
catch (JsonSerializationException jse)
{
var info = $"Deserialize JsonSerializationException: {jse.Message}. Data: {stringData}";
log?.Write(LogVerbosity.Error, info);
if (log == null) Debug.WriteLine(LogVerbosity.Error, info);
return null;
}
}
}
}