StarAgent支持NET40

This commit is contained in:
大石头 2021-04-27 00:46:43 +08:00
parent a1917bf089
commit 9334c2d232
5 changed files with 33 additions and 20 deletions

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net5.0;netcoreapp3.1;net45</TargetFrameworks>
<TargetFrameworks>net5.0;netcoreapp3.1;net45;net40</TargetFrameworks>
<AssemblyTitle>星尘代理</AssemblyTitle>
<Description>星尘,分布式资源调度,客户端代理部署于每一台机器节点,接受服务端命令,获取目标应用包并拉起进程。</Description>
<Company>新生命开发团队</Company>

View File

@ -12,6 +12,9 @@ using NewLife.Net;
using NewLife.Reflection;
using NewLife.Remoting;
using Stardust.Models;
#if !NET4
using TaskEx = System.Threading.Tasks.Task;
#endif
namespace Stardust
{
@ -236,7 +239,7 @@ namespace Stardust
/// <param name="target">目标目录</param>
public static Task ProbeAsync(String url = null, String version = null, String target = null)
{
return Task.Run(() =>
return TaskEx.Run(() =>
{
var client = new LocalStarClient();
client.ProbeAndInstall(url, version, target);

View File

@ -250,14 +250,14 @@ namespace Stardust.Monitors
{
var type = "XCode.DataAccessLayer.DAL".GetTypeEx(false);
var pi = type?.GetPropertyEx("GlobalTracer");
if (pi != null && pi.PropertyType == typeof(ITracer)) pi.SetValue(null, this);
if (pi != null && pi.PropertyType == typeof(ITracer)) pi.SetValue(null, this, null);
}
// 反射处理Cube追踪
{
var type = "NewLife.Cube.WebMiddleware.TracerMiddleware".GetTypeEx(false);
var pi = type?.GetPropertyEx("Tracer");
if (pi != null && pi.PropertyType == typeof(ITracer)) pi.SetValue(null, this);
if (pi != null && pi.PropertyType == typeof(ITracer)) pi.SetValue(null, this, null);
}
}
#endregion

View File

@ -6,7 +6,6 @@ using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.NetworkInformation;
using System.Net.WebSockets;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
@ -21,13 +20,16 @@ using NewLife.Serialization;
using NewLife.Threading;
using Stardust.Models;
using Stardust.Services;
#if !NET4
using System.Net.WebSockets;
#endif
namespace Stardust
{
/// <summary>星星客户端。每个设备节点有一个客户端连接服务端</summary>
public class StarClient : ApiHttpClient
{
#region
#region
/// <summary>证书</summary>
public String Code { get; set; }
@ -51,9 +53,9 @@ namespace Stardust
/// <summary>命令队列</summary>
public IQueueService<CommandModel> CommandQueue { get; } = new QueueService<CommandModel>();
#endregion
#endregion
#region
#region
/// <summary>实例化</summary>
public StarClient()
{
@ -88,9 +90,9 @@ namespace Stardust
base.Dispose(disposing);
}
#endregion
#endregion
#region
#region
/// <summary>远程调用拦截,支持重新登录</summary>
/// <typeparam name="TResult"></typeparam>
/// <param name="method"></param>
@ -119,9 +121,9 @@ namespace Stardust
throw;
}
}
#endregion
#endregion
#region
#region
/// <summary>登录</summary>
/// <returns></returns>
public async Task<Object> Login()
@ -272,9 +274,9 @@ namespace Stardust
/// <summary>注销</summary>
/// <returns></returns>
private async Task<LoginResponse> LogoutAsync(String reason) => await GetAsync<LoginResponse>("Node/Logout", new { reason });
#endregion
#endregion
#region
#region
private readonly String[] _excludes = new[] { "Idle", "System", "Registry", "smss", "csrss", "lsass", "wininit", "services", "winlogon", "fontdrvhost", "dwm", "svchost", "dllhost", "conhost", "taskhostw", "explorer", "ctfmon", "ChsIME", "WmiPrvSE", "WUDFHost", "igfxCUIServiceN", "igfxEMN", "sihost", "RuntimeBroker", "StartMenuExperienceHost", "SecurityHealthSystray", "SecurityHealthService", "ShellExperienceHost", "PerfWatson2", "audiodg" };
/// <summary>获取心跳信息</summary>
@ -425,9 +427,9 @@ namespace Stardust
/// <param name="data"></param>
/// <returns></returns>
private async Task<Object> ReportAsync(Int32 id, Byte[] data) => await PostAsync<Object>("Node/Report?Id=" + id, data);
#endregion
#endregion
#region
#region
private TimerX _timer;
private void StartTimer()
{
@ -437,7 +439,11 @@ namespace Stardust
{
if (_timer == null)
{
#if !NET4
_timer = new TimerX(DoPing, null, 1_000, 60_000, "Device") { Async = true };
#else
_timer = new TimerX(s=>Ping().Wait(), null, 1_000, 60_000, "Device") { Async = true };
#endif
}
}
}
@ -448,13 +454,16 @@ namespace Stardust
_timer.TryDispose();
_timer = null;
#if !NET4
if (_websocket.State == WebSocketState.Open) _websocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "finish", default).Wait();
_source.Cancel();
//_websocket.TryDispose();
_websocket = null;
#endif
}
#if !NET4
private WebSocket _websocket;
private CancellationTokenSource _source;
private async Task DoPing(Object state)
@ -502,9 +511,10 @@ namespace Stardust
if (socket.State == WebSocketState.Open) await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "finish", default);
}
#endregion
#endif
#endregion
#region
#region
/// <summary>获取更新信息</summary>
/// <param name="channel"></param>
/// <returns></returns>
@ -620,6 +630,6 @@ namespace Stardust
/// <param name="channel"></param>
/// <returns></returns>
public async Task<UpgradeInfo> UpgradeAsync(String channel) => await GetAsync<UpgradeInfo>("Node/Upgrade", new { channel });
#endregion
#endregion
}
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net45;netstandard2.0;net5.0</TargetFrameworks>
<TargetFrameworks>net45;netstandard2.0;net5.0;net40</TargetFrameworks>
<AssemblyName>Stardust</AssemblyName>
<AssemblyTitle>星尘分布式服务扩展</AssemblyTitle>
<Description>星尘,分布式服务框架。分布式资源调度,服务自动注册和发现,负载均衡,动态伸缩,故障转移,性能监控。</Description>