@@ -69,7 +69,7 @@ public RemotePythonExecutionService(IServiceProvider serviceProvider)
69
69
70
70
Subscribe ( ) ;
71
71
mTcpServer . Start ( ) ;
72
- mLogger . LogInformation ( "Server runing on {ip}:{port}" , Ip , Port ) ;
72
+ mLogger . LogInformation ( "Servers runing on {ip}:{port}" , Ip , Port ) ;
73
73
}
74
74
75
75
#endregion
@@ -94,6 +94,7 @@ private void UnSubscribe()
94
94
mTcpServer . Events . ClientDisconnected -= ClientDisconnected ;
95
95
mTcpServer . Events . MessageReceived -= MessageReceived ;
96
96
mTcpServer . Events . ExceptionEncountered -= ExceptionEncountered ;
97
+
97
98
AppDomain . CurrentDomain . ProcessExit -= AppProcessExit ;
98
99
}
99
100
@@ -109,35 +110,31 @@ private void OnChangeSettings(AppSettings settings, string arg2)
109
110
110
111
private void ClientConnected ( object sender , ConnectionEventArgs e )
111
112
{
112
- mLogger . LogInformation ( "Client connected. Connection id: {Guid}" , e . Client . Guid ) ;
113
113
var ip = e . Client . IpPort . Split ( ':' ) . FirstOrDefault ( ) ;
114
114
mCurrentClientParam = ( e . Client . Guid , ip ) ;
115
115
116
116
IsOutputEnded = false ;
117
- IsProcessEnded = false ;
117
+ mLogger . LogInformation ( "Client connected. Connection id: {Guid}. Client ip: {ip}" , e . Client . Guid , ip ) ;
118
118
}
119
119
120
120
private void ClientDisconnected ( object sender , DisconnectionEventArgs e )
121
121
{
122
122
mLogger . LogInformation ( "Client disconnected. Connection id: {Guid}" , e . Client . Guid ) ;
123
123
124
124
KillProcess ( ) ;
125
- IsOutputEnded = true ;
126
125
}
127
126
128
127
private void ExceptionEncountered ( object sender , ExceptionEventArgs e )
129
128
{
130
129
if ( e . Exception is IOException )
131
- return ;
130
+ mLogger . LogError ( "IOException" ) ;
132
131
133
132
/*if (e.Exception is SocketException)
134
- return;
133
+ return;*/
135
134
136
135
if ( e . Exception is OperationCanceledException )
137
- {
138
136
mLogger . LogError ( "OperationCanceledException" ) ;
139
- return;
140
- }*/
137
+
141
138
142
139
mLogger . LogError ( "Error happened {errorMessage}" , e . Exception ) ;
143
140
}
@@ -186,7 +183,7 @@ private void MessageReceived(object sender, MessageReceivedEventArgs e)
186
183
mLogger . LogInformation ( "Exit by client request" ) ;
187
184
188
185
KillProcess ( ) ;
189
- mIsOutputEnded = true ;
186
+ //IsOutputEnded = true;
190
187
break ;
191
188
}
192
189
}
@@ -199,12 +196,11 @@ private void ProcessErrorDataReceived(object sender, DataReceivedEventArgs e)
199
196
{
200
197
try
201
198
{
202
- var data = Encoding . UTF8 . GetBytes ( e . Data ) ;
203
-
204
- mUdpEndpoint . SendAsync ( mCurrentClientParam . ip , 19000 , data ) ;
199
+ //var data = Encoding.UTF8.GetBytes(e.Data);
200
+ mUdpEndpoint . SendAsync ( mCurrentClientParam . ip , Port , e . Data ) ;
205
201
206
202
mLogger . LogDebug ( "{data}" , e . Data ) ;
207
- IsOutputEnded = false ;
203
+
208
204
}
209
205
catch ( Exception exp )
210
206
{
@@ -220,13 +216,13 @@ private void ProcessOutputDataReceived(object sender, DataReceivedEventArgs e)
220
216
{
221
217
try
222
218
{
223
- var data = Encoding . UTF8 . GetBytes ( e . Data ) ;
224
- mUdpEndpoint . SendAsync ( mCurrentClientParam . ip , 19000 , data ) ;
219
+ // var data = Encoding.UTF8.GetBytes(e.Data);
220
+ mUdpEndpoint . SendAsync ( mCurrentClientParam . ip , Port , e . Data ) ;
225
221
226
222
227
223
mLogger . LogDebug ( "{data}" , e . Data ) ;
228
224
}
229
- catch ( TaskCanceledException )
225
+ /* catch (TaskCanceledException)
230
226
{
231
227
mLogger.LogError("Task was canceled");
232
228
IsOutputEnded = true;
@@ -238,7 +234,7 @@ private void ProcessOutputDataReceived(object sender, DataReceivedEventArgs e)
238
234
catch (OperationCanceledException)
239
235
{
240
236
mLogger.LogError("Operation canceled");
241
- }
237
+ }*/
242
238
catch ( Exception exp )
243
239
{
244
240
mLogger . LogError ( "Catch happened {exp}" , exp ) ;
@@ -247,16 +243,15 @@ private void ProcessOutputDataReceived(object sender, DataReceivedEventArgs e)
247
243
}
248
244
else
249
245
{
250
- mLogger . LogDebug ( "Output ended happened" ) ;
246
+ mLogger . LogInformation ( "Output ended happened" ) ;
251
247
//await Task.Delay(100);
252
248
IsOutputEnded = true ;
253
249
}
254
250
}
255
251
256
252
private void ProcessExited ( object sender , EventArgs e )
257
253
{
258
- mLogger . LogDebug ( "Process ended happened" ) ;
259
- IsProcessEnded = true ;
254
+ mLogger . LogInformation ( "Process ended happened" ) ;
260
255
}
261
256
262
257
private void AppProcessExit ( object sender , EventArgs e )
@@ -285,13 +280,14 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
285
280
{
286
281
while ( ! stoppingToken . IsCancellationRequested )
287
282
{
288
- while ( IsOutputEnded && IsProcessEnded )
283
+ while ( IsOutputEnded )
284
+ //while (IsOutputEnded && IsProcessEnded)
289
285
{
290
286
IsOutputEnded = false ;
291
- IsProcessEnded = false ;
287
+ // IsProcessEnded = false;
292
288
293
- /* if (mProcess == null)
294
- return;*/
289
+ // if (mProcess == null)
290
+ // return;
295
291
296
292
ExitData exitData = new ( ) ;
297
293
@@ -311,8 +307,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
311
307
ExitCode = mProcess . ExitCode
312
308
} ;
313
309
314
-
315
- //mProcess.Dispose();
310
+ mProcess . Dispose ( ) ;
316
311
//mProcess = null;
317
312
}
318
313
}
@@ -326,6 +321,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
326
321
327
322
if ( mTcpServer . IsClientConnected ( mCurrentClientParam . Guid ) )
328
323
{
324
+ mLogger . LogInformation ( "Send exit data" ) ;
329
325
await mTcpServer . SendAsync ( mCurrentClientParam . Guid , string . Empty , exitDictonary , token : stoppingToken ) ;
330
326
await mTcpServer . DisconnectClientAsync ( mCurrentClientParam . Guid , MessageStatus . Removed , true , stoppingToken ) ;
331
327
}
@@ -336,12 +332,6 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
336
332
}
337
333
}
338
334
339
- public override Task StopAsync ( CancellationToken cancellationToken )
340
- {
341
- mLogger . LogError ( "Host stopped" ) ;
342
-
343
- return base . StopAsync ( cancellationToken ) ;
344
- }
345
335
#endregion
346
336
347
337
#region Private fields
@@ -358,7 +348,7 @@ private bool IsOutputEnded
358
348
}
359
349
}
360
350
361
- private bool IsProcessEnded
351
+ /* private bool IsProcessEnded
362
352
{
363
353
get { return mIsProcessEnded; }
364
354
set
@@ -368,7 +358,7 @@ private bool IsProcessEnded
368
358
369
359
mIsProcessEnded = value;
370
360
}
371
- }
361
+ }*/
372
362
373
363
private string InterpreterPath
374
364
{
@@ -416,7 +406,6 @@ private string SourceCodeSavePath
416
406
mSourceCodeSavePath = value ;
417
407
mLogger . LogDebug ( "New path for {name} register with values {value}" , nameof ( SourceCodeSavePath ) , SourceCodeSavePath ) ;
418
408
}
419
-
420
409
}
421
410
422
411
private string mIp = string . Empty ;
@@ -464,9 +453,8 @@ private int Port
464
453
#region Private methods
465
454
466
455
private void KillProcess ( )
467
- {
468
- if ( mProcess == null )
469
- return ;
456
+ {
457
+ IsOutputEnded = true ;
470
458
471
459
try
472
460
{
@@ -477,6 +465,7 @@ private void KillProcess()
477
465
mProcess . CancelOutputRead ( ) ;
478
466
479
467
mProcess . Kill ( entireProcessTree : true ) ;
468
+ mLogger . LogInformation ( "KillProcess(): {id}," , mProcess . Id ) ;
480
469
}
481
470
catch ( Exception ex )
482
471
{
@@ -494,17 +483,23 @@ private void OnServerAddressChange()
494
483
if ( mTcpServer . Connections != 0 )
495
484
{
496
485
KillProcess ( ) ;
497
- IsOutputEnded = true ;
498
486
}
499
487
500
488
mTcpServer . Stop ( ) ;
489
+
490
+ mTcpServer . Dispose ( ) ;
491
+ mUdpEndpoint . Dispose ( ) ;
492
+
501
493
UnSubscribe ( ) ;
502
494
}
503
495
504
496
mTcpServer = new WatsonTcpServer ( Ip , Port ) ;
497
+ mUdpEndpoint = new UdpEndpoint ( Ip , Port ) ;
498
+
505
499
Subscribe ( ) ;
506
500
mTcpServer . Start ( ) ;
507
- mLogger . LogInformation ( "Server runing on {ip}:{port}" , Ip , Port ) ;
501
+
502
+ mLogger . LogInformation ( "Servers runing on {ip}:{port}" , Ip , Port ) ;
508
503
}
509
504
510
505
private void SetPath ( AppSettings appSettings )
@@ -561,7 +556,7 @@ private void StartProcess(bool withDebug = false)
561
556
mProcess = new ( )
562
557
{
563
558
StartInfo = proccesInfo ,
564
- EnableRaisingEvents = true ,
559
+ EnableRaisingEvents = true
565
560
} ;
566
561
567
562
mProcess . Exited += ProcessExited ;
@@ -571,7 +566,7 @@ private void StartProcess(bool withDebug = false)
571
566
572
567
mProcess . BeginOutputReadLine ( ) ;
573
568
mProcess . BeginErrorReadLine ( ) ;
574
-
569
+
575
570
mProcess . WaitForExit ( ) ;
576
571
}
577
572
@@ -584,7 +579,7 @@ protected virtual void Dispose(bool disposing)
584
579
if ( disposing )
585
580
{
586
581
KillProcess ( ) ;
587
- IsOutputEnded = true ;
582
+ //sOutputEnded = true;
588
583
589
584
UnSubscribe ( ) ;
590
585
mTcpServer . Stop ( ) ;
0 commit comments