From cda8b47ca36ded626ad3023a94b907802345fda5 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Tue, 27 Oct 2020 21:24:47 +0100 Subject: [PATCH] [ ADD] added message sending to all clients, doesn't work yet --- ClientApp/Utils/Client.cs | 2 +- ClientApp/Utils/EngineConnection.cs | 4 ++-- DoctorApp/ViewModels/ClientInfoViewModel.cs | 7 ++++--- DoctorApp/ViewModels/MainViewModel.cs | 11 ++++++++++- DoctorApp/ViewModels/MainWindowViewModel.cs | 1 + 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ClientApp/Utils/Client.cs b/ClientApp/Utils/Client.cs index 27d980a..a96a2ab 100644 --- a/ClientApp/Utils/Client.cs +++ b/ClientApp/Utils/Client.cs @@ -43,7 +43,7 @@ namespace ClientApp.Utils /// private void initEngine() { - Debug.WriteLine("init engine"); + Debug.WriteLine("[CLIENT] init engine"); engineConnection = EngineConnection.INSTANCE; engineConnection.OnNoTunnelId = RetryEngineConnection; engineConnection.OnSuccessFullConnection = engineConnected; diff --git a/ClientApp/Utils/EngineConnection.cs b/ClientApp/Utils/EngineConnection.cs index a717d0c..d9e905a 100644 --- a/ClientApp/Utils/EngineConnection.cs +++ b/ClientApp/Utils/EngineConnection.cs @@ -27,7 +27,7 @@ namespace ClientApp.Utils //new PC("DESKTOP-M2CIH87", "Fabian"), //new PC("T470S", "Shinichi"), //new PC("DESKTOP-DHS478C", "semme"), - //new PC("HP-ZBOOK-SEM", "Sem") + new PC("HP-ZBOOK-SEM", "Sem") //new PC("DESKTOP-TV73FKO", "Wouter"), //new PC("DESKTOP-SINMKT1", "Ralf van Aert"), //new PC("NA", "Bart") @@ -71,7 +71,7 @@ namespace ClientApp.Utils updateTimer.AutoReset = true; updateTimer.Enabled = false; - noVRResponseTimer = new System.Timers.Timer(15000); + noVRResponseTimer = new System.Timers.Timer(30000); noVRResponseTimer.Elapsed += noVRResponseTimeout; noVRResponseTimer.AutoReset = false; noVRResponseTimer.Enabled = false; diff --git a/DoctorApp/ViewModels/ClientInfoViewModel.cs b/DoctorApp/ViewModels/ClientInfoViewModel.cs index 9e64e9c..4b652a5 100644 --- a/DoctorApp/ViewModels/ClientInfoViewModel.cs +++ b/DoctorApp/ViewModels/ClientInfoViewModel.cs @@ -43,12 +43,14 @@ namespace DoctorApp.ViewModels public MainWindowViewModel MainWindowViewModel { get; set; } private Client client; + private MainViewModel parent; public Chart Chart { get; set; } - public ClientInfoViewModel(MainWindowViewModel mainWindowViewModel, string username) + public ClientInfoViewModel(MainViewModel parent,MainWindowViewModel mainWindowViewModel, string username) { MainWindowViewModel = mainWindowViewModel; + this.parent = parent; this.PatientInfo = new PatientInfo() { Username = username, Status = "Waiting to start" }; this.Chart = new Chart(this.PatientInfo); PatientInfo.ChatLog = new ObservableCollection(); @@ -75,8 +77,7 @@ namespace DoctorApp.ViewModels ChatToAll = new RelayCommand((parameter) => { - //todo save clientinfoviewmodels in mainviewmodel - //todo send message to client of every clientinfoviewmodel + this.parent?.SendToAllClients(((TextBox)parameter).Text); }); SetResistance = new RelayCommand((parameter) => diff --git a/DoctorApp/ViewModels/MainViewModel.cs b/DoctorApp/ViewModels/MainViewModel.cs index e61b202..0c28489 100644 --- a/DoctorApp/ViewModels/MainViewModel.cs +++ b/DoctorApp/ViewModels/MainViewModel.cs @@ -30,7 +30,7 @@ namespace DoctorApp.ViewModels Debug.WriteLine("new tab with name " + username); App.Current.Dispatcher.Invoke((Action)delegate { - Tabs.Add(new ClientInfoViewModel(MainWindowViewModel, username)); + Tabs.Add(new ClientInfoViewModel(this,MainWindowViewModel, username)); }); } @@ -72,6 +72,15 @@ namespace DoctorApp.ViewModels } } } + + internal void SendToAllClients(string text) + { + Debug.WriteLine("[MAINVIEWMODEL] Sending message to all clients: " + text); + foreach (ClientInfoViewModel item in Tabs) + { + item.SendMessageToClient(item.PatientInfo.Username, text); + } + } } diff --git a/DoctorApp/ViewModels/MainWindowViewModel.cs b/DoctorApp/ViewModels/MainWindowViewModel.cs index a15f026..ec272e0 100644 --- a/DoctorApp/ViewModels/MainWindowViewModel.cs +++ b/DoctorApp/ViewModels/MainWindowViewModel.cs @@ -6,6 +6,7 @@ using System.Windows.Input; using DoctorApp.Models; using DoctorApp.Utils; using Util.MagicCode; +using System; namespace DoctorApp.ViewModels {