@@ -28,7 +28,7 @@ public ShowServerInfoService(IDispatchThreadServerRequestExecutor dispatchThread
28
28
_shellHost = shellHost ;
29
29
}
30
30
31
- public void ShowServerStatusDialog ( ) {
31
+ public void ShowServerStatusDialog ( bool forceGarbageCollection ) {
32
32
var dialog = new ServerStatusDialog ( ) ;
33
33
dialog . HasMinimizeButton = false ;
34
34
dialog . HasMaximizeButton = false ;
@@ -38,7 +38,7 @@ public void ShowServerStatusDialog() {
38
38
var isClosed = false ;
39
39
dialog . Closed += ( sender , args ) => isClosed = true ;
40
40
41
- FetchDatabaseStatistics ( true , response => {
41
+ FetchDatabaseStatisticsImpl ( Guid . NewGuid ( ) . ToString ( ) , TimeSpan . Zero , forceGarbageCollection , response => {
42
42
if ( isClosed ) {
43
43
return ;
44
44
}
@@ -69,11 +69,12 @@ public void ShowServerStatusDialog() {
69
69
} else {
70
70
message . AppendFormat ( "Last updated: {0}\r \n " , "n/a (index is empty)" ) ;
71
71
}
72
+
72
73
dialog . ViewModel . IndexStatus = message . ToString ( ) . TrimSuffix ( "\r \n " ) ;
73
74
message . Clear ( ) ;
74
75
75
- message . AppendFormat ( "Managed memory: {0:n2} MB\r \n " , ( double ) response . ServerGcMemoryUsage / ( 1024 * 1024 ) ) ;
76
- message . AppendFormat ( "Native memory: {0:n2} MB\r \n " , ( double ) response . ServerNativeMemoryUsage / ( 1024 * 1024 ) ) ;
76
+ message . AppendFormat ( "Managed memory: {0:n2} MB\r \n " , ( double ) response . ServerGcMemoryUsage / ( 1024 * 1024 ) ) ;
77
+ message . AppendFormat ( "Native memory: {0:n2} MB\r \n " , ( double ) response . ServerNativeMemoryUsage / ( 1024 * 1024 ) ) ;
77
78
dialog . ViewModel . MemoryStatus = message . ToString ( ) . TrimSuffix ( "\r \n " ) ;
78
79
} ) ;
79
80
@@ -101,19 +102,19 @@ private void OnShowServerDetailsInvoked() {
101
102
dialog . ViewModel . Waiting = false ;
102
103
} ,
103
104
OnDispatchThreadSuccess = typedResponse => {
104
- var response = ( GetDatabaseDetailsResponse ) typedResponse ;
105
+ var response = ( GetDatabaseDetailsResponse ) typedResponse ;
105
106
var projectDetails = response . Projects . Select ( x => new ProjectDetailsViewModel {
106
107
ProjectDetails = x
107
108
} ) . ToList ( ) ;
108
109
foreach ( var x in projectDetails ) {
109
- x . ShowProjectConfigurationInvoked += ( sender , args ) => {
110
- ShowProjectConfiguration ( x ) ;
111
- } ;
110
+ x . ShowProjectConfigurationInvoked += ( sender , args ) => { ShowProjectConfiguration ( x ) ; } ;
112
111
}
112
+
113
113
dialog . ViewModel . Projects . AddRange ( projectDetails ) ;
114
114
if ( dialog . ViewModel . Projects . Count > 0 ) {
115
115
dialog . ViewModel . SelectedProject = dialog . ViewModel . Projects [ 0 ] ;
116
116
}
117
+
117
118
dialog . ViewModel . Waiting = false ;
118
119
}
119
120
} ) ;
@@ -147,7 +148,7 @@ public void ShowProjectIndexDetailsDialog(string path) {
147
148
_shellHost . ShowErrorMessageBox ( "Error" , error . Message ) ;
148
149
} ,
149
150
OnDispatchThreadSuccess = typedResponse => {
150
- var response = ( GetProjectDetailsResponse ) typedResponse ;
151
+ var response = ( GetProjectDetailsResponse ) typedResponse ;
151
152
dialog . ViewModel . ProjectDetails = response . ProjectDetails ;
152
153
dialog . ViewModel . Waiting = false ;
153
154
} ,
@@ -179,7 +180,7 @@ public void ShowDirectoryIndexDetailsDialog(string path) {
179
180
_shellHost . ShowErrorMessageBox ( "Error" , error . Message ) ;
180
181
} ,
181
182
OnDispatchThreadSuccess = typedResponse => {
182
- var response1 = ( GetDirectoryDetailsResponse ) typedResponse ;
183
+ var response1 = ( GetDirectoryDetailsResponse ) typedResponse ;
183
184
dialog . ViewModel . DirectoryDetails = response1 . DirectoryDetails ;
184
185
dialog . ViewModel . Waiting = false ;
185
186
} ,
@@ -199,20 +200,12 @@ private void ShowProjectConfiguration(ProjectDetailsViewModel projectDetailsView
199
200
dialog . ShowModal ( ) ;
200
201
}
201
202
202
- public void FetchDatabaseStatistics ( bool forceGarbageCollect , Action < GetDatabaseStatisticsResponse > callback ) {
203
- _dispatchThreadServerRequestExecutor . Post (
204
- new DispatchThreadServerRequest {
205
- Id = Guid . NewGuid ( ) . ToString ( ) ,
206
- Request = new GetDatabaseStatisticsRequest { ForceGabageCollection = forceGarbageCollect } ,
207
- OnDispatchThreadSuccess = typedResponse => {
208
- var response = ( GetDatabaseStatisticsResponse ) typedResponse ;
209
- callback ( response ) ;
210
- }
211
- } ) ;
203
+ public void FetchDatabaseStatistics ( Action < GetDatabaseStatisticsResponse > callback ) {
204
+ FetchDatabaseStatisticsImpl ( nameof ( FetchDatabaseStatistics ) , null , false , callback ) ;
212
205
}
213
206
214
207
public string GetIndexStatusText ( GetDatabaseStatisticsResponse response ) {
215
- var memoryUsageMb = ( double ) response . ServerNativeMemoryUsage / 1024L / 1024L ;
208
+ var memoryUsageMb = ( double ) response . ServerNativeMemoryUsage / 1024L / 1024L ;
216
209
var message = String . Format ( "Index: {0:n0} files - {1:n0} MB" , response . SearchableFileCount , memoryUsageMb ) ;
217
210
return message ;
218
211
}
@@ -259,22 +252,47 @@ public string HumanReadableDuration(DateTime utcTime) {
259
252
if ( span . TotalSeconds <= 5 ) {
260
253
return "a few seconds ago" ;
261
254
}
255
+
262
256
if ( span . TotalSeconds <= 50 ) {
263
257
return "less than 1 minute ago" ;
264
258
}
259
+
265
260
if ( span . TotalMinutes <= 1 ) {
266
261
return "about 1 minute ago" ;
267
262
}
263
+
268
264
if ( span . TotalMinutes <= 60 ) {
269
265
return string . Format ( "about {0:n0} minutes ago" , Math . Ceiling ( span . TotalMinutes ) ) ;
270
266
}
267
+
271
268
if ( span . TotalHours <= 1.5 ) {
272
269
return "about one hour ago" ;
273
270
}
271
+
274
272
if ( span . TotalHours <= 24 ) {
275
273
return string . Format ( "about {0:n0} hours ago" , Math . Ceiling ( span . TotalHours ) ) ;
276
274
}
275
+
277
276
return "more than one day ago" ;
278
277
}
278
+
279
+ public void FetchDatabaseStatisticsImpl ( string requestId , TimeSpan ? delay , bool forceGarbageCollect ,
280
+ Action < GetDatabaseStatisticsResponse > callback ) {
281
+ var request = new DispatchThreadServerRequest {
282
+ Id = requestId ,
283
+ Request = new GetDatabaseStatisticsRequest {
284
+ ForceGabageCollection = forceGarbageCollect
285
+ } ,
286
+ OnDispatchThreadSuccess = typedResponse => {
287
+ var response = ( GetDatabaseStatisticsResponse ) typedResponse ;
288
+ callback ( response ) ;
289
+ }
290
+ } ;
291
+ if ( delay != null ) {
292
+ request . Delay = delay . Value ;
293
+ }
294
+
295
+ _dispatchThreadServerRequestExecutor . Post ( request ) ;
296
+ }
279
297
}
280
298
}
0 commit comments