From dcf6c3c6d0da567aa7a0f76a4fbc59db4e9913fe Mon Sep 17 00:00:00 2001 From: shinichi Date: Mon, 19 Oct 2020 12:23:52 +0200 Subject: [PATCH] client can see if doctor connected --- ClientApp/Utils/Client.cs | 6 ++++++ ClientApp/ViewModels/LoginViewModel.cs | 10 ++++++++++ Server/Communication.cs | 11 ++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ClientApp/Utils/Client.cs b/ClientApp/Utils/Client.cs index 21bcf83..3315a05 100644 --- a/ClientApp/Utils/Client.cs +++ b/ClientApp/Utils/Client.cs @@ -163,6 +163,12 @@ namespace ClientApp.Utils sendMessage(DataParser.getSetResistanceResponseJson(true)); } break; + case DataParser.NEW_CONNECTION: + this.LoginViewModel.DoctorConnected(DataParser.getUsernameFromJson(payloadbytes)); + break; + case DataParser.DISCONNECT: + this.LoginViewModel.DoctorDisconnected(DataParser.getUsernameFromJson(payloadbytes)); + break; default: Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}"); break; diff --git a/ClientApp/ViewModels/LoginViewModel.cs b/ClientApp/ViewModels/LoginViewModel.cs index 7b9bfcf..0ec1488 100644 --- a/ClientApp/ViewModels/LoginViewModel.cs +++ b/ClientApp/ViewModels/LoginViewModel.cs @@ -42,5 +42,15 @@ namespace ClientApp.ViewModels this.MainWindowViewModel.SelectedViewModel = new MainViewModel(MainWindowViewModel); } } + + internal void DoctorConnected(string name) + { + this.MainWindowViewModel.InfoModel.DoctorConnected = true; + } + + internal void DoctorDisconnected(string name) + { + this.MainWindowViewModel.InfoModel.DoctorConnected = false; + } } } diff --git a/Server/Communication.cs b/Server/Communication.cs index 6e173cd..7a093fc 100644 --- a/Server/Communication.cs +++ b/Server/Communication.cs @@ -22,6 +22,7 @@ namespace Server this.clients.ForEach((client) => { this.mDoctor.sendMessage(DataParser.getNewConnectionJson(client.username)); + client.sendMessage(DataParser.getNewConnectionJson(this.mDoctor.username)); }); } } @@ -58,13 +59,21 @@ namespace Server public void NewLogin(Client client) { this.clients.Add(client); - Doctor?.sendMessage(DataParser.getNewConnectionJson(client.username)); + if (this.Doctor != null) + { + Doctor.sendMessage(DataParser.getNewConnectionJson(client.username)); + client.sendMessage(DataParser.getNewConnectionJson(Doctor.username)); + } } public void LogOff(Client client) { if (this.Doctor == client) { + this.clients.ForEach((client) => + { + client.sendMessage(DataParser.getDisconnectJson(this.mDoctor.username)); + }); this.Doctor = null; } this.clients.Remove(client);