55using AgileConfig . Server . IService ;
66using Microsoft . Extensions . Logging ;
77using System ;
8- using System . Collections . Concurrent ;
98using System . Collections . Generic ;
109using System . Threading . Tasks ;
1110
@@ -17,13 +16,14 @@ public class RemoteServerNodeProxy : IRemoteServerNodeProxy
1716 private readonly IRestClient _restClient ;
1817 private readonly IServerNodeService _serverNodeService ;
1918 private readonly ISysLogService _sysLogService ;
20-
21- private static ConcurrentDictionary < string , ClientInfos > _serverNodeClientReports =
22- new ConcurrentDictionary < string , ClientInfos > ( ) ;
23-
19+ private static readonly Dictionary < string , string > _modules = new ( )
20+ {
21+ { "r" , "Registration Center" } ,
22+ { "c" , "Configuration Center" }
23+ } ;
2424
2525 public RemoteServerNodeProxy (
26- ILoggerFactory loggerFactory ,
26+ ILoggerFactory loggerFactory ,
2727 IRestClient restClient ,
2828 IServerNodeService serverNodeService ,
2929 ISysLogService sysLogService )
@@ -47,20 +47,12 @@ public async Task<bool> AllClientsDoActionAsync(string address, WebsocketAction
4747 return false ;
4848 } , 5 ) ;
4949
50- var module = "" ;
51- if ( action . Module == "r" )
52- {
53- module = "注册中心" ;
54- }
55- if ( action . Module == "c" )
56- {
57- module = "配置中心" ;
58- }
50+ _modules . TryGetValue ( action . Module , out var moduleName ) ;
5951 await _sysLogService . AddSysLogAsync ( new SysLog
6052 {
6153 LogTime = DateTime . Now ,
6254 LogType = result ? SysLogType . Normal : SysLogType . Warn ,
63- LogText = $ "通知节点【 { address } 】所有客户端:【 { module } 】【 { action . Action } 】 响应: { ( result ? "成功 " : "失败 " ) } "
55+ LogText = $ "Notified node [ { address } ] all clients: [ { moduleName } ] [ { action . Action } ] Response: { ( result ? "Success " : "Failed " ) } "
6456 } ) ;
6557
6658 return result ;
@@ -80,21 +72,13 @@ public async Task<bool> AppClientsDoActionAsync(string address, string appId, st
8072 return false ;
8173 } , 5 ) ;
8274
83- var module = "" ;
84- if ( action . Module == "r" )
85- {
86- module = "注册中心" ;
87- }
88- if ( action . Module == "c" )
89- {
90- module = "配置中心" ;
91- }
75+ _modules . TryGetValue ( action . Module , out var moduleName ) ;
9276 await _sysLogService . AddSysLogAsync ( new SysLog
9377 {
9478 LogTime = DateTime . Now ,
9579 LogType = result ? SysLogType . Normal : SysLogType . Warn ,
9680 AppId = appId ,
97- LogText = $ "通知节点【 { address } 】应用【 { appId } 】的客户端:【 { module } 】【 { action . Action } 】 响应: { ( result ? "成功 " : "失败 " ) } "
81+ LogText = $ "Notified node [ { address } ] app [ { appId } ] clients: [ { moduleName } ] [ { action . Action } ] Response: { ( result ? "Success " : "Failed " ) } "
9882 } ) ;
9983 return result ;
10084 }
@@ -106,41 +90,15 @@ public async Task<bool> OneClientDoActionAsync(string address, string clientId,
10690 var url = $ "{ address } /RemoteOP/OneClientDoAction?clientId={ clientId } ";
10791 dynamic result = await _restClient . PostAsync < dynamic > ( url , action ) ;
10892
109- if ( ( bool ) result . success )
110- {
111- if ( action . Action == ActionConst . Offline )
112- {
113- if ( _serverNodeClientReports . ContainsKey ( address ) )
114- {
115- if ( _serverNodeClientReports [ address ] . Infos != null )
116- {
117- var report = _serverNodeClientReports [ address ] ;
118- report . Infos . RemoveAll ( c => c . Id == clientId ) ;
119- report . ClientCount = report . Infos . Count ;
120- }
121- }
122- }
123-
124- return true ;
125- }
126-
127- return false ;
93+ return ( bool ) result . success ;
12894 } , 5 ) ;
12995
130- var module = "" ;
131- if ( action . Module == "r" )
132- {
133- module = "注册中心" ;
134- }
135- if ( action . Module == "c" )
136- {
137- module = "配置中心" ;
138- }
96+ _modules . TryGetValue ( action . Module , out var moduleName ) ;
13997 await _sysLogService . AddSysLogAsync ( new SysLog
14098 {
14199 LogTime = DateTime . Now ,
142100 LogType = result ? SysLogType . Normal : SysLogType . Warn ,
143- LogText = $ "通知节点【 { address } 】的客户端【 { clientId } 】:【 { module } 】【 { action . Action } 】 响应: { ( result ? "成功 " : "失败 " ) } "
101+ LogText = $ "Notified node [ { address } ] client [ { clientId } ]: [ { moduleName } ] [ { action . Action } ] Response: { ( result ? "Success " : "Failed " ) } "
144102 } ) ;
145103
146104 return result ;
@@ -210,7 +168,7 @@ public async Task TestEchoAsync(string address)
210168 node . Status = NodeStatus . Offline ;
211169 _logger . LogInformation ( e , "Try test node {0} echo , but fail ." , node . Id ) ;
212170 }
213-
171+
214172 if ( node . Status == NodeStatus . Offline )
215173 {
216174 DateTime ? time = node . LastEchoTime ;
@@ -225,7 +183,7 @@ public async Task TestEchoAsync(string address)
225183 return ;
226184 }
227185 }
228-
186+
229187 await _serverNodeService . UpdateAsync ( node ) ;
230188 }
231189
@@ -259,7 +217,7 @@ public async Task ClearConfigServiceCache(string address)
259217 _logger . LogError ( e , "Try to clear node {0}'s config cache , but fail ." , address ) ;
260218 }
261219 }
262-
220+
263221 public async Task ClearServiceInfoCache ( string address )
264222 {
265223 try
0 commit comments