mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-09 08:56:13 +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; }
|
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
|
||||||
{
|
{
|
||||||
|
@ -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
|
||||||
|
@ -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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user