Merge branch 'develop' into window-restyle
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Util;
|
||||
|
||||
namespace ClientApp.Models
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using ClientApp.ViewModels;
|
||||
using ProftaakRH;
|
||||
using Util;
|
||||
|
||||
namespace ClientApp.Utils
|
||||
{
|
||||
@@ -265,10 +266,10 @@ namespace ClientApp.Utils
|
||||
/// </summary>
|
||||
public void tryLogin(string username, string password)
|
||||
{
|
||||
string hashUser = Hashing.Hasher.HashString(username);
|
||||
string hashPassword = Hashing.Hasher.HashString(password);
|
||||
|
||||
string hashPassword = Util.Hasher.HashString(password);
|
||||
|
||||
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(hashUser, hashPassword));
|
||||
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(username, hashPassword));
|
||||
|
||||
|
||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
|
||||
@@ -3,6 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using RH_Engine;
|
||||
using System.Net.Sockets;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Diagnostics;
|
||||
using LibNoise.Primitive;
|
||||
|
||||
namespace ClientApp.Utils
|
||||
{
|
||||
@@ -37,6 +40,8 @@ namespace ClientApp.Utils
|
||||
private static string panelId = string.Empty;
|
||||
private static string bikeId = string.Empty;
|
||||
private static string headId = string.Empty;
|
||||
private static string groundPlaneId = string.Empty;
|
||||
private static string terrainId = string.Empty;
|
||||
|
||||
public float BikeSpeed { get; set; }
|
||||
public float BikePower { get; set; }
|
||||
@@ -191,8 +196,11 @@ namespace ClientApp.Utils
|
||||
string headId = JSONParser.GetIdSceneInfoChild(message, "Head");
|
||||
string handLeftId = JSONParser.GetIdSceneInfoChild(message, "LeftHand");
|
||||
string handRightId = JSONParser.GetIdSceneInfoChild(message, "RightHand");
|
||||
groundPlaneId = JSONParser.GetIdSceneInfoChild(message, "GroundPlane");
|
||||
Write("--- Ground plane id is " + groundPlaneId);
|
||||
});
|
||||
// add the route and set the route id
|
||||
CreateTerrain();
|
||||
SendMessageAndOnResponse(mainCommand.RouteCommand("routeID"), "routeID", (message) => routeId = JSONParser.GetResponseUuid(message));
|
||||
}
|
||||
|
||||
@@ -217,8 +225,45 @@ namespace ClientApp.Utils
|
||||
|
||||
while (cameraId == string.Empty) { }
|
||||
SetFollowSpeed(5.0f);
|
||||
WriteTextMessage(mainCommand.RoadCommand(routeId, "road"));
|
||||
WriteTextMessage(mainCommand.ShowRoute("showRouteFalse", false));
|
||||
});
|
||||
});
|
||||
setEnvironment();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void setEnvironment()
|
||||
{
|
||||
Write("Setting environment");
|
||||
WriteTextMessage(mainCommand.DeleteNode(groundPlaneId, "none"));
|
||||
|
||||
PlaceHouses();
|
||||
|
||||
WriteTextMessage(mainCommand.SkyboxCommand(DateTime.Now.Hour));
|
||||
}
|
||||
|
||||
private void PlaceHouses()
|
||||
{
|
||||
PlaceHouse(2, new float[] { 10f, 1f, 30f }, 1);
|
||||
PlaceHouse(1, new float[] { 42f, 1f, 22f }, new float[] { 0f, 90f, 0f }, 2);
|
||||
PlaceHouse(11, new float[] { -20f, 1f, 0f }, new float[] { 0f, -35f, 0f }, 3);
|
||||
PlaceHouse(7, new float[] { -15f, 1f, 50f }, new float[] { 0f, -50f, 0f }, 4);
|
||||
PlaceHouse(24, new float[] { 40f, 1f, 40f }, new float[] { 0f, 75f, 0f }, 5);
|
||||
PlaceHouse(22, new float[] { 34f, 1f, -20f }, 6);
|
||||
PlaceHouse(14, new float[] { 0f, 1f, -20f }, new float[] { 0f, 210f, 0f }, 7);
|
||||
}
|
||||
|
||||
private void PlaceHouse(int numberHousemodel, float[] position, int serialNumber)
|
||||
{
|
||||
PlaceHouse(numberHousemodel, position, new float[] { 0f, 0f, 0f }, serialNumber);
|
||||
}
|
||||
|
||||
private void PlaceHouse(int numberHousemodel, float[] position, float[] rotation, int serialNumber)
|
||||
{
|
||||
string folderHouses = @"data\NetworkEngine\models\houses\set1\";
|
||||
SendMessageAndOnResponse(mainCommand.AddModel("House1", "housePlacement" + serialNumber, folderHouses + "house" + numberHousemodel + ".obj", position, 4, rotation), "housePlacement" + serialNumber, (message) => Console.WriteLine(message));
|
||||
}
|
||||
|
||||
public void UpdateInfoPanel()
|
||||
@@ -264,6 +309,41 @@ namespace ClientApp.Utils
|
||||
WriteTextMessage(mainCommand.RouteFollow(routeId, cameraId, speed));
|
||||
}
|
||||
|
||||
public void CreateTerrain()
|
||||
{
|
||||
float x = 0f;
|
||||
float[] height = new float[256 * 256];
|
||||
ImprovedPerlin improvedPerlin = new ImprovedPerlin(0, LibNoise.NoiseQuality.Best);
|
||||
for (int i = 0; i < 256 * 256; i++)
|
||||
{
|
||||
height[i] = improvedPerlin.GetValue(x /10, x / 10, x * 100) / 3.5f + 1;
|
||||
|
||||
//if (height[i] > 1.1f)
|
||||
//{
|
||||
// height[i] = height[i] * 0.8f;
|
||||
//}
|
||||
//else if (height[i] < 0.9f)
|
||||
//{
|
||||
// height[i] = height[i] * 1.2f;
|
||||
//}
|
||||
x += 0.001f;
|
||||
}
|
||||
|
||||
SendMessageAndOnResponse(mainCommand.TerrainAdd(new int[] { 256, 256 }, height, "terrain"), "terrain",
|
||||
(message) =>
|
||||
{
|
||||
|
||||
SendMessageAndOnResponse(mainCommand.renderTerrain("renderTerrain"), "renderTerrain",
|
||||
(message) =>
|
||||
{
|
||||
terrainId = JSONParser.GetTerrainID(message);
|
||||
string addLayerMsg = mainCommand.AddLayer(terrainId, "addLayer");
|
||||
SendMessageAndOnResponse(addLayerMsg, "addLayer", (message) => Console.WriteLine(""));
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region message send/receive
|
||||
@@ -315,7 +395,7 @@ namespace ClientApp.Utils
|
||||
}
|
||||
public void Write(string msg)
|
||||
{
|
||||
Console.WriteLine("[ENGINECONNECT] " + msg);
|
||||
Debug.WriteLine("[ENGINECONNECT] " + msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using ClientApp.Utils;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using Util;
|
||||
|
||||
namespace ClientApp.ViewModels
|
||||
{
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
using ClientApp.Models;
|
||||
using ClientApp.Utils;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using System.Diagnostics;
|
||||
using System.Windows.Input;
|
||||
using Util;
|
||||
|
||||
namespace ClientApp.ViewModels
|
||||
{
|
||||
class MainViewModel : ObservableObject
|
||||
{
|
||||
public ICommand RetryServerCommand { get; set; }
|
||||
public ICommand RetryVREngineCommand { get; set; }
|
||||
public MainWindowViewModel MainWindowViewModel { get; set; }
|
||||
|
||||
private Client client;
|
||||
@@ -24,15 +25,6 @@ namespace ClientApp.ViewModels
|
||||
//try connect server
|
||||
this.MainWindowViewModel.InfoModel.ConnectedToServer = true;
|
||||
});
|
||||
this.RetryVREngineCommand = new RelayCommand(() =>
|
||||
{
|
||||
//try connect vr-engine
|
||||
|
||||
this.MainWindowViewModel.InfoModel.ConnectedToVREngine = true;
|
||||
this.MainWindowViewModel.InfoModel.CanConnectToVR = false;
|
||||
client.engineConnection.CreateConnection();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void retryEngineConnection()
|
||||
|
||||
@@ -6,6 +6,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using Util;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
|
||||
@@ -40,12 +40,6 @@
|
||||
</Button.Content>
|
||||
</Button>
|
||||
|
||||
<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>
|
||||
</Button>
|
||||
|
||||
</Grid>
|
||||
|
||||
</DockPanel>
|
||||
|
||||
22
DoctorApp/App.xaml
Normal file
22
DoctorApp/App.xaml
Normal file
@@ -0,0 +1,22 @@
|
||||
<Application x:Class="DoctorApp.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:DoctorApp"
|
||||
xmlns:viewModels="clr-namespace:DoctorApp.ViewModels"
|
||||
xmlns:views="clr-namespace:DoctorApp.Views"
|
||||
StartupUri="Views/MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
<DataTemplate DataType="{x:Type viewModels:MainViewModel}">
|
||||
<views:MainView />
|
||||
<!-- This is a UserControl -->
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type viewModels:LoginViewModel}">
|
||||
<views:LoginView />
|
||||
<!-- This is a UserControl -->
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type viewModels:ClientInfoViewModel}">
|
||||
<views:ClientInfoView/>
|
||||
</DataTemplate>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
17
DoctorApp/App.xaml.cs
Normal file
17
DoctorApp/App.xaml.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace DoctorApp
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
}
|
||||
10
DoctorApp/AssemblyInfo.cs
Normal file
10
DoctorApp/AssemblyInfo.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Windows;
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
21
DoctorApp/DoctorApp.csproj
Normal file
21
DoctorApp/DoctorApp.csproj
Normal file
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AsyncAwaitBestPractices.MVVM" Version="4.3.0" />
|
||||
<PackageReference Include="MvvmLightLibsStd10" Version="5.4.1.1" />
|
||||
<PackageReference Include="PropertyChanged.Fody" Version="3.2.9" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ProftaakRH\ProftaakRH.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
|
||||
|
||||
</Project>
|
||||
3
DoctorApp/FodyWeavers.xml
Normal file
3
DoctorApp/FodyWeavers.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
||||
<PropertyChanged />
|
||||
</Weavers>
|
||||
74
DoctorApp/FodyWeavers.xsd
Normal file
74
DoctorApp/FodyWeavers.xsd
Normal file
@@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
|
||||
<xs:element name="Weavers">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="PropertyChanged" minOccurs="0" maxOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="InjectOnPropertyNameChanged" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>Used to control if the On_PropertyName_Changed feature is enabled.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="TriggerDependentProperties" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>Used to control if the Dependent properties feature is enabled.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="EnableIsChangedProperty" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>Used to control if the IsChanged property feature is enabled.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="EventInvokerNames" type="xs:string">
|
||||
<xs:annotation>
|
||||
<xs:documentation>Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="CheckForEquality" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="CheckForEqualityUsingBaseEquals" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>Used to control if equality checks should use the Equals method resolved from the base class.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="UseStaticEqualsFromBase" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>Used to control if equality checks should use the static Equals method resolved from the base class.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="SuppressWarnings" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>Used to turn off build warnings from this weaver.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="SuppressOnPropertyNameChangedWarning" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>Used to turn off build warnings about mismatched On_PropertyName_Changed methods.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:all>
|
||||
<xs:attribute name="VerifyAssembly" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
|
||||
<xs:annotation>
|
||||
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="GenerateXsd" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
17
DoctorApp/Models/Info.cs
Normal file
17
DoctorApp/Models/Info.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using DoctorApp.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Util;
|
||||
|
||||
namespace DoctorApp.Models
|
||||
{
|
||||
class Info : ObservableObject
|
||||
{
|
||||
public bool ConnectedToServer { get; set; }
|
||||
public bool ConnectedToVREngine { get; set; }
|
||||
public bool DoctorConnected { get; set; }
|
||||
|
||||
public bool CanConnectToVR { get; set; }
|
||||
}
|
||||
}
|
||||
270
DoctorApp/Utils/Client.cs
Normal file
270
DoctorApp/Utils/Client.cs
Normal file
@@ -0,0 +1,270 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using DoctorApp.ViewModels;
|
||||
using ProftaakRH;
|
||||
using Util;
|
||||
|
||||
namespace DoctorApp.Utils
|
||||
{
|
||||
public delegate void EngineCallback();
|
||||
public class Client : IDataReceiver
|
||||
{
|
||||
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 bool sessionRunning = false;
|
||||
private IHandler handler = null;
|
||||
private LoginViewModel LoginViewModel;
|
||||
private MainViewModel MainViewModel;
|
||||
private ClientInfoViewModel ClientInfoViewModel;
|
||||
|
||||
|
||||
public Client() : this("localhost", 5555)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Client(string adress, int port)
|
||||
{
|
||||
this.client = new TcpClient();
|
||||
this.connected = false;
|
||||
client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// callback method for when the TCP client is connected
|
||||
/// </summary>
|
||||
/// <param name="ar">the result of the async read</param>
|
||||
private void OnConnect(IAsyncResult ar)
|
||||
{
|
||||
this.client.EndConnect(ar);
|
||||
Console.WriteLine("TCP client Verbonden!");
|
||||
|
||||
this.stream = this.client.GetStream();
|
||||
|
||||
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// callback method for when there is a message read
|
||||
/// </summary>
|
||||
/// <param name="ar">the result of the async read</param>
|
||||
private void OnRead(IAsyncResult ar)
|
||||
{
|
||||
int receivedBytes = this.stream.EndRead(ar);
|
||||
|
||||
if (totalBufferReceived + receivedBytes > 1024)
|
||||
{
|
||||
throw new OutOfMemoryException("buffer too small");
|
||||
}
|
||||
Array.Copy(buffer, 0, totalBuffer, totalBufferReceived, receivedBytes);
|
||||
totalBufferReceived += receivedBytes;
|
||||
|
||||
int expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
|
||||
while (totalBufferReceived >= expectedMessageLength)
|
||||
{
|
||||
//volledig packet binnen
|
||||
byte[] messageBytes = new byte[expectedMessageLength];
|
||||
Array.Copy(totalBuffer, 0, messageBytes, 0, expectedMessageLength);
|
||||
|
||||
|
||||
byte[] payloadbytes = new byte[BitConverter.ToInt32(messageBytes, 0) - 5];
|
||||
|
||||
Array.Copy(messageBytes, 5, payloadbytes, 0, payloadbytes.Length);
|
||||
|
||||
string identifier;
|
||||
bool isJson = DataParser.getJsonIdentifier(messageBytes, out identifier);
|
||||
if (isJson)
|
||||
{
|
||||
switch (identifier)
|
||||
{
|
||||
case DataParser.LOGIN_RESPONSE:
|
||||
string responseStatus = DataParser.getResponseStatus(payloadbytes);
|
||||
if (responseStatus == "OK")
|
||||
{
|
||||
Debug.WriteLine("Username and password correct!");
|
||||
this.LoginViewModel.setLoginStatus(true);
|
||||
this.connected = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
this.LoginViewModel.setLoginStatus(false);
|
||||
Debug.WriteLine($"login failed \"{responseStatus}\"");
|
||||
}
|
||||
break;
|
||||
case DataParser.START_SESSION:
|
||||
Console.WriteLine("Session started!");
|
||||
this.sessionRunning = true;
|
||||
sendMessage(DataParser.getStartSessionJson());
|
||||
break;
|
||||
case DataParser.STOP_SESSION:
|
||||
Console.WriteLine("Stop session identifier");
|
||||
this.sessionRunning = false;
|
||||
sendMessage(DataParser.getStopSessionJson());
|
||||
break;
|
||||
case DataParser.SET_RESISTANCE:
|
||||
Console.WriteLine("Set resistance identifier");
|
||||
if (this.handler == null)
|
||||
{
|
||||
Console.WriteLine("handler is null");
|
||||
sendMessage(DataParser.getSetResistanceResponseJson(false));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.handler.setResistance(DataParser.getResistanceFromJson(payloadbytes));
|
||||
sendMessage(DataParser.getSetResistanceResponseJson(true));
|
||||
}
|
||||
break;
|
||||
case DataParser.NEW_CONNECTION:
|
||||
this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
|
||||
break;
|
||||
case DataParser.DISCONNECT:
|
||||
this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (DataParser.isRawData(messageBytes))
|
||||
{
|
||||
Console.WriteLine($"Received data: {BitConverter.ToString(payloadbytes)}");
|
||||
}
|
||||
|
||||
totalBufferReceived -= expectedMessageLength;
|
||||
expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
|
||||
}
|
||||
|
||||
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// starts sending a message to the server
|
||||
/// </summary>
|
||||
/// <param name="message">the message to send</param>
|
||||
private void sendMessage(byte[] message)
|
||||
{
|
||||
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// callback method for when a message is fully written to the server
|
||||
/// </summary>
|
||||
/// <param name="ar">the async result representing the asynchronous call</param>
|
||||
private void OnWrite(IAsyncResult ar)
|
||||
{
|
||||
this.stream.EndWrite(ar);
|
||||
}
|
||||
|
||||
#region interface
|
||||
//maybe move this to other place
|
||||
/// <summary>
|
||||
/// bpm method for receiving the BPM value from the bluetooth bike or the simulation
|
||||
/// </summary>
|
||||
/// <param name="bytes">the message</param>
|
||||
public void BPM(byte[] bytes)
|
||||
{
|
||||
if (!sessionRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (bytes == null)
|
||||
{
|
||||
throw new ArgumentNullException("no bytes");
|
||||
}
|
||||
byte[] message = DataParser.GetRawDataMessage(bytes);
|
||||
|
||||
|
||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// method for receiving the bike message from the bluetooth bike or the simulation
|
||||
/// </summary>
|
||||
/// <param name="bytes">the message</param>
|
||||
public void Bike(byte[] bytes)
|
||||
{
|
||||
|
||||
if (!sessionRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (bytes == null)
|
||||
{
|
||||
throw new ArgumentNullException("no bytes");
|
||||
}
|
||||
byte[] message = DataParser.GetRawDataMessage(bytes);
|
||||
|
||||
/* switch (bytes[0])
|
||||
{
|
||||
|
||||
case 0x10:
|
||||
|
||||
if (canSendToEngine) engineConnection.BikeSpeed = (bytes[4] | (bytes[5] << 8)) * 0.01f;
|
||||
break;
|
||||
case 0x19:
|
||||
if (canSendToEngine) engineConnection.BikePower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
|
||||
break;
|
||||
}*/
|
||||
|
||||
|
||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// wether or not the client stream is connected
|
||||
/// </summary>
|
||||
/// <returns>true if it's connected, false if not</returns>
|
||||
public bool IsConnected()
|
||||
{
|
||||
return this.connected;
|
||||
}
|
||||
/// <summary>
|
||||
/// tries to log in to the server by asking for a username and password
|
||||
/// </summary>
|
||||
public void tryLogin(string username, string password)
|
||||
{
|
||||
|
||||
string hashPassword = Util.Hasher.HashString(password);
|
||||
|
||||
byte[] message = DataParser.getJsonMessage(DataParser.LoginAsDoctor(username, hashPassword));
|
||||
|
||||
|
||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
{
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
internal void SetLoginViewModel(LoginViewModel loginViewModel)
|
||||
{
|
||||
this.LoginViewModel = loginViewModel;
|
||||
}
|
||||
|
||||
internal void SetMainViewModel(MainViewModel mainViewModel)
|
||||
{
|
||||
this.MainViewModel = mainViewModel;
|
||||
}
|
||||
|
||||
internal void SetClientInfoViewModel(ClientInfoViewModel clientInfoViewModel)
|
||||
{
|
||||
this.ClientInfoViewModel = clientInfoViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
DoctorApp/ViewModels/ClientInfoViewModel.cs
Normal file
13
DoctorApp/ViewModels/ClientInfoViewModel.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace DoctorApp.ViewModels
|
||||
{
|
||||
|
||||
class ClientInfoViewModel
|
||||
{
|
||||
public string Username { get; set; }
|
||||
public string TabName { get; set; }
|
||||
}
|
||||
}
|
||||
47
DoctorApp/ViewModels/LoginViewModel.cs
Normal file
47
DoctorApp/ViewModels/LoginViewModel.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
using DoctorApp.Utils;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Util;
|
||||
|
||||
namespace DoctorApp.ViewModels
|
||||
{
|
||||
class LoginViewModel : ObservableObject
|
||||
{
|
||||
public string Username { get; set; }
|
||||
public ICommand LoginCommand { get; set; }
|
||||
|
||||
public bool LoginStatus { get; set; }
|
||||
|
||||
public bool InvertedLoginStatus { get; set; }
|
||||
|
||||
private MainWindowViewModel mainWindowViewModel;
|
||||
public LoginViewModel(MainWindowViewModel mainWindowViewModel)
|
||||
{
|
||||
this.mainWindowViewModel = mainWindowViewModel;
|
||||
LoginCommand = new RelayCommand<object>((parameter) =>
|
||||
{
|
||||
//TODO send username and password to server
|
||||
this.mainWindowViewModel.client.tryLogin(Username, ((PasswordBox)parameter).Password);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
internal void setLoginStatus(bool status)
|
||||
{
|
||||
this.mainWindowViewModel.InfoModel.ConnectedToServer = status;
|
||||
this.InvertedLoginStatus = !status;
|
||||
if (status)
|
||||
{
|
||||
MainViewModel mainViewModel = new MainViewModel(mainWindowViewModel);
|
||||
this.mainWindowViewModel.client.SetMainViewModel(mainViewModel);
|
||||
this.mainWindowViewModel.SelectedViewModel = mainViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
46
DoctorApp/ViewModels/MainViewModel.cs
Normal file
46
DoctorApp/ViewModels/MainViewModel.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using DoctorApp.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
using System.Windows.Controls;
|
||||
using Util;
|
||||
|
||||
namespace DoctorApp.ViewModels
|
||||
{
|
||||
class MainViewModel : ObservableObject
|
||||
{
|
||||
public ObservableCollection<object> Tabs { get; set; }
|
||||
public int Selected { get; set; }
|
||||
public MainWindowViewModel MainWindowViewModel { get; set; }
|
||||
|
||||
Client client;
|
||||
|
||||
public MainViewModel(MainWindowViewModel mainWindowViewModel)
|
||||
{
|
||||
this.MainWindowViewModel = mainWindowViewModel;
|
||||
client = this.MainWindowViewModel.client;
|
||||
Tabs= new ObservableCollection<object>();
|
||||
}
|
||||
|
||||
public void NewConnectedUser(string username)
|
||||
{
|
||||
App.Current.Dispatcher.Invoke((Action)delegate
|
||||
{
|
||||
Tabs.Add(new ClientInfoViewModel
|
||||
{
|
||||
Username = username,
|
||||
TabName = username
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void DisconnectedUser(string username)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
26
DoctorApp/ViewModels/MainWindowViewModel.cs
Normal file
26
DoctorApp/ViewModels/MainWindowViewModel.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using DoctorApp.Models;
|
||||
using DoctorApp.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Util;
|
||||
|
||||
namespace DoctorApp.ViewModels
|
||||
{
|
||||
class MainWindowViewModel : ObservableObject
|
||||
{
|
||||
public Info InfoModel { get; set; }
|
||||
|
||||
public ObservableObject SelectedViewModel { get; set; }
|
||||
public Client client { get; }
|
||||
|
||||
public MainWindowViewModel(Client client)
|
||||
{
|
||||
this.InfoModel = new Info();
|
||||
this.client = client;
|
||||
LoginViewModel loginViewModel = new LoginViewModel(this);
|
||||
SelectedViewModel = loginViewModel;
|
||||
this.client.SetLoginViewModel(loginViewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
68
DoctorApp/Views/ClientInfoView.xaml
Normal file
68
DoctorApp/Views/ClientInfoView.xaml
Normal file
@@ -0,0 +1,68 @@
|
||||
<UserControl x:Class="DoctorApp.Views.ClientInfoView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:DoctorApp.Views"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
>
|
||||
<Grid Margin="15,5,15,15">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="5*"/>
|
||||
<ColumnDefinition Width="3*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="43*"/>
|
||||
<RowDefinition Height="47*"/>
|
||||
<RowDefinition Height="180*"/>
|
||||
<RowDefinition Height="180*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Horizontal" Grid.RowSpan="2" Margin="0,0,0,22">
|
||||
<StackPanel.Resources>
|
||||
<Style TargetType="{x:Type Label}">
|
||||
<Setter Property="Margin" Value="0,0,20,0"/>
|
||||
</Style>
|
||||
</StackPanel.Resources>
|
||||
<Label Content="UserName" Name="Username_Label"/>
|
||||
<Label Content="Status: " Name="Status_Label"/>
|
||||
</StackPanel>
|
||||
<StackPanel Margin="0,10,0,0" Grid.RowSpan="2" Grid.Row="1">
|
||||
<StackPanel.Resources>
|
||||
<Style TargetType="{x:Type DockPanel}">
|
||||
<Setter Property="Margin" Value="0,20,0,0"/>
|
||||
</Style>
|
||||
</StackPanel.Resources>
|
||||
<DockPanel Height="26" LastChildFill="False" HorizontalAlignment="Stretch">
|
||||
<Label Content="Resistance" Width="110" DockPanel.Dock="Right"/>
|
||||
<Label Content="Current Speed" Width="110" DockPanel.Dock="Left"/>
|
||||
<Label Content="Current BPM" Width="110" DockPanel.Dock="Top"/>
|
||||
</DockPanel>
|
||||
<DockPanel Height="26" LastChildFill="False" HorizontalAlignment="Stretch">
|
||||
<TextBox Name="textBox_Resistance" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
|
||||
<TextBox Name="textBox_CurrentSpeed" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
|
||||
<TextBox Name="textBox_CurrentBPM" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
|
||||
</DockPanel>
|
||||
<DockPanel Height="26" LastChildFill="False">
|
||||
<Label Content="Distance Covered" Width="110" DockPanel.Dock="Right"/>
|
||||
<Label Content="Current Power" Width="110" DockPanel.Dock="Left"/>
|
||||
<Label Content="Acc. Power" Width="110" DockPanel.Dock="Top"/>
|
||||
</DockPanel>
|
||||
<DockPanel Height="26" LastChildFill="False">
|
||||
<TextBox Name="textBox_DistanceCovered" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
|
||||
<TextBox Name="textBox_CurrentPower" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
|
||||
<TextBox Name="textBox_AccPower" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
<ListBox Name="ChatBox" Grid.Column="1" Margin="59,41,0,0" Grid.RowSpan="3"/>
|
||||
<TextBox Name="textBox_Chat" Grid.Column="1" HorizontalAlignment="Left" Margin="59,10,0,0" Grid.Row="3" Text="TextBox" TextWrapping="Wrap" VerticalAlignment="Top" Width="235"/>
|
||||
<Button Content="Button" Grid.Column="1" HorizontalAlignment="Left" Margin="59,33,0,0" Grid.Row="3" VerticalAlignment="Top" />
|
||||
<Button Content="Start Session" Grid.Column="1" HorizontalAlignment="Left" Margin="69,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97"/>
|
||||
<Button Content="Stop Session" Grid.Column="1" HorizontalAlignment="Left" Margin="187,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" />
|
||||
<TextBox x:Name="textBox_SetResistance" Grid.Column="1" HorizontalAlignment="Left" Margin="69,128,0,0" Grid.Row="3" TextWrapping="Wrap" VerticalAlignment="Top" Width="97"/>
|
||||
<Button Content="Set Resistance" Grid.Column="1" HorizontalAlignment="Left" Margin="187,128,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Height="18"/>
|
||||
<Canvas Grid.Row="3" Background="White" Margin="0,33,0,0"/>
|
||||
<ComboBox Name="DropBox" HorizontalAlignment="Left" Margin="0,6,0,0" Grid.Row="3" VerticalAlignment="Top" Width="190"/>
|
||||
<Button Content="Client Info" Grid.Column="1" HorizontalAlignment="Left" Margin="207,6,0,0" VerticalAlignment="Top" Height="26" Width="82"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
26
DoctorApp/Views/ClientInfoView.xaml.cs
Normal file
26
DoctorApp/Views/ClientInfoView.xaml.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace DoctorApp.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for ClientInfoView.xaml
|
||||
/// </summary>
|
||||
public partial class ClientInfoView : UserControl
|
||||
{
|
||||
public ClientInfoView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
24
DoctorApp/Views/LoginView.xaml
Normal file
24
DoctorApp/Views/LoginView.xaml
Normal file
@@ -0,0 +1,24 @@
|
||||
<UserControl x:Class="DoctorApp.Views.LoginView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:DoctorApp.Views"
|
||||
xmlns:viewModels="clr-namespace:DoctorApp.ViewModels"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
>
|
||||
|
||||
<DockPanel>
|
||||
<StackPanel VerticalAlignment="Center" Width="auto">
|
||||
<Label Content="Username" HorizontalContentAlignment="Center" />
|
||||
<TextBox x:Name="Username" Text="{Binding Username}" TextWrapping="Wrap" Width="120"/>
|
||||
<Label Content="Password" HorizontalContentAlignment="Center"/>
|
||||
<PasswordBox x:Name="Password" Width="120"/>
|
||||
<Button x:Name="Login" Content="Login" Command="{Binding LoginCommand}" CommandParameter="{Binding ElementName=Password}" Margin="0,20,0,0" Width="120"/>
|
||||
<Popup IsOpen="{Binding InvertedLoginStatus}" PopupAnimation = "Fade" HorizontalAlignment="Left">
|
||||
<Label Content="Login failed" Foreground="Red" Background="#FFFF" />
|
||||
</Popup>
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
</UserControl>
|
||||
26
DoctorApp/Views/LoginView.xaml.cs
Normal file
26
DoctorApp/Views/LoginView.xaml.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace DoctorApp.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for LoginView.xaml
|
||||
/// </summary>
|
||||
public partial class LoginView : UserControl
|
||||
{
|
||||
public LoginView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
24
DoctorApp/Views/MainView.xaml
Normal file
24
DoctorApp/Views/MainView.xaml
Normal file
@@ -0,0 +1,24 @@
|
||||
<UserControl x:Class="DoctorApp.Views.MainView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:DoctorApp.Views"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
|
||||
<Grid>
|
||||
<TabControl ItemsSource="{Binding Tabs}" SelectedItem="{Binding Selected}">
|
||||
<TabControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding TabName}"/>
|
||||
</DataTemplate>
|
||||
</TabControl.ItemTemplate>
|
||||
<TabControl.ContentTemplate>
|
||||
<DataTemplate>
|
||||
<ContentControl Content="{Binding}"/>
|
||||
</DataTemplate>
|
||||
</TabControl.ContentTemplate>
|
||||
</TabControl>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
26
DoctorApp/Views/MainView.xaml.cs
Normal file
26
DoctorApp/Views/MainView.xaml.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace DoctorApp.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainView.xaml
|
||||
/// </summary>
|
||||
public partial class MainView : UserControl
|
||||
{
|
||||
public MainView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
14
DoctorApp/Views/MainWindow.xaml
Normal file
14
DoctorApp/Views/MainWindow.xaml
Normal file
@@ -0,0 +1,14 @@
|
||||
<Window x:Class="DoctorApp.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:DoctorApp"
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="450" Width="800"
|
||||
WindowState="Maximized">
|
||||
<Grid>
|
||||
<ContentControl HorizontalAlignment="Center" VerticalAlignment="Center" Content="{Binding SelectedViewModel}" Focusable="False" />
|
||||
<Label Content="gemaakt door: mensen" DockPanel.Dock="Bottom" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontStyle="Italic" Foreground="Gray"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
32
DoctorApp/Views/MainWindow.xaml.cs
Normal file
32
DoctorApp/Views/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using DoctorApp.Utils;
|
||||
using DoctorApp.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace DoctorApp
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
Client client = new Client();
|
||||
InitializeComponent();
|
||||
DataContext = new MainWindowViewModel(client);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using System.Text;
|
||||
|
||||
namespace ClientApp.Utils
|
||||
namespace Util
|
||||
{
|
||||
public class DataParser
|
||||
{
|
||||
@@ -15,6 +15,10 @@ 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";
|
||||
public const string LOGIN_DOCTOR = "LOGIN DOCTOR";
|
||||
public const string MESSAGE = "MESSAGE";
|
||||
/// <summary>
|
||||
/// makes the json object with LOGIN identifier and username and password
|
||||
/// </summary>
|
||||
@@ -36,6 +40,34 @@ namespace ClientApp.Utils
|
||||
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
|
||||
}
|
||||
|
||||
public static byte[] GetMessageToSend(string messageToSend)
|
||||
{
|
||||
dynamic json = new
|
||||
{
|
||||
identifier = MESSAGE,
|
||||
data = new
|
||||
{
|
||||
message = messageToSend
|
||||
}
|
||||
};
|
||||
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
|
||||
}
|
||||
|
||||
public static byte[] LoginAsDoctor(string mUsername, string mPassword)
|
||||
{
|
||||
dynamic json = new
|
||||
{
|
||||
identifier = LOGIN_DOCTOR,
|
||||
data = new
|
||||
{
|
||||
username = mUsername,
|
||||
password = mPassword,
|
||||
}
|
||||
};
|
||||
|
||||
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
|
||||
}
|
||||
|
||||
public static bool GetUsernamePassword(byte[] jsonbytes, out string username, out string password)
|
||||
{
|
||||
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(jsonbytes));
|
||||
@@ -191,6 +223,24 @@ namespace ClientApp.Utils
|
||||
return getJsonMessage(SET_RESISTANCE, data);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public static float getResistanceFromJson(byte[] json)
|
||||
{
|
||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.resistance;
|
||||
@@ -201,6 +251,11 @@ namespace ClientApp.Utils
|
||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.worked;
|
||||
}
|
||||
|
||||
public static string getUsernameFromResponseJson(byte[] json)
|
||||
{
|
||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Hashing
|
||||
namespace Util
|
||||
{
|
||||
class Hasher
|
||||
{
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
<Import_RootNamespace>Hashing</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DataParser.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Hasher.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ObservableObject.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace ClientApp.Utils
|
||||
namespace Util
|
||||
{
|
||||
public abstract class ObservableObject : INotifyPropertyChanged
|
||||
{
|
||||
@@ -3,56 +3,50 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30413.136
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProftaakRH", "ProftaakRH.csproj", "{0F053CC5-D969-4970-9501-B3428EA3D777}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RH-Engine", "..\RH-Engine\RH-Engine.csproj", "{984E295E-47A2-41E7-90E5-50FDB9E67694}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "..\Server\Server.csproj", "{B1AB6F51-A20D-4162-9A7F-B3350B7510FD}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Message", "..\Message\Message.csproj", "{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DokterApp", "..\DokterApp\DokterApp.csproj", "{B150F08B-13DA-4D17-BD96-7E89F52727C6}"
|
||||
EndProject
|
||||
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Hashing", "..\Hashing\Hashing.shproj", "{70277749-D423-4871-B692-2EFC5A6ED932}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientApp", "..\ClientApp\ClientApp.csproj", "{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}"
|
||||
EndProject
|
||||
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Util", "..\Hashing\Util.shproj", "{70277749-D423-4871-B692-2EFC5A6ED932}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProftaakRH", "ProftaakRH.csproj", "{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RH-Engine", "..\RH-Engine\RH-Engine.csproj", "{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "..\Server\Server.csproj", "{7D751284-17E8-434C-A7F6-2EB37572E7AE}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DoctorApp", "..\DoctorApp\DoctorApp.csproj", "{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||
..\Hashing\Hashing.projitems*{70277749-d423-4871-b692-2efc5a6ed932}*SharedItemsImports = 13
|
||||
..\Hashing\Hashing.projitems*{7d751284-17e8-434c-a7f6-2eb37572e7ae}*SharedItemsImports = 5
|
||||
..\Hashing\Hashing.projitems*{7ef854c1-73eb-4099-a7d7-057cceee6f8f}*SharedItemsImports = 5
|
||||
..\Hashing\Hashing.projitems*{b150f08b-13da-4d17-bd96-7e89f52727c6}*SharedItemsImports = 5
|
||||
..\Hashing\Hashing.projitems*{b1ab6f51-a20d-4162-9a7f-b3350b7510fd}*SharedItemsImports = 5
|
||||
..\Hashing\Hashing.projitems*{a232f2d5-af98-4777-bf3a-fbddfbc02994}*SharedItemsImports = 5
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{0F053CC5-D969-4970-9501-B3428EA3D777}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0F053CC5-D969-4970-9501-B3428EA3D777}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0F053CC5-D969-4970-9501-B3428EA3D777}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0F053CC5-D969-4970-9501-B3428EA3D777}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{984E295E-47A2-41E7-90E5-50FDB9E67694}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{984E295E-47A2-41E7-90E5-50FDB9E67694}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{984E295E-47A2-41E7-90E5-50FDB9E67694}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{984E295E-47A2-41E7-90E5-50FDB9E67694}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B1AB6F51-A20D-4162-9A7F-B3350B7510FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B1AB6F51-A20D-4162-9A7F-B3350B7510FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B1AB6F51-A20D-4162-9A7F-B3350B7510FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B1AB6F51-A20D-4162-9A7F-B3350B7510FD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B150F08B-13DA-4D17-BD96-7E89F52727C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B150F08B-13DA-4D17-BD96-7E89F52727C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B150F08B-13DA-4D17-BD96-7E89F52727C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B150F08B-13DA-4D17-BD96-7E89F52727C6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7D751284-17E8-434C-A7F6-2EB37572E7AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7D751284-17E8-434C-A7F6-2EB37572E7AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7D751284-17E8-434C-A7F6-2EB37572E7AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7D751284-17E8-434C-A7F6-2EB37572E7AE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
|
||||
namespace RH_Engine
|
||||
@@ -122,5 +123,19 @@ namespace RH_Engine
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetChildUuid(string name, JArray children)
|
||||
{
|
||||
foreach (dynamic child in children)
|
||||
{
|
||||
if (child.name == name)
|
||||
{
|
||||
return child.uuid;
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Could not find id of " + name);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,9 @@ namespace RH_Engine
|
||||
//new PC("DESKTOP-M2CIH87", "Fabian"),
|
||||
//new PC("T470S", "Shinichi"),
|
||||
//new PC("DESKTOP-DHS478C", "semme"),
|
||||
//new PC("HP-ZBOOK-SEM", "Sem"),
|
||||
new PC("HP-ZBOOK-SEM", "Sem"),
|
||||
//new PC("DESKTOP-TV73FKO", "Wouter"),
|
||||
new PC("DESKTOP-SINMKT1", "Ralf van Aert"),
|
||||
//new PC("DESKTOP-SINMKT1", "Ralf van Aert"),
|
||||
//new PC("NA", "Bart")
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using ClientApp.Utils;
|
||||
using System.Diagnostics;
|
||||
using Util;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
@@ -16,14 +18,10 @@ namespace Server
|
||||
private byte[] totalBuffer = new byte[1024];
|
||||
private int totalBufferReceived = 0;
|
||||
private SaveData saveData;
|
||||
private string username = null;
|
||||
public string username = null;
|
||||
private DateTime sessionStart;
|
||||
private string fileName;
|
||||
|
||||
|
||||
|
||||
public string Username { get; set; }
|
||||
|
||||
public Client(Communication communication, TcpClient tcpClient)
|
||||
{
|
||||
this.sessionStart = DateTime.Now;
|
||||
@@ -39,6 +37,7 @@ namespace Server
|
||||
|
||||
int receivedBytes = this.stream.EndRead(ar);
|
||||
|
||||
if (totalBufferReceived + receivedBytes > 1024)
|
||||
if (totalBufferReceived + receivedBytes > 1024)
|
||||
{
|
||||
throw new OutOfMemoryException("buffer too small");
|
||||
@@ -96,27 +95,12 @@ namespace Server
|
||||
switch (identifier)
|
||||
{
|
||||
case DataParser.LOGIN:
|
||||
string username;
|
||||
string password;
|
||||
bool worked = DataParser.GetUsernamePassword(payloadbytes, out username, out password);
|
||||
if (worked)
|
||||
{
|
||||
if (verifyLogin(username, password))
|
||||
{
|
||||
Console.WriteLine("Log in");
|
||||
this.username = username;
|
||||
sendMessage(DataParser.getLoginResponse("OK"));
|
||||
sendMessage(DataParser.getStartSessionJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
sendMessage(DataParser.getLoginResponse("wrong username or password"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sendMessage(DataParser.getLoginResponse("invalid json"));
|
||||
}
|
||||
handleLogin(payloadbytes);
|
||||
break;
|
||||
case DataParser.LOGIN_DOCTOR:
|
||||
handleLogin(payloadbytes);
|
||||
communication.doctor = this;
|
||||
Console.WriteLine("Set doctor to " + communication.doctor + " , this is " + this);
|
||||
break;
|
||||
case DataParser.START_SESSION:
|
||||
this.saveData = new SaveData(Directory.GetCurrentDirectory() + "/" + this.username + "/" + sessionStart.ToString("yyyy-MM-dd HH-mm-ss"));
|
||||
@@ -125,7 +109,7 @@ namespace Server
|
||||
this.saveData = null;
|
||||
break;
|
||||
case DataParser.SET_RESISTANCE:
|
||||
worked = DataParser.getResistanceFromResponseJson(payloadbytes);
|
||||
bool worked = DataParser.getResistanceFromResponseJson(payloadbytes);
|
||||
Console.WriteLine($"set resistance worked is " + worked);
|
||||
//set resistance on doctor GUI
|
||||
break;
|
||||
@@ -161,6 +145,32 @@ namespace Server
|
||||
|
||||
}
|
||||
|
||||
private void handleLogin(byte[] payloadbytes)
|
||||
{
|
||||
string username;
|
||||
string password;
|
||||
bool worked = DataParser.GetUsernamePassword(payloadbytes, out username, out password);
|
||||
if (worked)
|
||||
{
|
||||
if (verifyLogin(username, password))
|
||||
{
|
||||
Console.WriteLine("Log in");
|
||||
this.username = username;
|
||||
sendMessage(DataParser.getLoginResponse("OK"));
|
||||
sendMessage(DataParser.getStartSessionJson());
|
||||
communication.NewLogin(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendMessage(DataParser.getLoginResponse("wrong username or password"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sendMessage(DataParser.getLoginResponse("invalid json"));
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(byte[] message)
|
||||
{
|
||||
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
@@ -168,6 +178,7 @@ namespace Server
|
||||
|
||||
private bool verifyLogin(string username, string password)
|
||||
{
|
||||
Console.WriteLine($"Got username {username} and password {password}");
|
||||
|
||||
|
||||
if (!File.Exists(fileName))
|
||||
@@ -182,27 +193,23 @@ namespace Server
|
||||
{
|
||||
Console.WriteLine("file exists, located at " + Path.GetFullPath(fileName));
|
||||
string[] usernamesPasswords = File.ReadAllLines(fileName);
|
||||
if (usernamesPasswords.Length == 0)
|
||||
{
|
||||
newUsers(username, password);
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (string s in usernamesPasswords)
|
||||
{
|
||||
string[] combo = s.Split(" ");
|
||||
if (combo[0] == username)
|
||||
{
|
||||
Console.WriteLine("correct info");
|
||||
Console.WriteLine("username found in file");
|
||||
return combo[1] == password;
|
||||
}
|
||||
|
||||
}
|
||||
Console.WriteLine("combo was not found in file");
|
||||
Console.WriteLine("username not found in file");
|
||||
newUsers(username, password);
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
Console.WriteLine("false");
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@ using System.IO.Pipes;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using ClientApp.Utils;
|
||||
using DoctorApp.Utils;
|
||||
using Util;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
@@ -12,8 +13,7 @@ namespace Server
|
||||
{
|
||||
private TcpListener listener;
|
||||
private List<Client> clients;
|
||||
private Client doctor;
|
||||
|
||||
public Client doctor;
|
||||
public Communication(TcpListener listener)
|
||||
{
|
||||
this.listener = listener;
|
||||
@@ -35,15 +35,15 @@ namespace Server
|
||||
var tcpClient = listener.EndAcceptTcpClient(ar);
|
||||
Console.WriteLine($"Client connected from {tcpClient.Client.RemoteEndPoint}");
|
||||
clients.Add(new Client(this, tcpClient));
|
||||
if (doctor == null)
|
||||
/*if (doctor == null)
|
||||
{
|
||||
doctor = clients.ElementAt(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
doctor.sendMessage(DataParser.getLoginResponse("new client"));
|
||||
}
|
||||
doctor.sendMessage(DataParser.getNewConnectionJson("jan"));
|
||||
}*/
|
||||
listener.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null);
|
||||
}
|
||||
|
||||
@@ -51,5 +51,18 @@ namespace Server
|
||||
{
|
||||
clients.Remove(client);
|
||||
}
|
||||
|
||||
public void NewLogin(Client client)
|
||||
{
|
||||
if (doctor == null)
|
||||
{
|
||||
doctor = client;
|
||||
}
|
||||
else
|
||||
{
|
||||
doctor.sendMessage(DataParser.getNewConnectionJson(client.username));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ClientApp\ClientApp.csproj" />
|
||||
<ProjectReference Include="..\DoctorApp\DoctorApp.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
|
||||
|
||||
Reference in New Issue
Block a user