恢复支持net40版本星尘代理

This commit is contained in:
大石头 2023-03-11 22:06:05 +08:00
parent 859d6fbdc7
commit bb1a508a63
9 changed files with 49 additions and 19 deletions

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net45;net461;net7.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net40;net45;net461;net7.0</TargetFrameworks>
<AssemblyTitle>星尘代理</AssemblyTitle>
<Description>星尘,分布式资源调度,部署于每一个节点,连接服务端,支持节点监控、远程发布。</Description>
<Company>新生命开发团队</Company>

View File

@ -1,6 +1,5 @@
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Net.WebSockets;
using System.Reflection;
using NewLife;
using NewLife.Log;
@ -11,6 +10,10 @@ using NewLife.Threading;
using Stardust.Models;
using Stardust.Registry;
using Stardust.Services;
#if NET45_OR_GREATER || NETCOREAPP || NETSTANDARD
using System.Net.WebSockets;
using TaskEx = System.Threading.Tasks.Task;
#endif
namespace Stardust;
@ -127,7 +130,7 @@ public class AppClient : ApiHttpClient, ICommandClient, IRegistry, IEventProvide
if (AppId != "StarServer")
{
// 等待注册到平台
var task = Task.Run(Register);
var task = TaskEx.Run(Register);
task.Wait(1_000);
}
}
@ -327,6 +330,7 @@ public class AppClient : ApiHttpClient, ICommandClient, IRegistry, IEventProvide
_eventTimer.TryDispose();
_eventTimer = null;
#if NET45_OR_GREATER || NETCOREAPP || NETSTANDARD
try
{
if (_websocket != null && _websocket.State == WebSocketState.Open)
@ -337,10 +341,9 @@ public class AppClient : ApiHttpClient, ICommandClient, IRegistry, IEventProvide
//_websocket.TryDispose();
_websocket = null;
#endif
}
private WebSocket _websocket;
private CancellationTokenSource _source;
private async Task DoPing(Object state)
{
DefaultSpan.Current = null;
@ -352,6 +355,7 @@ public class AppClient : ApiHttpClient, ICommandClient, IRegistry, IEventProvide
await RefreshPublish();
await RefreshConsume();
#if NET45_OR_GREATER || NETCOREAPP || NETSTANDARD
var svc = _currentService;
if (svc != null && UseWebSocket)
{
@ -374,6 +378,7 @@ public class AppClient : ApiHttpClient, ICommandClient, IRegistry, IEventProvide
_ = Task.Run(() => DoPull(client, _source.Token));
}
}
#endif
}
catch (Exception ex)
{
@ -381,6 +386,9 @@ public class AppClient : ApiHttpClient, ICommandClient, IRegistry, IEventProvide
}
}
#if NET45_OR_GREATER || NETCOREAPP || NETSTANDARD
private WebSocket _websocket;
private CancellationTokenSource _source;
private async Task DoPull(WebSocket socket, CancellationToken cancellationToken)
{
DefaultSpan.Current = null;
@ -421,6 +429,7 @@ public class AppClient : ApiHttpClient, ICommandClient, IRegistry, IEventProvide
if (socket.State == WebSocketState.Open)
await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "finish", default);
}
#endif
#endregion
#region

View File

@ -143,7 +143,7 @@ public class ZipDeploy
Shadow = shadow.CombinePath(name);
}
var hash = fi.MD5().ToHex()[..8].ToLower();
var hash = fi.MD5().ToHex().Substring(0, 8).ToLower();
var rundir = fi.Directory;
if (shadow.IsNullOrEmpty()) return false;
@ -326,7 +326,7 @@ public class ZipDeploy
var cfg = fis.FirstOrDefault(e => e.Name.EndsWithIgnoreCase(ext));
if (cfg != null)
{
var name = $"{cfg.Name[..^ext.Length]}.dll";
var name = $"{cfg.Name.Substring(0, cfg.Name.Length - ext.Length)}.dll";
runfile = fis.FirstOrDefault(e => e.Name.EqualIgnoreCase(name));
}
}

View File

@ -8,6 +8,9 @@ using NewLife.Log;
using NewLife.Messaging;
using NewLife.Remoting;
using Stardust.Models;
#if NET45_OR_GREATER || NETCOREAPP || NETSTANDARD
using TaskEx = System.Threading.Tasks.Task;
#endif
namespace Stardust;
@ -56,7 +59,7 @@ public class LocalStarClient
/// <returns></returns>
public AgentInfo GetInfo()
{
var task = Task.Run(GetInfoAsync);
var task = TaskEx.Run(GetInfoAsync);
return task.Wait(500) ? task.Result : null;
}
@ -333,7 +336,7 @@ public class LocalStarClient
/// <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

