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.
77 lines
2.9 KiB
77 lines
2.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using CoreAgent.ProtocolClient.Enums;
|
|
using CoreAgent.ProtocolClient.Models;
|
|
using Microsoft.Extensions.Logging;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace CoreAgent.ProtocolClient.ProtocolWsClient
|
|
{
|
|
public partial class ProtocolWsClient
|
|
{
|
|
#region 消息分发与业务流程
|
|
private void OnMessageReceived(object? sender, JObject message)
|
|
{
|
|
MessageReceived?.Invoke(this, message);
|
|
if (_messageManager.MessageIdManager.HandleMessageResponse(message, error => ConnectionError?.Invoke(this, error)))
|
|
{
|
|
return;
|
|
}
|
|
if (!_authManager.IsAuthenticated)
|
|
{
|
|
_authManager.HandleMessage(message);
|
|
return;
|
|
}
|
|
_protocolLogProcessor.HandleMessage(message);
|
|
_statsManager.HandleMessage(message);
|
|
}
|
|
|
|
private void OnSocketReady()
|
|
{
|
|
if (_isReady) return;
|
|
_logger.LogInformation($"[{_config.Name}] WebSocket准备就绪,开始初始化");
|
|
_isReady = true;
|
|
var firstCon = _config.Logs.Layers.Count == 0;
|
|
SendMessage(new JObject { ["message"] = "config_get" }, config =>
|
|
{
|
|
_logger.LogInformation($"[{_config.Name}] 配置已接收");
|
|
_context.LogContext.ResetLogs();
|
|
_context.BasicInfo.Version = config["version"]?.ToString();
|
|
_context.BasicInfo.Name = config["name"]?.ToString() ?? _config.Name;
|
|
_context.BasicInfo.Model = config["type"]?.ToString();
|
|
var ro = _config.Readonly;
|
|
var serverLogsConfig = config["logs"]?.ToObject<ProtocolClientLogsConfig>();
|
|
if (ro || firstCon)
|
|
{
|
|
if (serverLogsConfig != null) _config.Logs = serverLogsConfig;
|
|
}
|
|
if (config["cells"] != null)
|
|
{
|
|
var cells = config["cells"]?.ToObject<Dictionary<string, JObject>>();
|
|
if (cells != null)
|
|
{
|
|
foreach (var cell in cells)
|
|
{
|
|
var data = cell.Value.ToObject<CellConfig>();
|
|
_context.CellParameterManager.AddCell(Convert.ToInt32(cell.Key), data);
|
|
}
|
|
}
|
|
}
|
|
SetState(ClientState.Connected);
|
|
if (ro)
|
|
{
|
|
_protocolLogProcessor.GetLogs(new Dictionary<string, object> { ["timeout"] = 0 });
|
|
}
|
|
else
|
|
{
|
|
_protocolLogProcessor.SetLogsConfig(_config.Logs);
|
|
}
|
|
_statsManager.Start(true);
|
|
});
|
|
}
|
|
#endregion
|
|
}
|
|
}
|