Remove Tabs when disconnect

This commit is contained in:
fabjuuuh
2020-10-14 14:35:14 +02:00
parent 3547207cad
commit af5dca25f4
9 changed files with 52 additions and 8 deletions

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