From b31fa293fba07ae477df7e8fc6ac02e0412d1cd7 Mon Sep 17 00:00:00 2001 From: fabjuuuh Date: Fri, 16 Oct 2020 11:42:32 +0200 Subject: [PATCH] Commands --- DoctorApp/Utils/Client.cs | 8 ++-- DoctorApp/ViewModels/ClientInfoViewModel.cs | 44 ++++++++++++++++++++- DoctorApp/ViewModels/MainViewModel.cs | 3 +- Hashing/DataParser.cs | 11 ++++++ 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/DoctorApp/Utils/Client.cs b/DoctorApp/Utils/Client.cs index b390277..558a300 100644 --- a/DoctorApp/Utils/Client.cs +++ b/DoctorApp/Utils/Client.cs @@ -150,7 +150,7 @@ namespace DoctorApp.Utils /// starts sending a message to the server /// /// the message to send - private void sendMessage(byte[] message) + public void sendMessage(byte[] message) { stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); } @@ -234,10 +234,10 @@ namespace DoctorApp.Utils /// public void tryLogin(string username, string password) { - - string hashPassword = Util.Hasher.HashString(password); + string hashUser = Hasher.HashString(username); + string hashPassword = Hasher.HashString(password); - byte[] message = DataParser.getJsonMessage(DataParser.LoginAsDoctor(username, hashPassword)); + byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(hashUser, hashPassword)); this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); diff --git a/DoctorApp/ViewModels/ClientInfoViewModel.cs b/DoctorApp/ViewModels/ClientInfoViewModel.cs index 461985e..f316a6e 100644 --- a/DoctorApp/ViewModels/ClientInfoViewModel.cs +++ b/DoctorApp/ViewModels/ClientInfoViewModel.cs @@ -1,6 +1,10 @@ -using System; +using DoctorApp.Utils; +using GalaSoft.MvvmLight.Command; +using System; using System.Collections.Generic; using System.Text; +using System.Windows.Input; +using Util; namespace DoctorApp.ViewModels { @@ -9,5 +13,43 @@ namespace DoctorApp.ViewModels { public string Username { get; set; } public string Status { get; set; } + + public ICommand StartSession { get; set; } + + public ICommand StopSession { get; set; } + + public ICommand Chat { get; set; } + + public ICommand ChatToAll { get; set; } + + public ICommand ClientInfo { get; set; } + + public ICommand SetResistance { get; set; } + + public MainWindowViewModel MainWindowViewModel { get; set; } + private Client client; + + + + public ClientInfoViewModel(MainWindowViewModel mainWindowViewModel) + { + MainWindowViewModel = mainWindowViewModel; + client = mainWindowViewModel.client; + + StartSession = new RelayCommand(()=>{ + client.sendMessage(DataParser.getStartSessionJson()); + }); + + StopSession = new RelayCommand(() => { + client.sendMessage(DataParser.getStopSessionJson()); + }); + Chat = new RelayCommand((parameter) => + { + /*client.sendMessage(DataParser.)*/ + }); + + } + + } } diff --git a/DoctorApp/ViewModels/MainViewModel.cs b/DoctorApp/ViewModels/MainViewModel.cs index 8fbe2c8..7888a1d 100644 --- a/DoctorApp/ViewModels/MainViewModel.cs +++ b/DoctorApp/ViewModels/MainViewModel.cs @@ -28,9 +28,10 @@ namespace DoctorApp.ViewModels { App.Current.Dispatcher.Invoke((Action)delegate { - Tabs.Add(new ClientInfoViewModel + Tabs.Add(new ClientInfoViewModel(MainWindowViewModel) { Username = username, + Status = "Waiting to start" }); }); } diff --git a/Hashing/DataParser.cs b/Hashing/DataParser.cs index 1ba0581..ed97fdc 100644 --- a/Hashing/DataParser.cs +++ b/Hashing/DataParser.cs @@ -243,6 +243,17 @@ namespace Util return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username; } + /*public static bool getChatMessageFronJson(byte[] json, out string username, out string chat) + { + try + { + + } + dynamic jsn = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json)); + username = jsn.data.username; + chat = jsn.data.chat; + }*/ + } }