diff --git a/Plugins/MySqlAgent/MySqlAgent.csproj b/Plugins/MySqlAgent/MySqlAgent.csproj index 0a914ff2..d0168b70 100644 --- a/Plugins/MySqlAgent/MySqlAgent.csproj +++ b/Plugins/MySqlAgent/MySqlAgent.csproj @@ -20,7 +20,7 @@ - + diff --git a/Samples/TestA/TestA.csproj b/Samples/TestA/TestA.csproj index 454b6e67..2b6952b8 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 cf022f71..a34652e7 100644 --- a/Samples/TestB/TestB.csproj +++ b/Samples/TestB/TestB.csproj @@ -18,7 +18,7 @@ - + diff --git a/Stardust.Data/Stardust.Data.csproj b/Stardust.Data/Stardust.Data.csproj index 88637383..65b2f733 100644 --- a/Stardust.Data/Stardust.Data.csproj +++ b/Stardust.Data/Stardust.Data.csproj @@ -41,7 +41,7 @@ - + diff --git a/Stardust.Extensions/Caches/CacheFileProvider.cs b/Stardust.Extensions/Caches/CacheFileProvider.cs index d02b2d4e..2f1a3e2a 100644 --- a/Stardust.Extensions/Caches/CacheFileProvider.cs +++ b/Stardust.Extensions/Caches/CacheFileProvider.cs @@ -107,7 +107,7 @@ public IFileInfo GetFileInfo(String subpath) if (Path.GetFileName(fullPath).Contains('.')) { if (!fi.Exists) - fi = DownloadFile(subpath, fullPath).Result?.AsFile(); + fi = DownloadFile(subpath, fullPath).ConfigureAwait(false).GetAwaiter().GetResult()?.AsFile(); else if (fi.LastWriteTime.AddMonths(1) < DateTime.Now) _ = Task.Run(() => DownloadFile(subpath, fullPath)); } @@ -138,7 +138,7 @@ public IFileInfo GetFileInfo(String subpath) { using var fs = new FileStream(tmp, FileMode.OpenOrCreate); using var client = new HttpClient { Timeout = Timeout }; - using var rs = await client.GetStreamAsync(url); + using var rs = await client.GetStreamAsync(url).ConfigureAwait(false); rs.CopyTo(fs); fs.Flush(); fs.SetLength(fs.Position); @@ -248,7 +248,7 @@ public IDirectoryContents GetDirectoryContents(String subpath) XTrace.WriteLine("下载目录:{0}", url); using var client = new HttpClient { Timeout = Timeout }; - var html = await client.GetStringAsync(url); + var html = await client.GetStringAsync(url).ConfigureAwait(false); var links = Link.Parse(html, url); var list = links.Select(e => new FileInfoModel diff --git a/Stardust.Extensions/IpFilterMiddleware.cs b/Stardust.Extensions/IpFilterMiddleware.cs index 90d8a137..978a2ce2 100644 --- a/Stardust.Extensions/IpFilterMiddleware.cs +++ b/Stardust.Extensions/IpFilterMiddleware.cs @@ -46,7 +46,7 @@ public async Task Invoke(HttpContext ctx) } } - await _next.Invoke(ctx); + await _next.Invoke(ctx).ConfigureAwait(false); } Boolean ValidIP(String ip) diff --git a/Stardust.Extensions/Stardust.Extensions.csproj b/Stardust.Extensions/Stardust.Extensions.csproj index e81200f8..24e690f0 100644 --- a/Stardust.Extensions/Stardust.Extensions.csproj +++ b/Stardust.Extensions/Stardust.Extensions.csproj @@ -20,6 +20,8 @@ True ..\Doc\newlife.snk 1701;1702;NU5104;NETSDK1138;CS7035 + latest + CA2007 diff --git a/Stardust.Extensions/TracerMiddleware.cs b/Stardust.Extensions/TracerMiddleware.cs index cd4313d9..eb961509 100644 --- a/Stardust.Extensions/TracerMiddleware.cs +++ b/Stardust.Extensions/TracerMiddleware.cs @@ -58,7 +58,7 @@ public async Task Invoke(HttpContext ctx) { req.EnableBuffering(); - var count = await req.Body.ReadAsync(buf, 0, buf.Length); + var count = await req.Body.ReadAsync(buf, 0, buf.Length).ConfigureAwait(false); span.AppendTag("\r\n<=\r\n" + buf.ToStr(null, 0, count)); req.Body.Position = 0; flag = true; @@ -91,7 +91,7 @@ public async Task Invoke(HttpContext ctx) try { - await _next.Invoke(ctx); + await _next.Invoke(ctx).ConfigureAwait(false); // 自动记录用户访问主机地址 SaveServiceAddress(ctx); @@ -119,7 +119,7 @@ public async Task Invoke(HttpContext ctx) try { var p = res.Body.Position; - var count = await res.Body.ReadAsync(buf, 0, buf.Length); + var count = await res.Body.ReadAsync(buf, 0, buf.Length).ConfigureAwait(false); span.AppendTag("\r\n=>\r\n" + buf.ToStr(null, 0, count)); res.Body.Position = p; flag = true; diff --git a/Stardust.Server/Stardust.Server.csproj b/Stardust.Server/Stardust.Server.csproj index 300d6732..0db73667 100644 --- a/Stardust.Server/Stardust.Server.csproj +++ b/Stardust.Server/Stardust.Server.csproj @@ -46,7 +46,7 @@ - + diff --git a/Stardust.Web/Stardust.Web.csproj b/Stardust.Web/Stardust.Web.csproj index 218a6114..8d00271c 100644 --- a/Stardust.Web/Stardust.Web.csproj +++ b/Stardust.Web/Stardust.Web.csproj @@ -53,7 +53,7 @@ - + diff --git a/Stardust/AppClient.cs b/Stardust/AppClient.cs index fdc3af21..65913402 100644 --- a/Stardust/AppClient.cs +++ b/Stardust/AppClient.cs @@ -174,7 +174,7 @@ public override IPingRequest BuildPingRequest() if (_appInfo == null) return null; - return await local.PingAsync(_appInfo, WatchdogTimeout); + return await local.PingAsync(_appInfo, WatchdogTimeout).ConfigureAwait(false); } /// 心跳 @@ -187,13 +187,13 @@ protected override async Task OnPing(Object state) try { // 向服务端发送心跳后,再向本地发送心跳 - await base.OnPing(state); - await PingLocal(); + await base.OnPing(state).ConfigureAwait(false); + await PingLocal().ConfigureAwait(false); if (!NetworkInterface.GetIsNetworkAvailable()) return; - await RefreshPublish(); - await RefreshConsume(); + await RefreshPublish().ConfigureAwait(false); + await RefreshConsume().ConfigureAwait(false); } catch (Exception ex) { @@ -214,17 +214,17 @@ protected override async Task OnPing(Object state) // 如果没有设置地址,则不要调用接口 if (service.Address.IsNullOrEmpty()) return null; - return await InvokeAsync("App/RegisterService", service); + return await InvokeAsync("App/RegisterService", service).ConfigureAwait(false); } /// 取消服务(底层) /// 应用服务 /// - public async Task UnregisterAsync(PublishServiceInfo service) + public Task UnregisterAsync(PublishServiceInfo service) { _publishServices.TryRemove(service.ServiceName, out _); - return await InvokeAsync("App/UnregisterService", service); + return InvokeAsync("App/UnregisterService", service); } private void AddService(PublishServiceInfo service) @@ -284,7 +284,7 @@ public async Task RegisterAsync(String serviceName, String a service.Tag = tag; service.Health = health; - var rs = await RegisterAsync(service); + var rs = await RegisterAsync(service).ConfigureAwait(false); WriteLog("注册完成 {0}", rs?.ToJson()); return service; @@ -328,7 +328,7 @@ public PublishServiceInfo Register(String serviceName, Func addressCall /// 消费服务(底层) /// 应用服务 /// - public async Task ResolveAsync(ConsumeServiceInfo service) => await InvokeAsync("App/ResolveService", service); + public Task ResolveAsync(ConsumeServiceInfo service) => InvokeAsync("App/ResolveService", service); /// 消费得到服务地址信息 /// 服务名 @@ -356,7 +356,7 @@ public PublishServiceInfo Register(String serviceName, Func addressCall // 消费即使报错,也要往下走,借助缓存 try { - var models = await ResolveAsync(service); + var models = await ResolveAsync(service).ConfigureAwait(false); if (models != null && models.Length > 0) { _consumes[serviceName] = models; @@ -405,7 +405,7 @@ private async Task RefreshPublish() if (!address.IsNullOrEmpty()) svc.Address = address; } - if (!svc.Address.IsNullOrEmpty()) await RegisterAsync(svc); + if (!svc.Address.IsNullOrEmpty()) await RegisterAsync(svc).ConfigureAwait(false); } } @@ -415,7 +415,7 @@ private async Task RefreshConsume() foreach (var item in _consumeServices) { var svc = item.Value; - var ms = await ResolveAsync(svc); + var ms = await ResolveAsync(svc).ConfigureAwait(false); if (ms != null && ms.Length > 0) { _consumes[svc.ServiceName] = ms; @@ -473,7 +473,7 @@ public void Attach(ICommandClient client) private async Task DoRefresh(String? argument) { - await RefreshConsume(); + await RefreshConsume().ConfigureAwait(false); return "刷新服务成功"; } diff --git a/Stardust/DingTalk/DingTalkClient.cs b/Stardust/DingTalk/DingTalkClient.cs index 15b8a588..cf643a21 100644 --- a/Stardust/DingTalk/DingTalkClient.cs +++ b/Stardust/DingTalk/DingTalkClient.cs @@ -19,11 +19,11 @@ public class DingTalkClient #endregion #region 发送消息 - private async Task PostAsync(Object msg) + private Task PostAsync(Object msg) { _Client ??= Tracer.CreateHttpClient(); - return await _Client.PostAsync(Url, msg); + return _Client.PostAsync(Url, msg); } /// 发送文本消息 diff --git a/Stardust/LocalStarClient.cs b/Stardust/LocalStarClient.cs index 1ea6af97..b11cc24f 100644 --- a/Stardust/LocalStarClient.cs +++ b/Stardust/LocalStarClient.cs @@ -103,7 +103,7 @@ private void Init() try { - return Info = await _client.InvokeAsync("Info", _local); + return Info = await _client.InvokeAsync("Info", _local).ConfigureAwait(false); } catch (TimeoutException) { @@ -117,7 +117,7 @@ private void Init() /// 向StarAgent发送心跳 /// - public async Task PingAsync(AppInfo appInfo, Int32 watchdogTimeout) + public Task PingAsync(AppInfo appInfo, Int32 watchdogTimeout) { Init(); @@ -131,7 +131,7 @@ private void Init() WatchdogTimeout = watchdogTimeout, }; - return await _client.InvokeAsync("Ping", info); + return _client.InvokeAsync("Ping", info); } #endregion diff --git a/Stardust/Managers/FrameworkManager.cs b/Stardust/Managers/FrameworkManager.cs index 049d3852..90ce7c21 100644 --- a/Stardust/Managers/FrameworkManager.cs +++ b/Stardust/Managers/FrameworkManager.cs @@ -215,12 +215,12 @@ void CheckPing() { TaskEx.Run(async () => { - await client.Ping(); - await TaskEx.Delay(1000); + await client.Ping().ConfigureAwait(false); + await TaskEx.Delay(1000).ConfigureAwait(false); //!! 要执行整个升级动作,而不仅仅是拉取新版本 //await client.Upgrade("", ""); - await client.SendCommand("node/upgrade", ""); + await client.SendCommand("node/upgrade", "").ConfigureAwait(false); }); } } diff --git a/Stardust/Registry/IRegistry.cs b/Stardust/Registry/IRegistry.cs index 5de05cf4..bfe31634 100644 --- a/Stardust/Registry/IRegistry.cs +++ b/Stardust/Registry/IRegistry.cs @@ -91,7 +91,7 @@ public static async Task CreateForServiceAsync(this IRegistry regist if (registry is ILogFeature logFeature) http.Log = logFeature.Log; if (registry is ITracerFeature tracerFeature) http.Tracer = tracerFeature.Tracer; - var models = await registry.ResolveAsync(serviceName, null, tag); + var models = await registry.ResolveAsync(serviceName, null, tag).ConfigureAwait(false); if (models != null) BindServices(http, models); @@ -176,15 +176,15 @@ public static void BindServices(this ApiHttpClient client, ServiceModel[] ms) /// public static async Task ResolveAddressAsync(this IRegistry registry, String serviceName, String? minVersion = null, String? tag = null) { - var ms = await registry.ResolveAsync(serviceName, minVersion, tag); - if (ms == null) return new String[0]; + var ms = await registry.ResolveAsync(serviceName, minVersion, tag).ConfigureAwait(false); + if (ms == null) return []; var addrs = new List(); foreach (var item in ms) { if (!item.Address.IsNullOrEmpty()) { - var ss = item.Address.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); + var ss = item.Address.Split([',', ';'], StringSplitOptions.RemoveEmptyEntries); foreach (var elm in ss) { if (!elm.IsNullOrEmpty() && !addrs.Contains(elm)) addrs.Add(elm); diff --git a/Stardust/StarClient.cs b/Stardust/StarClient.cs index 33c8fff4..b39de4bc 100644 --- a/Stardust/StarClient.cs +++ b/Stardust/StarClient.cs @@ -345,7 +345,7 @@ public override IPingRequest BuildPingRequest() /// public override async Task Ping(CancellationToken cancellationToken = default) { - var rs = await base.Ping(cancellationToken); + var rs = await base.Ping(cancellationToken).ConfigureAwait(false); if (rs != null) { // 迁移到新服务器 @@ -356,13 +356,13 @@ public override IPingRequest BuildPingRequest() OnMigration?.Invoke(this, arg); if (!arg.Cancel) { - await Logout("切换新服务器", cancellationToken); + await Logout("切换新服务器", cancellationToken).ConfigureAwait(false); // 清空原有链接,添加新链接 Server = prs.NewServer; Client = null; - await Login(cancellationToken); + await Login(cancellationToken).ConfigureAwait(false); } } } @@ -374,16 +374,16 @@ public override IPingRequest BuildPingRequest() #region 部署 /// 获取分配到本节点的应用服务信息 /// - public async Task GetDeploy() => await InvokeAsync("Deploy/GetAll"); + public Task GetDeploy() => InvokeAsync("Deploy/GetAll"); /// 上传本节点的所有应用服务信息 /// /// - public async Task UploadDeploy(ServiceInfo[] services) => await InvokeAsync("Deploy/Upload", services); + public Task UploadDeploy(ServiceInfo[] services) => InvokeAsync("Deploy/Upload", services); /// 应用心跳。上报应用信息 /// /// - public async Task AppPing(AppInfo inf) => await InvokeAsync("Deploy/Ping", inf); + public Task AppPing(AppInfo inf) => InvokeAsync("Deploy/Ping", inf); #endregion } \ No newline at end of file diff --git a/Stardust/StarFactory.cs b/Stardust/StarFactory.cs index 9ea3a726..4975999f 100644 --- a/Stardust/StarFactory.cs +++ b/Stardust/StarFactory.cs @@ -462,11 +462,11 @@ public IRegistry? Service /// /// /// - public async Task SendNodeCommand(String nodeCode, String command, String? argument = null, Int32 startTime = 0, Int32 expire = 3600, Int32 timeout = 5) + public Task SendNodeCommand(String nodeCode, String command, String? argument = null, Int32 startTime = 0, Int32 expire = 3600, Int32 timeout = 5) { - if (!Valid()) return -1; + if (!Valid()) return Task.FromResult(-1); - return await _client.InvokeAsync("Node/SendCommand", new CommandInModel + return _client.InvokeAsync("Node/SendCommand", new CommandInModel { Code = nodeCode, Command = command, @@ -485,11 +485,11 @@ public async Task SendNodeCommand(String nodeCode, String command, String /// /// /// - public async Task SendAppCommand(String appId, String command, String? argument = null, Int32 startTime = 0, Int32 expire = 3600, Int32 timeout = 5) + public Task SendAppCommand(String appId, String command, String? argument = null, Int32 startTime = 0, Int32 expire = 3600, Int32 timeout = 5) { - if (!Valid()) return -1; + if (!Valid()) return Task.FromResult(-1); - return await _client.InvokeAsync("App/SendCommand", new CommandInModel + return _client.InvokeAsync("App/SendCommand", new CommandInModel { Code = appId, Command = command, diff --git a/Stardust/Stardust.csproj b/Stardust/Stardust.csproj index dc515657..a3fa68b3 100644 --- a/Stardust/Stardust.csproj +++ b/Stardust/Stardust.csproj @@ -20,6 +20,8 @@ True ..\Doc\newlife.snk 1701;1702;NU5104;NU1505;NETSDK1138;CS7035 + latest + CA2007 @@ -117,10 +119,10 @@ - + - + diff --git a/Stardust/WeiXin/WeiXinClient.cs b/Stardust/WeiXin/WeiXinClient.cs index de7c870e..962d38c9 100644 --- a/Stardust/WeiXin/WeiXinClient.cs +++ b/Stardust/WeiXin/WeiXinClient.cs @@ -18,11 +18,11 @@ public class WeiXinClient #endregion #region 发送消息 - private async Task PostAsync(Object msg) + private Task PostAsync(Object msg) { _Client ??= Tracer.CreateHttpClient(); - return await _Client.PostAsync(Url, msg); + return _Client.PostAsync(Url, msg); } /// 发送文本消息 diff --git a/Test/Test.csproj b/Test/Test.csproj index f2b3d9a9..5b72bace 100644 --- a/Test/Test.csproj +++ b/Test/Test.csproj @@ -30,7 +30,7 @@ - +