Merge branch 'newDoctor' into develop

This commit is contained in:
fabjuuuh
2020-10-14 13:07:20 +02:00
26 changed files with 1077 additions and 27 deletions

22
DoctorApp/App.xaml Normal file
View 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
View 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
View 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)
)]

View File

@@ -0,0 +1,22 @@
<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="..\DokterApp\DokterApp.csproj" />
<ProjectReference Include="..\ProftaakRH\ProftaakRH.csproj" />
</ItemGroup>
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
</Project>

View 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
View 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>

16
DoctorApp/Models/Info.cs Normal file
View File

@@ -0,0 +1,16 @@
using DoctorApp.Utils;
using System;
using System.Collections.Generic;
using System.Text;
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; }
}
}

269
DoctorApp/Utils/Client.cs Normal file
View File

@@ -0,0 +1,269 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using DoctorApp.ViewModels;
using ProftaakRH;
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 hashUser = Hashing.Hasher.HashString(username);
string hashPassword = Hashing.Hasher.HashString(password);
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(hashUser, 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;
}
}
}

View File

@@ -0,0 +1,231 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
namespace DoctorApp.Utils
{
public class DataParser
{
public const string LOGIN = "LOGIN";
public const string LOGIN_RESPONSE = "LOGIN RESPONSE";
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>
/// <param name="mUsername">username</param>
/// <param name="mPassword">password</param>
/// <returns>json object to ASCII to bytes</returns>
public static byte[] GetLoginJson(string mUsername, string mPassword)
{
dynamic json = new
{
identifier = LOGIN,
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));
try
{
username = json.data.username;
password = json.data.password;
return true;
}
catch
{
username = null;
password = null;
return false;
}
}
private static byte[] getJsonMessage(string mIdentifier, dynamic data)
{
dynamic json = new
{
identifier = mIdentifier,
data
};
return getMessage(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json)), 0x01);
}
private static byte[] getJsonMessage(string mIdentifier)
{
dynamic json = new
{
identifier = mIdentifier,
};
return getMessage(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json)), 0x01);
}
public static byte[] getLoginResponse(string mStatus)
{
return getJsonMessage(LOGIN_RESPONSE, new { status = mStatus });
}
public static string getResponseStatus(byte[] json)
{
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.status;
}
/// <summary>
/// get the identifier from json
/// </summary>
/// <param name="bytes">json in ASCII</param>
/// <param name="identifier">gets the identifier</param>
/// <returns>if it sucseeded</returns>
public static bool getJsonIdentifier(byte[] bytes, out string identifier)
{
if (bytes.Length <= 5)
{
throw new ArgumentException("bytes to short");
}
byte messageId = bytes[4];
if (messageId == 0x01)
{
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(bytes.Skip(5).ToArray()));
identifier = json.identifier;
return true;
}
else
{
identifier = "";
return false;
}
}
/// <summary>
/// checks if the de message is raw data according to the protocol
/// </summary>
/// <param name="bytes">message</param>
/// <returns>if message contains raw data</returns>
public static bool isRawData(byte[] bytes)
{
if (bytes.Length <= 5)
{
throw new ArgumentException("bytes to short");
}
return bytes[4] == 0x02;
}
/// <summary>
/// constructs a message with the payload, messageId and clientId
/// </summary>
/// <param name="payload"></param>
/// <param name="messageId"></param>
/// <param name="clientId"></param>
/// <returns>the message ready for sending</returns>
private static byte[] getMessage(byte[] payload, byte messageId)
{
byte[] res = new byte[payload.Length + 5];
Array.Copy(BitConverter.GetBytes(payload.Length + 5), 0, res, 0, 4);
res[4] = messageId;
Array.Copy(payload, 0, res, 5, payload.Length);
return res;
}
/// <summary>
/// constructs a message with the payload and clientId and assumes the payload is raw data
/// </summary>
/// <param name="payload"></param>
/// <param name="clientId"></param>
/// <returns>the message ready for sending</returns>
public static byte[] GetRawDataMessage(byte[] payload)
{
return getMessage(payload, 0x02);
}
/// <summary>
/// constructs a message with the payload and clientId and assumes the payload is json
/// </summary>
/// <param name="payload"></param>
/// <param name="clientId"></param>
/// <returns>the message ready for sending</returns>
public static byte[] getJsonMessage(byte[] payload)
{
return getMessage(payload, 0x01);
}
public static byte[] getStartSessionJson()
{
return getJsonMessage(START_SESSION);
}
public static byte[] getStopSessionJson()
{
return getJsonMessage(STOP_SESSION);
}
public static byte[] getSetResistanceJson(float mResistance)
{
dynamic data = new
{
resistance = mResistance
};
return getJsonMessage(SET_RESISTANCE, data);
}
public static byte[] getSetResistanceResponseJson(bool mWorked)
{
dynamic data = new
{
worked = mWorked
};
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;
}
public static bool getResistanceFromResponseJson(byte[] json)
{
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;
}
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace DoctorApp.Utils
{
public abstract class ObservableObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
}
}

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

