diff --git a/Samples/TestA/TestA.csproj b/Samples/TestA/TestA.csproj index 5941a00e..0277992b 100644 --- a/Samples/TestA/TestA.csproj +++ b/Samples/TestA/TestA.csproj @@ -18,7 +18,7 @@ - + diff --git a/Samples/TestB/TestB.csproj b/Samples/TestB/TestB.csproj index c518ca57..17baa4fc 100644 --- a/Samples/TestB/TestB.csproj +++ b/Samples/TestB/TestB.csproj @@ -18,7 +18,7 @@ - + diff --git a/Stardust.Server/Controllers/NodeController.cs b/Stardust.Server/Controllers/NodeController.cs index 99f16a80..36a4ed7f 100644 --- a/Stardust.Server/Controllers/NodeController.cs +++ b/Stardust.Server/Controllers/NodeController.cs @@ -203,8 +203,7 @@ public Int32 PostEvents(EventModel[] events) [HttpPost(nameof(Report))] public async Task Report(Int32 id) { - var node = _node; - if (node == null) throw new ApiException(401, "节点未登录"); + var node = _node ?? throw new ApiException(401, "节点未登录"); var cmd = NodeCommand.FindById(id); if (cmd != null && cmd.NodeID == node.ID) @@ -283,9 +282,7 @@ public async Task Notify() private async Task Handle(WebSocket socket, String token, String ip) { var (node, error) = _nodeService.DecodeToken(token, _setting.TokenSecret); - if (node == null) throw new ApiException(401, $"未登录![ip={ip}]"); - - _node = node; + _node = node ?? throw new ApiException(401, $"未登录![ip={ip}]"); if (error != null) throw error; var sid = Rand.Next(); diff --git a/Stardust.Server/Services/NodeService.cs b/Stardust.Server/Services/NodeService.cs index e060d3d3..fb55be59 100644 --- a/Stardust.Server/Services/NodeService.cs +++ b/Stardust.Server/Services/NodeService.cs @@ -191,8 +191,8 @@ private static Node CheckNode(Node node, NodeInfo di, String productCode, String // 网卡地址 if (di.Macs != node.MACs) { - var dims = di.Macs?.Split(",") ?? new String[0]; - var nodems = node.MACs?.Split(",") ?? new String[0]; + var dims = di.Macs?.Split(",") ?? []; + var nodems = node.MACs?.Split(",") ?? []; // 任意网卡匹配则通过 if (!nodems.Any(e => dims.Contains(e))) { diff --git a/Stardust.Web/Areas/Registry/Controllers/AppController.cs b/Stardust.Web/Areas/Registry/Controllers/AppController.cs index 63556874..106feab9 100644 --- a/Stardust.Web/Areas/Registry/Controllers/AppController.cs +++ b/Stardust.Web/Areas/Registry/Controllers/AppController.cs @@ -113,7 +113,7 @@ protected override IEnumerable Search(Pager p) if (id > 0) { var node = App.FindById(id); - if (node != null) return new[] { node }; + if (node != null) return [node]; } var projectId = p["projectId"].ToInt(-1); diff --git a/Stardust/AppClient.cs b/Stardust/AppClient.cs index e973a6aa..703d5909 100644 --- a/Stardust/AppClient.cs +++ b/Stardust/AppClient.cs @@ -58,8 +58,6 @@ public class AppClient : ClientBase, IRegistry private readonly ConcurrentDictionary _consumeServices = new(); private readonly ConcurrentDictionary _consumes = new(); private readonly ConcurrentDictionary> _consumeEvents = new(); - private readonly ConcurrentQueue _fails = new(); - private readonly ICache _cache = new MemoryCache(); #endregion #region 构造 @@ -439,7 +437,7 @@ public PublishServiceInfo Register(String serviceName, Func addressCall /// 回调方法 public void Bind(String serviceName, ServiceChangedCallback callback) { - var list = _consumeEvents.GetOrAdd(serviceName, k => new List()); + var list = _consumeEvents.GetOrAdd(serviceName, k => []); list.Add(callback); StartTimer(); diff --git a/Stardust/Services/StarTimeProvider.cs b/Stardust/Services/StarTimeProvider.cs new file mode 100644 index 00000000..f5c270f3 --- /dev/null +++ b/Stardust/Services/StarTimeProvider.cs @@ -0,0 +1,12 @@ +using NewLife.Remoting.Clients; + +namespace Stardust.Services; + +#if !NET40 +internal class StarTimeProvider : TimeProvider +{ + public ClientBase Client { get; set; } = null!; + + public override DateTimeOffset GetUtcNow() => Client != null ? Client.GetNow().ToUniversalTime() : base.GetUtcNow(); +} +#endif \ No newline at end of file diff --git a/Stardust/StarFactory.cs b/Stardust/StarFactory.cs index 7244c40a..4f978f39 100644 --- a/Stardust/StarFactory.cs +++ b/Stardust/StarFactory.cs @@ -14,10 +14,13 @@ using NewLife.Remoting.Clients; using NewLife.Remoting.Models; using NewLife.Security; +using NewLife.Threading; using Stardust.Configs; 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 @@ -290,6 +293,11 @@ private Boolean Valid() Log = Log, }; +#if !NET40 + // 设置全局定时调度器的时间提供者,借助服务器时间差,以获得更准确的时间。避免本地时间偏差导致定时任务执行时间不准确 + TimerScheduler.GlobalTimeProvider = new StarTimeProvider { Client = client }; +#endif + //var set = StarSetting.Current; //if (set.Debug) client.Log = XTrace.Log; client.WriteInfoEvent("应用启动", $"pid={Process.GetCurrentProcess().Id}"); diff --git a/Stardust/Stardust.csproj b/Stardust/Stardust.csproj index 945f701d..e0a3484b 100644 --- a/Stardust/Stardust.csproj +++ b/Stardust/Stardust.csproj @@ -112,10 +112,10 @@ - + - + diff --git a/Test/Test.csproj b/Test/Test.csproj index 0ebd5be2..97fc8833 100644 --- a/Test/Test.csproj +++ b/Test/Test.csproj @@ -30,7 +30,7 @@ - +