mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-09 00:46:19 +00:00
wip
This commit is contained in:
parent
12d5783625
commit
c931a60cb7
@ -23,7 +23,7 @@ namespace CryptoExchange.Net.Converters
|
||||
public abstract MessageInterpreterPipeline InterpreterPipeline { get; }
|
||||
|
||||
/// <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
|
||||
// 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);
|
||||
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
|
||||
{
|
||||
|
@ -312,7 +312,7 @@ namespace CryptoExchange.Net.Sockets
|
||||
/// <returns></returns>
|
||||
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)
|
||||
{
|
||||
// Not able to parse at all
|
||||
|
@ -5,13 +5,11 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.Sockets
|
||||
{
|
||||
internal class SocketListenerManager
|
||||
public class SocketListenerManager
|
||||
{
|
||||
private ILogger _logger;
|
||||
private int _socketId;
|
||||
@ -29,10 +27,13 @@ namespace CryptoExchange.Net.Sockets
|
||||
_socketId = socketId;
|
||||
}
|
||||
|
||||
public Dictionary<string, Type> GetMapping()
|
||||
public Type? IdToType(string id)
|
||||
{
|
||||
lock (this)
|
||||
return _typeMap;
|
||||
lock (_lock)
|
||||
{
|
||||
_typeMap.TryGetValue(id, out var type);
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
public List<string> GetListenIds()
|
||||
|
Loading…
x
Reference in New Issue
Block a user