1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-09 00:46:19 +00:00
This commit is contained in:
JKorf 2023-12-12 21:38:40 +01:00
parent 12d5783625
commit c931a60cb7
3 changed files with 22 additions and 18 deletions

View File

@ -23,7 +23,7 @@ namespace CryptoExchange.Net.Converters
public abstract MessageInterpreterPipeline InterpreterPipeline { get; } public abstract MessageInterpreterPipeline InterpreterPipeline { get; }
/// <inheritdoc /> /// <inheritdoc />
public BaseParsedMessage? ReadJson(WebSocketMessageType websocketMessageType, Stream stream, Dictionary<string, Type> processors, bool outputOriginalData) public BaseParsedMessage? ReadJson(WebSocketMessageType websocketMessageType, Stream stream, SocketListenerManager listenerManager, bool outputOriginalData)
{ {
// Start reading the data // Start reading the data
// Once we reach the properties that identify the message we save those in a dict // Once we reach the properties that identify the message we save those in a dict
@ -73,19 +73,22 @@ namespace CryptoExchange.Net.Converters
var identity = InterpreterPipeline.GetIdentity(accessor); var identity = InterpreterPipeline.GetIdentity(accessor);
if (identity != null) if (identity != null)
{ {
if (processors.TryGetValue(identity, out var type)) var result = listenerManager.IdToType(identity);
if (result == null)
{ {
var idInstance = InterpreterPipeline.ObjectInitializer(token, type);
if (outputOriginalData)
{
stream.Position = 0;
idInstance.OriginalData = sr.ReadToEnd();
}
idInstance.Identifier = identity;
idInstance.Parsed = true;
return idInstance;
} }
var idInstance = InterpreterPipeline.ObjectInitializer(token, result!);
if (outputOriginalData)
{
stream.Position = 0;
idInstance.OriginalData = sr.ReadToEnd();
}
idInstance.Identifier = identity;
idInstance.Parsed = true;
return idInstance;
} }
else else
{ {

View File

@ -312,7 +312,7 @@ namespace CryptoExchange.Net.Sockets
/// <returns></returns> /// <returns></returns>
protected virtual async Task HandleStreamMessage(WebSocketMessageType type, Stream stream) protected virtual async Task HandleStreamMessage(WebSocketMessageType type, Stream stream)
{ {
var result = ApiClient.StreamConverter.ReadJson(type, stream, _listenerManager.GetMapping(), ApiClient.ApiOptions.OutputOriginalData ?? ApiClient.ClientOptions.OutputOriginalData); var result = ApiClient.StreamConverter.ReadJson(type, stream, _listenerManager, ApiClient.ApiOptions.OutputOriginalData ?? ApiClient.ClientOptions.OutputOriginalData);
if(result == null) if(result == null)
{ {
// Not able to parse at all // Not able to parse at all

View File

@ -5,13 +5,11 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace CryptoExchange.Net.Sockets namespace CryptoExchange.Net.Sockets
{ {
internal class SocketListenerManager public class SocketListenerManager
{ {
private ILogger _logger; private ILogger _logger;
private int _socketId; private int _socketId;
@ -29,10 +27,13 @@ namespace CryptoExchange.Net.Sockets
_socketId = socketId; _socketId = socketId;
} }
public Dictionary<string, Type> GetMapping() public Type? IdToType(string id)
{ {
lock (this) lock (_lock)
return _typeMap; {
_typeMap.TryGetValue(id, out var type);
return type;
}
} }
public List<string> GetListenIds() public List<string> GetListenIds()