breakpoint

This commit is contained in:
CortexCore 2025-01-12 11:57:37 +08:00
parent 01b3d1be43
commit 000a079985
4 changed files with 104 additions and 92 deletions

View File

@ -176,12 +176,7 @@ namespace BITKit
/// <summary> /// <summary>
/// 依赖服务提供接口 /// 依赖服务提供接口
/// </summary> /// </summary>
public static ServiceProvider ServiceProvider public static ServiceProvider ServiceProvider { get; set; }
{
get=>_serviceProvider??=ServiceCollection.BuildServiceProvider();
set => _serviceProvider = value;
}
private static ServiceProvider _serviceProvider;
/// <summary> /// <summary>
/// 主线程 /// 主线程
/// </summary> /// </summary>

View File

@ -8,70 +8,92 @@ using UnityEngine;
namespace BITKit namespace BITKit
{ {
public static class BIT4Log public static class BIT4Log
{
#if UNITY_EDITOR && UNITY_5_3_OR_NEWER
[RuntimeInitializeOnLoadMethod]
private static void Reload()
{ {
OnLog = null; #if UNITY_EDITOR && UNITY_5_3_OR_NEWER
OnException = null; [RuntimeInitializeOnLoadMethod]
OnWarning = null; private static void Reload()
OnNextLine = null; {
} OnLog = null;
#endif OnException = null;
public static event Action<string> OnLog; OnWarning = null;
public static event Action<Exception> OnException; OnNextLine = null;
public static event Action<string> OnWarning; }
public static event Action OnNextLine;
#if UNITY_5_3_OR_NEWER
[HideInCallstack]
#endif #endif
public static void Log(object x) public static event Action<string> OnLog;
{ public static event Action<Exception> OnException;
if (OnLog is null) public static event Action<string> OnWarning;
{ public static event Action OnNextLine;
BITApp.ServiceProvider.GetRequiredService<ILogger<BITApp>>().LogInformation(x.ToString());
}
else
{
OnLog?.Invoke(x?.ToString());
}
}
#if UNITY_5_3_OR_NEWER #if UNITY_5_3_OR_NEWER
[HideInCallstack] [HideInCallstack]
#endif #endif
public static void Log<T>(object x) public static void Log(object x)
{ {
if (OnLog is null) if (OnLog is not null)
{ {
BITApp.ServiceProvider.GetRequiredService<ILogger<T>>().LogInformation(x.ToString()); OnLog.Invoke(x?.ToString());
} return;
else }
{
OnLog?.Invoke(x?.ToString());
}
}
#if UNITY_5_3_OR_NEWER #if UNITY_5_3_OR_NEWER
[HideInCallstack] UnityEngine.Debug.Log(x);
#endif #endif
public static void LogException(Exception e) }
{
OnException?.Invoke(e);
}
#if UNITY_5_3_OR_NEWER #if UNITY_5_3_OR_NEWER
[HideInCallstack] [HideInCallstack]
#endif #endif
public static void Warning(object x) public static void Log<T>(object x)
{ {
OnWarning?.Invoke(x.ToString()); if (OnLog is not null)
} {
OnLog.Invoke(x?.ToString());
return;
}
#if UNITY_5_3_OR_NEWER #if UNITY_5_3_OR_NEWER
[HideInCallstack] UnityEngine.Debug.Log($"<b>{typeof(T).Name}</b>" + x);
#endif #endif
public static void Warning<T>(object x) }
{ #if UNITY_5_3_OR_NEWER
Warning($"<color=#ffa500ff><b>{typeof(T).Name}</b></color>:{x}"); [HideInCallstack]
#endif
public static void LogException(Exception e)
{
if (OnException is not null)
{
OnException.Invoke(e);
return;
}
#if UNITY_5_3_OR_NEWER
UnityEngine.Debug.LogException(e);
#endif
}
#if UNITY_5_3_OR_NEWER
[HideInCallstack]
#endif
public static void Warning(object x)
{
if (OnWarning is not null)
{
OnWarning.Invoke(x.ToString());
return;
}
#if UNITY_5_3_OR_NEWER
UnityEngine.Debug.LogWarning(x);
#endif
}
#if UNITY_5_3_OR_NEWER
[HideInCallstack]
#endif
public static void Warning<T>(object x)
{
if (OnWarning is not null)
{
OnWarning.Invoke(x.ToString());
return;
}
#if UNITY_5_3_OR_NEWER
UnityEngine.Debug.LogWarning($"<b>{typeof(T).Name}</b>" + x);
#endif
}
} }
}
} }

