@@ -15,11 +15,16 @@ public partial class Online : IDisposable
1515 [ NotNull ]
1616 private IConnectionService ? ConnectionService { get ; set ; }
1717
18+ [ Inject ]
19+ [ NotNull ]
20+ private WebClientService ? WebClientService { get ; set ; }
21+
1822 private DynamicObjectContext ? DataTableDynamicContext { get ; set ; }
1923
2024 private readonly DataTable _table = new ( ) ;
2125
2226 private CancellationTokenSource ? _cancellationTokenSource = null ;
27+ private string ? _clientId ;
2328
2429 /// <summary>
2530 /// <inheritdoc/>
@@ -29,7 +34,6 @@ protected override void OnInitialized()
2934 base . OnInitialized ( ) ;
3035
3136 CreateTable ( ) ;
32- BuildContext ( ) ;
3337 }
3438
3539 /// <summary>
@@ -44,8 +48,9 @@ protected override void OnAfterRender(bool firstRender)
4448 {
4549 Task . Run ( async ( ) =>
4650 {
47- await Task . Delay ( 500 ) ;
48- _cancellationTokenSource = new ( ) ;
51+ var client = await WebClientService . GetClientInfo ( ) ;
52+ _clientId = client . Id ;
53+ _cancellationTokenSource ??= new ( ) ;
4954 while ( _cancellationTokenSource is { IsCancellationRequested : false } )
5055 {
5156 try
@@ -62,6 +67,7 @@ protected override void OnAfterRender(bool firstRender)
6267
6368 private void CreateTable ( )
6469 {
70+ _table . Columns . Add ( "Id" , typeof ( string ) ) ;
6571 _table . Columns . Add ( "ConnectionTime" , typeof ( DateTimeOffset ) ) ;
6672 _table . Columns . Add ( "LastBeatTime" , typeof ( DateTimeOffset ) ) ;
6773 _table . Columns . Add ( "Dur" , typeof ( TimeSpan ) ) ;
@@ -81,6 +87,7 @@ private void BuildContext()
8187 foreach ( var item in ConnectionService . Connections )
8288 {
8389 _table . Rows . Add (
90+ item . Id ,
8491 item . ConnectionTime ,
8592 item . LastBeatTime ,
8693 item . LastBeatTime - item . ConnectionTime ,
@@ -100,7 +107,11 @@ private void BuildContext()
100107 DataTableDynamicContext = new DataTableDynamicContext ( _table , ( context , col ) =>
101108 {
102109 col . Text = Localizer [ col . GetFieldName ( ) ] ;
103- if ( col . GetFieldName ( ) == "ConnectionTime" )
110+ if ( col . GetFieldName ( ) == "Id" )
111+ {
112+ col . Ignore = true ;
113+ }
114+ else if ( col . GetFieldName ( ) == "ConnectionTime" )
104115 {
105116 col . FormatString = "yyyy/MM/dd HH:mm:ss" ;
106117 col . Width = 118 ;
@@ -150,6 +161,12 @@ private static string FormatIp(object v)
150161 return ret ;
151162 }
152163
164+ private string ? SetRowClassFormatter ( DynamicObject context )
165+ {
166+ var id = context . GetValue ( "id" ) ? . ToString ( ) ;
167+ return _clientId == id ? "active" : null ;
168+ }
169+
153170 private void Dispose ( bool disposing )
154171 {
155172 if ( disposing )
0 commit comments