1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-08 00:16:27 +00:00
This commit is contained in:
JKorf 2024-01-04 21:27:59 +01:00
parent c1ee36dd8a
commit 9ead87d350
5 changed files with 37 additions and 7 deletions

View File

@ -112,8 +112,29 @@ namespace CryptoExchange.Net.Converters
return item.Type == JTokenType.Array; return item.Type == JTokenType.Array;
} }
public bool IsEmptyArray(IEnumerable<int> indexes)
{
var item = _token;
foreach (var index in indexes)
{
if (item.Type != JTokenType.Array)
return false;
var arr = ((JArray)item);
if (arr.Count <= index)
return false;
item = arr[index];
}
return item.Type == JTokenType.Array && !item.HasValues;
}
private JToken? GetToken(string key) private JToken? GetToken(string key)
{ {
if (key == null)
return _token;
if (_cache.TryGetValue(key, out var token)) if (_cache.TryGetValue(key, out var token))
return token; return token;

View File

@ -9,6 +9,7 @@ namespace CryptoExchange.Net.Interfaces
{ {
bool IsObject(string? key); bool IsObject(string? key);
bool IsArray(IEnumerable<int> indexes); bool IsArray(IEnumerable<int> indexes);
bool IsEmptyArray(IEnumerable<int> indexes);
string? GetStringValue(string key); string? GetStringValue(string key);
int? GetIntValue(string key); int? GetIntValue(string key);
public int? GetCount(string key); public int? GetCount(string key);

View File

@ -30,7 +30,7 @@ namespace CryptoExchange.Net.Sockets
/// <summary> /// <summary>
/// Strings to identify this subscription with /// Strings to identify this subscription with
/// </summary> /// </summary>
public abstract List<string> StreamIdentifiers { get; } public abstract List<string> StreamIdentifiers { get; set; }
/// <summary> /// <summary>
/// The query request object /// The query request object
@ -47,7 +47,7 @@ namespace CryptoExchange.Net.Sockets
/// </summary> /// </summary>
public int Weight { get; } public int Weight { get; }
public abstract Dictionary<string, Type> TypeMapping { get; } public abstract Dictionary<string, Type> TypeMapping { get; set; }
/// <summary> /// <summary>
/// ctor /// ctor
@ -108,10 +108,18 @@ namespace CryptoExchange.Net.Sockets
/// <typeparam name="TResponse">Response object type</typeparam> /// <typeparam name="TResponse">Response object type</typeparam>
public abstract class Query<TResponse> : BaseQuery public abstract class Query<TResponse> : BaseQuery
{ {
public override Dictionary<string, Type> TypeMapping => new Dictionary<string, Type> private Dictionary<string, Type> _typeMapping = new Dictionary<string, Type>
{ {
{ "", typeof(TResponse) } { "", typeof(TResponse) }
}; };
public override Dictionary<string, Type> TypeMapping
{
get => _typeMapping;
set
{
_typeMapping = value;
}
}
/// <summary> /// <summary>
/// The typed call result /// The typed call result

View File

@ -35,8 +35,8 @@ namespace CryptoExchange.Net.Sockets
if (listeners == null) if (listeners == null)
return null; return null;
listeners.First().TypeMapping.TryGetValue(typeIdentifier ?? "", out var type); var result = listeners.SelectMany(l => l.TypeMapping).FirstOrDefault(x => x.Key == (typeIdentifier ?? ""));
return type; return result.Value;
} }
} }
@ -85,7 +85,7 @@ namespace CryptoExchange.Net.Sockets
if (!_listeners.TryGetValue(id, out var idListeners)) if (!_listeners.TryGetValue(id, out var idListeners))
return false; return false;
listeners = idListeners.ToList(); listeners = idListeners.Where(i => data.TypeIdentifier == null || i.TypeMapping.ContainsKey(data.TypeIdentifier)).ToList();
} }
foreach (var listener in listeners) foreach (var listener in listeners)

View File

@ -57,7 +57,7 @@ namespace CryptoExchange.Net.Sockets
/// <summary> /// <summary>
/// Strings to identify this subscription with /// Strings to identify this subscription with
/// </summary> /// </summary>
public abstract List<string> StreamIdentifiers { get; } public abstract List<string> StreamIdentifiers { get; set; }
/// <summary> /// <summary>
/// Cancellation token registration /// Cancellation token registration