Develop #10
@@ -2,6 +2,7 @@
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using ClientApp.ViewModels;
|
||||
using ProftaakRH;
|
||||
|
||||
namespace ClientApp.Utils
|
||||
@@ -17,6 +18,7 @@ namespace ClientApp.Utils
|
||||
private EngineConnection engineConnection;
|
||||
private bool sessionRunning = false;
|
||||
private IHandler handler = null;
|
||||
private LoginViewModel LoginViewModel;
|
||||
|
||||
|
||||
public Client() : this("localhost", 5555)
|
||||
@@ -120,13 +122,13 @@ namespace ClientApp.Utils
|
||||
if (responseStatus == "OK")
|
||||
{
|
||||
Console.WriteLine("Username and password correct!");
|
||||
this.LoginViewModel.setLoginStatus(true);
|
||||
this.connected = true;
|
||||
initEngine();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"login failed \"{responseStatus}\"");
|
||||
tryLogin();
|
||||
}
|
||||
break;
|
||||
case DataParser.START_SESSION:
|
||||
@@ -261,14 +263,8 @@ namespace ClientApp.Utils
|
||||
/// <summary>
|
||||
/// tries to log in to the server by asking for a username and password
|
||||
/// </summary>
|
||||
private void tryLogin()
|
||||
public void tryLogin(string username, string password)
|
||||
{
|
||||
//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 hashPassword = Hashing.Hasher.HashString(password);
|
||||
|
||||
@@ -282,9 +278,14 @@ namespace ClientApp.Utils
|
||||
/// sets the handler for the client, so either the bike simulator or the bluetooth bike handler
|
||||
/// </summary>
|
||||
/// <param name="handler"></param>
|
||||
public void setHandler(IHandler handler)
|
||||
public void SetHandler(IHandler handler)
|
||||
{
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
internal void SetLoginViewModel(LoginViewModel loginViewModel)
|
||||
{
|
||||
this.LoginViewModel = loginViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,20 @@ namespace ClientApp.ViewModels
|
||||
this.mainWindowViewModel = mainWindowViewModel;
|
||||
LoginCommand = new RelayCommand<object>((parameter) =>
|
||||
{
|
||||
Debug.WriteLine($"username {Username} password {((PasswordBox)parameter).Password}");
|
||||
//TODO send username and password to server
|
||||
this.mainWindowViewModel.SelectedViewModel = new MainViewModel();
|
||||
this.mainWindowViewModel.client.tryLogin(Username, ((PasswordBox)parameter).Password);
|
||||
});
|
||||
}
|
||||
|
||||
public ICommand LoginCommand { get; set; }
|
||||
|
||||
internal void setLoginStatus(bool status)
|
||||
{
|
||||
this.mainWindowViewModel.infoModel.ConnectedToServer = true;
|
||||
if (status)
|
||||
{
|
||||
this.mainWindowViewModel.SelectedViewModel = new MainViewModel(mainWindowViewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,22 +7,23 @@ namespace ClientApp.ViewModels
|
||||
{
|
||||
class MainViewModel : ObservableObject
|
||||
{
|
||||
public Info infoModel { get; set; }
|
||||
public ICommand RetryServerCommand { get; set; }
|
||||
public ICommand RetryVREngineCommand { get; set; }
|
||||
public MainWindowViewModel MainWindowViewModel;
|
||||
|
||||
public MainViewModel()
|
||||
|
||||
public MainViewModel(MainWindowViewModel mainWindowViewModel)
|
||||
{
|
||||
this.infoModel = new Info();
|
||||
this.MainWindowViewModel = mainWindowViewModel;
|
||||
this.RetryServerCommand = new RelayCommand(() =>
|
||||
{
|
||||
//try connect server
|
||||
this.infoModel.ConnectedToServer = true;
|
||||
this.MainWindowViewModel.infoModel.ConnectedToServer = true;
|
||||
});
|
||||
this.RetryVREngineCommand = new RelayCommand(() =>
|
||||
{
|
||||
//try connect vr-engine
|
||||
this.infoModel.ConnectedToVREngine = true;
|
||||
this.MainWindowViewModel.infoModel.ConnectedToVREngine = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using ClientApp.Utils;
|
||||
using ClientApp.Models;
|
||||
using ClientApp.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
@@ -7,12 +8,19 @@ namespace ClientApp.ViewModels
|
||||
{
|
||||
class MainWindowViewModel : ObservableObject
|
||||
{
|
||||
public Info infoModel { get; set; }
|
||||
|
||||
public ObservableObject SelectedViewModel { get; set; }
|
||||
public Client client { get; }
|
||||
|
||||
public MainWindowViewModel()
|
||||
public MainWindowViewModel(Client client)
|
||||
{
|
||||
SelectedViewModel = new LoginViewModel(this);
|
||||
this.infoModel = new Info();
|
||||
this.client = client;
|
||||
LoginViewModel loginViewModel = new LoginViewModel(this);
|
||||
SelectedViewModel = loginViewModel;
|
||||
this.client.SetLoginViewModel(loginViewModel);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,17 +21,17 @@
|
||||
|
||||
<StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal" Margin="10">
|
||||
<Label Content="Connected to server:"/>
|
||||
<Label Content="{Binding Path=infoModel.ConnectedToServer}"/>
|
||||
<Label Content="{Binding Path=MainWindowViewModel.infoModel.ConnectToServer}"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal" Margin="10">
|
||||
<Label Content="Connected to VR-Engine:"/>
|
||||
<Label Content="{Binding Path=infoModel.ConnectedToVREngine}"/>
|
||||
<Label Content="{Binding Path=MainWindowViewModel.infoModel.ConnectedToVREngine}"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Column="2" Grid.Row="0" Orientation="Horizontal" Margin="10">
|
||||
<Label Content="Doctor connected:"/>
|
||||
<Label Content="{Binding Path=infoModel.DoctorConnected}"/>
|
||||
<Label Content="{Binding Path=MainWindowViewModel.infoModel.DoctorConnected}"/>
|
||||
</StackPanel>
|
||||
|
||||
<Button Grid.Column="0" Grid.Row="1" Command="{Binding RetryServerCommand}" Width="50" Height="20">
|
||||
|
||||
@@ -25,17 +25,12 @@ namespace ClientApp
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("derp1");
|
||||
|
||||
Client client = new Client();
|
||||
System.Diagnostics.Debug.WriteLine("derp2");
|
||||
|
||||
|
||||
InitializeComponent();
|
||||
DataContext = new MainWindowViewModel();
|
||||
System.Diagnostics.Debug.WriteLine("derp3");
|
||||
DataContext = new MainWindowViewModel(client);
|
||||
|
||||
|
||||
//BLEHandler bLEHandler = new BLEHandler(client);
|
||||
@@ -46,16 +41,12 @@ namespace ClientApp
|
||||
|
||||
|
||||
BikeSimulator bikeSimulator = new BikeSimulator(client);
|
||||
System.Diagnostics.Debug.WriteLine("derp4");
|
||||
|
||||
Thread newThread = new Thread(new ThreadStart(bikeSimulator.StartSimulation));
|
||||
newThread.Start();
|
||||
//bikeSimulator.StartSimulation();
|
||||
System.Diagnostics.Debug.WriteLine("derp5");
|
||||
|
||||
|
||||
client.setHandler(bikeSimulator);
|
||||
System.Diagnostics.Debug.WriteLine("derp6");
|
||||
client.SetHandler(bikeSimulator);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user