diff --git a/ClientApp/Utils/Client.cs b/ClientApp/Utils/Client.cs
index d3f015c..a2575a7 100644
--- a/ClientApp/Utils/Client.cs
+++ b/ClientApp/Utils/Client.cs
@@ -175,7 +175,7 @@ namespace ClientApp.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);
}
diff --git a/ClientApp/Utils/DataParser.cs b/ClientApp/Utils/DataParser.cs
index 6c1e4b7..d9feec1 100644
--- a/ClientApp/Utils/DataParser.cs
+++ b/ClientApp/Utils/DataParser.cs
@@ -15,6 +15,8 @@ namespace ClientApp.Utils
public const string START_SESSION = "START SESSION";
public const string STOP_SESSION = "STOP SESSION";
public const string SET_RESISTANCE = "SET RESISTANCE";
+ public const string NEW_CONNECTION = "NEW CONNECTION";
+ public const string DISCONNECT = "DISCONNECT";
///
/// makes the json object with LOGIN identifier and username and password
///
@@ -201,6 +203,24 @@ namespace ClientApp.Utils
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.worked;
}
+ public static byte[] getNewConnectionJson(string user)
+ {
+ dynamic data = new
+ {
+ username = user
+ };
+ return getJsonMessage(NEW_CONNECTION, data);
+ }
+
+ public static byte[] getDisconnectJson(string user)
+ {
+ dynamic data = new
+ {
+ username = user
+ };
+ return getJsonMessage(DISCONNECT, data);
+ }
+
}
}
diff --git a/ClientApp/ViewModels/MainWindowViewModel.cs b/ClientApp/ViewModels/MainWindowViewModel.cs
index f30bf73..5ccf3cd 100644
--- a/ClientApp/ViewModels/MainWindowViewModel.cs
+++ b/ClientApp/ViewModels/MainWindowViewModel.cs
@@ -2,6 +2,7 @@
using ClientApp.Utils;
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Text;
namespace ClientApp.ViewModels
@@ -13,13 +14,22 @@ namespace ClientApp.ViewModels
public ObservableObject SelectedViewModel { get; set; }
public Client client { get; }
+ LoginViewModel loginViewModel;
+
public MainWindowViewModel(Client client)
{
this.InfoModel = new Info();
this.client = client;
- LoginViewModel loginViewModel = new LoginViewModel(this);
+ loginViewModel = new LoginViewModel(this);
SelectedViewModel = loginViewModel;
this.client.SetLoginViewModel(loginViewModel);
+ App.Current.MainWindow.Closing += new CancelEventHandler(MainWindow_Closing);
+ }
+
+ void MainWindow_Closing(object sender, CancelEventArgs e)
+ {
+ this.client.sendMessage(DataParser.getDisconnectJson(loginViewModel.Username));
+
}
}
diff --git a/DoctorApp/Utils/Client.cs b/DoctorApp/Utils/Client.cs
index 9ce05b7..4239fba 100644
--- a/DoctorApp/Utils/Client.cs
+++ b/DoctorApp/Utils/Client.cs
@@ -125,7 +125,7 @@ namespace DoctorApp.Utils
this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
break;
case DataParser.DISCONNECT:
- this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
+ this.MainViewModel.DisconnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
break;
default:
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
diff --git a/DoctorApp/ViewModels/MainViewModel.cs b/DoctorApp/ViewModels/MainViewModel.cs
index 27c8e69..8c1f3fd 100644
--- a/DoctorApp/ViewModels/MainViewModel.cs
+++ b/DoctorApp/ViewModels/MainViewModel.cs
@@ -10,7 +10,7 @@ namespace DoctorApp.ViewModels
{
class MainViewModel : ObservableObject
{
- public ObservableCollection