Remove Tabs when disconnect
This commit is contained in:
@@ -175,7 +175,7 @@ namespace ClientApp.Utils
|
|||||||
/// starts sending a message to the server
|
/// starts sending a message to the server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">the message to send</param>
|
/// <param name="message">the message to send</param>
|
||||||
private void sendMessage(byte[] message)
|
public void sendMessage(byte[] message)
|
||||||
{
|
{
|
||||||
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ namespace ClientApp.Utils
|
|||||||
public const string START_SESSION = "START SESSION";
|
public const string START_SESSION = "START SESSION";
|
||||||
public const string STOP_SESSION = "STOP SESSION";
|
public const string STOP_SESSION = "STOP SESSION";
|
||||||
public const string SET_RESISTANCE = "SET RESISTANCE";
|
public const string SET_RESISTANCE = "SET RESISTANCE";
|
||||||
|
public const string NEW_CONNECTION = "NEW CONNECTION";
|
||||||
|
public const string DISCONNECT = "DISCONNECT";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// makes the json object with LOGIN identifier and username and password
|
/// makes the json object with LOGIN identifier and username and password
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -201,6 +203,24 @@ namespace ClientApp.Utils
|
|||||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.worked;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using ClientApp.Utils;
|
using ClientApp.Utils;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace ClientApp.ViewModels
|
namespace ClientApp.ViewModels
|
||||||
@@ -13,13 +14,22 @@ namespace ClientApp.ViewModels
|
|||||||
public ObservableObject SelectedViewModel { get; set; }
|
public ObservableObject SelectedViewModel { get; set; }
|
||||||
public Client client { get; }
|
public Client client { get; }
|
||||||
|
|
||||||
|
LoginViewModel loginViewModel;
|
||||||
|
|
||||||
public MainWindowViewModel(Client client)
|
public MainWindowViewModel(Client client)
|
||||||
{
|
{
|
||||||
this.InfoModel = new Info();
|
this.InfoModel = new Info();
|
||||||
this.client = client;
|
this.client = client;
|
||||||
LoginViewModel loginViewModel = new LoginViewModel(this);
|
loginViewModel = new LoginViewModel(this);
|
||||||
SelectedViewModel = loginViewModel;
|
SelectedViewModel = loginViewModel;
|
||||||
this.client.SetLoginViewModel(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));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ namespace DoctorApp.Utils
|
|||||||
this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
|
this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
|
||||||
break;
|
break;
|
||||||
case DataParser.DISCONNECT:
|
case DataParser.DISCONNECT:
|
||||||
this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
|
this.MainViewModel.DisconnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace DoctorApp.ViewModels
|
|||||||
{
|
{
|
||||||
class MainViewModel : ObservableObject
|
class MainViewModel : ObservableObject
|
||||||
{
|
{
|
||||||
public ObservableCollection<object> Tabs { get; set; }
|
public ObservableCollection<ClientInfoViewModel> Tabs { get; set; }
|
||||||
public int Selected { get; set; }
|
public int Selected { get; set; }
|
||||||
public MainWindowViewModel MainWindowViewModel { get; set; }
|
public MainWindowViewModel MainWindowViewModel { get; set; }
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ namespace DoctorApp.ViewModels
|
|||||||
{
|
{
|
||||||
this.MainWindowViewModel = mainWindowViewModel;
|
this.MainWindowViewModel = mainWindowViewModel;
|
||||||
client = this.MainWindowViewModel.client;
|
client = this.MainWindowViewModel.client;
|
||||||
Tabs= new ObservableCollection<object>();
|
Tabs= new ObservableCollection<ClientInfoViewModel>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NewConnectedUser(string username)
|
public void NewConnectedUser(string username)
|
||||||
@@ -37,7 +37,17 @@ namespace DoctorApp.ViewModels
|
|||||||
|
|
||||||
public void DisconnectedUser(string username)
|
public void DisconnectedUser(string username)
|
||||||
{
|
{
|
||||||
|
App.Current.Dispatcher.Invoke((Action)delegate
|
||||||
|
{
|
||||||
|
foreach (ClientInfoViewModel item in Tabs)
|
||||||
|
{
|
||||||
|
if (item.Username == username)
|
||||||
|
{
|
||||||
|
Tabs.Remove(item);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
d:DesignHeight="450" d:DesignWidth="800">
|
d:DesignHeight="450" d:DesignWidth="800">
|
||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<TabControl ItemsSource="{Binding Tabs}" SelectedItem="{Binding Selected}">
|
<TabControl TabStripPlacement="Left" ItemsSource="{Binding Tabs}" SelectedItem="{Binding Selected}">
|
||||||
<TabControl.ItemTemplate>
|
<TabControl.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<TextBlock Text="{Binding TabName}"/>
|
<TextBlock Text="{Binding TabName}"/>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
Title="MainWindow" Height="450" Width="800"
|
Title="MainWindow" Height="450" Width="800"
|
||||||
WindowState="Maximized">
|
WindowState="Maximized">
|
||||||
<Grid>
|
<Grid>
|
||||||
<ContentControl HorizontalAlignment="Center" VerticalAlignment="Center" Content="{Binding SelectedViewModel}" Focusable="False" />
|
<ContentControl Content="{Binding SelectedViewModel}" Focusable="False" />
|
||||||
<Label Content="gemaakt door: mensen" DockPanel.Dock="Bottom" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontStyle="Italic" Foreground="Gray"/>
|
<Label Content="gemaakt door: mensen" DockPanel.Dock="Bottom" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontStyle="Italic" Foreground="Gray"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -127,6 +127,9 @@ namespace Server
|
|||||||
Console.WriteLine($"set resistance worked is " + worked);
|
Console.WriteLine($"set resistance worked is " + worked);
|
||||||
//set resistance on doctor GUI
|
//set resistance on doctor GUI
|
||||||
break;
|
break;
|
||||||
|
case DataParser.DISCONNECT:
|
||||||
|
communication.Disconnect(this);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ namespace Server
|
|||||||
internal void Disconnect(Client client)
|
internal void Disconnect(Client client)
|
||||||
{
|
{
|
||||||
clients.Remove(client);
|
clients.Remove(client);
|
||||||
|
doctor.sendMessage(DataParser.getDisconnectJson(client.username));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NewLogin(Client client)
|
public void NewLogin(Client client)
|
||||||
|
|||||||
Reference in New Issue
Block a user