Connect new tab
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -55,7 +55,7 @@ namespace Client
|
|||||||
|
|
||||||
this.stream = this.client.GetStream();
|
this.stream = this.client.GetStream();
|
||||||
|
|
||||||
tryLoginDoctor("hi","hi");
|
tryLogin();
|
||||||
|
|
||||||
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
|
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ namespace Client
|
|||||||
if (responseStatus == "OK")
|
if (responseStatus == "OK")
|
||||||
{
|
{
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
initEngine();
|
//initEngine();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Hardware.Simulators;
|
|||||||
using RH_Engine;
|
using RH_Engine;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace Client
|
namespace Client
|
||||||
{
|
{
|
||||||
@@ -14,6 +15,7 @@ namespace Client
|
|||||||
Console.WriteLine("Hello World!");
|
Console.WriteLine("Hello World!");
|
||||||
//connect fiets?
|
//connect fiets?
|
||||||
|
|
||||||
|
Thread.Sleep(20000);
|
||||||
Client client = new Client();
|
Client client = new Client();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,12 @@ namespace DokterApp
|
|||||||
private IHandler handler = null;
|
private IHandler handler = null;
|
||||||
private string username;
|
private string username;
|
||||||
private string password;
|
private string password;
|
||||||
|
private Del callback;
|
||||||
|
|
||||||
|
|
||||||
public Client(string adress, int port, string username, string password)
|
public Client(string adress, int port, string username, string password, Del callback)
|
||||||
{
|
{
|
||||||
|
this.callback = callback;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.client = new TcpClient();
|
this.client = new TcpClient();
|
||||||
@@ -82,8 +84,9 @@ namespace DokterApp
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
callback("yeet");
|
||||||
Console.WriteLine($"login failed \"{responseStatus}\"");
|
Console.WriteLine($"login failed \"{responseStatus}\"");
|
||||||
tryLogin();
|
//tryLogin();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DataParser.START_SESSION:
|
case DataParser.START_SESSION:
|
||||||
@@ -173,14 +176,6 @@ namespace DokterApp
|
|||||||
private void tryLogin()
|
private void tryLogin()
|
||||||
{
|
{
|
||||||
//TODO File in lezen
|
//TODO File in lezen
|
||||||
/*Console.WriteLine("enter username");
|
|
||||||
string username = Console.ReadLine();
|
|
||||||
Console.WriteLine("enter password");
|
|
||||||
string password = Console.ReadLine();*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
string hashUser = Hashing.Hasher.HashString(username);
|
string hashUser = Hashing.Hasher.HashString(username);
|
||||||
string hashPassword = Hashing.Hasher.HashString(password);
|
string hashPassword = Hashing.Hasher.HashString(password);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
<ColumnDefinition/>
|
<ColumnDefinition/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<StackPanel Grid.ColumnSpan="2" Grid.RowSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" Orientation="Vertical">
|
<StackPanel Grid.ColumnSpan="2" Grid.RowSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" Orientation="Vertical">
|
||||||
<Label Content="Yo dokter login" Margin="0,0,0,20" HorizontalAlignment="Center"/>
|
<Label x:Name="Label" Content="Yo dokter login" Margin="0,0,0,20" HorizontalAlignment="Center"/>
|
||||||
<Label Content="Username" HorizontalContentAlignment="Center"/>
|
<Label Content="Username" HorizontalContentAlignment="Center"/>
|
||||||
<TextBox x:Name="Username" TextWrapping="Wrap" Width="120"/>
|
<TextBox x:Name="Username" TextWrapping="Wrap" Width="120"/>
|
||||||
<Label Content="Password" HorizontalContentAlignment="Center"/>
|
<Label Content="Password" HorizontalContentAlignment="Center"/>
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace DokterApp
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
|
Del handler;
|
||||||
Client client;
|
Client client;
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
@@ -27,18 +28,27 @@ namespace DokterApp
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Login_Click_1(object sender, RoutedEventArgs e)
|
private void Login_Click_1(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
WindowTabs windowTabs = new WindowTabs();
|
WindowTabs windowTabs = new WindowTabs();
|
||||||
|
handler = windowTabs.NewTab;
|
||||||
|
|
||||||
|
this.Label.Content = "Waiting";
|
||||||
|
this.client = new Client("localhost", 5555, this.Username.Text, this.Password.Text, handler);
|
||||||
|
while (!client.IsConnected())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
windowTabs.Show();
|
windowTabs.Show();
|
||||||
this.client = new Client("localhost", 5555, this.Username.Text, this.Password.Text);
|
|
||||||
this.Close();
|
this.Close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public delegate void Del(string message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,14 +31,23 @@ namespace DokterApp
|
|||||||
|
|
||||||
private void Button_Click(object sender, RoutedEventArgs e)
|
private void Button_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
TabItem newTabItem = new TabItem
|
NewTab("Test");
|
||||||
{
|
}
|
||||||
Header = "Test",
|
|
||||||
Width = 110,
|
public void NewTab(string username)
|
||||||
Height = 40
|
{
|
||||||
};
|
Application.Current.Dispatcher.Invoke((Action)delegate {
|
||||||
newTabItem.Content = new UserControlForTab();
|
// your code
|
||||||
this.tbControl.Items.Add(newTabItem);
|
TabItem newTabItem = new TabItem
|
||||||
|
{
|
||||||
|
Header = username,
|
||||||
|
Width = 110,
|
||||||
|
Height = 40
|
||||||
|
};
|
||||||
|
newTabItem.Content = new UserControlForTab();
|
||||||
|
this.tbControl.Items.Add(newTabItem);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ namespace Server
|
|||||||
|
|
||||||
private void OnRead(IAsyncResult ar)
|
private void OnRead(IAsyncResult ar)
|
||||||
{
|
{
|
||||||
|
|
||||||
int receivedBytes = this.stream.EndRead(ar);
|
int receivedBytes = this.stream.EndRead(ar);
|
||||||
|
|
||||||
if (totalBufferReceived + receivedBytes > 1024)
|
if (totalBufferReceived + receivedBytes > 1024)
|
||||||
@@ -160,7 +161,7 @@ namespace Server
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using Client;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO.Pipes;
|
using System.IO.Pipes;
|
||||||
|
using System.Linq;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -10,6 +12,7 @@ namespace Server
|
|||||||
{
|
{
|
||||||
private TcpListener listener;
|
private TcpListener listener;
|
||||||
private List<Client> clients;
|
private List<Client> clients;
|
||||||
|
private Client doctor;
|
||||||
|
|
||||||
public Communication(TcpListener listener)
|
public Communication(TcpListener listener)
|
||||||
{
|
{
|
||||||
@@ -28,9 +31,19 @@ namespace Server
|
|||||||
|
|
||||||
private void OnConnect(IAsyncResult ar)
|
private void OnConnect(IAsyncResult ar)
|
||||||
{
|
{
|
||||||
|
|
||||||
var tcpClient = listener.EndAcceptTcpClient(ar);
|
var tcpClient = listener.EndAcceptTcpClient(ar);
|
||||||
Console.WriteLine($"Client connected from {tcpClient.Client.RemoteEndPoint}");
|
Console.WriteLine($"Client connected from {tcpClient.Client.RemoteEndPoint}");
|
||||||
clients.Add(new Client(this, tcpClient));
|
clients.Add(new Client(this, tcpClient));
|
||||||
|
if (doctor == null)
|
||||||
|
{
|
||||||
|
doctor = clients.ElementAt(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
doctor.sendMessage(DataParser.getLoginResponse("new client"));
|
||||||
|
}
|
||||||
listener.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null);
|
listener.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user