Develop #10
@@ -10,5 +10,7 @@ namespace ClientApp.Models
|
||||
public bool ConnectedToServer { get; set; }
|
||||
public bool ConnectedToVREngine { get; set; }
|
||||
public bool DoctorConnected { get; set; }
|
||||
|
||||
public bool CanConnectToVR { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,15 +8,18 @@ using ProftaakRH;
|
||||
|
||||
namespace ClientApp.Utils
|
||||
{
|
||||
public delegate void EngineCallback();
|
||||
public class Client : IDataReceiver
|
||||
{
|
||||
public EngineCallback engineConnectFailed;
|
||||
public EngineCallback engineConnectSuccess;
|
||||
private TcpClient client;
|
||||
private NetworkStream stream;
|
||||
private byte[] buffer = new byte[1024];
|
||||
private bool connected;
|
||||
private byte[] totalBuffer = new byte[1024];
|
||||
private int totalBufferReceived = 0;
|
||||
private EngineConnection engineConnection;
|
||||
public EngineConnection engineConnection;
|
||||
private bool sessionRunning = false;
|
||||
private IHandler handler = null;
|
||||
private LoginViewModel LoginViewModel;
|
||||
@@ -40,7 +43,7 @@ namespace ClientApp.Utils
|
||||
private void initEngine()
|
||||
{
|
||||
engineConnection = EngineConnection.INSTANCE;
|
||||
engineConnection.OnNoTunnelId = retryEngineConnection;
|
||||
engineConnection.OnNoTunnelId = RetryEngineConnection;
|
||||
engineConnection.OnSuccessFullConnection = engineConnected;
|
||||
if (!engineConnection.Connected) engineConnection.Connect();
|
||||
}
|
||||
@@ -48,24 +51,16 @@ namespace ClientApp.Utils
|
||||
/// <summary>
|
||||
/// retries to connect to the VR engine if no tunnel id was found
|
||||
/// </summary>
|
||||
private void retryEngineConnection()
|
||||
public void RetryEngineConnection()
|
||||
{
|
||||
Console.WriteLine("-- Could not connect to the VR engine. Please make sure you are running the simulation!");
|
||||
Console.WriteLine("-- Press ENTER to retry connecting to the VR engine.");
|
||||
Console.WriteLine("-- Press 'q' and then ENTER to not connect to the VR engine");
|
||||
string input = Console.ReadLine();
|
||||
if (input == string.Empty) engineConnection.CreateConnection();
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Skipping connecting to VR engine...");
|
||||
engineConnection.Stop();
|
||||
}
|
||||
engineConnectFailed?.Invoke();
|
||||
|
||||
}
|
||||
|
||||
private void engineConnected()
|
||||
{
|
||||
Console.WriteLine("successfully connected to VR engine");
|
||||
engineConnectSuccess?.Invoke();
|
||||
engineConnection.initScene();
|
||||
if (engineConnection.Connected && sessionRunning && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
|
||||
}
|
||||
@@ -126,6 +121,7 @@ namespace ClientApp.Utils
|
||||
this.LoginViewModel.setLoginStatus(true);
|
||||
this.connected = true;
|
||||
initEngine();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace ClientApp.ViewModels
|
||||
public string Username { get; set; }
|
||||
public ICommand LoginCommand { get; set; }
|
||||
public bool LoginStatus { get; set; }
|
||||
|
||||
private MainWindowViewModel mainWindowViewModel;
|
||||
public LoginViewModel(MainWindowViewModel mainWindowViewModel)
|
||||
{
|
||||
|
||||
@@ -11,10 +11,14 @@ namespace ClientApp.ViewModels
|
||||
public ICommand RetryVREngineCommand { get; set; }
|
||||
public MainWindowViewModel MainWindowViewModel { get; set; }
|
||||
|
||||
private Client client;
|
||||
|
||||
public MainViewModel(MainWindowViewModel mainWindowViewModel)
|
||||
{
|
||||
this.MainWindowViewModel = mainWindowViewModel;
|
||||
client = this.MainWindowViewModel.client;
|
||||
client.engineConnectFailed = retryEngineConnection;
|
||||
client.engineConnectSuccess = succesEngineConnection;
|
||||
this.RetryServerCommand = new RelayCommand(() =>
|
||||
{
|
||||
//try connect server
|
||||
@@ -23,8 +27,28 @@ namespace ClientApp.ViewModels
|
||||
this.RetryVREngineCommand = new RelayCommand(() =>
|
||||
{
|
||||
//try connect vr-engine
|
||||
|
||||
this.MainWindowViewModel.InfoModel.ConnectedToVREngine = true;
|
||||
this.MainWindowViewModel.InfoModel.CanConnectToVR = false;
|
||||
client.engineConnection.CreateConnection();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void retryEngineConnection()
|
||||
{
|
||||
this.MainWindowViewModel.InfoModel.ConnectedToVREngine = false;
|
||||
this.MainWindowViewModel.InfoModel.CanConnectToVR = true;
|
||||
client.engineConnection.CreateConnection();
|
||||
}
|
||||
|
||||
private void succesEngineConnection()
|
||||
{
|
||||
this.MainWindowViewModel.InfoModel.ConnectedToVREngine = true;
|
||||
this.MainWindowViewModel.InfoModel.CanConnectToVR = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
</Button.Content>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Column="1" Grid.Row="1" Command="{Binding RetryVREngineCommand}" Width="50" Height="20">
|
||||
<Button Grid.Column="1" Grid.Row="1" Command="{Binding RetryVREngineCommand}" Width="50" Height="20" IsEnabled="{Binding MainWindowViewModel.InfoModel.CanConnectToVR}">
|
||||
<Button.Content>
|
||||
<TextBlock TextWrapping="Wrap" Text="retry"/>
|
||||
</Button.Content>
|
||||
|
||||
Reference in New Issue
Block a user