View File

@@ -0,0 +1,46 @@

using DoctorApp.Utils;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Controls;
using System.Windows.Input;
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;
}
}
}
}

View File

@@ -0,0 +1,45 @@
using DoctorApp.Utils;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text;
using System.Windows.Controls;
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)
{
}
}
}

View File

@@ -0,0 +1,25 @@
using DoctorApp.Models;
using DoctorApp.Utils;
using System;
using System.Collections.Generic;
using System.Text;
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);
}
}
}

View 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>

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

View 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>

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

View 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>

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

View 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>

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

View File

@@ -15,12 +15,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RH-Engine", "..\RH-Engine\R
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "..\Server\Server.csproj", "{7D751284-17E8-434C-A7F6-2EB37572E7AE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientApp", "..\ClientApp\ClientApp.csproj", "{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}"
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*{97183aad-7964-4776-a932-f5ef1795b852}*SharedItemsImports = 5
..\Hashing\Hashing.projitems*{a232f2d5-af98-4777-bf3a-fbddfbc02994}*SharedItemsImports = 5
..\Hashing\Hashing.projitems*{b150f08b-13da-4d17-bd96-7e89f52727c6}*SharedItemsImports = 5
..\Hashing\Hashing.projitems*{b1ab6f51-a20d-4162-9a7f-b3350b7510fd}*SharedItemsImports = 5
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -31,22 +37,10 @@ Global
{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
{97183AAD-7964-4776-A932-F5EF1795B852}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{97183AAD-7964-4776-A932-F5EF1795B852}.Debug|Any CPU.Build.0 = Debug|Any CPU
{97183AAD-7964-4776-A932-F5EF1795B852}.Release|Any CPU.ActiveCfg = Release|Any CPU
{97183AAD-7964-4776-A932-F5EF1795B852}.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

View File

@@ -16,14 +16,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 +35,7 @@ namespace Server
int receivedBytes = this.stream.EndRead(ar);
if (totalBufferReceived + receivedBytes > 1024)
if (totalBufferReceived + receivedBytes > 1024)
{
throw new OutOfMemoryException("buffer too small");
@@ -107,6 +104,7 @@ namespace Server
this.username = username;
sendMessage(DataParser.getLoginResponse("OK"));
sendMessage(DataParser.getStartSessionJson());
communication.NewLogin(this);
}
else
{

View File

@@ -4,7 +4,7 @@ using System.IO.Pipes;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using ClientApp.Utils;
using DoctorApp.Utils;
namespace Server
{
@@ -13,7 +13,6 @@ namespace Server
private TcpListener listener;
private List<Client> clients;
private Client doctor;
public Communication(TcpListener listener)
{
this.listener = listener;
@@ -35,15 +34,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 +50,18 @@ namespace Server
{
clients.Remove(client);
}
public void NewLogin(Client client)
{
if (doctor == null)
{
doctor = client;
}
else
{
doctor.sendMessage(DataParser.getNewConnectionJson(client.username));
}
}
}
}

View File

@@ -11,6 +11,7 @@
<ItemGroup>
<ProjectReference Include="..\ClientApp\ClientApp.csproj" />
<ProjectReference Include="..\DoctorApp\DoctorApp.csproj" />
</ItemGroup>
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />