Develop #10

Merged
SemvdH merged 229 commits from develop into master 2020-10-29 22:50:49 +00:00
9 changed files with 52 additions and 8 deletions
Showing only changes of commit af5dca25f4 - Show all commits

View File

@@ -175,7 +175,7 @@ namespace ClientApp.Utils
/// starts sending a message to the server
/// </summary>
/// <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);
}

View File

@@ -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";
/// <summary>
/// makes the json object with LOGIN identifier and username and password
/// </summary>
@@ -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);
}
}
}

View File

@@ -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));
}
}

View File

@@ -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)}");

View File

@@ -10,7 +10,7 @@ namespace DoctorApp.ViewModels
{
class MainViewModel : ObservableObject
{
public ObservableCollection<object> Tabs { get; set; }
public ObservableCollection<ClientInfoViewModel> Tabs { get; set; }
public int Selected { get; set; }
public MainWindowViewModel MainWindowViewModel { get; set; }
@@ -20,7 +20,7 @@ namespace DoctorApp.ViewModels
{
this.MainWindowViewModel = mainWindowViewModel;
client = this.MainWindowViewModel.client;
Tabs= new ObservableCollection<object>();
Tabs= new ObservableCollection<ClientInfoViewModel>();
}
public void NewConnectedUser(string username)
@@ -37,7 +37,17 @@ namespace DoctorApp.ViewModels
public void DisconnectedUser(string username)
{
App.Current.Dispatcher.Invoke((Action)delegate
{
foreach (ClientInfoViewModel item in Tabs)
{
if (item.Username == username)
{
Tabs.Remove(item);
break;
}
}
});
}
}

View File

@@ -8,7 +8,7 @@
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<TabControl ItemsSource="{Binding Tabs}" SelectedItem="{Binding Selected}">
<TabControl TabStripPlacement="Left" ItemsSource="{Binding Tabs}" SelectedItem="{Binding Selected}">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding TabName}"/>

View File

@@ -8,7 +8,7 @@
Title="MainWindow" Height="450" Width="800"
WindowState="Maximized">
<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"/>
</Grid>
</Window>

View File

@@ -127,6 +127,9 @@ namespace Server
Console.WriteLine($"set resistance worked is " + worked);
//set resistance on doctor GUI
break;
case DataParser.DISCONNECT:
communication.Disconnect(this);
break;
default:
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
break;

View File

@@ -49,6 +49,7 @@ namespace Server
internal void Disconnect(Client client)
{
clients.Remove(client);
doctor.sendMessage(DataParser.getDisconnectJson(client.username));
}
public void NewLogin(Client client)