From cc046d66113f5343ef0c7e75d43787e701d22efa Mon Sep 17 00:00:00 2001 From: shinichi Date: Fri, 16 Oct 2020 16:24:07 +0200 Subject: [PATCH] wip --- DoctorApp/Models/PatientInfo.cs | 25 +++++++++++ DoctorApp/Utils/Client.cs | 1 - DoctorApp/ViewModels/ClientInfoViewModel.cs | 47 ++++++++------------- DoctorApp/ViewModels/MainViewModel.cs | 11 ++--- DoctorApp/Views/ClientInfoView.xaml | 26 ++++++------ DoctorApp/Views/MainWindow.xaml | 2 + Server/Client.cs | 9 +--- Server/Communication.cs | 18 ++------ 8 files changed, 67 insertions(+), 72 deletions(-) create mode 100644 DoctorApp/Models/PatientInfo.cs diff --git a/DoctorApp/Models/PatientInfo.cs b/DoctorApp/Models/PatientInfo.cs new file mode 100644 index 0000000..c7ed295 --- /dev/null +++ b/DoctorApp/Models/PatientInfo.cs @@ -0,0 +1,25 @@ +using System.Collections.ObjectModel; +using Util; + +namespace DoctorApp.Models +{ + class PatientInfo : ObservableObject + { + public ObservableCollection ChatLog { get; set; } + public string Username { get; set; } + + public string Status { get; set; } + + public int Speed { get; set; } + + public int BPM { get; set; } + + public int Resistance { get; set; } + public int Acc_Power { get; set; } + + public int Curr_Power { get; set; } + + public int Distance { get; set; } + + } +} diff --git a/DoctorApp/Utils/Client.cs b/DoctorApp/Utils/Client.cs index a55151d..4e727d0 100644 --- a/DoctorApp/Utils/Client.cs +++ b/DoctorApp/Utils/Client.cs @@ -82,7 +82,6 @@ namespace DoctorApp.Utils string identifier; bool isJson = DataParser.getJsonIdentifier(messageBytes, out identifier); - Debug.WriteLine("doctor " + Encoding.ASCII.GetString(payloadbytes)); if (isJson) { switch (identifier) diff --git a/DoctorApp/ViewModels/ClientInfoViewModel.cs b/DoctorApp/ViewModels/ClientInfoViewModel.cs index c40f6ea..6b239c0 100644 --- a/DoctorApp/ViewModels/ClientInfoViewModel.cs +++ b/DoctorApp/ViewModels/ClientInfoViewModel.cs @@ -1,4 +1,5 @@ -using DoctorApp.Utils; +using DoctorApp.Models; +using DoctorApp.Utils; using GalaSoft.MvvmLight.Command; using System; using System.Collections.Generic; @@ -11,25 +12,10 @@ using Util; namespace DoctorApp.ViewModels { - + class ClientInfoViewModel : ObservableObject { - public ObservableCollection ChatLog { get; set; } - public string Username { get; set; } - - public string Status { get; set; } - - public int Speed { get; set; } - - public int BPM { get; set; } - - public int Resistance { get; set; } - public int Acc_Power { get; set; } - - public int Curr_Power { get; set; } - - public int Distance { get; set; } - + public PatientInfo PatientInfo { get; set; } public ICommand StartSession { get; set; } public ICommand StopSession { get; set; } @@ -45,33 +31,36 @@ namespace DoctorApp.ViewModels public MainWindowViewModel MainWindowViewModel { get; set; } private Client client; - public ClientInfoViewModel(MainWindowViewModel mainWindowViewModel) + public ClientInfoViewModel(MainWindowViewModel mainWindowViewModel, string username) { MainWindowViewModel = mainWindowViewModel; - ChatLog = new ObservableCollection(); + this.PatientInfo = new PatientInfo() { Username = username, Status = "Waiting to start" }; + PatientInfo.ChatLog = new ObservableCollection(); client = mainWindowViewModel.client; - StartSession = new RelayCommand(()=>{ - client.sendMessage(DataParser.getStartSessionJson(Username)); - Status = "Session started"; + StartSession = new RelayCommand(() => + { + client.sendMessage(DataParser.getStartSessionJson(PatientInfo.Username)); + PatientInfo.Status = "Session started"; }); - StopSession = new RelayCommand(() => { - client.sendMessage(DataParser.getStopSessionJson(Username)); - Status = "Session stopped, waiting to start again."; + StopSession = new RelayCommand(() => + { + client.sendMessage(DataParser.getStopSessionJson(PatientInfo.Username)); + PatientInfo.Status = "Session stopped, waiting to start again."; }); Chat = new RelayCommand((parameter) => { - client.sendMessage(DataParser.getChatJson(Username, ((TextBox)parameter).Text)); - ChatLog.Add(DateTime.Now+": "+ ((TextBox)parameter).Text); + client.sendMessage(DataParser.getChatJson(PatientInfo.Username, ((TextBox)parameter).Text)); + PatientInfo.ChatLog.Add(DateTime.Now + ": " + ((TextBox)parameter).Text); }); //TODO RelayCommand ChatToAll SetResistance = new RelayCommand((parameter) => { - client.sendMessage(DataParser.getSetResistanceJson(Username, float.Parse(((TextBox)parameter).Text))); + client.sendMessage(DataParser.getSetResistanceJson(PatientInfo.Username, float.Parse(((TextBox)parameter).Text))); }); } diff --git a/DoctorApp/ViewModels/MainViewModel.cs b/DoctorApp/ViewModels/MainViewModel.cs index 90d4509..b12d8dd 100644 --- a/DoctorApp/ViewModels/MainViewModel.cs +++ b/DoctorApp/ViewModels/MainViewModel.cs @@ -21,19 +21,14 @@ namespace DoctorApp.ViewModels { this.MainWindowViewModel = mainWindowViewModel; client = this.MainWindowViewModel.client; - Tabs= new ObservableCollection(); + Tabs = new ObservableCollection(); } public void NewConnectedUser(string username) { - System.Diagnostics.Debug.WriteLine("CREATING TAB FOR " + username); App.Current.Dispatcher.Invoke((Action)delegate { - Tabs.Add(new ClientInfoViewModel(MainWindowViewModel) - { - Username = username, - Status = "Waiting to start" - }); + Tabs.Add(new ClientInfoViewModel(MainWindowViewModel, username)); }); } @@ -43,7 +38,7 @@ namespace DoctorApp.ViewModels { foreach (ClientInfoViewModel item in Tabs) { - if (item.Username == username) + if (item.PatientInfo.Username == username) { Tabs.Remove(item); break; diff --git a/DoctorApp/Views/ClientInfoView.xaml b/DoctorApp/Views/ClientInfoView.xaml index 33a0c12..5724874 100644 --- a/DoctorApp/Views/ClientInfoView.xaml +++ b/DoctorApp/Views/ClientInfoView.xaml @@ -24,8 +24,8 @@ -