diff --git a/DoctorApp/App.xaml b/DoctorApp/App.xaml
index 5159278..1fcbd5c 100644
--- a/DoctorApp/App.xaml
+++ b/DoctorApp/App.xaml
@@ -14,6 +14,9 @@
-
-
+
+
+
+
+
diff --git a/DoctorApp/Utils/Client.cs b/DoctorApp/Utils/Client.cs
index a3b6273..9ce05b7 100644
--- a/DoctorApp/Utils/Client.cs
+++ b/DoctorApp/Utils/Client.cs
@@ -20,6 +20,8 @@ namespace DoctorApp.Utils
private bool sessionRunning = false;
private IHandler handler = null;
private LoginViewModel LoginViewModel;
+ private MainViewModel MainViewModel;
+ private ClientInfoViewModel ClientInfoViewModel;
public Client() : this("localhost", 5555)
@@ -119,6 +121,12 @@ namespace DoctorApp.Utils
sendMessage(DataParser.getSetResistanceResponseJson(true));
}
break;
+ case DataParser.NEW_CONNECTION:
+ this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
+ break;
+ case DataParser.DISCONNECT:
+ this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
+ break;
default:
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
break;
@@ -247,5 +255,15 @@ namespace DoctorApp.Utils
{
this.LoginViewModel = loginViewModel;
}
+
+ internal void SetMainViewModel(MainViewModel mainViewModel)
+ {
+ this.MainViewModel = mainViewModel;
+ }
+
+ internal void SetClientInfoViewModel(ClientInfoViewModel clientInfoViewModel)
+ {
+ this.ClientInfoViewModel = clientInfoViewModel;
+ }
}
}
diff --git a/DoctorApp/Utils/DataParser.cs b/DoctorApp/Utils/DataParser.cs
index 0e06fe8..ca7ca90 100644
--- a/DoctorApp/Utils/DataParser.cs
+++ b/DoctorApp/Utils/DataParser.cs
@@ -15,6 +15,8 @@ namespace DoctorApp.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
///
@@ -191,6 +193,24 @@ namespace DoctorApp.Utils
return getJsonMessage(SET_RESISTANCE, data);
}
+ 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);
+ }
+
public static float getResistanceFromJson(byte[] json)
{
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.resistance;
@@ -201,6 +221,11 @@ namespace DoctorApp.Utils
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.worked;
}
+ public static string getUsernameFromResponseJson(byte[] json)
+ {
+ return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username;
+ }
+
}
}
diff --git a/DoctorApp/ViewModels/ClientInfoViewModel.cs b/DoctorApp/ViewModels/ClientInfoViewModel.cs
index 987c76c..54d2df0 100644
--- a/DoctorApp/ViewModels/ClientInfoViewModel.cs
+++ b/DoctorApp/ViewModels/ClientInfoViewModel.cs
@@ -4,7 +4,10 @@ using System.Text;
namespace DoctorApp.ViewModels
{
+
class ClientInfoViewModel
{
+ public string Username { get; set; }
+ public string TabName { get; set; }
}
}
diff --git a/DoctorApp/ViewModels/LoginViewModel.cs b/DoctorApp/ViewModels/LoginViewModel.cs
index 791aa02..a8e26ae 100644
--- a/DoctorApp/ViewModels/LoginViewModel.cs
+++ b/DoctorApp/ViewModels/LoginViewModel.cs
@@ -37,7 +37,9 @@ namespace DoctorApp.ViewModels
this.InvertedLoginStatus = !status;
if (status)
{
- this.mainWindowViewModel.SelectedViewModel = new MainViewModel(mainWindowViewModel);
+ MainViewModel mainViewModel = new MainViewModel(mainWindowViewModel);
+ this.mainWindowViewModel.client.SetMainViewModel(mainViewModel);
+ this.mainWindowViewModel.SelectedViewModel = mainViewModel;
}
}
}
diff --git a/DoctorApp/ViewModels/MainViewModel.cs b/DoctorApp/ViewModels/MainViewModel.cs
index fe7feba..27c8e69 100644
--- a/DoctorApp/ViewModels/MainViewModel.cs
+++ b/DoctorApp/ViewModels/MainViewModel.cs
@@ -1,12 +1,17 @@
using DoctorApp.Utils;
using System;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
using System.Text;
+using System.Windows.Controls;
namespace DoctorApp.ViewModels
{
class MainViewModel : ObservableObject
{
+ public ObservableCollection