@ -2,6 +2,9 @@
using NewLife.Log;
using NewLife.Remoting;
using Stardust.Models;
#if NET45_OR_GREATER || NETCOREAPP || NETSTANDARD
using TaskEx = System.Threading.Tasks.Task;
#endif
namespace Stardust.Registry;
@ -95,7 +98,7 @@ public static class RegistryExtensions
/// <param name="serviceName">服务名</param>
/// <param name="tag"></param>
/// <returns></returns>
public static IApiClient CreateForService(this IRegistry registry, String serviceName, String tag = null) => Task.Run(() => CreateForServiceAsync(registry, serviceName, tag)).Result;
public static IApiClient CreateForService(this IRegistry registry, String serviceName, String tag = null) => TaskEx.Run(() => CreateForServiceAsync(registry, serviceName, tag)).Result;
private static void Bind(ApiHttpClient client, ServiceModel[] ms)
{
@ -109,7 +112,7 @@ public static class RegistryExtensions
{
// 同时考虑两个地址
var name = item.Client;
var addrs = (item.Address + "," + item.Address2).Split(',', StringSplitOptions.RemoveEmptyEntries);
var addrs = (item.Address + "," + item.Address2).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var set = new HashSet<String>();
for (var i = 0; i < addrs.Length; i++)
{

View File

@ -1,7 +1,6 @@
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Net.NetworkInformation;
using System.Net.WebSockets;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
@ -14,7 +13,11 @@ using NewLife.Serialization;
using NewLife.Threading;
using Stardust.Models;
using Stardust.Services;
using System.Threading.Tasks;
#if NET45_OR_GREATER || NETCOREAPP || NETSTANDARD
using System.Net.WebSockets;
using WebSocket = System.Net.WebSockets.WebSocket;
#endif
namespace Stardust;
@ -658,15 +661,15 @@ public class StarClient : ApiHttpClient, ICommandClient, IEventProvider
_timer.TryDispose();
_timer = null;
#if NET45_OR_GREATER || NETCOREAPP || NETSTANDARD
if (_websocket != null && _websocket.State == WebSocketState.Open) _websocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "finish", default).Wait(1_000);
_source?.Cancel();
//_websocket.TryDispose();
_websocket = null;
#endif
}
private WebSocket _websocket;
private CancellationTokenSource _source;
private async Task DoPing(Object state)
{
DefaultSpan.Current = null;
@ -674,6 +677,7 @@ public class StarClient : ApiHttpClient, ICommandClient, IEventProvider
{
await Ping();
#if NET45_OR_GREATER || NETCOREAPP || NETSTANDARD
var svc = _currentService;
if (svc == null || Token == null) return;
@ -690,6 +694,7 @@ public class StarClient : ApiHttpClient, ICommandClient, IEventProvider
_source = new CancellationTokenSource();
_ = Task.Run(() => DoPull(client, _source.Token));
}
#endif
}
catch (Exception ex)
{
@ -697,6 +702,9 @@ public class StarClient : ApiHttpClient, ICommandClient, IEventProvider
}
}
#if NET45_OR_GREATER || NETCOREAPP || NETSTANDARD
private WebSocket _websocket;
private CancellationTokenSource _source;
private async Task DoPull(WebSocket socket, CancellationToken cancellationToken)
{
DefaultSpan.Current = null;
@ -719,6 +727,7 @@ public class StarClient : ApiHttpClient, ICommandClient, IEventProvider
if (socket.State == WebSocketState.Open) await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "finish", default);
}
#endif
async Task ReceiveCommand(CommandModel model)
{

View File

@ -15,6 +15,9 @@ using Stardust.Models;
using Stardust.Monitors;
using Stardust.Registry;
using Stardust.Services;
#if NET45_OR_GREATER || NETCOREAPP || NETSTANDARD
using TaskEx = System.Threading.Tasks.Task;
#endif
namespace Stardust;
@ -372,7 +375,7 @@ public class StarFactory : DisposeBase
/// <param name="serviceName"></param>
/// <param name="tag"></param>
/// <returns></returns>
public IApiClient CreateForService(String serviceName, String tag = null) => Task.Run(() => CreateForServiceAsync(serviceName, tag)).Result;
public IApiClient CreateForService(String serviceName, String tag = null) => TaskEx.Run(() => CreateForServiceAsync(serviceName, tag)).Result;
/// <summary>为指定服务创建客户端,从星尘注册中心获取服务地址。单例,应避免频繁创建客户端</summary>
/// <param name="serviceName"></param>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net45;net461;netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0;net6.0-windows;net7.0;net7.0-windows</TargetFrameworks>
<TargetFrameworks>net40;net45;net461;netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0;net6.0-windows;net7.0;net7.0-windows</TargetFrameworks>
<AssemblyName>Stardust</AssemblyName>
<AssemblyTitle>星尘分布式服务核心</AssemblyTitle>
<Description>星尘,分布式服务框架。节点管理,监控中心,配置中心,发布中心,注册中心</Description>
@ -70,9 +70,12 @@
</None>
</ItemGroup>
<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'!='net40'">
<PackageReference Include="NewLife.Core" Version="10.2.2023.301" />
<PackageReference Include="NewLife.Remoting" Version="2.1.2023.301" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net40'">
<PackageReference Include="NewLife.Core" Version="10.2.2023.309-net40" />
</ItemGroup>
</Project>

View File

@ -274,8 +274,8 @@ public class Upgrade
var p = cmd.IndexOf(' ');
if (p > 0)
{
args = cmd[(p + 1)..];
cmd = cmd[..p];
args = cmd.Substring(p + 1);
cmd = cmd.Substring(0, p);
}
RunShell(cmd, args);