You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.6 KiB
62 lines
2.6 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using CoreAgent.ProtocolClient.Context;
|
|
using CoreAgent.ProtocolClient.Enums;
|
|
using CoreAgent.ProtocolClient.Managers.WebSocketMgr;
|
|
using CoreAgent.ProtocolClient.Models;
|
|
using CoreAgent.ProtocolClient.ProtocolEngineCore;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace CoreAgent.ProtocolClient.ProtocolWsClient
|
|
{
|
|
/// <summary>
|
|
/// 协议 WebSocket 客户端主类(核心字段与构造)。
|
|
/// </summary>
|
|
public partial class ProtocolWsClient : IProtocolWsClient
|
|
{
|
|
#region 字段
|
|
private readonly WebSocketMessageManager _messageManager;
|
|
private readonly ILogger<ProtocolWsClient> _logger;
|
|
private readonly ProtocolClientConfig _config;
|
|
private readonly ProtocolClientContext _context;
|
|
private bool _isReady = false;
|
|
private bool _disposed = false;
|
|
#endregion
|
|
|
|
#region 管理器
|
|
private readonly AuthenticationManager _authManager;
|
|
private readonly ProtocolLogProcessor _protocolLogProcessor;
|
|
private readonly StatsManager _statsManager;
|
|
private readonly MessageHandlerManager _handlerManager;
|
|
#endregion
|
|
|
|
#region 定时器
|
|
private Timer? _reconnectTimer;
|
|
private Timer? _readyTimer;
|
|
#endregion
|
|
|
|
#region 属性
|
|
public bool IsConnected => _messageManager.IsConnected;
|
|
public ClientState State => _context.State;
|
|
public bool IsReadonly => _config.Readonly;
|
|
public ProtocolClientContext Context => _context;
|
|
public ProtocolClientConfig Config => _config;
|
|
#endregion
|
|
|
|
public ProtocolWsClient(ProtocolClientConfig config, ILoggerFactory loggerFactory, IProtocolLogObserver protocolLogObserver)
|
|
{
|
|
_config = config;
|
|
_logger = loggerFactory.CreateLogger<ProtocolWsClient>();
|
|
_context = new ProtocolClientContext(loggerFactory);
|
|
_messageManager = new WebSocketMessageManager(config.Name, loggerFactory);
|
|
_authManager = new AuthenticationManager(_config, _logger, (msg) => _messageManager.SendMessage(msg));
|
|
_statsManager = new StatsManager(_config.Name, _logger, (msg, cb, err) => _messageManager.SendMessage(msg, cb, err));
|
|
_protocolLogProcessor = new ProtocolLogProcessor(_config, _context, _logger, _messageManager, protocolLogObserver);
|
|
_handlerManager = new MessageHandlerManager(_messageManager, (msg, cb, err) => _messageManager.SendMessage(msg, cb, err));
|
|
SubscribeToEvents();
|
|
}
|
|
}
|
|
}
|
|
|