View File

@ -17,6 +17,7 @@ using BITKit.Net.Examples;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Unity.Mathematics; using Unity.Mathematics;
using UnityEngine;
namespace BITKit.Net namespace BITKit.Net
{ {
@ -132,7 +133,7 @@ namespace BITKit.Net
{ {
if (IsConnecting) if (IsConnecting)
{ {
BIT4Log.Warning<KcpNetClient>("正在连接中"); _logger.LogWarning("正在连接中");
return false; return false;
} }
_userConnected = true; _userConnected = true;
@ -203,7 +204,7 @@ namespace BITKit.Net
} }
catch (Exception e) catch (Exception e)
{ {
BIT4Log.LogException(e); _logger.LogCritical(e,e.Message);
if (BITApp.SynchronizationContext is not null) if (BITApp.SynchronizationContext is not null)
await UniTask.SwitchToSynchronizationContext(BITApp.SynchronizationContext); await UniTask.SwitchToSynchronizationContext(BITApp.SynchronizationContext);
OnConnectedFailed?.Invoke(); OnConnectedFailed?.Invoke();
@ -223,7 +224,7 @@ namespace BITKit.Net
} }
catch (Exception e) catch (Exception e)
{ {
BIT4Log.LogException(e); _logger.LogCritical(e,e.Message);
} }
} }
private async void OnDataInternel(ArraySegment<byte> bytes, KcpChannel channel) private async void OnDataInternel(ArraySegment<byte> bytes, KcpChannel channel)
@ -255,7 +256,7 @@ namespace BITKit.Net
} }
catch (Exception e) catch (Exception e)
{ {
BIT4Log.LogException(e); _logger.LogCritical(e,e.Message);
} }
break; break;
@ -270,7 +271,11 @@ namespace BITKit.Net
Ping = (int)(DateTime.Now - _lastPingTime).TotalMilliseconds; Ping = (int)(DateTime.Now - _lastPingTime).TotalMilliseconds;
break; break;
case NetCommandType.ReturnToClient: case NetCommandType.ReturnToClient:
var id = reader.ReadInt32(); var id = reader.ReadInt32();
try try
{ {
if (reader.ReadBoolean()) if (reader.ReadBoolean())
@ -281,13 +286,14 @@ namespace BITKit.Net
else else
{ {
var message = reader.ReadString(); var message = reader.ReadString();
_p2p.TryAdd(id,new Exception(message)); _p2p.TryAdd(id,new Exception(message));
} }
} }
catch (Exception e) catch (Exception e)
{ {
BIT4Log.Warning<INetClient>($"请求返回失败:{id}"); _logger.LogWarning($"请求返回失败:{id}");
BIT4Log.LogException(e); _logger.LogCritical(e,e.Message);
} }
break; break;
case NetCommandType.GetFromClient: case NetCommandType.GetFromClient:
@ -327,9 +333,9 @@ namespace BITKit.Net
value = methodInfo.Invoke(handle, pars); value = methodInfo.Invoke(handle, pars);
} }
} }
catch (Exception e) catch (Exception)
{ {
BIT4Log.Warning<KcpNetClient>(path); _logger.LogWarning(path);
throw; throw;
} }
@ -369,7 +375,7 @@ namespace BITKit.Net
} }
catch (Exception e) catch (Exception e)
{ {
BIT4Log.LogException(e); _logger.LogCritical(e,e.Message);
returnWriter.Write(false); returnWriter.Write(false);
returnWriter.Write(e.Message); returnWriter.Write(e.Message);
} }
@ -379,7 +385,7 @@ namespace BITKit.Net
} }
catch(Exception e) catch(Exception e)
{ {
BIT4Log.LogException(e); _logger.LogCritical(e,e.Message);
} }
break; break;
case NetCommandType.AllRpc: case NetCommandType.AllRpc:
@ -419,13 +425,12 @@ namespace BITKit.Net
reportBuilder.AppendLine($"参数{parameter.GetType()}类型匹配:{parameterInfo.ParameterType}"); reportBuilder.AppendLine($"参数{parameter.GetType()}类型匹配:{parameterInfo.ParameterType}");
} }
} }
_logger.LogWarning(reportBuilder.ToString());
BIT4Log.Warning<KcpNetClient>(reportBuilder);
throw; throw;
} }
catch (Exception e) catch (Exception e)
{ {
BIT4Log.Warning<KcpNetClient>(rpcName); _logger.LogWarning(rpcName);
throw; throw;
} }
@ -439,6 +444,7 @@ namespace BITKit.Net
if (eventDelegate is null) if (eventDelegate is null)
{ {
//BIT4Log.Warning<KcpNetClient>($"未找到对应的事件:{rpcName}"); //BIT4Log.Warning<KcpNetClient>($"未找到对应的事件:{rpcName}");
} }
else else
@ -451,14 +457,13 @@ namespace BITKit.Net
} }
else else
{ {
_logger.LogWarning($"未找到对应的Rpc方法:{rpcName}");
BIT4Log.Warning<KcpNetClient>($"未找到对应的Rpc方法:{rpcName}");
} }
} }
break; break;
default: default:
_logger.LogInformation($"未知消息类型:{type},字节:{(byte)type}"); _logger.LogWarning($"未知消息类型:{type},字节:{(byte)type}");
if (bytes.Array != null) if (bytes.Array != null)
_logger.LogInformation( _logger.LogInformation(
$"已收到:({Id}, {BitConverter.ToString(bytes.Array, bytes.Offset, bytes.Count)} @ {channel})"); $"已收到:({Id}, {BitConverter.ToString(bytes.Array, bytes.Offset, bytes.Count)} @ {channel})");
@ -694,7 +699,7 @@ namespace BITKit.Net
{ {
if (DateTime.Now - _lastHeartbeat > TimeSpan.FromSeconds(5)) if (DateTime.Now - _lastHeartbeat > TimeSpan.FromSeconds(5))
{ {
BIT4Log.Warning<KcpNetClient>("心跳超时,自动断开"); _logger.LogWarning("心跳超时,自动断开");
DisconnectInternal(); DisconnectInternal();
_commandQueue.Clear(); _commandQueue.Clear();
return; return;
@ -726,7 +731,7 @@ namespace BITKit.Net
} }
catch (Exception e) catch (Exception e)
{ {
BIT4Log.LogException(e); _logger.LogCritical(e,e.Message);
} }
} }

View File

@ -66,12 +66,6 @@ namespace BITKit
{ {
var outputPath = PathHelper.GetTempFilePath(); var outputPath = PathHelper.GetTempFilePath();
//DI.TryGet<IUXWaiting>(out var waiting);
//todo
IUXWaiting waiting = null;
var handle = waiting?.Get();
handle?.SetMessage("正在编译");
try try
{ {
if (Installed is false) if (Installed is false)
@ -125,7 +119,7 @@ namespace BITKit
// CreateNoWindow = false, // CreateNoWindow = false,
// }; // };
var StartInfo = new ProcessStartInfo var startInfo = new ProcessStartInfo
{ {
//FileName = MCSPath, //FileName = MCSPath,
FileName = "dotnet", FileName = "dotnet",
@ -142,7 +136,7 @@ namespace BITKit
var process = new Process() var process = new Process()
{ {
StartInfo = StartInfo, StartInfo = startInfo,
}; };
var reportBuilder = new StringBuilder(); var reportBuilder = new StringBuilder();
process.OutputDataReceived += (sender, args) => process.OutputDataReceived += (sender, args) =>
@ -184,14 +178,10 @@ namespace BITKit
BIT4Log.Log<BITSharp>(reportBuilder); BIT4Log.Log<BITSharp>(reportBuilder);
waiting?.Release(handle);
return Assembly.Load(bytes); return Assembly.Load(bytes);
} }
catch (Exception e) catch (Exception e)
{ {
waiting?.Release(handle);
throw new Exception($"编译失败:{e}"); throw new Exception($"编译失败:{e}");
} }