Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4afbbe4c38 | ||
|
|
749498ba5b |
@@ -123,7 +123,7 @@ namespace Client
|
|||||||
{
|
{
|
||||||
Console.WriteLine("Username and password correct!");
|
Console.WriteLine("Username and password correct!");
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
initEngine();
|
//initEngine();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -189,7 +189,6 @@ namespace Client
|
|||||||
private void OnWrite(IAsyncResult ar)
|
private void OnWrite(IAsyncResult ar)
|
||||||
{
|
{
|
||||||
this.stream.EndWrite(ar);
|
this.stream.EndWrite(ar);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region interface
|
#region interface
|
||||||
@@ -213,7 +212,7 @@ namespace Client
|
|||||||
if (engineConnection.Connected && engineConnection.FollowingRoute)
|
if (engineConnection.Connected && engineConnection.FollowingRoute)
|
||||||
{
|
{
|
||||||
engineConnection.BikeBPM = bytes[1];
|
engineConnection.BikeBPM = bytes[1];
|
||||||
|
engineConnection.UpdateInfoPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -226,7 +225,6 @@ namespace Client
|
|||||||
/// <param name="bytes">the message</param>
|
/// <param name="bytes">the message</param>
|
||||||
public void Bike(byte[] bytes)
|
public void Bike(byte[] bytes)
|
||||||
{
|
{
|
||||||
bool canSendToEngine = engineConnection.Connected && engineConnection.FollowingRoute;
|
|
||||||
if (!sessionRunning)
|
if (!sessionRunning)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -240,13 +238,14 @@ namespace Client
|
|||||||
{
|
{
|
||||||
case 0x10:
|
case 0x10:
|
||||||
|
|
||||||
if (canSendToEngine) engineConnection.BikeSpeed = (bytes[4] | (bytes[5] << 8)) * 0.01f;
|
engineConnection.BikeSpeed = (bytes[4] | (bytes[5] << 8)) * 0.01f;
|
||||||
break;
|
break;
|
||||||
case 0x19:
|
case 0x19:
|
||||||
if (canSendToEngine) engineConnection.BikePower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
|
engineConnection.BikePower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (engineConnection.Connected && engineConnection.FollowingRoute)
|
||||||
|
engineConnection.UpdateInfoPanel();
|
||||||
|
|
||||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ namespace Client
|
|||||||
{
|
{
|
||||||
private static EngineConnection instance = null;
|
private static EngineConnection instance = null;
|
||||||
private static readonly object padlock = new object();
|
private static readonly object padlock = new object();
|
||||||
private static System.Timers.Timer updateTimer;
|
|
||||||
public HandleNoTunnelId OnNoTunnelId;
|
public HandleNoTunnelId OnNoTunnelId;
|
||||||
public OnSuccessfullConnection OnSuccessFullConnection;
|
public OnSuccessfullConnection OnSuccessFullConnection;
|
||||||
|
|
||||||
@@ -58,15 +57,6 @@ namespace Client
|
|||||||
BikePower = 0;
|
BikePower = 0;
|
||||||
BikeBPM = 0;
|
BikeBPM = 0;
|
||||||
BikeResistance = 50;
|
BikeResistance = 50;
|
||||||
updateTimer = new System.Timers.Timer(1000);
|
|
||||||
updateTimer.Elapsed += UpdateTimer_Elapsed;
|
|
||||||
updateTimer.AutoReset = true;
|
|
||||||
updateTimer.Enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
|
||||||
{
|
|
||||||
UpdateInfoPanel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -174,7 +164,6 @@ namespace Client
|
|||||||
|
|
||||||
public void initScene()
|
public void initScene()
|
||||||
{
|
{
|
||||||
|
|
||||||
Write("initializing scene...");
|
Write("initializing scene...");
|
||||||
mainCommand = new Command(tunnelId);
|
mainCommand = new Command(tunnelId);
|
||||||
|
|
||||||
@@ -190,6 +179,9 @@ namespace Client
|
|||||||
string headId = JSONParser.GetIdSceneInfoChild(message, "Head");
|
string headId = JSONParser.GetIdSceneInfoChild(message, "Head");
|
||||||
string handLeftId = JSONParser.GetIdSceneInfoChild(message, "LeftHand");
|
string handLeftId = JSONParser.GetIdSceneInfoChild(message, "LeftHand");
|
||||||
string handRightId = JSONParser.GetIdSceneInfoChild(message, "RightHand");
|
string handRightId = JSONParser.GetIdSceneInfoChild(message, "RightHand");
|
||||||
|
|
||||||
|
//Force(stream, mainCommand.DeleteNode(handLeftId, "deleteHandL"), "deleteHandL", (message) => Console.WriteLine("Left hand deleted"));
|
||||||
|
//Force(stream, mainCommand.DeleteNode(handRightId, "deleteHandR"), "deleteHandR", (message) => Console.WriteLine("Right hand deleted"));
|
||||||
});
|
});
|
||||||
// add the route and set the route id
|
// add the route and set the route id
|
||||||
SendMessageAndOnResponse(mainCommand.RouteCommand("routeID"), "routeID", (message) => routeId = JSONParser.GetResponseUuid(message));
|
SendMessageAndOnResponse(mainCommand.RouteCommand("routeID"), "routeID", (message) => routeId = JSONParser.GetResponseUuid(message));
|
||||||
@@ -212,7 +204,6 @@ namespace Client
|
|||||||
|
|
||||||
WriteTextMessage(mainCommand.ColorPanel(panelId));
|
WriteTextMessage(mainCommand.ColorPanel(panelId));
|
||||||
UpdateInfoPanel();
|
UpdateInfoPanel();
|
||||||
updateTimer.Enabled = true;
|
|
||||||
|
|
||||||
while (cameraId == string.Empty) { }
|
while (cameraId == string.Empty) { }
|
||||||
SetFollowSpeed(5.0f);
|
SetFollowSpeed(5.0f);
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ namespace Client
|
|||||||
{
|
{
|
||||||
Console.WriteLine("// Connecting... //");
|
Console.WriteLine("// Connecting... //");
|
||||||
//connect fiets?
|
//connect fiets?
|
||||||
|
|
||||||
|
Thread.Sleep(20000);
|
||||||
Client client = new Client();
|
Client client = new Client();
|
||||||
|
|
||||||
|
|
||||||
@@ -21,22 +23,22 @@ namespace Client
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
BLEHandler bLEHandler = new BLEHandler(client);
|
//BLEHandler bLEHandler = new BLEHandler(client);
|
||||||
|
|
||||||
bLEHandler.Connect();
|
//bLEHandler.Connect();
|
||||||
|
|
||||||
client.setHandler(bLEHandler);
|
//client.setHandler(bLEHandler);
|
||||||
|
|
||||||
|
|
||||||
//BikeSimulator bikeSimulator = new BikeSimulator(client);
|
BikeSimulator bikeSimulator = new BikeSimulator(client);
|
||||||
|
|
||||||
//bikeSimulator.StartSimulation();
|
bikeSimulator.StartSimulation();
|
||||||
|
|
||||||
//client.setHandler(bikeSimulator);
|
client.setHandler(bikeSimulator);
|
||||||
|
|
||||||
//while (true)
|
while (true)
|
||||||
//{
|
{
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,25 +6,13 @@
|
|||||||
xmlns:views="clr-namespace:ClientApp.Views"
|
xmlns:views="clr-namespace:ClientApp.Views"
|
||||||
StartupUri="Views/MainWindow.xaml">
|
StartupUri="Views/MainWindow.xaml">
|
||||||
<Application.Resources>
|
<Application.Resources>
|
||||||
|
<DataTemplate DataType="{x:Type viewModels:MainViewModel}">
|
||||||
|
<views:MainView />
|
||||||
<ResourceDictionary>
|
<!-- This is a UserControl -->
|
||||||
<DataTemplate DataType="{x:Type viewModels:MainViewModel}">
|
</DataTemplate>
|
||||||
<views:MainView />
|
<DataTemplate DataType="{x:Type viewModels:LoginViewModel}">
|
||||||
<!-- This is a Page -->
|
<views:LoginView />
|
||||||
</DataTemplate>
|
<!-- This is a UserControl -->
|
||||||
<DataTemplate DataType="{x:Type viewModels:LoginViewModel}">
|
</DataTemplate>
|
||||||
<views:LoginView />
|
|
||||||
<!-- This is a Page -->
|
|
||||||
</DataTemplate>
|
|
||||||
|
|
||||||
<ResourceDictionary.MergedDictionaries>
|
|
||||||
<ResourceDictionary Source="WPFStuff/Styles/Fonts.xaml"/>
|
|
||||||
<ResourceDictionary Source="WPFStuff/Styles/Colors.xaml"/>
|
|
||||||
<ResourceDictionary Source="WPFStuff/Styles/Buttons.xaml"/>
|
|
||||||
<ResourceDictionary Source="WPFStuff/Styles/Texts.xaml"/>
|
|
||||||
<ResourceDictionary Source="WPFStuff/Styles/Windows.xaml"/>
|
|
||||||
</ResourceDictionary.MergedDictionaries>
|
|
||||||
</ResourceDictionary>
|
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
</Application>
|
</Application>
|
||||||
|
|||||||
@@ -1,66 +1,23 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
<ApplicationIcon>Images\Logo\icon1.ico</ApplicationIcon>
|
</PropertyGroup>
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<ItemGroup>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<PackageReference Include="AsyncAwaitBestPractices.MVVM" Version="4.3.0" />
|
||||||
</PropertyGroup>
|
<PackageReference Include="MvvmLightLibsStd10" Version="5.4.1.1" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
|
<PackageReference Include="PropertyChanged.Fody" Version="3.2.9" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
<ItemGroup>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<ProjectReference Include="..\ProftaakRH\ProftaakRH.csproj" />
|
||||||
</PropertyGroup>
|
<ProjectReference Include="..\RH-Engine\RH-Engine.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
|
||||||
<None Remove="Images\CoolBackground.jpg" />
|
|
||||||
<None Remove="Images\Icons\CheckMark.png" />
|
|
||||||
<None Remove="Images\Icons\CrossMark.png" />
|
|
||||||
<None Remove="Images\Logo\icon1.ico" />
|
|
||||||
<None Remove="Images\re15.jpg" />
|
|
||||||
<None Remove="Images\stone.png" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Content Include="Images\CoolBackground.jpg">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
<Content Include="Images\Icons\CheckMark.png">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
<Content Include="Images\Icons\CrossMark.png">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
<Content Include="Images\Logo\icon1.ico">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
<Content Include="Images\re15.jpg">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
<Content Include="Images\stone.png">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="AsyncAwaitBestPractices.MVVM" Version="4.3.0" />
|
|
||||||
<PackageReference Include="MvvmLightLibsStd10" Version="5.4.1.1" />
|
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
|
||||||
<PackageReference Include="PropertyChanged.Fody" Version="3.2.9" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\ProftaakRH\ProftaakRH.csproj" />
|
|
||||||
<ProjectReference Include="..\RH-Engine\RH-Engine.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Properties\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
Before Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 66 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 1.6 KiB |
@@ -1,212 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Interop;
|
|
||||||
|
|
||||||
namespace ClientApp.MagicCode
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Fixes the issue with Windows of Style <see cref="WindowStyle.None"/> covering the taskbar
|
|
||||||
/// </summary>
|
|
||||||
public class WindowResizer
|
|
||||||
{
|
|
||||||
#region Private Members
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The window to handle the resizing for
|
|
||||||
/// </summary>
|
|
||||||
private Window mWindow;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Dll Imports
|
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
|
||||||
static extern bool GetCursorPos(out POINT lpPoint);
|
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
|
||||||
static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
|
|
||||||
|
|
||||||
[DllImport("user32.dll", SetLastError = true)]
|
|
||||||
static extern IntPtr MonitorFromPoint(POINT pt, MonitorOptions dwFlags);
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructor
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Default constructor
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="window">The window to monitor and correctly maximize</param>
|
|
||||||
/// <param name="adjustSize">The callback for the host to adjust the maximum available size if needed</param>
|
|
||||||
public WindowResizer(Window window)
|
|
||||||
{
|
|
||||||
mWindow = window;
|
|
||||||
|
|
||||||
// Listen out for source initialized to setup
|
|
||||||
mWindow.SourceInitialized += Window_SourceInitialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Initialize
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initialize and hook into the windows message pump
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void Window_SourceInitialized(object sender, System.EventArgs e)
|
|
||||||
{
|
|
||||||
// Get the handle of this window
|
|
||||||
var handle = (new WindowInteropHelper(mWindow)).Handle;
|
|
||||||
var handleSource = HwndSource.FromHwnd(handle);
|
|
||||||
|
|
||||||
// If not found, end
|
|
||||||
if (handleSource == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Hook into it's Windows messages
|
|
||||||
handleSource.AddHook(WindowProc);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Windows Proc
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Listens out for all windows messages for this window
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="hwnd"></param>
|
|
||||||
/// <param name="msg"></param>
|
|
||||||
/// <param name="wParam"></param>
|
|
||||||
/// <param name="lParam"></param>
|
|
||||||
/// <param name="handled"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
|
||||||
{
|
|
||||||
switch (msg)
|
|
||||||
{
|
|
||||||
// Handle the GetMinMaxInfo of the Window
|
|
||||||
case 0x0024:/* WM_GETMINMAXINFO */
|
|
||||||
WmGetMinMaxInfo(hwnd, lParam);
|
|
||||||
handled = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (IntPtr)0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get the min/max window size for this window
|
|
||||||
/// Correctly accounting for the taskbar size and position
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="hwnd"></param>
|
|
||||||
/// <param name="lParam"></param>
|
|
||||||
private void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
|
|
||||||
{
|
|
||||||
POINT lMousePosition;
|
|
||||||
GetCursorPos(out lMousePosition);
|
|
||||||
|
|
||||||
IntPtr lPrimaryScreen = MonitorFromPoint(new POINT(0, 0), MonitorOptions.MONITOR_DEFAULTTOPRIMARY);
|
|
||||||
MONITORINFO lPrimaryScreenInfo = new MONITORINFO();
|
|
||||||
if (GetMonitorInfo(lPrimaryScreen, lPrimaryScreenInfo) == false)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
IntPtr lCurrentScreen = MonitorFromPoint(lMousePosition, MonitorOptions.MONITOR_DEFAULTTONEAREST);
|
|
||||||
|
|
||||||
MINMAXINFO lMmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
|
|
||||||
|
|
||||||
if (lPrimaryScreen.Equals(lCurrentScreen) == true)
|
|
||||||
{
|
|
||||||
lMmi.ptMaxPosition.X = lPrimaryScreenInfo.rcWork.Left;
|
|
||||||
lMmi.ptMaxPosition.Y = lPrimaryScreenInfo.rcWork.Top;
|
|
||||||
lMmi.ptMaxSize.X = lPrimaryScreenInfo.rcWork.Right - lPrimaryScreenInfo.rcWork.Left;
|
|
||||||
lMmi.ptMaxSize.Y = lPrimaryScreenInfo.rcWork.Bottom - lPrimaryScreenInfo.rcWork.Top;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lMmi.ptMaxPosition.X = lPrimaryScreenInfo.rcMonitor.Left;
|
|
||||||
lMmi.ptMaxPosition.Y = lPrimaryScreenInfo.rcMonitor.Top;
|
|
||||||
lMmi.ptMaxSize.X = lPrimaryScreenInfo.rcMonitor.Right - lPrimaryScreenInfo.rcMonitor.Left;
|
|
||||||
lMmi.ptMaxSize.Y = lPrimaryScreenInfo.rcMonitor.Bottom - lPrimaryScreenInfo.rcMonitor.Top;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we have the max size, allow the host to tweak as needed
|
|
||||||
Marshal.StructureToPtr(lMmi, lParam, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Dll Helper Structures
|
|
||||||
|
|
||||||
enum MonitorOptions : uint
|
|
||||||
{
|
|
||||||
MONITOR_DEFAULTTONULL = 0x00000000,
|
|
||||||
MONITOR_DEFAULTTOPRIMARY = 0x00000001,
|
|
||||||
MONITOR_DEFAULTTONEAREST = 0x00000002
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
|
||||||
public class MONITORINFO
|
|
||||||
{
|
|
||||||
public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
|
|
||||||
public Rectangle rcMonitor = new Rectangle();
|
|
||||||
public Rectangle rcWork = new Rectangle();
|
|
||||||
public int dwFlags = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct Rectangle
|
|
||||||
{
|
|
||||||
public int Left, Top, Right, Bottom;
|
|
||||||
|
|
||||||
public Rectangle(int left, int top, int right, int bottom)
|
|
||||||
{
|
|
||||||
this.Left = left;
|
|
||||||
this.Top = top;
|
|
||||||
this.Right = right;
|
|
||||||
this.Bottom = bottom;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct MINMAXINFO
|
|
||||||
{
|
|
||||||
public POINT ptReserved;
|
|
||||||
public POINT ptMaxSize;
|
|
||||||
public POINT ptMaxPosition;
|
|
||||||
public POINT ptMinTrackSize;
|
|
||||||
public POINT ptMaxTrackSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct POINT
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// x coordinate of point.
|
|
||||||
/// </summary>
|
|
||||||
public int X;
|
|
||||||
/// <summary>
|
|
||||||
/// y coordinate of point.
|
|
||||||
/// </summary>
|
|
||||||
public int Y;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Construct a point of coordinates (x,y).
|
|
||||||
/// </summary>
|
|
||||||
public POINT(int x, int y)
|
|
||||||
{
|
|
||||||
this.X = x;
|
|
||||||
this.Y = y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Util;
|
|
||||||
|
|
||||||
namespace ClientApp.Models
|
namespace ClientApp.Models
|
||||||
{
|
{
|
||||||
@@ -11,7 +10,5 @@ namespace ClientApp.Models
|
|||||||
public bool ConnectedToServer { get; set; }
|
public bool ConnectedToServer { get; set; }
|
||||||
public bool ConnectedToVREngine { get; set; }
|
public bool ConnectedToVREngine { get; set; }
|
||||||
public bool DoctorConnected { get; set; }
|
public bool DoctorConnected { get; set; }
|
||||||
|
|
||||||
public bool CanConnectToVR { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,22 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using ClientApp.ViewModels;
|
using ClientApp.ViewModels;
|
||||||
using ProftaakRH;
|
using ProftaakRH;
|
||||||
using Util;
|
|
||||||
|
|
||||||
namespace ClientApp.Utils
|
namespace ClientApp.Utils
|
||||||
{
|
{
|
||||||
public delegate void EngineCallback();
|
public class Client : IDataReceiver
|
||||||
public class Client : IDataReceiver, IDisposable
|
|
||||||
{
|
{
|
||||||
public EngineCallback engineConnectFailed;
|
|
||||||
public EngineCallback engineConnectSuccess;
|
|
||||||
private TcpClient client;
|
private TcpClient client;
|
||||||
private NetworkStream stream;
|
private NetworkStream stream;
|
||||||
private byte[] buffer = new byte[1024];
|
private byte[] buffer = new byte[1024];
|
||||||
private bool connected;
|
private bool connected;
|
||||||
private byte[] totalBuffer = new byte[1024];
|
private byte[] totalBuffer = new byte[1024];
|
||||||
private int totalBufferReceived = 0;
|
private int totalBufferReceived = 0;
|
||||||
public EngineConnection engineConnection;
|
private EngineConnection engineConnection;
|
||||||
private bool sessionRunning = true;
|
private bool sessionRunning = false;
|
||||||
private IHandler handler = null;
|
private IHandler handler = null;
|
||||||
private LoginViewModel LoginViewModel;
|
private LoginViewModel LoginViewModel;
|
||||||
|
|
||||||
@@ -43,27 +38,33 @@ namespace ClientApp.Utils
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void initEngine()
|
private void initEngine()
|
||||||
{
|
{
|
||||||
Debug.WriteLine("init engine");
|
|
||||||
engineConnection = EngineConnection.INSTANCE;
|
engineConnection = EngineConnection.INSTANCE;
|
||||||
engineConnection.OnNoTunnelId = RetryEngineConnection;
|
engineConnection.OnNoTunnelId = retryEngineConnection;
|
||||||
engineConnection.OnSuccessFullConnection = engineConnected;
|
engineConnection.OnSuccessFullConnection = engineConnected;
|
||||||
engineConnection.OnEngineDisconnect = RetryEngineConnection;
|
|
||||||
if (!engineConnection.Connected) engineConnection.Connect();
|
if (!engineConnection.Connected) engineConnection.Connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// retries to connect to the VR engine if no tunnel id was found
|
/// retries to connect to the VR engine if no tunnel id was found
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void RetryEngineConnection()
|
private void retryEngineConnection()
|
||||||
{
|
{
|
||||||
engineConnectFailed?.Invoke();
|
Console.WriteLine("-- Could not connect to the VR engine. Please make sure you are running the simulation!");
|
||||||
|
Console.WriteLine("-- Press ENTER to retry connecting to the VR engine.");
|
||||||
|
Console.WriteLine("-- Press 'q' and then ENTER to not connect to the VR engine");
|
||||||
|
string input = Console.ReadLine();
|
||||||
|
if (input == string.Empty) engineConnection.CreateConnection();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Skipping connecting to VR engine...");
|
||||||
|
engineConnection.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void engineConnected()
|
private void engineConnected()
|
||||||
{
|
{
|
||||||
Console.WriteLine("successfully connected to VR engine");
|
Console.WriteLine("successfully connected to VR engine");
|
||||||
engineConnectSuccess?.Invoke();
|
|
||||||
engineConnection.initScene();
|
engineConnection.initScene();
|
||||||
if (engineConnection.Connected && sessionRunning && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
|
if (engineConnection.Connected && sessionRunning && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
|
||||||
}
|
}
|
||||||
@@ -89,11 +90,6 @@ namespace ClientApp.Utils
|
|||||||
/// <param name="ar">the result of the async read</param>
|
/// <param name="ar">the result of the async read</param>
|
||||||
private void OnRead(IAsyncResult ar)
|
private void OnRead(IAsyncResult ar)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("got message in client app");
|
|
||||||
if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead))
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
int receivedBytes = this.stream.EndRead(ar);
|
int receivedBytes = this.stream.EndRead(ar);
|
||||||
|
|
||||||
if (totalBufferReceived + receivedBytes > 1024)
|
if (totalBufferReceived + receivedBytes > 1024)
|
||||||
@@ -125,64 +121,46 @@ namespace ClientApp.Utils
|
|||||||
string responseStatus = DataParser.getResponseStatus(payloadbytes);
|
string responseStatus = DataParser.getResponseStatus(payloadbytes);
|
||||||
if (responseStatus == "OK")
|
if (responseStatus == "OK")
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Username and password correct!");
|
Console.WriteLine("Username and password correct!");
|
||||||
this.LoginViewModel.setLoginStatus(true);
|
this.LoginViewModel.setLoginStatus(true);
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
initEngine();
|
initEngine();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.LoginViewModel.setLoginStatus(false);
|
Console.WriteLine($"login failed \"{responseStatus}\"");
|
||||||
Debug.WriteLine($"login failed \"{responseStatus}\"");
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DataParser.START_SESSION:
|
case DataParser.START_SESSION:
|
||||||
Debug.WriteLine("Session started!");
|
Console.WriteLine("Session started!");
|
||||||
this.sessionRunning = true;
|
this.sessionRunning = true;
|
||||||
if (engineConnection.Connected && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
|
if (engineConnection.Connected && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
|
||||||
Debug.WriteLine("start");
|
sendMessage(DataParser.getStartSessionJson());
|
||||||
break;
|
break;
|
||||||
case DataParser.STOP_SESSION:
|
case DataParser.STOP_SESSION:
|
||||||
Console.WriteLine("Stop session identifier");
|
Console.WriteLine("Stop session identifier");
|
||||||
this.sessionRunning = false;
|
this.sessionRunning = false;
|
||||||
stopBikeInSimulation();
|
sendMessage(DataParser.getStopSessionJson());
|
||||||
Debug.WriteLine("stop");
|
|
||||||
break;
|
break;
|
||||||
case DataParser.SET_RESISTANCE:
|
case DataParser.SET_RESISTANCE:
|
||||||
Debug.WriteLine("Set resistance identifier");
|
Console.WriteLine("Set resistance identifier");
|
||||||
if (this.handler == null)
|
if (this.handler == null)
|
||||||
{
|
{
|
||||||
// send that the operation was not successful if the handler is null
|
Console.WriteLine("handler is null");
|
||||||
Debug.WriteLine("handler is null");
|
|
||||||
sendMessage(DataParser.getSetResistanceResponseJson(false));
|
sendMessage(DataParser.getSetResistanceResponseJson(false));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// set the resistance in the vr scene and send that it was successful
|
this.handler.setResistance(DataParser.getResistanceFromJson(payloadbytes));
|
||||||
float resistance = DataParser.getResistanceFromJson(payloadbytes);
|
|
||||||
Debug.WriteLine("resistance set was " + resistance);
|
|
||||||
this.handler.setResistance(resistance);
|
|
||||||
engineConnection.BikeResistance = resistance;
|
|
||||||
sendMessage(DataParser.getSetResistanceResponseJson(true));
|
sendMessage(DataParser.getSetResistanceResponseJson(true));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DataParser.MESSAGE:
|
|
||||||
Debug.WriteLine("client has received message from doctor");
|
|
||||||
engineConnection.DoctorMessage = DataParser.getChatMessageFromJson(payloadbytes);
|
|
||||||
break;
|
|
||||||
case DataParser.NEW_CONNECTION:
|
|
||||||
this.LoginViewModel.DoctorConnected(DataParser.getUsernameFromJson(payloadbytes));
|
|
||||||
break;
|
|
||||||
case DataParser.DISCONNECT:
|
|
||||||
this.LoginViewModel.DoctorDisconnected(DataParser.getUsernameFromJson(payloadbytes));
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (DataParser.isRawDataBikeServer(messageBytes))
|
else if (DataParser.isRawData(messageBytes))
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Received data: {BitConverter.ToString(payloadbytes)}");
|
Console.WriteLine($"Received data: {BitConverter.ToString(payloadbytes)}");
|
||||||
}
|
}
|
||||||
@@ -199,7 +177,7 @@ namespace ClientApp.Utils
|
|||||||
/// starts sending a message to the server
|
/// starts sending a message to the server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">the message to send</param>
|
/// <param name="message">the message to send</param>
|
||||||
public void sendMessage(byte[] message)
|
private void sendMessage(byte[] message)
|
||||||
{
|
{
|
||||||
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||||
}
|
}
|
||||||
@@ -229,14 +207,16 @@ namespace ClientApp.Utils
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException("no bytes");
|
throw new ArgumentNullException("no bytes");
|
||||||
}
|
}
|
||||||
byte[] message = DataParser.GetRawBPMDataMessageServer(bytes);
|
byte[] message = DataParser.GetRawDataMessage(bytes);
|
||||||
|
|
||||||
if (engineConnection != null && engineConnection.Connected && engineConnection.FollowingRoute)
|
if (engineConnection.Connected && engineConnection.FollowingRoute)
|
||||||
{
|
{
|
||||||
engineConnection.BikeBPM = bytes[1];
|
engineConnection.BikeBPM = bytes[1];
|
||||||
|
engineConnection.UpdateInfoPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.stream?.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
|
||||||
|
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -245,7 +225,6 @@ namespace ClientApp.Utils
|
|||||||
/// <param name="bytes">the message</param>
|
/// <param name="bytes">the message</param>
|
||||||
public void Bike(byte[] bytes)
|
public void Bike(byte[] bytes)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!sessionRunning)
|
if (!sessionRunning)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -254,30 +233,21 @@ namespace ClientApp.Utils
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException("no bytes");
|
throw new ArgumentNullException("no bytes");
|
||||||
}
|
}
|
||||||
byte[] message = DataParser.GetRawBikeDataMessageServer(bytes);
|
byte[] message = DataParser.GetRawDataMessage(bytes);
|
||||||
bool canSendToEngine = engineConnection != null && engineConnection.Connected && engineConnection.FollowingRoute && this.sessionRunning;
|
|
||||||
switch (bytes[0])
|
switch (bytes[0])
|
||||||
{
|
{
|
||||||
|
|
||||||
case 0x10:
|
case 0x10:
|
||||||
|
|
||||||
if (canSendToEngine) engineConnection.BikeSpeed = (bytes[4] | (bytes[5] << 8)) * 0.01f;
|
engineConnection.BikeSpeed = (bytes[4] | (bytes[5] << 8)) * 0.01f;
|
||||||
else if (engineConnection != null) engineConnection.BikeSpeed = 0;
|
|
||||||
break;
|
break;
|
||||||
case 0x19:
|
case 0x19:
|
||||||
if (canSendToEngine) engineConnection.BikePower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
|
engineConnection.BikePower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
|
||||||
else if (engineConnection != null) engineConnection.BikePower = 0;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (engineConnection.Connected && engineConnection.FollowingRoute)
|
||||||
|
engineConnection.UpdateInfoPanel();
|
||||||
|
|
||||||
|
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||||
this.stream?.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void stopBikeInSimulation()
|
|
||||||
{
|
|
||||||
engineConnection.BikeSpeed = 0;
|
|
||||||
engineConnection.BikePower = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -295,10 +265,10 @@ namespace ClientApp.Utils
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void tryLogin(string username, string password)
|
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);
|
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||||
@@ -317,15 +287,5 @@ namespace ClientApp.Utils
|
|||||||
{
|
{
|
||||||
this.LoginViewModel = loginViewModel;
|
this.LoginViewModel = loginViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Debug.WriteLine("client dispose called");
|
|
||||||
sendMessage(DataParser.getDisconnectJson(LoginViewModel.Username));
|
|
||||||
this.stream.Dispose();
|
|
||||||
this.client.Dispose();
|
|
||||||
this.handler.stop();
|
|
||||||
this.engineConnection.Stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
206
ClientApp/Utils/DataParser.cs
Normal file
@@ -0,0 +1,206 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices.WindowsRuntime;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace ClientApp.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";
|
||||||
|
/// <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 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,33 +1,28 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using RH_Engine;
|
using RH_Engine;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using LibNoise.Primitive;
|
|
||||||
|
|
||||||
namespace ClientApp.Utils
|
namespace ClientApp.Utils
|
||||||
{
|
{
|
||||||
public delegate void HandleSerial(string message);
|
public delegate void HandleSerial(string message);
|
||||||
public delegate void EngineDelegate();
|
public delegate void HandleNoTunnelId();
|
||||||
|
public delegate void OnSuccessfullConnection();
|
||||||
|
|
||||||
public sealed class EngineConnection
|
public sealed class EngineConnection
|
||||||
{
|
{
|
||||||
private static EngineConnection instance = null;
|
private static EngineConnection instance = null;
|
||||||
private static readonly object padlock = new object();
|
private static readonly object padlock = new object();
|
||||||
private static System.Timers.Timer updateTimer;
|
public HandleNoTunnelId OnNoTunnelId;
|
||||||
private static System.Timers.Timer noVRResponseTimer;
|
public OnSuccessfullConnection OnSuccessFullConnection;
|
||||||
public EngineDelegate OnNoTunnelId;
|
|
||||||
public EngineDelegate OnSuccessFullConnection;
|
|
||||||
public EngineDelegate OnEngineDisconnect;
|
|
||||||
|
|
||||||
|
|
||||||
private static PC[] PCs = {
|
private static PC[] PCs = {
|
||||||
//new PC("DESKTOP-M2CIH87", "Fabian"),
|
//new PC("DESKTOP-M2CIH87", "Fabian"),
|
||||||
//new PC("T470S", "Shinichi"),
|
//new PC("T470S", "Shinichi"),
|
||||||
//new PC("DESKTOP-DHS478C", "semme"),
|
//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-TV73FKO", "Wouter"),
|
||||||
//new PC("DESKTOP-SINMKT1", "Ralf van Aert"),
|
//new PC("DESKTOP-SINMKT1", "Ralf van Aert"),
|
||||||
//new PC("NA", "Bart")
|
//new PC("NA", "Bart")
|
||||||
@@ -41,10 +36,7 @@ namespace ClientApp.Utils
|
|||||||
private static string panelId = string.Empty;
|
private static string panelId = string.Empty;
|
||||||
private static string bikeId = string.Empty;
|
private static string bikeId = string.Empty;
|
||||||
private static string headId = string.Empty;
|
private static string headId = string.Empty;
|
||||||
private static string groundPlaneId = string.Empty;
|
|
||||||
private static string terrainId = string.Empty;
|
|
||||||
|
|
||||||
public string DoctorMessage { get; set; }
|
|
||||||
public float BikeSpeed { get; set; }
|
public float BikeSpeed { get; set; }
|
||||||
public float BikePower { get; set; }
|
public float BikePower { get; set; }
|
||||||
public float BikeBPM { get; set; }
|
public float BikeBPM { get; set; }
|
||||||
@@ -65,37 +57,6 @@ namespace ClientApp.Utils
|
|||||||
BikePower = 0;
|
BikePower = 0;
|
||||||
BikeBPM = 0;
|
BikeBPM = 0;
|
||||||
BikeResistance = 50;
|
BikeResistance = 50;
|
||||||
DoctorMessage = "No message received yet";
|
|
||||||
updateTimer = new System.Timers.Timer(1000);
|
|
||||||
updateTimer.Elapsed += UpdateTimer_Elapsed;
|
|
||||||
updateTimer.AutoReset = true;
|
|
||||||
updateTimer.Enabled = false;
|
|
||||||
|
|
||||||
noVRResponseTimer = new System.Timers.Timer(15000);
|
|
||||||
noVRResponseTimer.Elapsed += noVRResponseTimeout;
|
|
||||||
noVRResponseTimer.AutoReset = false;
|
|
||||||
noVRResponseTimer.Enabled = false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
|
||||||
{
|
|
||||||
UpdateInfoPanel();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void noVRResponseTimeout(object sender, System.Timers.ElapsedEventArgs e)
|
|
||||||
{
|
|
||||||
Write("VR RESPONSE TIMEOUT");
|
|
||||||
noVRResponseTimer.Stop();
|
|
||||||
sessionId = string.Empty;
|
|
||||||
tunnelId = string.Empty;
|
|
||||||
cameraId = string.Empty;
|
|
||||||
routeId = string.Empty;
|
|
||||||
panelId = string.Empty;
|
|
||||||
bikeId = string.Empty;
|
|
||||||
groundPlaneId = string.Empty;
|
|
||||||
terrainId = string.Empty;
|
|
||||||
OnEngineDisconnect?.Invoke();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -179,7 +140,7 @@ namespace ClientApp.Utils
|
|||||||
Console.WriteLine("set tunnel id to " + tunnelId);
|
Console.WriteLine("set tunnel id to " + tunnelId);
|
||||||
if (tunnelId == null)
|
if (tunnelId == null)
|
||||||
{
|
{
|
||||||
//Write("could not find a valid tunnel id!");
|
Write("could not find a valid tunnel id!");
|
||||||
OnNoTunnelId?.Invoke();
|
OnNoTunnelId?.Invoke();
|
||||||
Connected = false;
|
Connected = false;
|
||||||
FollowingRoute = false;
|
FollowingRoute = false;
|
||||||
@@ -189,7 +150,6 @@ namespace ClientApp.Utils
|
|||||||
{
|
{
|
||||||
Write("got tunnel id! " + tunnelId);
|
Write("got tunnel id! " + tunnelId);
|
||||||
Connected = true;
|
Connected = true;
|
||||||
noVRResponseTimer.Enabled = true;
|
|
||||||
OnSuccessFullConnection?.Invoke();
|
OnSuccessFullConnection?.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,14 +161,10 @@ namespace ClientApp.Utils
|
|||||||
//Console.WriteLine("Got serial " + serial);
|
//Console.WriteLine("Got serial " + serial);
|
||||||
if (serialResponses.ContainsKey(serial)) serialResponses[serial].Invoke(message);
|
if (serialResponses.ContainsKey(serial)) serialResponses[serial].Invoke(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
noVRResponseTimer.Stop();
|
|
||||||
noVRResponseTimer.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initScene()
|
public void initScene()
|
||||||
{
|
{
|
||||||
|
|
||||||
Write("initializing scene...");
|
Write("initializing scene...");
|
||||||
mainCommand = new Command(tunnelId);
|
mainCommand = new Command(tunnelId);
|
||||||
|
|
||||||
@@ -224,10 +180,11 @@ namespace ClientApp.Utils
|
|||||||
string headId = JSONParser.GetIdSceneInfoChild(message, "Head");
|
string headId = JSONParser.GetIdSceneInfoChild(message, "Head");
|
||||||
string handLeftId = JSONParser.GetIdSceneInfoChild(message, "LeftHand");
|
string handLeftId = JSONParser.GetIdSceneInfoChild(message, "LeftHand");
|
||||||
string handRightId = JSONParser.GetIdSceneInfoChild(message, "RightHand");
|
string handRightId = JSONParser.GetIdSceneInfoChild(message, "RightHand");
|
||||||
groundPlaneId = JSONParser.GetIdSceneInfoChild(message, "GroundPlane");
|
|
||||||
|
//Force(stream, mainCommand.DeleteNode(handLeftId, "deleteHandL"), "deleteHandL", (message) => Console.WriteLine("Left hand deleted"));
|
||||||
|
//Force(stream, mainCommand.DeleteNode(handRightId, "deleteHandR"), "deleteHandR", (message) => Console.WriteLine("Right hand deleted"));
|
||||||
});
|
});
|
||||||
// add the route and set the route id
|
// add the route and set the route id
|
||||||
CreateTerrain();
|
|
||||||
SendMessageAndOnResponse(mainCommand.RouteCommand("routeID"), "routeID", (message) => routeId = JSONParser.GetResponseUuid(message));
|
SendMessageAndOnResponse(mainCommand.RouteCommand("routeID"), "routeID", (message) => routeId = JSONParser.GetResponseUuid(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,7 +193,7 @@ namespace ClientApp.Utils
|
|||||||
Write("Starting route follow...");
|
Write("Starting route follow...");
|
||||||
FollowingRoute = true;
|
FollowingRoute = true;
|
||||||
|
|
||||||
SendMessageAndOnResponse(mainCommand.AddBikeModelAnim("bikeID", 0.01f), "bikeID",
|
SendMessageAndOnResponse(mainCommand.AddBikeModel("bikeID"), "bikeID",
|
||||||
(message) =>
|
(message) =>
|
||||||
{
|
{
|
||||||
bikeId = JSONParser.GetResponseUuid(message);
|
bikeId = JSONParser.GetResponseUuid(message);
|
||||||
@@ -248,49 +205,11 @@ namespace ClientApp.Utils
|
|||||||
|
|
||||||
WriteTextMessage(mainCommand.ColorPanel(panelId));
|
WriteTextMessage(mainCommand.ColorPanel(panelId));
|
||||||
UpdateInfoPanel();
|
UpdateInfoPanel();
|
||||||
updateTimer.Enabled = true;
|
|
||||||
|
|
||||||
while (cameraId == string.Empty) { }
|
while (cameraId == string.Empty) { }
|
||||||
SetFollowSpeed(5.0f);
|
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()
|
public void UpdateInfoPanel()
|
||||||
@@ -324,11 +243,6 @@ namespace ClientApp.Utils
|
|||||||
{
|
{
|
||||||
// TODO check if is drawn
|
// TODO check if is drawn
|
||||||
});
|
});
|
||||||
SendMessageAndOnResponse(mainCommand.showMessage(panelId, "message", DoctorMessage), "message",
|
|
||||||
(message) =>
|
|
||||||
{
|
|
||||||
// TODO check if is drawn
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check if every text is drawn!
|
// Check if every text is drawn!
|
||||||
|
|
||||||
@@ -337,46 +251,10 @@ namespace ClientApp.Utils
|
|||||||
|
|
||||||
private void SetFollowSpeed(float speed)
|
private void SetFollowSpeed(float speed)
|
||||||
{
|
{
|
||||||
Write("starting route follow");
|
|
||||||
WriteTextMessage(mainCommand.RouteFollow(routeId, bikeId, speed, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 }));
|
WriteTextMessage(mainCommand.RouteFollow(routeId, bikeId, speed, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 }));
|
||||||
WriteTextMessage(mainCommand.RouteFollow(routeId, cameraId, speed));
|
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
|
#endregion
|
||||||
|
|
||||||
#region message send/receive
|
#region message send/receive
|
||||||
@@ -428,7 +306,7 @@ namespace ClientApp.Utils
|
|||||||
}
|
}
|
||||||
public void Write(string msg)
|
public void Write(string msg)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("[ENGINECONNECT] " + msg);
|
Console.WriteLine("[ENGINECONNECT] " + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,15 +3,10 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Util
|
namespace ClientApp.Utils
|
||||||
{
|
{
|
||||||
public abstract class ObservableObject : INotifyPropertyChanged
|
public abstract class ObservableObject : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
public void OnPropertyChanged(string name)
|
|
||||||
{
|
|
||||||
PropertyChanged(this, new PropertyChangedEventArgs(name));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
|
|
||||||
namespace ClientApp.ValueConverters
|
|
||||||
{
|
|
||||||
//[ValueConversion(typeof(bool), typeof(BitmapImage))]
|
|
||||||
|
|
||||||
class BoolToMarkConverter : IValueConverter
|
|
||||||
{
|
|
||||||
public BitmapImage TrueImage { get; set; } = new BitmapImage(new Uri("pack://application:,,,/Images/Icons/CheckMark.png"));
|
|
||||||
public BitmapImage FalseImage { get; set; } = new BitmapImage(new Uri("pack://application:,,,/Images/Icons/CrossMark.png"));
|
|
||||||
|
|
||||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
||||||
{
|
|
||||||
if (!(value is bool))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool b = (bool)value;
|
|
||||||
if (b)
|
|
||||||
{
|
|
||||||
return this.TrueImage;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return this.FalseImage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,50 +7,32 @@ using System.Windows.Controls;
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using ClientApp.Utils;
|
using ClientApp.Utils;
|
||||||
using GalaSoft.MvvmLight.Command;
|
using GalaSoft.MvvmLight.Command;
|
||||||
using Util;
|
|
||||||
|
|
||||||
namespace ClientApp.ViewModels
|
namespace ClientApp.ViewModels
|
||||||
{
|
{
|
||||||
class LoginViewModel : ObservableObject
|
class LoginViewModel : ObservableObject
|
||||||
{
|
{
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
public ICommand LoginCommand { get; set; }
|
private MainWindowViewModel mainWindowViewModel;
|
||||||
|
|
||||||
public bool LoginStatus { get; set; } = false;
|
|
||||||
|
|
||||||
public bool InvertedLoginStatus { get; set; }
|
|
||||||
|
|
||||||
private MainWindowViewModel MainWindowViewModel;
|
|
||||||
public LoginViewModel(MainWindowViewModel mainWindowViewModel)
|
public LoginViewModel(MainWindowViewModel mainWindowViewModel)
|
||||||
{
|
{
|
||||||
this.MainWindowViewModel = mainWindowViewModel;
|
this.mainWindowViewModel = mainWindowViewModel;
|
||||||
LoginCommand = new RelayCommand<object>((parameter) =>
|
LoginCommand = new RelayCommand<object>((parameter) =>
|
||||||
{
|
{
|
||||||
//TODO send username and password to server
|
//TODO send username and password to server
|
||||||
this.MainWindowViewModel.client.tryLogin(Username, ((PasswordBox)parameter).Password);
|
this.mainWindowViewModel.client.tryLogin(Username, ((PasswordBox)parameter).Password);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ICommand LoginCommand { get; set; }
|
||||||
|
|
||||||
internal void setLoginStatus(bool status)
|
internal void setLoginStatus(bool status)
|
||||||
{
|
{
|
||||||
this.MainWindowViewModel.InfoModel.ConnectedToServer = status;
|
this.mainWindowViewModel.InfoModel.ConnectedToServer = true;
|
||||||
this.InvertedLoginStatus = !status;
|
|
||||||
if (status)
|
if (status)
|
||||||
{
|
{
|
||||||
this.MainWindowViewModel.SelectedViewModel = new MainViewModel(MainWindowViewModel);
|
this.mainWindowViewModel.SelectedViewModel = new MainViewModel(mainWindowViewModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void DoctorConnected(string name)
|
|
||||||
{
|
|
||||||
this.MainWindowViewModel.InfoModel.DoctorConnected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void DoctorDisconnected(string name)
|
|
||||||
{
|
|
||||||
this.MainWindowViewModel.InfoModel.DoctorConnected = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,46 +1,30 @@
|
|||||||
using ClientApp.Models;
|
using ClientApp.Models;
|
||||||
using ClientApp.Utils;
|
using ClientApp.Utils;
|
||||||
using GalaSoft.MvvmLight.Command;
|
using GalaSoft.MvvmLight.Command;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using Util;
|
|
||||||
|
|
||||||
namespace ClientApp.ViewModels
|
namespace ClientApp.ViewModels
|
||||||
{
|
{
|
||||||
class MainViewModel : ObservableObject
|
class MainViewModel : ObservableObject
|
||||||
{
|
{
|
||||||
public ICommand RetryServerCommand { get; set; }
|
public ICommand RetryServerCommand { get; set; }
|
||||||
public MainWindowViewModel MainWindowViewModel { get; set; }
|
public ICommand RetryVREngineCommand { get; set; }
|
||||||
|
public MainWindowViewModel MainWindowViewModel;
|
||||||
|
|
||||||
private Client client;
|
|
||||||
|
|
||||||
public MainViewModel(MainWindowViewModel mainWindowViewModel)
|
public MainViewModel(MainWindowViewModel mainWindowViewModel)
|
||||||
{
|
{
|
||||||
this.MainWindowViewModel = mainWindowViewModel;
|
this.MainWindowViewModel = mainWindowViewModel;
|
||||||
client = this.MainWindowViewModel.client;
|
|
||||||
client.engineConnectFailed = retryEngineConnection;
|
|
||||||
client.engineConnectSuccess = succesEngineConnection;
|
|
||||||
this.RetryServerCommand = new RelayCommand(() =>
|
this.RetryServerCommand = new RelayCommand(() =>
|
||||||
{
|
{
|
||||||
//try connect server
|
//try connect server
|
||||||
this.MainWindowViewModel.InfoModel.ConnectedToServer = true;
|
this.MainWindowViewModel.InfoModel.ConnectedToServer = true;
|
||||||
});
|
});
|
||||||
|
this.RetryVREngineCommand = new RelayCommand(() =>
|
||||||
|
{
|
||||||
|
//try connect vr-engine
|
||||||
|
this.MainWindowViewModel.InfoModel.ConnectedToVREngine = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void retryEngineConnection()
|
|
||||||
{
|
|
||||||
this.MainWindowViewModel.InfoModel.ConnectedToVREngine = false;
|
|
||||||
this.MainWindowViewModel.InfoModel.CanConnectToVR = true;
|
|
||||||
client.engineConnection.CreateConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void succesEngineConnection()
|
|
||||||
{
|
|
||||||
this.MainWindowViewModel.InfoModel.ConnectedToVREngine = true;
|
|
||||||
this.MainWindowViewModel.InfoModel.CanConnectToVR = false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,137 +1,26 @@
|
|||||||
using ClientApp.MagicCode;
|
using ClientApp.Models;
|
||||||
using ClientApp.Models;
|
|
||||||
using ClientApp.Utils;
|
using ClientApp.Utils;
|
||||||
using GalaSoft.MvvmLight.Command;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Util;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Input;
|
|
||||||
|
|
||||||
namespace ClientApp.ViewModels
|
namespace ClientApp.ViewModels
|
||||||
{
|
{
|
||||||
class MainWindowViewModel : ObservableObject
|
class MainWindowViewModel : ObservableObject
|
||||||
{
|
{
|
||||||
#region private members
|
|
||||||
|
|
||||||
private Window mWindow;
|
|
||||||
|
|
||||||
private int mOuterMarginSize = 10;
|
|
||||||
private int mWindowRadius = 10;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region commands
|
|
||||||
|
|
||||||
public ICommand MinimizeCommand { get; set; }
|
|
||||||
|
|
||||||
public ICommand MaximizeCommand { get; set; }
|
|
||||||
|
|
||||||
public ICommand CloseCommand { get; set; }
|
|
||||||
|
|
||||||
public ICommand MenuCommand { get; set; }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public properties
|
|
||||||
public Info InfoModel { get; set; }
|
public Info InfoModel { get; set; }
|
||||||
|
|
||||||
public ObservableObject SelectedViewModel { get; set; }
|
public ObservableObject SelectedViewModel { get; set; }
|
||||||
|
|
||||||
public Client client { get; }
|
public Client client { get; }
|
||||||
|
|
||||||
/// <summary>
|
public MainWindowViewModel(Client client)
|
||||||
/// size of the resize border around the window
|
|
||||||
/// </summary>
|
|
||||||
|
|
||||||
public double MinimumWidth { get; set; } = 250;
|
|
||||||
|
|
||||||
public double MinimumHeight { get; set; } = 250;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public int ResizeBorder { get; set; } = 6;
|
|
||||||
|
|
||||||
public Thickness ResizeBorderThickness { get { return new Thickness(ResizeBorder + OuterMarginSize); } }
|
|
||||||
|
|
||||||
public Thickness InnerContentPadding { get { return new Thickness(ResizeBorder); } }
|
|
||||||
|
|
||||||
|
|
||||||
public Thickness OuterMarginThickness { get { return new Thickness(OuterMarginSize); } }
|
|
||||||
|
|
||||||
public CornerRadius WindowCornerRadius { get { return new CornerRadius(WindowRadius); } }
|
|
||||||
|
|
||||||
public int OuterMarginSize
|
|
||||||
{
|
{
|
||||||
get
|
|
||||||
{
|
|
||||||
return mWindow.WindowState == WindowState.Maximized ? 0 : mOuterMarginSize;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
mOuterMarginSize = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int WindowRadius
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return mWindow.WindowState == WindowState.Maximized ? 0 : mWindowRadius;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
mWindowRadius = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int TitleHeight { get; set; } = 42;
|
|
||||||
|
|
||||||
public GridLength TitleHeightGridLength { get { return new GridLength(TitleHeight + ResizeBorder); } }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
public MainWindowViewModel(Window window, Client client)
|
|
||||||
{
|
|
||||||
this.mWindow = window;
|
|
||||||
|
|
||||||
this.mWindow.StateChanged += (sender, e) =>
|
|
||||||
{
|
|
||||||
OnPropertyChanged(nameof(ResizeBorderThickness));
|
|
||||||
OnPropertyChanged(nameof(OuterMarginThickness));
|
|
||||||
OnPropertyChanged(nameof(WindowCornerRadius));
|
|
||||||
OnPropertyChanged(nameof(OuterMarginSize));
|
|
||||||
OnPropertyChanged(nameof(WindowRadius));
|
|
||||||
};
|
|
||||||
|
|
||||||
this.InfoModel = new Info();
|
this.InfoModel = new Info();
|
||||||
this.client = client;
|
this.client = client;
|
||||||
LoginViewModel loginViewModel = new LoginViewModel(this);
|
LoginViewModel loginViewModel = new LoginViewModel(this);
|
||||||
SelectedViewModel = loginViewModel;
|
SelectedViewModel = loginViewModel;
|
||||||
this.client.SetLoginViewModel(loginViewModel);
|
this.client.SetLoginViewModel(loginViewModel);
|
||||||
|
|
||||||
this.MinimizeCommand = new RelayCommand(() => this.mWindow.WindowState = WindowState.Minimized);
|
|
||||||
this.MaximizeCommand = new RelayCommand(() => this.mWindow.WindowState ^= WindowState.Maximized);
|
|
||||||
this.CloseCommand = new RelayCommand(() => this.mWindow.Close());
|
|
||||||
this.MenuCommand = new RelayCommand(() => SystemCommands.ShowSystemMenu(this.mWindow, GetMousePosition()));
|
|
||||||
|
|
||||||
var resizer = new WindowResizer(this.mWindow);
|
|
||||||
|
|
||||||
this.mWindow.Closed += (sender, e) => this.client.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#region helper
|
|
||||||
|
|
||||||
private Point GetMousePosition()
|
|
||||||
{
|
|
||||||
Debug.WriteLine("getmousePosition called");
|
|
||||||
var p = Mouse.GetPosition(this.mWindow);
|
|
||||||
return new Point(p.X + this.mWindow.Left, p.Y + this.mWindow.Top);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,18 @@
|
|||||||
<Page x:Class="ClientApp.Views.LoginView"
|
<UserControl x:Class="ClientApp.Views.LoginView"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:local="clr-namespace:ClientApp.Views"
|
xmlns:local="clr-namespace:ClientApp.Views"
|
||||||
xmlns:viewModels="clr-namespace:ClientApp.ViewModels"
|
|
||||||
xmlns:Util="clr-namespace:Util.MagicCode"
|
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
ShowsNavigationUI="False"
|
|
||||||
d:DesignHeight="450" d:DesignWidth="800">
|
d:DesignHeight="450" d:DesignWidth="800">
|
||||||
<DockPanel>
|
<DockPanel>
|
||||||
<DockPanel.Background>
|
|
||||||
<ImageBrush TileMode="Tile" ViewportUnits="Absolute" Viewport="0 0 64 64" ImageSource="\images\stone.png"/>
|
|
||||||
</DockPanel.Background>
|
|
||||||
<StackPanel VerticalAlignment="Center" Width="auto">
|
<StackPanel VerticalAlignment="Center" Width="auto">
|
||||||
<Label Content="Username" HorizontalContentAlignment="Center" />
|
<Label Content="Username" HorizontalContentAlignment="Center" />
|
||||||
<TextBox x:Name="Username" Text="{Binding Username}" TextWrapping="Wrap" Width="120" Util:FocusAdvancement.AdvancesByEnterKey="True" />
|
<TextBox x:Name="Username" Text="{Binding Username}" TextWrapping="Wrap" Width="120"/>
|
||||||
<Label Content="Password" HorizontalContentAlignment="Center"/>
|
<Label Content="Password" HorizontalContentAlignment="Center"/>
|
||||||
<PasswordBox x:Name="Password" Width="120" Util:FocusAdvancement.AdvancesByEnterKey="True"/>
|
<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"/>
|
<Button x:Name="Login" Content="Login" Command="{Binding LoginCommand}" CommandParameter="{Binding ElementName=Password}" Margin="0,20,0,0" Width="120"/>
|
||||||
<Label Content="Login failed" Foreground="Red" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Background="Transparent" IsEnabled="{Binding InvertedLoginStatus}"/>
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
</Page>
|
</UserControl>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace ClientApp.Views
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interaction logic for LoginView.xaml
|
/// Interaction logic for LoginView.xaml
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class LoginView : Page
|
public partial class LoginView : UserControl
|
||||||
{
|
{
|
||||||
public LoginView()
|
public LoginView()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,16 +1,11 @@
|
|||||||
<Page x:Class="ClientApp.Views.MainView"
|
<UserControl x:Class="ClientApp.Views.MainView"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:local="clr-namespace:ClientApp.Views"
|
xmlns:local="clr-namespace:ClientApp.Views"
|
||||||
xmlns:converter="clr-namespace:ClientApp.ValueConverters"
|
|
||||||
ShowsNavigationUI="False"
|
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="450" d:DesignWidth="800">
|
d:DesignHeight="450" d:DesignWidth="800">
|
||||||
<Page.Resources>
|
|
||||||
<converter:BoolToMarkConverter x:Key="BoolToMarkConverter"/>
|
|
||||||
</Page.Resources>
|
|
||||||
<DockPanel>
|
<DockPanel>
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
@@ -19,22 +14,39 @@
|
|||||||
<ColumnDefinition Width="*"/>
|
<ColumnDefinition Width="*"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition/>
|
||||||
|
<RowDefinition/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
<StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal" Margin="20" HorizontalAlignment="Center">
|
<StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal" Margin="10">
|
||||||
<Label Content="Connected to server:" VerticalAlignment="Center"/>
|
<Label Content="Connected to server:"/>
|
||||||
<Image Source="{Binding Converter={StaticResource BoolToMarkConverter},Path=MainWindowViewModel.InfoModel.ConnectedToServer}" Stretch="Uniform" Width="20" Height="20"/>
|
<Label Content="{Binding Path=MainWindowViewModel.InfoModel.ConnectedToServer}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal" Margin="20" HorizontalAlignment="Center">
|
<StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal" Margin="10">
|
||||||
<Label Content="Connected to VR-Engine:" VerticalAlignment="Center"/>
|
<Label Content="Connected to VR-Engine:"/>
|
||||||
<Image Source="{Binding Converter={StaticResource BoolToMarkConverter},Path=MainWindowViewModel.InfoModel.ConnectedToVREngine}" Stretch="Uniform" Width="20" Height="20"/>
|
<Label Content="{Binding Path=MainWindowViewModel.InfoModel.ConnectedToVREngine}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<StackPanel Grid.Column="2" Grid.Row="0" Orientation="Horizontal" Margin="20" HorizontalAlignment="Center">
|
<StackPanel Grid.Column="2" Grid.Row="0" Orientation="Horizontal" Margin="10">
|
||||||
<Label Content="Doctor connected:" VerticalAlignment="Center"/>
|
<Label Content="Doctor connected:"/>
|
||||||
<Image Source="{Binding Converter={StaticResource BoolToMarkConverter},Path=MainWindowViewModel.InfoModel.DoctorConnected}" Stretch="Uniform" Width="20" Height="20"/>
|
<Label Content="{Binding Path=MainWindowViewModel.InfoModel.DoctorConnected}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
<Button Grid.Column="0" Grid.Row="1" Command="{Binding RetryServerCommand}" Width="50" Height="20">
|
||||||
|
<Button.Content>
|
||||||
|
<TextBlock TextWrapping="Wrap" Text="retry"/>
|
||||||
|
</Button.Content>
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button Grid.Column="1" Grid.Row="1" Command="{Binding RetryVREngineCommand}" Width="50" Height="20">
|
||||||
|
<Button.Content>
|
||||||
|
<TextBlock TextWrapping="Wrap" Text="retry"/>
|
||||||
|
</Button.Content>
|
||||||
|
</Button>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
</Page>
|
</UserControl>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace ClientApp.Views
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interaction logic for MainView.xaml
|
/// Interaction logic for MainView.xaml
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainView : Page
|
public partial class MainView : UserControl
|
||||||
{
|
{
|
||||||
public MainView()
|
public MainView()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,124 +5,12 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:ClientApp"
|
xmlns:local="clr-namespace:ClientApp"
|
||||||
xmlns:views="clr-namespace:ClientApp.Views"
|
xmlns:views="clr-namespace:ClientApp.Views"
|
||||||
xmlns:images="clrnamespace.Images"
|
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
WindowStyle="None"
|
Title="Whaazzzzuuuuuuuup" Height="450" Width="800">
|
||||||
AllowsTransparency="True"
|
|
||||||
x:Name="applicatonWindow"
|
|
||||||
WindowStartupLocation="CenterScreen"
|
|
||||||
MinHeight="{Binding MinimumHeight}"
|
|
||||||
MinWidth="{Binding MinimumWidth}"
|
|
||||||
Title="Whaazzzzuuuuuuuup">
|
|
||||||
<!--Icon="/Images/Logo/icon1_small.ico"-->
|
|
||||||
<!--Icon="pack://application:,,,/Images/Log/icon1_small.ico"-->
|
|
||||||
|
|
||||||
<Window.Resources>
|
|
||||||
<Style TargetType="{x:Type local:MainWindow}">
|
|
||||||
<Setter Property="Template">
|
|
||||||
<Setter.Value>
|
|
||||||
<ControlTemplate TargetType="{x:Type Window}">
|
|
||||||
<Border Padding="{Binding OuterMarginThickness, FallbackValue=10}" >
|
|
||||||
<Grid>
|
|
||||||
|
|
||||||
<!-- opacity mask -->
|
|
||||||
<Border x:Name="Container"
|
|
||||||
Background="{StaticResource BackgroundLightBrush}"
|
|
||||||
CornerRadius="{Binding WindowCornerRadius, FallbackValue=10}"/>
|
|
||||||
|
|
||||||
|
|
||||||
<Border CornerRadius="{Binding WindowCornerRadius, FallbackValue=10}"
|
<DockPanel>
|
||||||
Background="{StaticResource BackgroundVeryLightBrush}">
|
|
||||||
<Border.Effect>
|
|
||||||
<DropShadowEffect ShadowDepth="0" Opacity="0.2"/>
|
|
||||||
</Border.Effect>
|
|
||||||
</Border>
|
|
||||||
|
|
||||||
|
|
||||||
<Grid>
|
|
||||||
|
|
||||||
<Grid.OpacityMask>
|
|
||||||
<VisualBrush Visual="{Binding ElementName=Container}"/>
|
|
||||||
</Grid.OpacityMask>
|
|
||||||
|
|
||||||
<Grid.RowDefinitions>
|
|
||||||
<RowDefinition Height="{Binding TitleHeightGridLength, FallbackValue=42}"/>
|
|
||||||
<RowDefinition Height="*"/>
|
|
||||||
</Grid.RowDefinitions>
|
|
||||||
|
|
||||||
<!-- Title bar -->
|
|
||||||
<Grid Grid.Column="0" Grid.Row="0" Panel.ZIndex="1" Background="{StaticResource BackgroundLightBrush}">
|
|
||||||
<Grid.ColumnDefinitions>
|
|
||||||
<ColumnDefinition Width="Auto"/>
|
|
||||||
<ColumnDefinition Width="*"/>
|
|
||||||
<ColumnDefinition Width="Auto"/>
|
|
||||||
</Grid.ColumnDefinitions>
|
|
||||||
|
|
||||||
<!-- icon -->
|
|
||||||
<Button Grid.Column="0" Style="{StaticResource SystemIconButton}" Command="{Binding MenuCommand}">
|
|
||||||
<Image Source="/Images/Logo/icon1.ico"/>
|
|
||||||
<!--<TextBlock Text="icon"/>-->
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<!-- Title -->
|
|
||||||
<Viewbox Grid.Column="1" Margin="0">
|
|
||||||
<TextBlock Style="{StaticResource HeaderText}" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title, FallbackValue=failed}"/>
|
|
||||||
</Viewbox>
|
|
||||||
|
|
||||||
<!-- Window buttons -->
|
|
||||||
<StackPanel Grid.Column="2" Orientation="Horizontal">
|
|
||||||
<Button Style="{StaticResource WindowControlButton}" Content="_" Command="{Binding MinimizeCommand}"/>
|
|
||||||
<Button Style="{StaticResource WindowControlButton}" Content="[]" Command="{Binding MaximizeCommand}"/>
|
|
||||||
<Button Style="{StaticResource WindowCloseButton}" Content="X" Command="{Binding CloseCommand}"/>
|
|
||||||
</StackPanel>
|
|
||||||
|
|
||||||
</Grid>
|
|
||||||
|
|
||||||
<!-- Page content -->
|
|
||||||
<Border Grid.Row="1" Grid.Column="0">
|
|
||||||
<ContentPresenter Content="{TemplateBinding Content}"/>
|
|
||||||
</Border>
|
|
||||||
|
|
||||||
<!-- shadow? -->
|
|
||||||
<Border Grid.Row="1" Height="6" BorderThickness="0 0.2 0 0" VerticalAlignment="Top">
|
|
||||||
<!--<Border.BorderBrush>
|
|
||||||
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
|
|
||||||
<GradientStop Color="{StaticResource BackgroundSemiLight}" Offset="0.0"/>
|
|
||||||
<GradientStop Color="{StaticResource BackgroundVeryLight}" Offset="1.0"/>
|
|
||||||
</LinearGradientBrush>
|
|
||||||
</Border.BorderBrush>-->
|
|
||||||
|
|
||||||
|
|
||||||
<Border.Background>
|
|
||||||
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
|
|
||||||
<GradientStop Color="Transparent" Offset="1.0"/>
|
|
||||||
<GradientStop Color="#7000" Offset="0.0"/>
|
|
||||||
</LinearGradientBrush>
|
|
||||||
</Border.Background>
|
|
||||||
</Border>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</Grid>
|
|
||||||
|
|
||||||
</Grid>
|
|
||||||
</Border>
|
|
||||||
</ControlTemplate>
|
|
||||||
</Setter.Value>
|
|
||||||
</Setter>
|
|
||||||
</Style>
|
|
||||||
</Window.Resources>
|
|
||||||
|
|
||||||
<WindowChrome.WindowChrome>
|
|
||||||
<WindowChrome
|
|
||||||
ResizeBorderThickness="{Binding ResizeBorderThickness}"
|
|
||||||
CaptionHeight="{Binding TitleHeight}"
|
|
||||||
CornerRadius="0"
|
|
||||||
GlassFrameThickness="0"/>
|
|
||||||
</WindowChrome.WindowChrome>
|
|
||||||
|
|
||||||
<Grid>
|
|
||||||
<Frame Content="{Binding SelectedViewModel}" Focusable="False" NavigationUIVisibility="Hidden"/>
|
|
||||||
<Label Content="gemaakt door: mensen" DockPanel.Dock="Bottom" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontStyle="Italic" Foreground="Gray"/>
|
<Label Content="gemaakt door: mensen" DockPanel.Dock="Bottom" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontStyle="Italic" Foreground="Gray"/>
|
||||||
</Grid>
|
<ContentControl HorizontalAlignment="Center" VerticalAlignment="Center" Content="{Binding SelectedViewModel}" />
|
||||||
|
</DockPanel>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ using System.Windows.Shapes;
|
|||||||
using ClientApp.Utils;
|
using ClientApp.Utils;
|
||||||
using Hardware.Simulators;
|
using Hardware.Simulators;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using ProftaakRH;
|
|
||||||
|
|
||||||
namespace ClientApp
|
namespace ClientApp
|
||||||
{
|
{
|
||||||
@@ -25,13 +24,14 @@ namespace ClientApp
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
private IHandler handler;
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
Client client = new Client();
|
Client client = new Client();
|
||||||
|
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
DataContext = new MainWindowViewModel(this, client);
|
DataContext = new MainWindowViewModel(client);
|
||||||
|
|
||||||
|
|
||||||
//BLEHandler bLEHandler = new BLEHandler(client);
|
//BLEHandler bLEHandler = new BLEHandler(client);
|
||||||
|
|
||||||
@@ -39,19 +39,16 @@ namespace ClientApp
|
|||||||
|
|
||||||
//client.setHandler(bLEHandler);
|
//client.setHandler(bLEHandler);
|
||||||
|
|
||||||
|
|
||||||
BikeSimulator bikeSimulator = new BikeSimulator(client);
|
BikeSimulator bikeSimulator = new BikeSimulator(client);
|
||||||
|
|
||||||
Thread newThread = new Thread(new ThreadStart(bikeSimulator.StartSimulation));
|
Thread newThread = new Thread(new ThreadStart(bikeSimulator.StartSimulation));
|
||||||
newThread.Start();
|
newThread.Start();
|
||||||
|
|
||||||
client.SetHandler(bikeSimulator);
|
|
||||||
handler = bikeSimulator;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnClosed(EventArgs e)
|
client.SetHandler(bikeSimulator);
|
||||||
{
|
|
||||||
base.OnClosed(e);
|
|
||||||
handler.stop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
<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>
|
|
||||||
<ResourceDictionary>
|
|
||||||
<DataTemplate DataType="{x:Type viewModels:MainViewModel}">
|
|
||||||
<views:MainView />
|
|
||||||
<!-- This is a Page -->
|
|
||||||
</DataTemplate>
|
|
||||||
<DataTemplate DataType="{x:Type viewModels:LoginViewModel}">
|
|
||||||
<views:LoginView />
|
|
||||||
<!-- This is a Page -->
|
|
||||||
</DataTemplate>
|
|
||||||
<DataTemplate DataType="{x:Type viewModels:ClientInfoViewModel}">
|
|
||||||
<views:ClientInfoView/>
|
|
||||||
</DataTemplate>
|
|
||||||
|
|
||||||
<ResourceDictionary.MergedDictionaries>
|
|
||||||
<ResourceDictionary Source="WPFStuff/Styles/Fonts.xaml"/>
|
|
||||||
<ResourceDictionary Source="WPFStuff/Styles/Colors.xaml"/>
|
|
||||||
<ResourceDictionary Source="WPFStuff/Styles/Buttons.xaml"/>
|
|
||||||
<ResourceDictionary Source="WPFStuff/Styles/Texts.xaml"/>
|
|
||||||
<ResourceDictionary Source="WPFStuff/Styles/Windows.xaml"/>
|
|
||||||
</ResourceDictionary.MergedDictionaries>
|
|
||||||
</ResourceDictionary>
|
|
||||||
|
|
||||||
</Application.Resources>
|
|
||||||
</Application>
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
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
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
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)
|
|
||||||
)]
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>WinExe</OutputType>
|
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
|
||||||
<UseWPF>true</UseWPF>
|
|
||||||
<ApplicationIcon>doctor.ico</ApplicationIcon>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Remove="img\doctor.ico" />
|
|
||||||
<None Remove="img\patient.png" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Content Include="img\doctor.ico">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
<Content Include="img\patient.png">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="AsyncAwaitBestPractices.MVVM" Version="4.3.0" />
|
|
||||||
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
|
|
||||||
<PackageReference Include="MvvmLightLibsStd10" Version="5.4.1.1" />
|
|
||||||
<PackageReference Include="Prism.Wpf" Version="8.0.0.1909" />
|
|
||||||
<PackageReference Include="PropertyChanged.Fody" Version="3.2.9" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\ProftaakRH\ProftaakRH.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
|
||||||
<PropertyChanged />
|
|
||||||
</Weavers>
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
<?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>
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using LiveCharts;
|
|
||||||
using LiveCharts.Configurations;
|
|
||||||
using Util;
|
|
||||||
|
|
||||||
namespace DoctorApp.Models
|
|
||||||
{
|
|
||||||
class Chart : ObservableObject,INotifyPropertyChanged
|
|
||||||
{
|
|
||||||
|
|
||||||
private double _axisMax;
|
|
||||||
private double _axisMin;
|
|
||||||
private double _trend;
|
|
||||||
|
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
|
||||||
|
|
||||||
public ChartValues<MeasureModel> ChartValues { get; set; }
|
|
||||||
public Func<double, string> DateTimeFormatter { get; set; }
|
|
||||||
|
|
||||||
public PatientInfo PatientInfo { get; set; }
|
|
||||||
public double AxisStep { get; set; }
|
|
||||||
public double AxisUnit { get; set; }
|
|
||||||
|
|
||||||
public double AxisMax
|
|
||||||
{
|
|
||||||
get { return _axisMax; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_axisMax = value;
|
|
||||||
OnPropertyChanged("AxisMax");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public double AxisMin
|
|
||||||
{
|
|
||||||
get { return _axisMin; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_axisMin = value;
|
|
||||||
OnPropertyChanged("AxisMin");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsReading { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Chart(PatientInfo patientInfo)
|
|
||||||
{
|
|
||||||
var mapper = Mappers.Xy<MeasureModel>()
|
|
||||||
.X(model => model.DateTime.Ticks)
|
|
||||||
.Y(model => model.Value);
|
|
||||||
|
|
||||||
Charting.For<MeasureModel>(mapper);
|
|
||||||
|
|
||||||
ChartValues = new ChartValues<MeasureModel>();
|
|
||||||
|
|
||||||
DateTimeFormatter = value => new DateTime((long)value).ToString("mm:ss");
|
|
||||||
|
|
||||||
AxisStep = TimeSpan.FromSeconds(1).Ticks;
|
|
||||||
|
|
||||||
AxisUnit = TimeSpan.TicksPerSecond;
|
|
||||||
|
|
||||||
SetAxisLimits(DateTime.Now);
|
|
||||||
|
|
||||||
IsReading = true;
|
|
||||||
|
|
||||||
ChartValues.Add(new MeasureModel
|
|
||||||
{
|
|
||||||
DateTime = DateTime.Now,
|
|
||||||
Value = 8
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetAxisLimits(DateTime now)
|
|
||||||
{
|
|
||||||
AxisMax = now.Ticks + TimeSpan.FromSeconds(1).Ticks; // lets force the axis to be 1 second ahead
|
|
||||||
AxisMin = now.Ticks - TimeSpan.FromSeconds(8).Ticks; // and 8 seconds behind
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnPropertyChanged(string propertyName = null)
|
|
||||||
{
|
|
||||||
if (PropertyChanged != null)
|
|
||||||
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void NewValue(double value)
|
|
||||||
{
|
|
||||||
var now = DateTime.Now;
|
|
||||||
_trend = value;
|
|
||||||
ChartValues.Add(new MeasureModel
|
|
||||||
{
|
|
||||||
DateTime = now,
|
|
||||||
Value = _trend
|
|
||||||
});
|
|
||||||
|
|
||||||
SetAxisLimits(now);
|
|
||||||
|
|
||||||
if (ChartValues.Count > 150) ChartValues.RemoveAt(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
Debug.WriteLine("clear");
|
|
||||||
ChartValues.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class MeasureModel
|
|
||||||
{
|
|
||||||
public DateTime DateTime { get; set; }
|
|
||||||
public double Value { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
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; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
using System.Collections.ObjectModel;
|
|
||||||
using Util;
|
|
||||||
|
|
||||||
namespace DoctorApp.Models
|
|
||||||
{
|
|
||||||
class PatientInfo : ObservableObject
|
|
||||||
{
|
|
||||||
public ObservableCollection<string> ChatLog { get; set; }
|
|
||||||
public string Username { get; set; }
|
|
||||||
|
|
||||||
public string Status { get; set; }
|
|
||||||
|
|
||||||
public double Speed { get; set; }
|
|
||||||
|
|
||||||
public int BPM { get; set; }
|
|
||||||
|
|
||||||
public float Resistance { get; set; }
|
|
||||||
public int Acc_Power { get; set; }
|
|
||||||
|
|
||||||
public int Curr_Power { get; set; }
|
|
||||||
|
|
||||||
public int Distance { get; set; }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,254 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Text;
|
|
||||||
using DoctorApp.ViewModels;
|
|
||||||
using Microsoft.Win32;
|
|
||||||
using ProftaakRH;
|
|
||||||
using Util;
|
|
||||||
|
|
||||||
namespace DoctorApp.Utils
|
|
||||||
{
|
|
||||||
public delegate void EngineCallback();
|
|
||||||
public class Client
|
|
||||||
{
|
|
||||||
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 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)
|
|
||||||
{
|
|
||||||
if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead))
|
|
||||||
return;
|
|
||||||
|
|
||||||
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("Doctor 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!");
|
|
||||||
break;
|
|
||||||
case DataParser.STOP_SESSION:
|
|
||||||
Console.WriteLine("Stop session identifier");
|
|
||||||
break;
|
|
||||||
case DataParser.SET_RESISTANCE:
|
|
||||||
Console.WriteLine("Set resistance identifier");
|
|
||||||
break;
|
|
||||||
case DataParser.NEW_CONNECTION:
|
|
||||||
this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromJson(payloadbytes));
|
|
||||||
break;
|
|
||||||
case DataParser.DISCONNECT:
|
|
||||||
this.MainViewModel.DisconnectedUser(DataParser.getUsernameFromJson(payloadbytes));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (DataParser.isRawDataBikeDoctor(messageBytes))
|
|
||||||
{
|
|
||||||
MainViewModel.TransferDataToClientBike(payloadbytes);
|
|
||||||
}
|
|
||||||
else if (DataParser.isRawDataBPMDoctor(messageBytes))
|
|
||||||
{
|
|
||||||
MainViewModel.TransferDataToClientBPM(payloadbytes);
|
|
||||||
}
|
|
||||||
else if (DataParser.IsHistoricBikeData(messageBytes))
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
// todo change to name of patient
|
|
||||||
string name = MainViewModel.Tabs[0].PatientInfo.Username;
|
|
||||||
string result = "PATIENT INFO FOR " + name + "\n\n";
|
|
||||||
for (int i = 0; i < payloadbytes.Length; i += 8)
|
|
||||||
{
|
|
||||||
byte[] res = new byte[8];
|
|
||||||
Array.Copy(payloadbytes, i, res, 0, 8);
|
|
||||||
result += handleBikeHistory(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/" + name + ".txt";
|
|
||||||
File.WriteAllText(path,result);
|
|
||||||
}
|
|
||||||
Array.Copy(totalBuffer, expectedMessageLength, totalBuffer, 0, (totalBufferReceived - expectedMessageLength)); //maybe unsafe idk
|
|
||||||
totalBufferReceived -= expectedMessageLength;
|
|
||||||
expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead) || !this.client.Connected)
|
|
||||||
return;
|
|
||||||
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private string handleBikeHistory(byte[] bytes)
|
|
||||||
{
|
|
||||||
string res = string.Empty;
|
|
||||||
switch (bytes[0])
|
|
||||||
{
|
|
||||||
case 0x10:
|
|
||||||
res += "Time elapsed: " + bytes[2] / 4 + "s\n";
|
|
||||||
res += "Distance traveled: " + bytes[3] + "\n";
|
|
||||||
int input = bytes[4] | (bytes[5] << 8);
|
|
||||||
res += $"Speed {input * 0.01}m/s\n";
|
|
||||||
res += $"Heart rate: { Convert.ToString(bytes[6], 10)}";
|
|
||||||
break;
|
|
||||||
case 0x19:
|
|
||||||
res += $"RPM: {bytes[2]}\n";
|
|
||||||
int accumPower = bytes[3] | (bytes[4] << 8);
|
|
||||||
res += $"Accumulated power: {accumPower} watt\n";
|
|
||||||
int instantPower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
|
|
||||||
if (instantPower != 0xFFF)
|
|
||||||
{
|
|
||||||
res += $"Instant power: {instantPower} watt\n";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
return res + "\n";
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// starts sending a message to the server
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">the message to send</param>
|
|
||||||
public 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void SetLoginViewModel(LoginViewModel loginViewModel)
|
|
||||||
{
|
|
||||||
this.LoginViewModel = loginViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void SetMainViewModel(MainViewModel mainViewModel)
|
|
||||||
{
|
|
||||||
this.MainViewModel = mainViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void SetClientInfoViewModel(ClientInfoViewModel clientInfoViewModel)
|
|
||||||
{
|
|
||||||
this.ClientInfoViewModel = clientInfoViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Debug.WriteLine("client dispose called");
|
|
||||||
sendMessage(DataParser.getDisconnectJson(LoginViewModel.Username));
|
|
||||||
this.stream.Dispose();
|
|
||||||
this.client.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,149 +0,0 @@
|
|||||||
using DoctorApp.Models;
|
|
||||||
using DoctorApp.Utils;
|
|
||||||
using GalaSoft.MvvmLight.Command;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using Util;
|
|
||||||
|
|
||||||
namespace DoctorApp.ViewModels
|
|
||||||
{
|
|
||||||
|
|
||||||
class ClientInfoViewModel : ObservableObject
|
|
||||||
{
|
|
||||||
public PatientInfo PatientInfo { get; set; }
|
|
||||||
|
|
||||||
private string _mySelectedItem;
|
|
||||||
public string MySelectedItem
|
|
||||||
{
|
|
||||||
get { return _mySelectedItem; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
Chart.Clear();
|
|
||||||
_mySelectedItem = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICommand StartSession { get; set; }
|
|
||||||
|
|
||||||
public ICommand StopSession { get; set; }
|
|
||||||
|
|
||||||
public ICommand Chat { get; set; }
|
|
||||||
|
|
||||||
public ICommand ChatToAll { get; set; }
|
|
||||||
|
|
||||||
public ICommand ClientInfo { get; set; }
|
|
||||||
|
|
||||||
public ICommand SetResistance { get; set; }
|
|
||||||
|
|
||||||
public ICommand SaveHistoricData { get; set; }
|
|
||||||
|
|
||||||
public MainWindowViewModel MainWindowViewModel { get; set; }
|
|
||||||
private Client client;
|
|
||||||
|
|
||||||
public Chart Chart { get; set; }
|
|
||||||
|
|
||||||
public ClientInfoViewModel(MainWindowViewModel mainWindowViewModel, string username)
|
|
||||||
{
|
|
||||||
MainWindowViewModel = mainWindowViewModel;
|
|
||||||
this.PatientInfo = new PatientInfo() { Username = username, Status = "Waiting to start" };
|
|
||||||
this.Chart = new Chart(this.PatientInfo);
|
|
||||||
PatientInfo.ChatLog = new ObservableCollection<string>();
|
|
||||||
client = mainWindowViewModel.client;
|
|
||||||
|
|
||||||
StartSession = new RelayCommand(() =>
|
|
||||||
{
|
|
||||||
client.sendMessage(DataParser.getStartSessionJson(PatientInfo.Username));
|
|
||||||
PatientInfo.Status = "Session started";
|
|
||||||
});
|
|
||||||
|
|
||||||
StopSession = new RelayCommand(() =>
|
|
||||||
{
|
|
||||||
client.sendMessage(DataParser.getStopSessionJson(PatientInfo.Username));
|
|
||||||
PatientInfo.Status = "Session stopped, waiting to start again.";
|
|
||||||
});
|
|
||||||
|
|
||||||
Chat = new RelayCommand<object>((parameter) =>
|
|
||||||
{
|
|
||||||
client.sendMessage(DataParser.getChatJson(PatientInfo.Username, ((TextBox)parameter).Text));
|
|
||||||
PatientInfo.ChatLog.Add(DateTime.Now + ": " + ((TextBox)parameter).Text);
|
|
||||||
});
|
|
||||||
|
|
||||||
//TODO RelayCommand ChatToAll
|
|
||||||
|
|
||||||
SetResistance = new RelayCommand<object>((parameter) =>
|
|
||||||
{
|
|
||||||
Debug.WriteLine("resistance");
|
|
||||||
//client.sendMessage(DataParser.getSetResistanceJson(PatientInfo.Username, float.Parse(((TextBox)parameter).Text)));
|
|
||||||
PatientInfo.Resistance = float.Parse(((TextBox)parameter).Text);
|
|
||||||
});
|
|
||||||
|
|
||||||
// request the historic data from the server
|
|
||||||
this.SaveHistoricData = new RelayCommand<object>((parameter) =>
|
|
||||||
{
|
|
||||||
this.client.sendMessage(DataParser.GetGetFileMessage(PatientInfo.Username));
|
|
||||||
// data is stored on the server
|
|
||||||
// send request to server that we want to get the current historic data from the patient
|
|
||||||
// server sends this back
|
|
||||||
// we parse it
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void BPMData(byte[] bytes)
|
|
||||||
{
|
|
||||||
//TODO
|
|
||||||
//Parsen van de data you fuck
|
|
||||||
PatientInfo.BPM = bytes[1];
|
|
||||||
if (bytes[0] == 0x00)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (MySelectedItem == "BPM")
|
|
||||||
{
|
|
||||||
Chart.NewValue(PatientInfo.BPM);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void BikeData(byte[] bytes)
|
|
||||||
{
|
|
||||||
//TODO
|
|
||||||
//Parsen van de data you fuck
|
|
||||||
switch (bytes[0])
|
|
||||||
{
|
|
||||||
case 0x10:
|
|
||||||
if (bytes[1] != 25)
|
|
||||||
{
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
PatientInfo.Distance = bytes[3];
|
|
||||||
PatientInfo.Speed = (bytes[4] | (bytes[5] << 8)) * 0.01;
|
|
||||||
if (MySelectedItem == "Speed")
|
|
||||||
{
|
|
||||||
Chart.NewValue(PatientInfo.Speed);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 0x19:
|
|
||||||
PatientInfo.Acc_Power = bytes[3] | (bytes[4] << 8);
|
|
||||||
PatientInfo.Curr_Power = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Debug.WriteLine("rip");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
using DoctorApp.Utils;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using Util;
|
|
||||||
|
|
||||||
namespace DoctorApp.ViewModels
|
|
||||||
{
|
|
||||||
class MainViewModel : ObservableObject
|
|
||||||
{
|
|
||||||
public ObservableCollection<ClientInfoViewModel> 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<ClientInfoViewModel>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void NewConnectedUser(string username)
|
|
||||||
{
|
|
||||||
Debug.WriteLine("new tab with name " + username);
|
|
||||||
App.Current.Dispatcher.Invoke((Action)delegate
|
|
||||||
{
|
|
||||||
Tabs.Add(new ClientInfoViewModel(MainWindowViewModel, username));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DisconnectedUser(string username)
|
|
||||||
{
|
|
||||||
App.Current.Dispatcher.Invoke((Action)delegate
|
|
||||||
{
|
|
||||||
foreach (ClientInfoViewModel item in Tabs)
|
|
||||||
{
|
|
||||||
if (item.PatientInfo.Username == username)
|
|
||||||
{
|
|
||||||
Tabs.Remove(item);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void TransferDataToClientBike(byte[] bytes)
|
|
||||||
{
|
|
||||||
string username = DataParser.getNameFromBytesBike(bytes);
|
|
||||||
foreach (ClientInfoViewModel item in Tabs)
|
|
||||||
{
|
|
||||||
if (item.PatientInfo.Username == username)
|
|
||||||
{
|
|
||||||
item.BikeData(DataParser.getDataWithoutName(bytes, 0, 8));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Debug.WriteLine("[MainViewModel] did not find client (bike) username is " + username);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void TransferDataToClientBPM(byte[] bytes)
|
|
||||||
{
|
|
||||||
string username = DataParser.getNameFromBytesBPM(bytes);
|
|
||||||
foreach (ClientInfoViewModel item in Tabs)
|
|
||||||
{
|
|
||||||
if (item.PatientInfo.Username == username)
|
|
||||||
{
|
|
||||||
item.BPMData(DataParser.getDataWithoutName(bytes, 0, 2));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Debug.WriteLine("[MainViewModel] did not find client (bpm) username is " + username);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,134 +0,0 @@
|
|||||||
using GalaSoft.MvvmLight.Command;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using Util;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using DoctorApp.Models;
|
|
||||||
using DoctorApp.Utils;
|
|
||||||
using Util.MagicCode;
|
|
||||||
|
|
||||||
namespace DoctorApp.ViewModels
|
|
||||||
{
|
|
||||||
class MainWindowViewModel : ObservableObject
|
|
||||||
{
|
|
||||||
#region private members
|
|
||||||
|
|
||||||
private Window mWindow;
|
|
||||||
|
|
||||||
private int mOuterMarginSize = 10;
|
|
||||||
private int mWindowRadius = 10;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region commands
|
|
||||||
|
|
||||||
public ICommand MinimizeCommand { get; set; }
|
|
||||||
|
|
||||||
public ICommand MaximizeCommand { get; set; }
|
|
||||||
|
|
||||||
public ICommand CloseCommand { get; set; }
|
|
||||||
|
|
||||||
public ICommand MenuCommand { get; set; }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public properties
|
|
||||||
public Info InfoModel { get; set; }
|
|
||||||
|
|
||||||
public ObservableObject SelectedViewModel { get; set; }
|
|
||||||
|
|
||||||
public Client client { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// size of the resize border around the window
|
|
||||||
/// </summary>
|
|
||||||
|
|
||||||
public double MinimumWidth { get; set; } = 250;
|
|
||||||
|
|
||||||
public double MinimumHeight { get; set; } = 250;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public int ResizeBorder { get; set; } = 6;
|
|
||||||
|
|
||||||
public Thickness ResizeBorderThickness { get { return new Thickness(ResizeBorder + OuterMarginSize); } }
|
|
||||||
|
|
||||||
public Thickness InnerContentPadding { get { return new Thickness(ResizeBorder); } }
|
|
||||||
|
|
||||||
|
|
||||||
public Thickness OuterMarginThickness { get { return new Thickness(OuterMarginSize); } }
|
|
||||||
|
|
||||||
public CornerRadius WindowCornerRadius { get { return new CornerRadius(WindowRadius); } }
|
|
||||||
|
|
||||||
public int OuterMarginSize
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return mWindow.WindowState == WindowState.Maximized ? 0 : mOuterMarginSize;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
mOuterMarginSize = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int WindowRadius
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return mWindow.WindowState == WindowState.Maximized ? 0 : mWindowRadius;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
mWindowRadius = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int TitleHeight { get; set; } = 42;
|
|
||||||
|
|
||||||
public GridLength TitleHeightGridLength { get { return new GridLength(TitleHeight + ResizeBorder); } }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
public MainWindowViewModel(Window window, Client client)
|
|
||||||
{
|
|
||||||
this.mWindow = window;
|
|
||||||
|
|
||||||
this.mWindow.StateChanged += (sender, e) =>
|
|
||||||
{
|
|
||||||
OnPropertyChanged(nameof(ResizeBorderThickness));
|
|
||||||
OnPropertyChanged(nameof(OuterMarginThickness));
|
|
||||||
OnPropertyChanged(nameof(WindowCornerRadius));
|
|
||||||
OnPropertyChanged(nameof(OuterMarginSize));
|
|
||||||
OnPropertyChanged(nameof(WindowRadius));
|
|
||||||
};
|
|
||||||
|
|
||||||
this.InfoModel = new Info();
|
|
||||||
this.client = client;
|
|
||||||
LoginViewModel loginViewModel = new LoginViewModel(this);
|
|
||||||
SelectedViewModel = loginViewModel;
|
|
||||||
this.client.SetLoginViewModel(loginViewModel);
|
|
||||||
|
|
||||||
this.MinimizeCommand = new RelayCommand(() => this.mWindow.WindowState = WindowState.Minimized);
|
|
||||||
this.MaximizeCommand = new RelayCommand(() => this.mWindow.WindowState ^= WindowState.Maximized);
|
|
||||||
this.CloseCommand = new RelayCommand(() => this.mWindow.Close());
|
|
||||||
this.MenuCommand = new RelayCommand(() => SystemCommands.ShowSystemMenu(this.mWindow, GetMousePosition()));
|
|
||||||
|
|
||||||
var resizer = new WindowResizer(this.mWindow);
|
|
||||||
|
|
||||||
this.mWindow.Closed += (sender, e) => this.client.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#region helper
|
|
||||||
|
|
||||||
private Point GetMousePosition()
|
|
||||||
{
|
|
||||||
Debug.WriteLine("getmousePosition called");
|
|
||||||
var p = Mouse.GetPosition(this.mWindow);
|
|
||||||
return new Point(p.X + this.mWindow.Left, p.Y + this.mWindow.Top);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
<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"
|
|
||||||
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
|
|
||||||
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>
|
|
||||||
|
|
||||||
<Grid Grid.RowSpan="2" Margin="0,0,0,22">
|
|
||||||
<StackPanel Orientation="Horizontal" >
|
|
||||||
<StackPanel.Resources>
|
|
||||||
<Style TargetType="{x:Type Label}">
|
|
||||||
<Setter Property="Margin" Value="0,0,20,0"/>
|
|
||||||
</Style>
|
|
||||||
</StackPanel.Resources>
|
|
||||||
<Label Content="{Binding Path=PatientInfo.Username}"/>
|
|
||||||
<Label Content="{Binding Path=PatientInfo.Status}"/>
|
|
||||||
</StackPanel>
|
|
||||||
<Button Content="Save Historic Data" HorizontalAlignment="Right" VerticalAlignment="Center" Padding="5" Command="{Binding SaveHistoricData}"/>
|
|
||||||
</Grid>
|
|
||||||
<StackPanel Margin="0,10,0,0" Grid.Row="2">
|
|
||||||
<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="{Binding Path=PatientInfo.Resistance}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
|
|
||||||
<TextBox Name="textBox_CurrentSpeed" Text="{Binding Path=PatientInfo.Speed, StringFormat=N2}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
|
|
||||||
<TextBox Name="textBox_CurrentBPM" Text="{Binding Path=PatientInfo.BPM}" 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="{Binding Path=PatientInfo.Distance}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
|
|
||||||
<TextBox Name="textBox_CurrentPower" Text="{Binding Path=PatientInfo.Curr_Power}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
|
|
||||||
<TextBox Name="textBox_AccPower" Text="{Binding Path=PatientInfo.Acc_Power}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
|
|
||||||
</DockPanel>
|
|
||||||
</StackPanel>
|
|
||||||
<ListBox Name="ChatBox" ItemsSource="{Binding PatientInfo.ChatLog}" 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="" TextWrapping="Wrap" VerticalAlignment="Top" Width="235"/>
|
|
||||||
<Button x:Name="Send" Content="Send" Grid.Column="1" HorizontalAlignment="Left" Margin="59,33,0,0" Grid.Row="3" VerticalAlignment="Top" Command="{Binding Chat}" CommandParameter="{Binding ElementName=textBox_Chat}"/>
|
|
||||||
<Button Content="Start Session" Grid.Column="1" HorizontalAlignment="Left" Margin="69,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Command="{Binding StartSession}" CommandParameter=""/>
|
|
||||||
<Button Content="Stop Session" Grid.Column="1" HorizontalAlignment="Left" Margin="187,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Command="{Binding StopSession}" CommandParameter=""/>
|
|
||||||
<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" Command="{Binding SetResistance}" CommandParameter="{Binding ElementName=textBox_SetResistance}"/>
|
|
||||||
<lvc:CartesianChart Grid.Row="3" AnimationsSpeed="0:0:0.5" Hoverable="False" DataTooltip="{x:Null}" Margin="0,33,0,-5">
|
|
||||||
<lvc:CartesianChart.Series>
|
|
||||||
<lvc:LineSeries Values="{Binding Chart.ChartValues}"
|
|
||||||
PointGeometry="{x:Null}"
|
|
||||||
LineSmoothness="1"
|
|
||||||
StrokeThickness="6"
|
|
||||||
Stroke="#F34336"
|
|
||||||
Fill="Transparent"/>
|
|
||||||
</lvc:CartesianChart.Series>
|
|
||||||
<lvc:CartesianChart.AxisX>
|
|
||||||
<lvc:Axis LabelFormatter="{Binding Chart.DateTimeFormatter}"
|
|
||||||
MaxValue="{Binding Chart.AxisMax}"
|
|
||||||
MinValue="{Binding Chart.AxisMin}"
|
|
||||||
Unit="{Binding Chart.AxisUnit}">
|
|
||||||
<lvc:Axis.Separator>
|
|
||||||
<lvc:Separator Step="{Binding Chart.AxisStep}" />
|
|
||||||
</lvc:Axis.Separator>
|
|
||||||
</lvc:Axis>
|
|
||||||
</lvc:CartesianChart.AxisX>
|
|
||||||
</lvc:CartesianChart>
|
|
||||||
<ComboBox Name="DropBox" HorizontalAlignment="Left" Margin="0,6,0,0" Grid.Row="3" VerticalAlignment="Top" Width="190" SelectedItem="{Binding Path=MySelectedItem}">
|
|
||||||
<ComboBoxItem Content="Speed" IsSelected="True"></ComboBoxItem>
|
|
||||||
<ComboBoxItem Content="BPM"></ComboBoxItem>
|
|
||||||
</ComboBox>
|
|
||||||
</Grid>
|
|
||||||
</UserControl>
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
<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"
|
|
||||||
xmlns:Util="clr-namespace:Util.MagicCode"
|
|
||||||
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" Util:FocusAdvancement.AdvancesByEnterKey="True"/>
|
|
||||||
<Label Content="Password" HorizontalContentAlignment="Center"/>
|
|
||||||
<PasswordBox x:Name="Password" Width="120" Util:FocusAdvancement.AdvancesByEnterKey="True"/>
|
|
||||||
<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>
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
<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 TabStripPlacement="Left" ItemsSource="{Binding Tabs}" SelectedItem="{Binding Selected}">
|
|
||||||
<TabControl.ItemTemplate>
|
|
||||||
<DataTemplate>
|
|
||||||
<StackPanel Orientation="Horizontal">
|
|
||||||
<Image Source="/img/patient.png" Width="25" Margin="0 0 5 0"/>
|
|
||||||
<TextBlock Text="{Binding PatientInfo.Username}" FontSize="20" MaxWidth="100" Width="100" TextTrimming="CharacterEllipsis"/>
|
|
||||||
</StackPanel>
|
|
||||||
</DataTemplate>
|
|
||||||
</TabControl.ItemTemplate>
|
|
||||||
<TabControl.ContentTemplate>
|
|
||||||
<DataTemplate>
|
|
||||||
<ContentControl Content="{Binding}"/>
|
|
||||||
</DataTemplate>
|
|
||||||
</TabControl.ContentTemplate>
|
|
||||||
</TabControl>
|
|
||||||
</Grid>
|
|
||||||
</UserControl>
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
<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"
|
|
||||||
Background="Transparent"
|
|
||||||
WindowStyle="None"
|
|
||||||
AllowsTransparency="True"
|
|
||||||
MinHeight="{Binding MinimumHeight}"
|
|
||||||
MinWidth="{Binding MinimumWidth}"
|
|
||||||
Title="MainWindow" Height="800" Width="1500">
|
|
||||||
<Window.Resources>
|
|
||||||
<Style TargetType="{x:Type local:MainWindow}">
|
|
||||||
<Setter Property="Template">
|
|
||||||
<Setter.Value>
|
|
||||||
<ControlTemplate TargetType="{x:Type Window}">
|
|
||||||
<Border Padding="{Binding OuterMarginThickness, FallbackValue=10}" >
|
|
||||||
<Grid>
|
|
||||||
|
|
||||||
<!-- opacity mask -->
|
|
||||||
<Border x:Name="Container"
|
|
||||||
Background="{StaticResource BackgroundLightBrush}"
|
|
||||||
CornerRadius="{Binding WindowCornerRadius, FallbackValue=10}"/>
|
|
||||||
|
|
||||||
|
|
||||||
<Border CornerRadius="{Binding WindowCornerRadius, FallbackValue=10}"
|
|
||||||
Background="{StaticResource BackgroundVeryLightBrush}">
|
|
||||||
<Border.Effect>
|
|
||||||
<DropShadowEffect ShadowDepth="0" Opacity="0.2"/>
|
|
||||||
</Border.Effect>
|
|
||||||
</Border>
|
|
||||||
|
|
||||||
|
|
||||||
<Grid>
|
|
||||||
|
|
||||||
<Grid.OpacityMask>
|
|
||||||
<VisualBrush Visual="{Binding ElementName=Container}"/>
|
|
||||||
</Grid.OpacityMask>
|
|
||||||
|
|
||||||
<Grid.RowDefinitions>
|
|
||||||
<RowDefinition Height="{Binding TitleHeightGridLength, FallbackValue=42}"/>
|
|
||||||
<RowDefinition Height="*"/>
|
|
||||||
</Grid.RowDefinitions>
|
|
||||||
|
|
||||||
<!-- Title bar -->
|
|
||||||
<Grid Grid.Column="0" Grid.Row="0" Panel.ZIndex="1" Background="{StaticResource BackgroundLightBrush}">
|
|
||||||
<Grid.ColumnDefinitions>
|
|
||||||
<ColumnDefinition Width="Auto"/>
|
|
||||||
<ColumnDefinition Width="*"/>
|
|
||||||
<ColumnDefinition Width="Auto"/>
|
|
||||||
</Grid.ColumnDefinitions>
|
|
||||||
|
|
||||||
<!-- icon -->
|
|
||||||
<Button Grid.Column="0" Style="{StaticResource SystemIconButton}" Command="{Binding MenuCommand}">
|
|
||||||
<Image Source="/img/doctor.ico"/>
|
|
||||||
<!--<TextBlock Text="icon"/>-->
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<!-- Title -->
|
|
||||||
<Viewbox Grid.Column="1" Margin="0">
|
|
||||||
<TextBlock Style="{StaticResource HeaderText}" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title, FallbackValue=failed}"/>
|
|
||||||
</Viewbox>
|
|
||||||
|
|
||||||
<!-- Window buttons -->
|
|
||||||
<StackPanel Grid.Column="2" Orientation="Horizontal">
|
|
||||||
<Button Style="{StaticResource WindowControlButton}" Content="_" Command="{Binding MinimizeCommand}"/>
|
|
||||||
<Button Style="{StaticResource WindowControlButton}" Content="[]" Command="{Binding MaximizeCommand}"/>
|
|
||||||
<Button Style="{StaticResource WindowCloseButton}" Content="X" Command="{Binding CloseCommand}"/>
|
|
||||||
</StackPanel>
|
|
||||||
|
|
||||||
</Grid>
|
|
||||||
|
|
||||||
<!-- Page content -->
|
|
||||||
<Border Grid.Row="1" Grid.Column="0">
|
|
||||||
<ContentPresenter Content="{TemplateBinding Content}"/>
|
|
||||||
</Border>
|
|
||||||
|
|
||||||
<!-- shadow? -->
|
|
||||||
<Border Grid.Row="1" Height="6" BorderThickness="0 0.2 0 0" VerticalAlignment="Top">
|
|
||||||
<!--<Border.BorderBrush>
|
|
||||||
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
|
|
||||||
<GradientStop Color="{StaticResource BackgroundSemiLight}" Offset="0.0"/>
|
|
||||||
<GradientStop Color="{StaticResource BackgroundVeryLight}" Offset="1.0"/>
|
|
||||||
</LinearGradientBrush>
|
|
||||||
</Border.BorderBrush>-->
|
|
||||||
|
|
||||||
|
|
||||||
<Border.Background>
|
|
||||||
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
|
|
||||||
<GradientStop Color="Transparent" Offset="1.0"/>
|
|
||||||
<GradientStop Color="#7000" Offset="0.0"/>
|
|
||||||
</LinearGradientBrush>
|
|
||||||
</Border.Background>
|
|
||||||
</Border>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</Grid>
|
|
||||||
|
|
||||||
</Grid>
|
|
||||||
</Border>
|
|
||||||
</ControlTemplate>
|
|
||||||
</Setter.Value>
|
|
||||||
</Setter>
|
|
||||||
</Style>
|
|
||||||
</Window.Resources>
|
|
||||||
|
|
||||||
<WindowChrome.WindowChrome>
|
|
||||||
<WindowChrome
|
|
||||||
ResizeBorderThickness="{Binding ResizeBorderThickness}"
|
|
||||||
CaptionHeight="{Binding TitleHeight}"
|
|
||||||
CornerRadius="0"
|
|
||||||
GlassFrameThickness="0"/>
|
|
||||||
</WindowChrome.WindowChrome>
|
|
||||||
|
|
||||||
<Grid>
|
|
||||||
<Frame Content="{Binding SelectedViewModel}" Focusable="False" NavigationUIVisibility="Hidden"/>
|
|
||||||
<Label Content="gemaakt door: mensen" DockPanel.Dock="Bottom" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontStyle="Italic" Foreground="Gray"/>
|
|
||||||
</Grid>
|
|
||||||
</Window>
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
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(this, client);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 252 KiB |
|
Before Width: | Height: | Size: 252 KiB |
|
Before Width: | Height: | Size: 11 KiB |
@@ -21,7 +21,7 @@
|
|||||||
<Label Content="Username" HorizontalContentAlignment="Center"/>
|
<Label Content="Username" HorizontalContentAlignment="Center"/>
|
||||||
<TextBox x:Name="Username" TextWrapping="Wrap" Width="120"/>
|
<TextBox x:Name="Username" TextWrapping="Wrap" Width="120"/>
|
||||||
<Label Content="Password" HorizontalContentAlignment="Center"/>
|
<Label Content="Password" HorizontalContentAlignment="Center"/>
|
||||||
<PasswordBox x:Name="Password" Width="120"/>
|
<TextBox x:Name="Password" TextWrapping="Wrap" Width="120"/>
|
||||||
<Button x:Name="Login" Content="Login" Margin="0,20,0,0" Click="Login_Click_1" />
|
<Button x:Name="Login" Content="Login" Margin="0,20,0,0" Click="Login_Click_1" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
|||||||
@@ -28,19 +28,24 @@ namespace DokterApp
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void Login_Click_1(object sender, RoutedEventArgs e)
|
private void Login_Click_1(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
WindowTabs windowTabs = new WindowTabs();
|
WindowTabs windowTabs = new WindowTabs();
|
||||||
handler = windowTabs.NewTab;
|
handler = windowTabs.NewTab;
|
||||||
|
|
||||||
this.Label.Content = "Waiting";
|
this.Label.Content = "Waiting";
|
||||||
this.client = new Client("localhost", 5555, this.Username.Text, this.Password.Password, handler);
|
this.client = new Client("localhost", 5555, this.Username.Text, this.Password.Text, handler);
|
||||||
while (!client.IsConnected())
|
while (!client.IsConnected())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
windowTabs.Show();
|
windowTabs.Show();
|
||||||
|
|
||||||
this.Close();
|
this.Close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
<UserControl x:Class="DokterApp.UserControlForTab"
|
<UserControl x:Class="DokterApp.UserControlForTab"
|
||||||
|
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:local="clr-namespace:DokterApp"
|
xmlns:local="clr-namespace:DokterApp"
|
||||||
|
xmlns:constantChanges="clr-namespace:DokterApp"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="450" d:DesignWidth="800">
|
d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance constantChanges:UserControlForTab}">
|
||||||
<Grid Margin="15,5,15,15">
|
<Grid Margin="15,5,15,15">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="5*"/>
|
<ColumnDefinition Width="5*"/>
|
||||||
@@ -60,8 +62,31 @@
|
|||||||
<Button Content="Stop Session" Grid.Column="1" HorizontalAlignment="Left" Margin="187,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Click="StopSession_Click"/>
|
<Button Content="Stop Session" Grid.Column="1" HorizontalAlignment="Left" Margin="187,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Click="StopSession_Click"/>
|
||||||
<TextBox x:Name="textBox_SetResistance" Grid.Column="1" HorizontalAlignment="Left" Margin="69,128,0,0" Grid.Row="3" TextWrapping="Wrap" 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" Click="SetResistance_Click"/>
|
<Button Content="Set Resistance" Grid.Column="1" HorizontalAlignment="Left" Margin="187,128,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Height="18" Click="SetResistance_Click"/>
|
||||||
<Canvas Grid.Row="3" Background="White" Margin="0,33,0,0"/>
|
<lvc:CartesianChart Grid.Row="3" AnimationsSpeed="0:0:0.5" Hoverable="False" DataTooltip="{x:Null}" Margin="-10,33,10,0">
|
||||||
<ComboBox Name="DropBox" HorizontalAlignment="Left" Margin="0,6,0,0" Grid.Row="3" VerticalAlignment="Top" Width="190"/>
|
<lvc:CartesianChart.Series>
|
||||||
|
<lvc:LineSeries Values="{Binding ChartValues}"
|
||||||
|
PointGeometry="{x:Null}"
|
||||||
|
LineSmoothness="1"
|
||||||
|
StrokeThickness="6"
|
||||||
|
Stroke="#F34336"
|
||||||
|
Fill="Transparent"/>
|
||||||
|
</lvc:CartesianChart.Series>
|
||||||
|
<lvc:CartesianChart.AxisX>
|
||||||
|
<lvc:Axis LabelFormatter="{Binding DateTimeFormatter}"
|
||||||
|
MaxValue="{Binding AxisMax}"
|
||||||
|
MinValue="{Binding AxisMin}"
|
||||||
|
Unit="{Binding AxisUnit}">
|
||||||
|
<lvc:Axis.Separator>
|
||||||
|
<lvc:Separator Step="{Binding AxisStep}" />
|
||||||
|
</lvc:Axis.Separator>
|
||||||
|
</lvc:Axis>
|
||||||
|
</lvc:CartesianChart.AxisX>
|
||||||
|
</lvc:CartesianChart>
|
||||||
|
<ComboBox Name="DropBox" HorizontalAlignment="Left" Margin="0,6,0,0" Grid.Row="3" VerticalAlignment="Top" Width="190" SelectionChanged="InjectStopOnClick">
|
||||||
|
<ComboBoxItem Content="Speed"/>
|
||||||
|
<ComboBoxItem Content="BPM"/>
|
||||||
|
<ComboBoxItem Content="Resistance"/>
|
||||||
|
</ComboBox>
|
||||||
<Button Content="Client Info" Grid.Column="1" HorizontalAlignment="Left" Margin="207,6,0,0" VerticalAlignment="Top" Height="26" Width="82" Click="ClientInfo_Click"/>
|
<Button Content="Client Info" Grid.Column="1" HorizontalAlignment="Left" Margin="207,6,0,0" VerticalAlignment="Top" Height="26" Width="82" Click="ClientInfo_Click"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
using System;
|
using LiveCharts;
|
||||||
|
using LiveCharts.Configurations;
|
||||||
|
using LiveCharts.Wpf;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
@@ -16,13 +22,122 @@ namespace DokterApp
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interaction logic for UserControlForTab.xaml
|
/// Interaction logic for UserControlForTab.xaml
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class UserControlForTab : UserControl
|
public partial class UserControlForTab : UserControl, INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private double _axisMax;
|
||||||
|
private double _axisMin;
|
||||||
|
private double _trend;
|
||||||
public UserControlForTab()
|
public UserControlForTab()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
Username_Label.Content = "Bob";
|
Username_Label.Content = "Bob";
|
||||||
Status_Label.Content = "Status: Dead";
|
Status_Label.Content = "Status: Dead";
|
||||||
|
|
||||||
|
//To handle live data easily, in this case we built a specialized type
|
||||||
|
//the MeasureModel class, it only contains 2 properties
|
||||||
|
//DateTime and Value
|
||||||
|
//We need to configure LiveCharts to handle MeasureModel class
|
||||||
|
//The next code configures MeasureModel globally, this means
|
||||||
|
//that LiveCharts learns to plot MeasureModel and will use this config every time
|
||||||
|
//a IChartValues instance uses this type.
|
||||||
|
//this code ideally should only run once
|
||||||
|
//you can configure series in many ways, learn more at
|
||||||
|
//http://lvcharts.net/App/examples/v1/wpf/Types%20and%20Configuration
|
||||||
|
|
||||||
|
var mapper = Mappers.Xy<MeasureModel>()
|
||||||
|
.X(model => model.DateTime.Ticks) //use DateTime.Ticks as X
|
||||||
|
.Y(model => model.Value); //use the value property as Y
|
||||||
|
|
||||||
|
//lets save the mapper globally.
|
||||||
|
Charting.For<MeasureModel>(mapper);
|
||||||
|
|
||||||
|
//the values property will store our values array
|
||||||
|
ChartValues = new ChartValues<MeasureModel>();
|
||||||
|
|
||||||
|
//lets set how to display the X Labels
|
||||||
|
DateTimeFormatter = value => new DateTime((long)value).ToString("mm:ss");
|
||||||
|
|
||||||
|
//AxisStep forces the distance between each separator in the X axis
|
||||||
|
AxisStep = TimeSpan.FromSeconds(1).Ticks;
|
||||||
|
//AxisUnit forces lets the axis know that we are plotting seconds
|
||||||
|
//this is not always necessary, but it can prevent wrong labeling
|
||||||
|
AxisUnit = TimeSpan.TicksPerSecond;
|
||||||
|
|
||||||
|
SetAxisLimits(DateTime.Now);
|
||||||
|
|
||||||
|
//The next code simulates data changes every 300 ms
|
||||||
|
|
||||||
|
IsReading = false;
|
||||||
|
|
||||||
|
DataContext = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double AxisMax
|
||||||
|
{
|
||||||
|
get { return _axisMax; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_axisMax = value;
|
||||||
|
OnPropertyChanged("AxisMax");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public double AxisMin
|
||||||
|
{
|
||||||
|
get { return _axisMin; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_axisMin = value;
|
||||||
|
OnPropertyChanged("AxisMin");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsReading { get; set; }
|
||||||
|
|
||||||
|
private void Read()
|
||||||
|
{
|
||||||
|
var r = new Random();
|
||||||
|
|
||||||
|
while (IsReading)
|
||||||
|
{
|
||||||
|
Thread.Sleep(150);
|
||||||
|
var now = DateTime.Now;
|
||||||
|
|
||||||
|
_trend += r.Next(-8, 10);
|
||||||
|
|
||||||
|
ChartValues.Add(new MeasureModel
|
||||||
|
{
|
||||||
|
DateTime = now,
|
||||||
|
Value = _trend
|
||||||
|
});
|
||||||
|
|
||||||
|
SetAxisLimits(now);
|
||||||
|
|
||||||
|
//lets only use the last 150 values
|
||||||
|
if (ChartValues.Count > 150) ChartValues.RemoveAt(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetAxisLimits(DateTime now)
|
||||||
|
{
|
||||||
|
AxisMax = now.Ticks + TimeSpan.FromSeconds(1).Ticks; // lets force the axis to be 1 second ahead
|
||||||
|
AxisMin = now.Ticks - TimeSpan.FromSeconds(8).Ticks; // and 8 seconds behind
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InjectStopOnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
IsReading = !IsReading;
|
||||||
|
if (IsReading) Task.Factory.StartNew(Read);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
|
protected virtual void OnPropertyChanged(string propertyName = null)
|
||||||
|
{
|
||||||
|
if (PropertyChanged != null)
|
||||||
|
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
@@ -51,9 +166,25 @@ namespace DokterApp
|
|||||||
|
|
||||||
private void ClientInfo_Click(object sender, RoutedEventArgs e)
|
private void ClientInfo_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
MessageBox.Show("firstname:\tBob\n" +
|
MessageBox.Show("Firstname:\tBob\n" +
|
||||||
"surname:\t\tde Bouwer");
|
"Lastname:\t\tde Bouwer");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DropBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
//Andere graph
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChartValues<MeasureModel> ChartValues { get; set; }
|
||||||
|
public Func<double, string> DateTimeFormatter { get; set; }
|
||||||
|
public double AxisStep { get; set; }
|
||||||
|
public double AxisUnit { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MeasureModel
|
||||||
|
{
|
||||||
|
public DateTime DateTime { get; set; }
|
||||||
|
public double Value { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,508 +0,0 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Serialization;
|
|
||||||
using System;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Printing.IndexedProperties;
|
|
||||||
using System.Runtime.InteropServices.WindowsRuntime;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Media.Animation;
|
|
||||||
|
|
||||||
namespace Util
|
|
||||||
{
|
|
||||||
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";
|
|
||||||
public const string LOGIN_DOCTOR = "LOGIN DOCTOR";
|
|
||||||
public const string MESSAGE = "MESSAGE";
|
|
||||||
public const string GET_FILE = "GET FILE";
|
|
||||||
/// <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));
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static string getNameFromBytesBike(byte[] bytes)
|
|
||||||
{
|
|
||||||
return getName(bytes, 8, bytes.Length - 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// converts the given string parameter into a message using our protocol.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="messageToSend">the message string to send</param>
|
|
||||||
/// <returns>a byte array using our protocol to send the message</returns>
|
|
||||||
public static byte[] GetMessageToSend(string messageToSend)
|
|
||||||
{
|
|
||||||
dynamic json = new
|
|
||||||
{
|
|
||||||
identifier = MESSAGE,
|
|
||||||
data = new
|
|
||||||
{
|
|
||||||
message = messageToSend
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static string getNameFromBytesBPM(byte[] bytes)
|
|
||||||
{
|
|
||||||
return getName(bytes, 2, bytes.Length - 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string getName(byte[] bytes, int offset, int lenght)
|
|
||||||
{
|
|
||||||
byte[] nameArray = new byte[lenght];
|
|
||||||
Array.Copy(bytes, offset, nameArray, 0, lenght);
|
|
||||||
return Encoding.UTF8.GetString(nameArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// creates a message for when the doctor wants to log in.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="mUsername">the username of the doctor</param>
|
|
||||||
/// <param name="mPassword">the (hashed) password of the doctor</param>
|
|
||||||
/// <returns>a byte array using our protocol that contains the username and password of the doctor</returns>
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// gets the username and password from a given message array.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="jsonbytes">the array of bytes containing the message</param>
|
|
||||||
/// <param name="username">the username variable that the username will be put into</param>
|
|
||||||
/// <param name="password">the password variable that the password will be put into</param>
|
|
||||||
/// <returns><c>true</c> if the username and password were received correctly, <c>false</c> otherwise</returns>
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// gets message using our protocol of the given identifier and data.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="mIdentifier">the identifier string of the message</param>
|
|
||||||
/// <param name="data">the payload data of the message</param>
|
|
||||||
/// <returns>a byte array containing the json message with the given parameters, using our protocol.</returns>
|
|
||||||
private static byte[] getJsonMessage(string mIdentifier, dynamic data)
|
|
||||||
{
|
|
||||||
dynamic json = new
|
|
||||||
{
|
|
||||||
identifier = mIdentifier,
|
|
||||||
data
|
|
||||||
};
|
|
||||||
return getMessage(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json)), 0x01);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// gets a message using our protocol with only the given identifier string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="mIdentifier">the identifier to put into the message</param>
|
|
||||||
/// <returns>a byte array containing the json with only the identifier, using our protocol.</returns>
|
|
||||||
private static byte[] getJsonMessage(string mIdentifier)
|
|
||||||
{
|
|
||||||
dynamic json = new
|
|
||||||
{
|
|
||||||
identifier = mIdentifier,
|
|
||||||
};
|
|
||||||
return getMessage(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json)), 0x01);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// gets the login response of the given status
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="mStatus">the status of the response</param>
|
|
||||||
/// <returns>a byte array containing the response for the given status, using our protocol.</returns>
|
|
||||||
public static byte[] getLoginResponse(string mStatus)
|
|
||||||
{
|
|
||||||
return getJsonMessage(LOGIN_RESPONSE, new { status = mStatus });
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// gets the status of the given json message
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="json">the byte array containing a json message using our protocol</param>
|
|
||||||
/// <returns>the response of the message</returns>
|
|
||||||
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 isRawDataBikeServer(byte[] bytes)
|
|
||||||
{
|
|
||||||
if (bytes.Length <= 5)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("bytes to short");
|
|
||||||
}
|
|
||||||
return bytes[4] == 0x02;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool isRawDataBPMServer(byte[] bytes)
|
|
||||||
{
|
|
||||||
if (bytes.Length <= 5)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("bytes to short");
|
|
||||||
}
|
|
||||||
return bytes[4] == 0x03;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool isRawDataBikeDoctor(byte[] bytes)
|
|
||||||
{
|
|
||||||
if (bytes.Length <= 5)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("bytes to short");
|
|
||||||
}
|
|
||||||
return bytes[4] == 0x04;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool isRawDataBPMDoctor(byte[] bytes)
|
|
||||||
{
|
|
||||||
if (bytes.Length <= 5)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("bytes to short");
|
|
||||||
}
|
|
||||||
return bytes[4] == 0x05;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsHistoricBikeData(byte[] bytes)
|
|
||||||
{
|
|
||||||
if (bytes.Length <= 5) throw new ArgumentException("bytes too short");
|
|
||||||
return bytes[4] == 0x06;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <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[] GetRawBikeDataMessageServer(byte[] payload)
|
|
||||||
{
|
|
||||||
return getMessage(payload, 0x02);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] GetRawBPMDataMessageServer(byte[] payload)
|
|
||||||
{
|
|
||||||
return getMessage(payload, 0x03);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] GetRawBikeDataDoctor(byte[] payload, string username)
|
|
||||||
{
|
|
||||||
|
|
||||||
return GetRawDataDoctor(payload, username, 0x04);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] GetRawBPMDataDoctor(byte[] payload, string username)
|
|
||||||
{
|
|
||||||
return GetRawDataDoctor(payload, username, 0x05);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static byte[] GetRawDataDoctor(byte[] payload, string username, byte messageID)
|
|
||||||
{
|
|
||||||
byte[] nameArray = Encoding.ASCII.GetBytes(username);
|
|
||||||
byte[] total = new byte[nameArray.Length + payload.Length];
|
|
||||||
Array.Copy(payload, 0, total, 0, payload.Length);
|
|
||||||
Array.Copy(nameArray, 0, total, payload.Length, nameArray.Length);
|
|
||||||
return getMessage(total, messageID);
|
|
||||||
|
|
||||||
}
|
|
||||||
/// <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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// gets the message to start a session with the given user username
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="user">the username of the user we want to start the session for</param>
|
|
||||||
/// <returns>a byte array containing the message to start the session of the given user, using our protocol.</returns>
|
|
||||||
public static byte[] getStartSessionJson(string user)
|
|
||||||
{
|
|
||||||
dynamic data = new
|
|
||||||
{
|
|
||||||
username = user
|
|
||||||
};
|
|
||||||
return getJsonMessage(START_SESSION, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// gets the message to stop a session with the given user username
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="user">the username of the user we want to stop the session for</param>
|
|
||||||
/// <returns>a byte array containing the message to stop the session of the given user, using our protocol.</returns>
|
|
||||||
public static byte[] getStopSessionJson(string user)
|
|
||||||
{
|
|
||||||
dynamic data = new
|
|
||||||
{
|
|
||||||
username = user
|
|
||||||
};
|
|
||||||
return getJsonMessage(STOP_SESSION, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// gets the message to set the resistance of the given user with the given resistance.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="user">the username to set the resistance of.</param>
|
|
||||||
/// <param name="mResistance">the resistance value to set</param>
|
|
||||||
/// <returns>a byte array containing a json messsage to set the user's resistance, using our protocol.</returns>
|
|
||||||
public static byte[] getSetResistanceJson(string user, float mResistance)
|
|
||||||
{
|
|
||||||
dynamic data = new
|
|
||||||
{
|
|
||||||
username = user,
|
|
||||||
resistance = mResistance
|
|
||||||
};
|
|
||||||
return getJsonMessage(SET_RESISTANCE, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// gets the response message with the given value.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="mWorked">the boolean value to indicate if the operation we want to send a response for was successful or not.</param>
|
|
||||||
/// <returns>a byte array containing a json message with the response and the given value.</returns>
|
|
||||||
public static byte[] getSetResistanceResponseJson(bool mWorked)
|
|
||||||
{
|
|
||||||
dynamic data = new
|
|
||||||
{
|
|
||||||
worked = mWorked
|
|
||||||
};
|
|
||||||
return getJsonMessage(SET_RESISTANCE, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// gets the message to indicate a new connection for the given user.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="user">the username of the user to start a connection for.</param>
|
|
||||||
/// <returns>a byte array containing a json message to indicate a new connection for the given user, using our protocol.</returns>
|
|
||||||
public static byte[] getNewConnectionJson(string user)
|
|
||||||
{
|
|
||||||
if (user == null)
|
|
||||||
throw new ArgumentNullException("user null");
|
|
||||||
dynamic data = new
|
|
||||||
{
|
|
||||||
username = user
|
|
||||||
};
|
|
||||||
return getJsonMessage(NEW_CONNECTION, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// gets the message for when a user has been disconnected.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="user">the username of the user that has been disconnected</param>
|
|
||||||
/// <returns>a byte array containing a json message to indicate that the given user has disconnected, using our protocol.</returns>
|
|
||||||
public static byte[] getDisconnectJson(string user)
|
|
||||||
{
|
|
||||||
dynamic data = new
|
|
||||||
{
|
|
||||||
username = user
|
|
||||||
};
|
|
||||||
return getJsonMessage(DISCONNECT, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// gets the resistance from the given json message
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="json">the json messag</param>
|
|
||||||
/// <returns>the resistance that was in the message</returns>
|
|
||||||
public static float getResistanceFromJson(byte[] json)
|
|
||||||
{
|
|
||||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.resistance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// gets the resistance response from the given json message
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="json">the byte array containin the json message</param>
|
|
||||||
/// <returns>the response of the message, so wether it was successful or not.</returns>
|
|
||||||
public static bool getResistanceFromResponseJson(byte[] json)
|
|
||||||
{
|
|
||||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.worked;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// gets the username from the given response message.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="json">the byte array containin the json message</param>
|
|
||||||
/// <returns>the username in the message.</returns>
|
|
||||||
public static string getUsernameFromResponseJson(byte[] json)
|
|
||||||
{
|
|
||||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// gets the chat message from the given json message.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="json">the byte array containin the json message</param>
|
|
||||||
/// <returns>the chat message in the json message</returns>
|
|
||||||
public static string getChatMessageFromJson(byte[] json)
|
|
||||||
{
|
|
||||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.chat;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// gets the username from the given json message.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="json">the byte array containin the json message</param>
|
|
||||||
/// <returns>the username that is in the message</returns>
|
|
||||||
public static string getUsernameFromJson(byte[] json)
|
|
||||||
{
|
|
||||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// gets the byte array with the json message to send a message with the given parameters.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="user">the username of the user that wants to send the message</param>
|
|
||||||
/// <param name="message">the message the user wants to send</param>
|
|
||||||
/// <returns>a byte array containing a json message with the username and corresponding message, using our protocol.</returns>
|
|
||||||
public static byte[] getChatJson(string user, string message)
|
|
||||||
{
|
|
||||||
dynamic data = new
|
|
||||||
{
|
|
||||||
username = user,
|
|
||||||
chat = message
|
|
||||||
};
|
|
||||||
return getJsonMessage(MESSAGE, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] getDataWithoutName(byte[] bytes, int offset, int length)
|
|
||||||
{
|
|
||||||
byte[] data = new byte[length];
|
|
||||||
Array.Copy(bytes, offset, data, 0, length);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] GetGetFileMessage(string mUsername)
|
|
||||||
{
|
|
||||||
if (mUsername == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("username null");
|
|
||||||
}
|
|
||||||
dynamic data = new
|
|
||||||
{
|
|
||||||
username = mUsername,
|
|
||||||
};
|
|
||||||
return getJsonMessage(GET_FILE, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetUsernameFromGetFileBytes(byte[] json)
|
|
||||||
{
|
|
||||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetDateFromGetFileBytes(byte[] json)
|
|
||||||
{
|
|
||||||
return ((string)((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.dateTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] GetFileMessage(byte[] file)
|
|
||||||
{
|
|
||||||
return getMessage(file, 0x06);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Util
|
namespace Hashing
|
||||||
{
|
{
|
||||||
class Hasher
|
class Hasher
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,32 +9,6 @@
|
|||||||
<Import_RootNamespace>Hashing</Import_RootNamespace>
|
<Import_RootNamespace>Hashing</Import_RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)DataParser.cs" />
|
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Hasher.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Hasher.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)WPFStuff\MagicCode\FocusAdvancement.cs" />
|
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)WPFStuff\MagicCode\WindowResizer.cs" />
|
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)WPFStuff\ObservableObject.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Page Include="$(MSBuildThisFileDirectory)WPFStuff\Styles\Buttons.xaml">
|
|
||||||
<SubType>Designer</SubType>
|
|
||||||
<Generator>MSBuild:Compile</Generator>
|
|
||||||
</Page>
|
|
||||||
<Page Include="$(MSBuildThisFileDirectory)WPFStuff\Styles\Colors.xaml">
|
|
||||||
<SubType>Designer</SubType>
|
|
||||||
<Generator>MSBuild:Compile</Generator>
|
|
||||||
</Page>
|
|
||||||
<Page Include="$(MSBuildThisFileDirectory)WPFStuff\Styles\Fonts.xaml">
|
|
||||||
<SubType>Designer</SubType>
|
|
||||||
<Generator>MSBuild:Compile</Generator>
|
|
||||||
</Page>
|
|
||||||
<Page Include="$(MSBuildThisFileDirectory)WPFStuff\Styles\Texts.xaml">
|
|
||||||
<SubType>Designer</SubType>
|
|
||||||
<Generator>MSBuild:Compile</Generator>
|
|
||||||
</Page>
|
|
||||||
<Page Include="$(MSBuildThisFileDirectory)WPFStuff\Styles\Windows.xaml">
|
|
||||||
<SubType>Designer</SubType>
|
|
||||||
<Generator>MSBuild:Compile</Generator>
|
|
||||||
</Page>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
xmlns:local="clr-namespace:ClientApp">
|
|
||||||
|
|
||||||
<ResourceDictionary.MergedDictionaries>
|
|
||||||
<ResourceDictionary Source="Colors.xaml"/>
|
|
||||||
</ResourceDictionary.MergedDictionaries>
|
|
||||||
|
|
||||||
<Style TargetType="{x:Type Button}" x:Key="Hoverless">
|
|
||||||
<Setter Property="Background" Value="Transparent"/>
|
|
||||||
<Setter Property="BorderThickness" Value="0"/>
|
|
||||||
<Setter Property="Template">
|
|
||||||
<Setter.Value>
|
|
||||||
<ControlTemplate TargetType="{x:Type Button}">
|
|
||||||
<Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}">
|
|
||||||
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
|
||||||
</Border>
|
|
||||||
</ControlTemplate>
|
|
||||||
</Setter.Value>
|
|
||||||
</Setter>
|
|
||||||
</Style>
|
|
||||||
|
|
||||||
<Style TargetType="{x:Type Button}" x:Key="SystemIconButton" BasedOn="{StaticResource Hoverless}" >
|
|
||||||
<Setter Property="WindowChrome.IsHitTestVisibleInChrome" Value="True"/>
|
|
||||||
<Setter Property="Padding" Value="4"/>
|
|
||||||
</Style>
|
|
||||||
|
|
||||||
<Style TargetType="{x:Type Button}" x:Key="WindowControlButton">
|
|
||||||
<Setter Property="WindowChrome.IsHitTestVisibleInChrome" Value="True"/>
|
|
||||||
<Setter Property="Background" Value="Transparent"/>
|
|
||||||
<Setter Property="VerticalAlignment" Value="Stretch"/>
|
|
||||||
<Setter Property="Foreground" Value="{StaticResource ForegroundMainBrush}"/>
|
|
||||||
<Setter Property="Padding" Value="6"/>
|
|
||||||
|
|
||||||
<Setter Property="LayoutTransform">
|
|
||||||
<Setter.Value>
|
|
||||||
<ScaleTransform ScaleX="2"/>
|
|
||||||
</Setter.Value>
|
|
||||||
</Setter>
|
|
||||||
|
|
||||||
<Setter Property="Template">
|
|
||||||
<Setter.Value>
|
|
||||||
<ControlTemplate TargetType="{x:Type Button}">
|
|
||||||
<Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}">
|
|
||||||
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
|
||||||
</Border>
|
|
||||||
</ControlTemplate>
|
|
||||||
</Setter.Value>
|
|
||||||
</Setter>
|
|
||||||
|
|
||||||
<Style.Triggers>
|
|
||||||
<Trigger Property="IsMouseOver" Value="True">
|
|
||||||
<Setter Property="Background" Value="{StaticResource BackgroundSemiLightBrush}"/>
|
|
||||||
</Trigger>
|
|
||||||
</Style.Triggers>
|
|
||||||
</Style>
|
|
||||||
|
|
||||||
<Style TargetType="{x:Type Button}" x:Key="WindowCloseButton" BasedOn="{StaticResource WindowControlButton}">
|
|
||||||
<Style.Triggers>
|
|
||||||
<Trigger Property="IsMouseOver" Value="True">
|
|
||||||
<Setter Property="Background" Value="Red"/>
|
|
||||||
</Trigger>
|
|
||||||
</Style.Triggers>
|
|
||||||
</Style>
|
|
||||||
</ResourceDictionary>
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
xmlns:local="clr-namespace:ClientApp">
|
|
||||||
|
|
||||||
<Color x:Key="BackgroundLight">#efefef</Color>
|
|
||||||
<SolidColorBrush x:Key="BackgroundLightBrush" Color="{StaticResource BackgroundLight}"/>
|
|
||||||
|
|
||||||
|
|
||||||
<Color x:Key="BackgroundVeryLight">#fafafa</Color>
|
|
||||||
<SolidColorBrush x:Key="BackgroundVeryLightBrush" Color="{StaticResource BackgroundVeryLight}"/>
|
|
||||||
|
|
||||||
<Color x:Key="BackgroundSemiLight">#d7d7d7</Color>
|
|
||||||
<SolidColorBrush x:Key="BackgroundSemiLightBrush" Color="{StaticResource BackgroundSemiLight}"/>
|
|
||||||
|
|
||||||
<Color x:Key="ForegroundMain">#686868</Color>
|
|
||||||
<SolidColorBrush x:Key="ForegroundMainBrush" Color="{StaticResource ForegroundMain}"/>
|
|
||||||
|
|
||||||
<Color x:Key="ForegroundVeryDark">#000</Color>
|
|
||||||
<SolidColorBrush x:Key="ForegroundVeryDarkBrush" Color="{StaticResource ForegroundVeryDark}"/>
|
|
||||||
|
|
||||||
<Color x:Key="ForegroundWhite">#fff</Color>
|
|
||||||
<SolidColorBrush x:Key="ForegroundWhiteBrush" Color="{StaticResource ForegroundWhite}"/>
|
|
||||||
|
|
||||||
|
|
||||||
</ResourceDictionary>
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
xmlns:local="clr-namespace:ClientApp">
|
|
||||||
|
|
||||||
</ResourceDictionary>
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
xmlns:local="clr-namespace:ClientApp">
|
|
||||||
|
|
||||||
<Style TargetType="{x:Type TextBlock}" x:Key="HeaderText">
|
|
||||||
<Setter Property="Foreground" Value="{StaticResource ForegroundMainBrush}"/>
|
|
||||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
|
||||||
<Setter Property="HorizontalAlignment" Value="Center"/>
|
|
||||||
<Setter Property="Margin" Value="0 4"/>
|
|
||||||
</Style>
|
|
||||||
</ResourceDictionary>
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
xmlns:local="clr-namespace:ClientApp">
|
|
||||||
|
|
||||||
</ResourceDictionary>
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Input;
|
|
||||||
|
|
||||||
namespace Util.MagicCode
|
|
||||||
{
|
|
||||||
public static class FocusAdvancement
|
|
||||||
{
|
|
||||||
public static bool GetAdvancesByEnterKey(DependencyObject obj)
|
|
||||||
{
|
|
||||||
return (bool)obj.GetValue(AdvancesByEnterKeyProperty);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SetAdvancesByEnterKey(DependencyObject obj, bool value)
|
|
||||||
{
|
|
||||||
obj.SetValue(AdvancesByEnterKeyProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static readonly DependencyProperty AdvancesByEnterKeyProperty =
|
|
||||||
DependencyProperty.RegisterAttached("AdvancesByEnterKey", typeof(bool), typeof(FocusAdvancement),
|
|
||||||
new UIPropertyMetadata(OnAdvancesByEnterKeyPropertyChanged));
|
|
||||||
|
|
||||||
static void OnAdvancesByEnterKeyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
||||||
{
|
|
||||||
var element = d as UIElement;
|
|
||||||
if (element == null) return;
|
|
||||||
|
|
||||||
if ((bool)e.NewValue) element.KeyDown += Keydown;
|
|
||||||
else element.KeyDown -= Keydown;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Keydown(object sender, KeyEventArgs e)
|
|
||||||
{
|
|
||||||
if (!e.Key.Equals(Key.Enter)) return;
|
|
||||||
|
|
||||||
var element = sender as UIElement;
|
|
||||||
if (element != null) element.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,212 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Interop;
|
|
||||||
|
|
||||||
namespace Util.MagicCode
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Fixes the issue with Windows of Style <see cref="WindowStyle.None"/> covering the taskbar
|
|
||||||
/// </summary>
|
|
||||||
public class WindowResizer
|
|
||||||
{
|
|
||||||
#region Private Members
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The window to handle the resizing for
|
|
||||||
/// </summary>
|
|
||||||
private Window mWindow;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Dll Imports
|
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
|
||||||
static extern bool GetCursorPos(out POINT lpPoint);
|
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
|
||||||
static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
|
|
||||||
|
|
||||||
[DllImport("user32.dll", SetLastError = true)]
|
|
||||||
static extern IntPtr MonitorFromPoint(POINT pt, MonitorOptions dwFlags);
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructor
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Default constructor
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="window">The window to monitor and correctly maximize</param>
|
|
||||||
/// <param name="adjustSize">The callback for the host to adjust the maximum available size if needed</param>
|
|
||||||
public WindowResizer(Window window)
|
|
||||||
{
|
|
||||||
mWindow = window;
|
|
||||||
|
|
||||||
// Listen out for source initialized to setup
|
|
||||||
mWindow.SourceInitialized += Window_SourceInitialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Initialize
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initialize and hook into the windows message pump
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void Window_SourceInitialized(object sender, System.EventArgs e)
|
|
||||||
{
|
|
||||||
// Get the handle of this window
|
|
||||||
var handle = (new WindowInteropHelper(mWindow)).Handle;
|
|
||||||
var handleSource = HwndSource.FromHwnd(handle);
|
|
||||||
|
|
||||||
// If not found, end
|
|
||||||
if (handleSource == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Hook into it's Windows messages
|
|
||||||
handleSource.AddHook(WindowProc);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Windows Proc
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Listens out for all windows messages for this window
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="hwnd"></param>
|
|
||||||
/// <param name="msg"></param>
|
|
||||||
/// <param name="wParam"></param>
|
|
||||||
/// <param name="lParam"></param>
|
|
||||||
/// <param name="handled"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
|
||||||
{
|
|
||||||
switch (msg)
|
|
||||||
{
|
|
||||||
// Handle the GetMinMaxInfo of the Window
|
|
||||||
case 0x0024:/* WM_GETMINMAXINFO */
|
|
||||||
WmGetMinMaxInfo(hwnd, lParam);
|
|
||||||
handled = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (IntPtr)0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get the min/max window size for this window
|
|
||||||
/// Correctly accounting for the taskbar size and position
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="hwnd"></param>
|
|
||||||
/// <param name="lParam"></param>
|
|
||||||
private void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
|
|
||||||
{
|
|
||||||
POINT lMousePosition;
|
|
||||||
GetCursorPos(out lMousePosition);
|
|
||||||
|
|
||||||
IntPtr lPrimaryScreen = MonitorFromPoint(new POINT(0, 0), MonitorOptions.MONITOR_DEFAULTTOPRIMARY);
|
|
||||||
MONITORINFO lPrimaryScreenInfo = new MONITORINFO();
|
|
||||||
if (GetMonitorInfo(lPrimaryScreen, lPrimaryScreenInfo) == false)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
IntPtr lCurrentScreen = MonitorFromPoint(lMousePosition, MonitorOptions.MONITOR_DEFAULTTONEAREST);
|
|
||||||
|
|
||||||
MINMAXINFO lMmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
|
|
||||||
|
|
||||||
if (lPrimaryScreen.Equals(lCurrentScreen) == true)
|
|
||||||
{
|
|
||||||
lMmi.ptMaxPosition.X = lPrimaryScreenInfo.rcWork.Left;
|
|
||||||
lMmi.ptMaxPosition.Y = lPrimaryScreenInfo.rcWork.Top;
|
|
||||||
lMmi.ptMaxSize.X = lPrimaryScreenInfo.rcWork.Right - lPrimaryScreenInfo.rcWork.Left;
|
|
||||||
lMmi.ptMaxSize.Y = lPrimaryScreenInfo.rcWork.Bottom - lPrimaryScreenInfo.rcWork.Top;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lMmi.ptMaxPosition.X = lPrimaryScreenInfo.rcMonitor.Left;
|
|
||||||
lMmi.ptMaxPosition.Y = lPrimaryScreenInfo.rcMonitor.Top;
|
|
||||||
lMmi.ptMaxSize.X = lPrimaryScreenInfo.rcMonitor.Right - lPrimaryScreenInfo.rcMonitor.Left;
|
|
||||||
lMmi.ptMaxSize.Y = lPrimaryScreenInfo.rcMonitor.Bottom - lPrimaryScreenInfo.rcMonitor.Top;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we have the max size, allow the host to tweak as needed
|
|
||||||
Marshal.StructureToPtr(lMmi, lParam, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Dll Helper Structures
|
|
||||||
|
|
||||||
enum MonitorOptions : uint
|
|
||||||
{
|
|
||||||
MONITOR_DEFAULTTONULL = 0x00000000,
|
|
||||||
MONITOR_DEFAULTTOPRIMARY = 0x00000001,
|
|
||||||
MONITOR_DEFAULTTONEAREST = 0x00000002
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
|
||||||
public class MONITORINFO
|
|
||||||
{
|
|
||||||
public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
|
|
||||||
public Rectangle rcMonitor = new Rectangle();
|
|
||||||
public Rectangle rcWork = new Rectangle();
|
|
||||||
public int dwFlags = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct Rectangle
|
|
||||||
{
|
|
||||||
public int Left, Top, Right, Bottom;
|
|
||||||
|
|
||||||
public Rectangle(int left, int top, int right, int bottom)
|
|
||||||
{
|
|
||||||
this.Left = left;
|
|
||||||
this.Top = top;
|
|
||||||
this.Right = right;
|
|
||||||
this.Bottom = bottom;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct MINMAXINFO
|
|
||||||
{
|
|
||||||
public POINT ptReserved;
|
|
||||||
public POINT ptMaxSize;
|
|
||||||
public POINT ptMaxPosition;
|
|
||||||
public POINT ptMinTrackSize;
|
|
||||||
public POINT ptMaxTrackSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct POINT
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// x coordinate of point.
|
|
||||||
/// </summary>
|
|
||||||
public int X;
|
|
||||||
/// <summary>
|
|
||||||
/// y coordinate of point.
|
|
||||||
/// </summary>
|
|
||||||
public int Y;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Construct a point of coordinates (x,y).
|
|
||||||
/// </summary>
|
|
||||||
public POINT(int x, int y)
|
|
||||||
{
|
|
||||||
this.X = x;
|
|
||||||
this.Y = y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
xmlns:local="clr-namespace:ClientApp">
|
|
||||||
|
|
||||||
<ResourceDictionary.MergedDictionaries>
|
|
||||||
<ResourceDictionary Source="Colors.xaml"/>
|
|
||||||
</ResourceDictionary.MergedDictionaries>
|
|
||||||
|
|
||||||
<Style TargetType="{x:Type Button}" x:Key="Hoverless">
|
|
||||||
<Setter Property="Background" Value="Transparent"/>
|
|
||||||
<Setter Property="BorderThickness" Value="0"/>
|
|
||||||
<Setter Property="Template">
|
|
||||||
<Setter.Value>
|
|
||||||
<ControlTemplate TargetType="{x:Type Button}">
|
|
||||||
<Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}">
|
|
||||||
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
|
||||||
</Border>
|
|
||||||
</ControlTemplate>
|
|
||||||
</Setter.Value>
|
|
||||||
</Setter>
|
|
||||||
</Style>
|
|
||||||
|
|
||||||
<Style TargetType="{x:Type Button}" x:Key="SystemIconButton" BasedOn="{StaticResource Hoverless}" >
|
|
||||||
<Setter Property="WindowChrome.IsHitTestVisibleInChrome" Value="True"/>
|
|
||||||
<Setter Property="Padding" Value="4"/>
|
|
||||||
</Style>
|
|
||||||
|
|
||||||
<Style TargetType="{x:Type Button}" x:Key="WindowControlButton">
|
|
||||||
<Setter Property="WindowChrome.IsHitTestVisibleInChrome" Value="True"/>
|
|
||||||
<Setter Property="Background" Value="Transparent"/>
|
|
||||||
<Setter Property="VerticalAlignment" Value="Stretch"/>
|
|
||||||
<Setter Property="Foreground" Value="{StaticResource ForegroundMainBrush}"/>
|
|
||||||
<Setter Property="Padding" Value="6"/>
|
|
||||||
|
|
||||||
<Setter Property="LayoutTransform">
|
|
||||||
<Setter.Value>
|
|
||||||
<ScaleTransform ScaleX="2"/>
|
|
||||||
</Setter.Value>
|
|
||||||
</Setter>
|
|
||||||
|
|
||||||
<Setter Property="Template">
|
|
||||||
<Setter.Value>
|
|
||||||
<ControlTemplate TargetType="{x:Type Button}">
|
|
||||||
<Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}">
|
|
||||||
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
|
||||||
</Border>
|
|
||||||
</ControlTemplate>
|
|
||||||
</Setter.Value>
|
|
||||||
</Setter>
|
|
||||||
|
|
||||||
<Style.Triggers>
|
|
||||||
<Trigger Property="IsMouseOver" Value="True">
|
|
||||||
<Setter Property="Background" Value="{StaticResource BackgroundSemiLightBrush}"/>
|
|
||||||
</Trigger>
|
|
||||||
</Style.Triggers>
|
|
||||||
</Style>
|
|
||||||
|
|
||||||
<Style TargetType="{x:Type Button}" x:Key="WindowCloseButton" BasedOn="{StaticResource WindowControlButton}">
|
|
||||||
<Style.Triggers>
|
|
||||||
<Trigger Property="IsMouseOver" Value="True">
|
|
||||||
<Setter Property="Background" Value="Red"/>
|
|
||||||
</Trigger>
|
|
||||||
</Style.Triggers>
|
|
||||||
</Style>
|
|
||||||
</ResourceDictionary>
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
xmlns:local="clr-namespace:ClientApp">
|
|
||||||
|
|
||||||
<Color x:Key="BackgroundLight">#efefef</Color>
|
|
||||||
<SolidColorBrush x:Key="BackgroundLightBrush" Color="{StaticResource BackgroundLight}"/>
|
|
||||||
|
|
||||||
|
|
||||||
<Color x:Key="BackgroundVeryLight">#fafafa</Color>
|
|
||||||
<SolidColorBrush x:Key="BackgroundVeryLightBrush" Color="{StaticResource BackgroundVeryLight}"/>
|
|
||||||
|
|
||||||
<Color x:Key="BackgroundSemiLight">#d7d7d7</Color>
|
|
||||||
<SolidColorBrush x:Key="BackgroundSemiLightBrush" Color="{StaticResource BackgroundSemiLight}"/>
|
|
||||||
|
|
||||||
<Color x:Key="ForegroundMain">#686868</Color>
|
|
||||||
<SolidColorBrush x:Key="ForegroundMainBrush" Color="{StaticResource ForegroundMain}"/>
|
|
||||||
|
|
||||||
<Color x:Key="ForegroundVeryDark">#000</Color>
|
|
||||||
<SolidColorBrush x:Key="ForegroundVeryDarkBrush" Color="{StaticResource ForegroundVeryDark}"/>
|
|
||||||
|
|
||||||
<Color x:Key="ForegroundWhite">#fff</Color>
|
|
||||||
<SolidColorBrush x:Key="ForegroundWhiteBrush" Color="{StaticResource ForegroundWhite}"/>
|
|
||||||
|
|
||||||
|
|
||||||
</ResourceDictionary>
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
xmlns:local="clr-namespace:ClientApp">
|
|
||||||
|
|
||||||
</ResourceDictionary>
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
xmlns:local="clr-namespace:ClientApp">
|
|
||||||
|
|
||||||
<Style TargetType="{x:Type TextBlock}" x:Key="HeaderText">
|
|
||||||
<Setter Property="Foreground" Value="{StaticResource ForegroundMainBrush}"/>
|
|
||||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
|
||||||
<Setter Property="HorizontalAlignment" Value="Center"/>
|
|
||||||
<Setter Property="Margin" Value="0 4"/>
|
|
||||||
</Style>
|
|
||||||
</ResourceDictionary>
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
xmlns:local="clr-namespace:ClientApp">
|
|
||||||
|
|
||||||
</ResourceDictionary>
|
|
||||||
@@ -51,13 +51,13 @@ namespace Hardware
|
|||||||
|
|
||||||
// List available devices
|
// List available devices
|
||||||
List<String> bleBikeList = bleBike.ListDevices();
|
List<String> bleBikeList = bleBike.ListDevices();
|
||||||
Console.WriteLine("[BLEHANDLER] Devices found: ");
|
Console.WriteLine("Devices found: ");
|
||||||
foreach (var name in bleBikeList)
|
foreach (var name in bleBikeList)
|
||||||
{
|
{
|
||||||
Console.WriteLine(name);
|
Console.WriteLine(name);
|
||||||
if (name.Contains("Avans Bike"))
|
if (name.Contains("Avans Bike"))
|
||||||
{
|
{
|
||||||
Console.WriteLine("[BLEHANDLER] connecting to {0}", name);
|
Console.WriteLine("connecting to {0}", name);
|
||||||
Connect(name);
|
Connect(name);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -203,11 +203,5 @@ namespace Hardware
|
|||||||
|
|
||||||
bleBike.WriteCharacteristic("6e40fec3-b5a3-f393-e0a9-e50e24dcca9e", antMessage);
|
bleBike.WriteCharacteristic("6e40fec3-b5a3-f393-e0a9-e50e24dcca9e", antMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop()
|
|
||||||
{
|
|
||||||
bleBike.SubscriptionValueChanged -= BleBike_SubscriptionValueChanged;
|
|
||||||
bleHeart.SubscriptionValueChanged -= BleBike_SubscriptionValueChanged;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
using ProftaakRH;
|
using ProftaakRH;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -29,8 +28,6 @@ namespace Hardware.Simulators
|
|||||||
byte[] powerArray;
|
byte[] powerArray;
|
||||||
byte[] accPowerArray;
|
byte[] accPowerArray;
|
||||||
|
|
||||||
bool running = false;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public BikeSimulator(IDataReceiver dataReceiver)
|
public BikeSimulator(IDataReceiver dataReceiver)
|
||||||
@@ -54,14 +51,12 @@ namespace Hardware.Simulators
|
|||||||
//Example BLE Message
|
//Example BLE Message
|
||||||
//4A-09-4E-05-19-16-00-FF-28-00-00-20-F0
|
//4A-09-4E-05-19-16-00-FF-28-00-00-20-F0
|
||||||
|
|
||||||
this.running = true;
|
|
||||||
|
|
||||||
float x = 0.0f;
|
float x = 0.0f;
|
||||||
|
|
||||||
//Perlin for Random values
|
//Perlin for Random values
|
||||||
ImprovedPerlin improvedPerlin = new ImprovedPerlin(0, LibNoise.NoiseQuality.Best);
|
ImprovedPerlin improvedPerlin = new ImprovedPerlin(0, LibNoise.NoiseQuality.Best);
|
||||||
|
|
||||||
while (this.running)
|
while (true)
|
||||||
{
|
{
|
||||||
CalculateVariables(improvedPerlin.GetValue(x) + 1);
|
CalculateVariables(improvedPerlin.GetValue(x) + 1);
|
||||||
|
|
||||||
@@ -93,24 +88,8 @@ namespace Hardware.Simulators
|
|||||||
//Generate an ANT message for page 0x10
|
//Generate an ANT message for page 0x10
|
||||||
private byte[] GenerateBike0x10()
|
private byte[] GenerateBike0x10()
|
||||||
{
|
{
|
||||||
|
byte[] bikeByte = { 0x10, Convert.ToByte(equipmentType), Convert.ToByte(elapsedTime * 4 % 64), Convert.ToByte(distanceTraveled), speedArray[0], speedArray[1], Convert.ToByte(BPM), 0xFF };
|
||||||
try
|
return bikeByte;
|
||||||
{
|
|
||||||
byte[] bikeByte = { 0x10, check(equipmentType), check(elapsedTime * 4 % 64), check((int)Math.Round(distanceTraveled)), speedArray[0], speedArray[1], check(BPM), 0xFF };
|
|
||||||
return bikeByte;
|
|
||||||
}
|
|
||||||
catch (OverflowException e)
|
|
||||||
{
|
|
||||||
Debug.WriteLine(e);
|
|
||||||
byte[] res = { 0x10,0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0xFF};
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte check(int value)
|
|
||||||
{
|
|
||||||
|
|
||||||
return value > 255 ? Convert.ToByte(255) : value < 0 ? Convert.ToByte(0) : Convert.ToByte(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Generate an ANT message for BPM
|
//Generate an ANT message for BPM
|
||||||
@@ -145,10 +124,6 @@ namespace Hardware.Simulators
|
|||||||
this.resistance = (byte)Math.Max(Math.Min(Math.Round(percentage / 0.5), 255), 0);
|
this.resistance = (byte)Math.Max(Math.Min(Math.Round(percentage / 0.5), 255), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop()
|
|
||||||
{
|
|
||||||
this.running = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,5 @@ namespace ProftaakRH
|
|||||||
public interface IHandler
|
public interface IHandler
|
||||||
{
|
{
|
||||||
void setResistance(float percentage);
|
void setResistance(float percentage);
|
||||||
|
|
||||||
void stop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,64 +3,56 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 16
|
# Visual Studio Version 16
|
||||||
VisualStudioVersion = 16.0.30413.136
|
VisualStudioVersion = 16.0.30413.136
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientApp", "..\ClientApp\ClientApp.csproj", "{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProftaakRH", "ProftaakRH.csproj", "{0F053CC5-D969-4970-9501-B3428EA3D777}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Util", "..\Hashing\Util.shproj", "{70277749-D423-4871-B692-2EFC5A6ED932}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RH-Engine", "..\RH-Engine\RH-Engine.csproj", "{984E295E-47A2-41E7-90E5-50FDB9E67694}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProftaakRH", "ProftaakRH.csproj", "{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "..\Server\Server.csproj", "{B1AB6F51-A20D-4162-9A7F-B3350B7510FD}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RH-Engine", "..\RH-Engine\RH-Engine.csproj", "{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Message", "..\Message\Message.csproj", "{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "..\Server\Server.csproj", "{7D751284-17E8-434C-A7F6-2EB37572E7AE}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DokterApp", "..\DokterApp\DokterApp.csproj", "{B150F08B-13DA-4D17-BD96-7E89F52727C6}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DoctorApp", "..\DoctorApp\DoctorApp.csproj", "{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}"
|
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Hashing", "..\Hashing\Hashing.shproj", "{70277749-D423-4871-B692-2EFC5A6ED932}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTestRH", "..\UnitTestRH\UnitTestRH.csproj", "{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientApp", "..\ClientApp\ClientApp.csproj", "{013AADBA-1D27-4A52-81D8-217697E91039}"
|
||||||
ProjectSection(ProjectDependencies) = postProject
|
|
||||||
{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B} = {BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}
|
|
||||||
{7D751284-17E8-434C-A7F6-2EB37572E7AE} = {7D751284-17E8-434C-A7F6-2EB37572E7AE}
|
|
||||||
{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F} = {7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}
|
|
||||||
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994} = {A232F2D5-AF98-4777-BF3A-FBDDFBC02994}
|
|
||||||
{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3} = {C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}
|
|
||||||
EndProjectSection
|
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||||
..\Hashing\Hashing.projitems*{0b6ccc1d-5e76-420e-b54d-eb3e5ffea6cb}*SharedItemsImports = 5
|
..\Hashing\Hashing.projitems*{013aadba-1d27-4a52-81d8-217697e91039}*SharedItemsImports = 5
|
||||||
..\Hashing\Hashing.projitems*{70277749-d423-4871-b692-2efc5a6ed932}*SharedItemsImports = 13
|
..\Hashing\Hashing.projitems*{70277749-d423-4871-b692-2efc5a6ed932}*SharedItemsImports = 13
|
||||||
..\Hashing\Hashing.projitems*{7d751284-17e8-434c-a7f6-2eb37572e7ae}*SharedItemsImports = 5
|
..\Hashing\Hashing.projitems*{b150f08b-13da-4d17-bd96-7e89f52727c6}*SharedItemsImports = 5
|
||||||
..\Hashing\Hashing.projitems*{7ef854c1-73eb-4099-a7d7-057cceee6f8f}*SharedItemsImports = 5
|
..\Hashing\Hashing.projitems*{b1ab6f51-a20d-4162-9a7f-b3350b7510fd}*SharedItemsImports = 5
|
||||||
..\Hashing\Hashing.projitems*{a232f2d5-af98-4777-bf3a-fbddfbc02994}*SharedItemsImports = 5
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{0F053CC5-D969-4970-9501-B3428EA3D777}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{0F053CC5-D969-4970-9501-B3428EA3D777}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{0F053CC5-D969-4970-9501-B3428EA3D777}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}.Release|Any CPU.Build.0 = Release|Any CPU
|
{0F053CC5-D969-4970-9501-B3428EA3D777}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{984E295E-47A2-41E7-90E5-50FDB9E67694}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{984E295E-47A2-41E7-90E5-50FDB9E67694}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{984E295E-47A2-41E7-90E5-50FDB9E67694}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}.Release|Any CPU.Build.0 = Release|Any CPU
|
{984E295E-47A2-41E7-90E5-50FDB9E67694}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{B1AB6F51-A20D-4162-9A7F-B3350B7510FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{B1AB6F51-A20D-4162-9A7F-B3350B7510FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{B1AB6F51-A20D-4162-9A7F-B3350B7510FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}.Release|Any CPU.Build.0 = Release|Any CPU
|
{B1AB6F51-A20D-4162-9A7F-B3350B7510FD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{7D751284-17E8-434C-A7F6-2EB37572E7AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{7D751284-17E8-434C-A7F6-2EB37572E7AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{7D751284-17E8-434C-A7F6-2EB37572E7AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{7D751284-17E8-434C-A7F6-2EB37572E7AE}.Release|Any CPU.Build.0 = Release|Any CPU
|
{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{B150F08B-13DA-4D17-BD96-7E89F52727C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{B150F08B-13DA-4D17-BD96-7E89F52727C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{B150F08B-13DA-4D17-BD96-7E89F52727C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Release|Any CPU.Build.0 = Release|Any CPU
|
{B150F08B-13DA-4D17-BD96-7E89F52727C6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{013AADBA-1D27-4A52-81D8-217697E91039}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{013AADBA-1D27-4A52-81D8-217697E91039}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{013AADBA-1D27-4A52-81D8-217697E91039}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}.Release|Any CPU.Build.0 = Release|Any CPU
|
{013AADBA-1D27-4A52-81D8-217697E91039}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -19,32 +19,30 @@ namespace RH_Engine
|
|||||||
this.tunnelID = tunnelID;
|
this.tunnelID = tunnelID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string TerrainAdd(int[] sizeArray, float[] heightsArray, string serialCode)
|
public string TerrainCommand(int[] sizeArray, float[] heightsArray)
|
||||||
{
|
{
|
||||||
dynamic payload = new
|
dynamic payload = new
|
||||||
{
|
{
|
||||||
id = "scene/terrain/add",
|
id = "scene/terrain/add",
|
||||||
serial = serialCode,
|
|
||||||
data = new
|
data = new
|
||||||
{
|
{
|
||||||
size = sizeArray,
|
size = sizeArray,
|
||||||
heights = heightsArray,
|
heights = heightsArray
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return JsonConvert.SerializeObject(Payload(payload));
|
return JsonConvert.SerializeObject(Payload(payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
public string AddLayer(string uuid, string serialCode)
|
public string AddLayer(string uid, string texture)
|
||||||
{
|
{
|
||||||
dynamic payload = new
|
dynamic payload = new
|
||||||
{
|
{
|
||||||
id = "scene/node/addlayer",
|
id = "scene/node/addlayer",
|
||||||
serial = serialCode,
|
|
||||||
data = new
|
data = new
|
||||||
{
|
{
|
||||||
id = uuid,
|
id = uid,
|
||||||
diffuse = @"data\NetworkEngine\textures\terrain\grass_green_d.jpg",
|
diffuse = @"C:\Users\woute\Downloads\NetworkEngine.18.10.10.1\NetworkEngine\data\NetworkEngine\textures\terrain\adesert_cracks_d.jpg",
|
||||||
normal = @"data\NetworkEngine\textures\terrain\grass_green_n.jpg",
|
normal = @"C:\Users\woute\Downloads\NetworkEngine.18.10.10.1\NetworkEngine\data\NetworkEngine\textures\terrain\adesert_mntn_d.jpg",
|
||||||
minHeight = 0,
|
minHeight = 0,
|
||||||
maxHeight = 10,
|
maxHeight = 10,
|
||||||
fadeDist = 1
|
fadeDist = 1
|
||||||
@@ -65,27 +63,19 @@ namespace RH_Engine
|
|||||||
return JsonConvert.SerializeObject(Payload(payload));
|
return JsonConvert.SerializeObject(Payload(payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
public string renderTerrain(string serialCode)
|
public string AddNodeCommand()
|
||||||
{
|
{
|
||||||
dynamic payload = new
|
dynamic payload = new
|
||||||
{
|
{
|
||||||
id = "scene/node/add",
|
id = "scene/node/add",
|
||||||
serial = serialCode,
|
|
||||||
data = new
|
data = new
|
||||||
{
|
{
|
||||||
name = "newNode",
|
name = "newNode",
|
||||||
components = new
|
components = new
|
||||||
{
|
{
|
||||||
transform = new
|
|
||||||
{
|
|
||||||
position = new int[] { -80, 0, -80 },
|
|
||||||
scale = 1f,
|
|
||||||
rotation = new int[] { 0, 0, 0 }
|
|
||||||
},
|
|
||||||
terrain = new
|
terrain = new
|
||||||
{
|
{
|
||||||
smoothnormals = true,
|
smoothnormals = true
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,7 +164,7 @@ namespace RH_Engine
|
|||||||
return JsonConvert.SerializeObject(Payload(payload));
|
return JsonConvert.SerializeObject(Payload(payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
public string showOnPanel(string uuidPanel, string serialCode, string mText, int index)
|
private string showOnPanel(string uuidPanel, string serialCode, string mText, int index)
|
||||||
{
|
{
|
||||||
dynamic payload = new
|
dynamic payload = new
|
||||||
{
|
{
|
||||||
@@ -197,7 +187,23 @@ namespace RH_Engine
|
|||||||
|
|
||||||
public string showBikespeed(string uuidPanel, string serialCode, double speed)
|
public string showBikespeed(string uuidPanel, string serialCode, double speed)
|
||||||
{
|
{
|
||||||
return showOnPanel(uuidPanel, serialCode, $"Speed: {string.Format("{0:.##}", speed)} m /s ({string.Format("{0:.##}", speed * 3.6)} km/h)", 0);
|
//dynamic payload = new
|
||||||
|
//{
|
||||||
|
// id = "scene/panel/drawtext",
|
||||||
|
// serial = serialCode,
|
||||||
|
// data = new
|
||||||
|
// {
|
||||||
|
// id = uuidPanel,
|
||||||
|
// text = "Speed: " + speed + " m/s",
|
||||||
|
// position = new int[] { 4, 24 },
|
||||||
|
// size = 36.0,
|
||||||
|
// color = new int[] { 0, 0, 0, 1 },
|
||||||
|
// font = "segoeui"
|
||||||
|
// }
|
||||||
|
//};
|
||||||
|
|
||||||
|
//return JsonConvert.SerializeObject(Payload(payload));
|
||||||
|
return showOnPanel(uuidPanel, serialCode, "Speed: " + speed + " m/s", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string showHeartrate(string uuidPanel, string serialCode, int bpm)
|
public string showHeartrate(string uuidPanel, string serialCode, int bpm)
|
||||||
@@ -215,11 +221,6 @@ namespace RH_Engine
|
|||||||
return showOnPanel(uuidPanel, serialCode, "Resistance: " + resistance + " %", 3);
|
return showOnPanel(uuidPanel, serialCode, "Resistance: " + resistance + " %", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string showMessage(string uuidPanel, string serialCode, string message)
|
|
||||||
{
|
|
||||||
return showOnPanel(uuidPanel, serialCode, "Last message: " + message, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
public string SwapPanelCommand(string uuid)
|
public string SwapPanelCommand(string uuid)
|
||||||
{
|
{
|
||||||
dynamic payload = new
|
dynamic payload = new
|
||||||
@@ -253,11 +254,6 @@ namespace RH_Engine
|
|||||||
return AddModel("bike", serial, "data\\NetworkEngine\\models\\bike\\bike.fbx");
|
return AddModel("bike", serial, "data\\NetworkEngine\\models\\bike\\bike.fbx");
|
||||||
}
|
}
|
||||||
|
|
||||||
public string AddBikeModelAnim(string serial, float scalar)
|
|
||||||
{
|
|
||||||
return AddModel("bike", serial, "data\\NetworkEngine\\models\\bike\\bike_anim.fbx", "Armature|Fietsen", new float[] { 0, 0, 0 }, scalar, new float[] { 0, 0, 0 });
|
|
||||||
}
|
|
||||||
|
|
||||||
public string AddModel(string nodeName, string serial, string fileLocation)
|
public string AddModel(string nodeName, string serial, string fileLocation)
|
||||||
{
|
{
|
||||||
return AddModel(nodeName, serial, fileLocation, null, new float[] { 0, 0, 0 }, 1, new float[] { 0, 0, 0 });
|
return AddModel(nodeName, serial, fileLocation, null, new float[] { 0, 0, 0 }, 1, new float[] { 0, 0, 0 });
|
||||||
@@ -331,19 +327,6 @@ namespace RH_Engine
|
|||||||
return JsonConvert.SerializeObject(Payload(payload));
|
return JsonConvert.SerializeObject(Payload(payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ShowRoute(string serialCode, bool goShow)
|
|
||||||
{
|
|
||||||
dynamic payload = new
|
|
||||||
{
|
|
||||||
id = "route/show",
|
|
||||||
data = new
|
|
||||||
{
|
|
||||||
show = goShow
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return JsonConvert.SerializeObject(Payload(payload));
|
|
||||||
}
|
|
||||||
|
|
||||||
public string RouteCommand(string serialToSend)
|
public string RouteCommand(string serialToSend)
|
||||||
{
|
{
|
||||||
ImprovedPerlin improvedPerlin = new ImprovedPerlin(4325, LibNoise.NoiseQuality.Best);
|
ImprovedPerlin improvedPerlin = new ImprovedPerlin(4325, LibNoise.NoiseQuality.Best);
|
||||||
@@ -455,13 +438,12 @@ namespace RH_Engine
|
|||||||
return JsonConvert.SerializeObject(Payload(payload));
|
return JsonConvert.SerializeObject(Payload(payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string RoadCommand(string uuid_route)
|
||||||
public string RoadCommand(string uuid_route, string serialCode)
|
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("road");
|
||||||
dynamic payload = new
|
dynamic payload = new
|
||||||
{
|
{
|
||||||
id = "scene/road/add",
|
id = "scene/road/add",
|
||||||
serial = serialCode,
|
|
||||||
data = new
|
data = new
|
||||||
{
|
{
|
||||||
route = uuid_route,
|
route = uuid_route,
|
||||||
@@ -498,7 +480,6 @@ namespace RH_Engine
|
|||||||
|
|
||||||
public string SkyboxCommand(double timeToSet)
|
public string SkyboxCommand(double timeToSet)
|
||||||
{
|
{
|
||||||
Console.WriteLine(timeToSet);
|
|
||||||
if (timeToSet < 0 || timeToSet > 24)
|
if (timeToSet < 0 || timeToSet > 24)
|
||||||
{
|
{
|
||||||
throw new Exception("The time must be between 0 and 24!");
|
throw new Exception("The time must be between 0 and 24!");
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace RH_Engine
|
namespace RH_Engine
|
||||||
@@ -74,7 +73,6 @@ namespace RH_Engine
|
|||||||
|
|
||||||
public static string GetID(string json)
|
public static string GetID(string json)
|
||||||
{
|
{
|
||||||
//TODO fix null
|
|
||||||
dynamic d = JsonConvert.DeserializeObject(json);
|
dynamic d = JsonConvert.DeserializeObject(json);
|
||||||
return d.id;
|
return d.id;
|
||||||
}
|
}
|
||||||
@@ -89,16 +87,6 @@ namespace RH_Engine
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetTerrainID(string json)
|
|
||||||
{
|
|
||||||
dynamic jsonData = JsonConvert.DeserializeObject(json);
|
|
||||||
if (jsonData.data.data.status == "ok")
|
|
||||||
{
|
|
||||||
return jsonData.data.data.data.uuid;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// method to get the uuid from requests for adding a node,route or road
|
/// method to get the uuid from requests for adding a node,route or road
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -124,19 +112,5 @@ namespace RH_Engine
|
|||||||
}
|
}
|
||||||
return null;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,6 @@ using Newtonsoft.Json;
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Dynamic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -19,15 +17,13 @@ namespace RH_Engine
|
|||||||
//new PC("DESKTOP-M2CIH87", "Fabian"),
|
//new PC("DESKTOP-M2CIH87", "Fabian"),
|
||||||
//new PC("T470S", "Shinichi"),
|
//new PC("T470S", "Shinichi"),
|
||||||
//new PC("DESKTOP-DHS478C", "semme"),
|
//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-TV73FKO", "Wouter"),
|
||||||
new PC("DESKTOP-SINMKT1", "Ralf van Aert"),
|
//new PC("DESKTOP-SINMKT1", "Ralf van Aert"),
|
||||||
//new PC("NA", "Bart")
|
//new PC("NA", "Bart")
|
||||||
};
|
};
|
||||||
|
|
||||||
private static ServerResponseReader serverResponseReader;
|
private static ServerResponseReader serverResponseReader;
|
||||||
|
|
||||||
private static string terrainId = string.Empty;
|
|
||||||
private static string sessionId = string.Empty;
|
private static string sessionId = string.Empty;
|
||||||
private static string tunnelId = string.Empty;
|
private static string tunnelId = string.Empty;
|
||||||
private static string cameraId = string.Empty;
|
private static string cameraId = string.Empty;
|
||||||
@@ -36,12 +32,6 @@ namespace RH_Engine
|
|||||||
private static string bikeId = string.Empty;
|
private static string bikeId = string.Empty;
|
||||||
private static string headId = string.Empty;
|
private static string headId = string.Empty;
|
||||||
|
|
||||||
private static double bikeSpeed = 6.66;
|
|
||||||
private static int bpm = 6;
|
|
||||||
private static int power = 6;
|
|
||||||
private static int resistance = 6;
|
|
||||||
private static string lastMessage = "No message received yet";
|
|
||||||
|
|
||||||
private static Dictionary<string, HandleSerial> serialResponses = new Dictionary<string, HandleSerial>();
|
private static Dictionary<string, HandleSerial> serialResponses = new Dictionary<string, HandleSerial>();
|
||||||
|
|
||||||
private static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
@@ -181,11 +171,9 @@ namespace RH_Engine
|
|||||||
//Force(stream, mainCommand.DeleteNode(handRightId, "deleteHandR"), "deleteHandR", (message) => Console.WriteLine("Right hand deleted"));
|
//Force(stream, mainCommand.DeleteNode(handRightId, "deleteHandR"), "deleteHandR", (message) => Console.WriteLine("Right hand deleted"));
|
||||||
});
|
});
|
||||||
|
|
||||||
CreateTerrain(stream, mainCommand);
|
|
||||||
|
|
||||||
//Add route, bike and put camera and bike to follow route at same speed.
|
//Add route, bike and put camera and bike to follow route at same speed.
|
||||||
SendMessageAndOnResponse(stream, mainCommand.RouteCommand("routeID"), "routeID", (message) => routeId = JSONParser.GetResponseUuid(message));
|
SendMessageAndOnResponse(stream, mainCommand.RouteCommand("routeID"), "routeID", (message) => routeId = JSONParser.GetResponseUuid(message));
|
||||||
SendMessageAndOnResponse(stream, mainCommand.AddBikeModelAnim("bikeID", 0.01f), "bikeID",
|
SendMessageAndOnResponse(stream, mainCommand.AddBikeModel("bikeID"), "bikeID",
|
||||||
(message) =>
|
(message) =>
|
||||||
{
|
{
|
||||||
bikeId = JSONParser.GetResponseUuid(message);
|
bikeId = JSONParser.GetResponseUuid(message);
|
||||||
@@ -195,53 +183,64 @@ namespace RH_Engine
|
|||||||
bool speedReplied = false;
|
bool speedReplied = false;
|
||||||
bool moveReplied = true;
|
bool moveReplied = true;
|
||||||
panelId = JSONParser.getPanelID(message);
|
panelId = JSONParser.getPanelID(message);
|
||||||
|
WriteTextMessage(stream, mainCommand.ColorPanel(panelId));
|
||||||
|
WriteTextMessage(stream, mainCommand.ClearPanel(panelId));
|
||||||
|
|
||||||
showPanel(stream, mainCommand);
|
|
||||||
|
showPanel(stream, mainCommand, 5.3, 83, 52, 53);
|
||||||
|
|
||||||
|
|
||||||
//while (!(speedReplied && moveReplied)) { }
|
//while (!(speedReplied && moveReplied)) { }
|
||||||
|
|
||||||
while (cameraId == string.Empty) { }
|
while (cameraId == string.Empty) { }
|
||||||
SetFollowSpeed(5.0f, stream, mainCommand);
|
SetFollowSpeed(5.0f, stream, mainCommand);
|
||||||
WriteTextMessage(stream, mainCommand.RoadCommand(routeId, "road"));
|
|
||||||
WriteTextMessage(stream, mainCommand.ShowRoute("showRouteFalse", false));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
string groundplaneId = GetId("GroundPlane", stream, mainCommand);
|
//Force(stream, mainCommand.addPanel("panelID", bikeId), "panelID",
|
||||||
WriteTextMessage(stream, mainCommand.DeleteNode(groundplaneId, "none"));
|
// (message) =>
|
||||||
|
// {
|
||||||
|
// Console.WriteLine("panel response: " + message);
|
||||||
|
// panelId = JSONParser.GetResponseUuid(message);
|
||||||
|
// while(bikeId == string.Empty) { }
|
||||||
|
// SetFollowSpeed(5.0f, stream, mainCommand);
|
||||||
|
// });
|
||||||
|
//SendMessageAndOnResponse(stream, maincommand.addpanel("panelid", bikeid), "panelid",
|
||||||
|
// (message) =>
|
||||||
|
// {
|
||||||
|
// console.writeline("panelid: " + message);
|
||||||
|
// //panelid = jsonparser.getpanelid(message);
|
||||||
|
// panelid = jsonparser.getresponseuuid(message);
|
||||||
|
// while (bikeid == string.empty) { }
|
||||||
|
// setfollowspeed(5.0f, stream, maincommand);
|
||||||
|
// });
|
||||||
|
|
||||||
PlaceHouses(stream, mainCommand);
|
|
||||||
|
|
||||||
WriteTextMessage(stream, mainCommand.SkyboxCommand(DateTime.Now.Hour));
|
|
||||||
|
|
||||||
}
|
//WriteTextMessage(stream, mainCommand.TerrainCommand(new int[] { 256, 256 }, null));
|
||||||
|
//string command;
|
||||||
|
|
||||||
private static void PlaceHouses(NetworkStream stream, Command mainCommand)
|
|
||||||
{
|
|
||||||
// public string AddModel(string nodeName, string serial, string fileLocation, float[] positionVector, float scalar, float[] rotationVector)
|
|
||||||
//string folderHouses = @"data\NetworkEngine\models\houses\set1\";
|
|
||||||
//SendMessageAndOnResponse(stream, mainCommand.AddModel("House1", "uselessSerial_atm", folderHouses + "house1.obj", new float[] { -20f, 1f, 0f }, 4 , new float[] { 0f, 0f, 0f }), "uselessSerial_atm", (message) => Console.WriteLine(message));
|
|
||||||
//WriteTextMessage(stream, mainCommand.AddModel("House1", "uselessSerial_atm", @"C:\Users\Ralf van Aert\Documents\AvansTI\NetworkEngine.18.10.10.1\NetworkEngine\data\NetworkEngine\models\houses\set1\house4.obj"));
|
|
||||||
|
|
||||||
PlaceHouse(stream, mainCommand, 2, new float[] { 10f, 1f, 30f }, 1);
|
|
||||||
PlaceHouse(stream, mainCommand, 1, new float[] { 42f, 1f, 22f }, new float[] { 0f, 90f, 0f }, 2);
|
|
||||||
PlaceHouse(stream, mainCommand, 11, new float[] { -20f, 1f, 0f }, new float[] { 0f, -35f, 0f }, 3);
|
|
||||||
PlaceHouse(stream, mainCommand, 7, new float[] { -15f, 1f, 50f }, new float[] { 0f, -50f, 0f }, 4);
|
|
||||||
PlaceHouse(stream, mainCommand, 24, new float[] { 40f, 1f, 40f }, new float[] { 0f, 75f, 0f }, 5);
|
|
||||||
PlaceHouse(stream, mainCommand, 22, new float[] { 34f, 1f, -20f }, 6);
|
|
||||||
PlaceHouse(stream, mainCommand, 14, new float[] { 0f, 1f, -20f }, new float[] { 0f, 210f, 0f }, 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void PlaceHouse(NetworkStream stream, Command mainCommand, int numberHousemodel, float[] position, int serialNumber)
|
//Console.WriteLine("id of head " + GetId(Command.STANDARD_HEAD, stream, mainCommand));
|
||||||
{
|
|
||||||
PlaceHouse(stream, mainCommand, numberHousemodel, position, new float[] { 0f, 0f, 0f }, serialNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void PlaceHouse(NetworkStream stream, Command mainCommand, int numberHousemodel, float[] position, float[] rotation, int serialNumber)
|
//command = mainCommand.AddModel("car", "data\\customModels\\TeslaRoadster.fbx");
|
||||||
{
|
//WriteTextMessage(stream, command);
|
||||||
string folderHouses = @"data\NetworkEngine\models\houses\set1\";
|
|
||||||
SendMessageAndOnResponse(stream, mainCommand.AddModel("House1", "housePlacement" + serialNumber, folderHouses + "house" + numberHousemodel + ".obj", position, 4, rotation), "housePlacement" + serialNumber, (message) => Console.WriteLine(message));
|
//command = mainCommand.addPanel();
|
||||||
|
// WriteTextMessage(stream, command);
|
||||||
|
// string response = ReadPrefMessage(stream);
|
||||||
|
// Console.WriteLine("add Panel response: \n\r" + response);
|
||||||
|
// string uuidPanel = JSONParser.getPanelID(response);
|
||||||
|
// WriteTextMessage(stream, mainCommand.ClearPanel(uuidPanel));
|
||||||
|
// Console.WriteLine(ReadPrefMessage(stream));
|
||||||
|
// WriteTextMessage(stream, mainCommand.bikeSpeed(uuidPanel, 2.42));
|
||||||
|
// Console.WriteLine(ReadPrefMessage(stream));
|
||||||
|
// WriteTextMessage(stream, mainCommand.ColorPanel(uuidPanel));
|
||||||
|
// Console.WriteLine("Color panel: " + ReadPrefMessage(stream));
|
||||||
|
// WriteTextMessage(stream, mainCommand.SwapPanel(uuidPanel));
|
||||||
|
// Console.WriteLine("Swap panel: " + ReadPrefMessage(stream));
|
||||||
|
Console.WriteLine("id of head " + GetId(Command.STANDARD_HEAD, stream, mainCommand));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -273,32 +272,12 @@ namespace RH_Engine
|
|||||||
ImprovedPerlin improvedPerlin = new ImprovedPerlin(0, LibNoise.NoiseQuality.Best);
|
ImprovedPerlin improvedPerlin = new ImprovedPerlin(0, LibNoise.NoiseQuality.Best);
|
||||||
for (int i = 0; i < 256 * 256; i++)
|
for (int i = 0; i < 256 * 256; i++)
|
||||||
{
|
{
|
||||||
height[i] = improvedPerlin.GetValue(x / 10, x / 10, x * 100)/3.5f + 1;
|
height[i] = improvedPerlin.GetValue(x / 10, x / 10, x * 100) + 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;
|
x += 0.001f;
|
||||||
}
|
}
|
||||||
|
WriteTextMessage(stream, createGraphics.TerrainCommand(new int[] { 256, 256 }, height));
|
||||||
|
|
||||||
SendMessageAndOnResponse(stream, createGraphics.TerrainAdd(new int[] { 256, 256 }, height, "terrain"), "terrain",
|
WriteTextMessage(stream, createGraphics.AddNodeCommand());
|
||||||
(message) =>
|
|
||||||
{
|
|
||||||
|
|
||||||
SendMessageAndOnResponse(stream, createGraphics.renderTerrain("renderTerrain"), "renderTerrain",
|
|
||||||
(message) =>
|
|
||||||
{
|
|
||||||
terrainId = JSONParser.GetTerrainID(message);
|
|
||||||
string addLayerMsg = createGraphics.AddLayer(terrainId, "addLayer");
|
|
||||||
SendMessageAndOnResponse(stream, addLayerMsg, "addLayer", (message) => Console.WriteLine(""));
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -341,10 +320,8 @@ namespace RH_Engine
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void showPanel(NetworkStream stream, Command mainCommand)
|
private static void showPanel(NetworkStream stream, Command mainCommand, double bikeSpeed, int bpm, int power, int resistance)
|
||||||
{
|
{
|
||||||
WriteTextMessage(stream, mainCommand.ColorPanel(panelId));
|
|
||||||
WriteTextMessage(stream, mainCommand.ClearPanel(panelId));
|
|
||||||
SendMessageAndOnResponse(stream, mainCommand.showBikespeed(panelId, "bikeSpeed", bikeSpeed), "bikeSpeed",
|
SendMessageAndOnResponse(stream, mainCommand.showBikespeed(panelId, "bikeSpeed", bikeSpeed), "bikeSpeed",
|
||||||
(message) =>
|
(message) =>
|
||||||
{
|
{
|
||||||
@@ -365,11 +342,6 @@ namespace RH_Engine
|
|||||||
{
|
{
|
||||||
// TODO check if is drawn
|
// TODO check if is drawn
|
||||||
});
|
});
|
||||||
SendMessageAndOnResponse(stream, mainCommand.showMessage(panelId, "message", lastMessage), "message",
|
|
||||||
(message) =>
|
|
||||||
{
|
|
||||||
// TODO check if is drawn
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check if every text is drawn!
|
// Check if every text is drawn!
|
||||||
|
|
||||||
@@ -380,7 +352,6 @@ namespace RH_Engine
|
|||||||
{
|
{
|
||||||
WriteTextMessage(stream, mainCommand.RouteFollow(routeId, bikeId, speed, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 }));
|
WriteTextMessage(stream, mainCommand.RouteFollow(routeId, bikeId, speed, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 }));
|
||||||
WriteTextMessage(stream, mainCommand.RouteFollow(routeId, cameraId, speed));
|
WriteTextMessage(stream, mainCommand.RouteFollow(routeId, cameraId, speed));
|
||||||
//WriteTextMessage(stream, mainCommand.RouteFollow(routeId, panelId, speed, 1f, "XYZ", 1, false, new float[] { 0, 0, 0 }, new float[] { 0f, 5f, 5f }));
|
|
||||||
}
|
}
|
||||||
//string routeID, string nodeID, float speedValue, float offsetValue, string rotateValue, float smoothingValue, bool followHeightValue, float[] rotateOffsetVector, float[] positionOffsetVector)
|
//string routeID, string nodeID, float speedValue, float offsetValue, string rotateValue, float smoothingValue, bool followHeightValue, float[] rotateOffsetVector, float[] positionOffsetVector)
|
||||||
private static void Force(NetworkStream stream, string message, string serial, HandleSerial action)
|
private static void Force(NetworkStream stream, string message, string serial, HandleSerial action)
|
||||||
|
|||||||
205
Server/Client.cs
@@ -1,13 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Timers;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Util;
|
using ClientApp.Utils;
|
||||||
|
|
||||||
namespace Server
|
namespace Server
|
||||||
{
|
{
|
||||||
@@ -20,15 +16,13 @@ namespace Server
|
|||||||
private byte[] totalBuffer = new byte[1024];
|
private byte[] totalBuffer = new byte[1024];
|
||||||
private int totalBufferReceived = 0;
|
private int totalBufferReceived = 0;
|
||||||
private SaveData saveData;
|
private SaveData saveData;
|
||||||
public string username = null;
|
private string username = null;
|
||||||
private DateTime sessionStart;
|
private DateTime sessionStart;
|
||||||
private string fileName;
|
private string fileName;
|
||||||
private Timer timer;
|
|
||||||
private volatile byte[] BikeDataBuffer;
|
|
||||||
private volatile byte[] BPMDataBuffer;
|
|
||||||
private bool BPMdata = false;
|
public string Username { get; set; }
|
||||||
private bool Bikedata = false;
|
|
||||||
private object token = new object { };
|
|
||||||
|
|
||||||
public Client(Communication communication, TcpClient tcpClient)
|
public Client(Communication communication, TcpClient tcpClient)
|
||||||
{
|
{
|
||||||
@@ -37,28 +31,18 @@ namespace Server
|
|||||||
this.tcpClient = tcpClient;
|
this.tcpClient = tcpClient;
|
||||||
this.stream = this.tcpClient.GetStream();
|
this.stream = this.tcpClient.GetStream();
|
||||||
this.fileName = Directory.GetCurrentDirectory() + "/userInfo.dat";
|
this.fileName = Directory.GetCurrentDirectory() + "/userInfo.dat";
|
||||||
this.timer = new Timer();
|
|
||||||
this.BikeDataBuffer = new byte[16];
|
|
||||||
this.BPMDataBuffer = new byte[2];
|
|
||||||
this.timer.Interval = 1000;
|
|
||||||
this.timer.AutoReset = false;
|
|
||||||
this.timer.Elapsed += SendDataToDoctor;
|
|
||||||
Console.WriteLine("token is " + token);
|
|
||||||
stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnRead), null);
|
stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnRead), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnRead(IAsyncResult ar)
|
private void OnRead(IAsyncResult ar)
|
||||||
{
|
{
|
||||||
if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead) || !this.tcpClient.Client.Connected)
|
|
||||||
return;
|
|
||||||
|
|
||||||
int receivedBytes = this.stream.EndRead(ar);
|
int receivedBytes = this.stream.EndRead(ar);
|
||||||
|
|
||||||
if (totalBufferReceived + receivedBytes > 1024)
|
if (totalBufferReceived + receivedBytes > 1024)
|
||||||
if (totalBufferReceived + receivedBytes > 1024)
|
{
|
||||||
{
|
throw new OutOfMemoryException("buffer too small");
|
||||||
throw new OutOfMemoryException("buffer too small");
|
}
|
||||||
}
|
|
||||||
Array.Copy(buffer, 0, totalBuffer, totalBufferReceived, receivedBytes);
|
Array.Copy(buffer, 0, totalBuffer, totalBufferReceived, receivedBytes);
|
||||||
totalBufferReceived += receivedBytes;
|
totalBufferReceived += receivedBytes;
|
||||||
|
|
||||||
@@ -80,8 +64,6 @@ namespace Server
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead) || !this.tcpClient.Client.Connected)
|
|
||||||
return;
|
|
||||||
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
|
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -109,47 +91,43 @@ namespace Server
|
|||||||
|
|
||||||
string identifier;
|
string identifier;
|
||||||
bool isJson = DataParser.getJsonIdentifier(message, out identifier);
|
bool isJson = DataParser.getJsonIdentifier(message, out identifier);
|
||||||
|
|
||||||
if (isJson)
|
if (isJson)
|
||||||
{
|
{
|
||||||
switch (identifier)
|
switch (identifier)
|
||||||
{
|
{
|
||||||
case DataParser.LOGIN:
|
case DataParser.LOGIN:
|
||||||
if (handleLogin(payloadbytes))
|
string username;
|
||||||
communication.NewLogin(this);
|
string password;
|
||||||
break;
|
bool worked = DataParser.GetUsernamePassword(payloadbytes, out username, out password);
|
||||||
case DataParser.LOGIN_DOCTOR:
|
if (worked)
|
||||||
if (communication.Doctor != null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (handleLogin(payloadbytes))
|
|
||||||
{
|
{
|
||||||
communication.Doctor = this;
|
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"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DataParser.START_SESSION:
|
case DataParser.START_SESSION:
|
||||||
this.communication.StartSessionUser(DataParser.getUsernameFromJson(payloadbytes));
|
this.saveData = new SaveData(Directory.GetCurrentDirectory() + "/" + this.username + "/" + sessionStart.ToString("yyyy-MM-dd HH-mm-ss"));
|
||||||
if (communication.Doctor != this)
|
|
||||||
this.timer.Start();
|
|
||||||
break;
|
break;
|
||||||
case DataParser.STOP_SESSION:
|
case DataParser.STOP_SESSION:
|
||||||
this.communication.StopSessionUser(DataParser.getUsernameFromJson(payloadbytes));
|
this.saveData = null;
|
||||||
this.timer.Stop();
|
|
||||||
break;
|
break;
|
||||||
case DataParser.SET_RESISTANCE:
|
case DataParser.SET_RESISTANCE:
|
||||||
//bool worked = DataParser.getResistanceFromResponseJson(payloadbytes);
|
worked = DataParser.getResistanceFromResponseJson(payloadbytes);
|
||||||
communication.SendMessageToClient(DataParser.getUsernameFromJson(payloadbytes), message);
|
Console.WriteLine($"set resistance worked is " + worked);
|
||||||
//set resistance on doctor GUI
|
//set resistance on doctor GUI
|
||||||
|
|
||||||
break;
|
|
||||||
case DataParser.DISCONNECT:
|
|
||||||
communication.LogOff(this);
|
|
||||||
break;
|
|
||||||
case DataParser.MESSAGE:
|
|
||||||
communication.SendMessageToClient(DataParser.getUsernameFromJson(payloadbytes), message);
|
|
||||||
break;
|
|
||||||
case DataParser.GET_FILE:
|
|
||||||
getClientBikeData(payloadbytes);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
||||||
@@ -161,84 +139,26 @@ namespace Server
|
|||||||
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(payloadbytes));
|
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(payloadbytes));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (DataParser.isRawDataBikeServer(message))
|
else if (DataParser.isRawData(message))
|
||||||
{
|
{
|
||||||
//Bikedata = true;
|
// print the raw data
|
||||||
saveData?.WriteDataRAWBike(payloadbytes);
|
Console.WriteLine(BitConverter.ToString(payloadbytes));
|
||||||
lock (token)
|
// TODO change, checking for length is not that safe
|
||||||
|
if (payloadbytes.Length == 8)
|
||||||
{
|
{
|
||||||
Array.Copy(this.BikeDataBuffer, 0, this.BikeDataBuffer, 8, 8);
|
saveData?.WriteDataRAWBike(payloadbytes);
|
||||||
Array.Copy(payloadbytes, 0, this.BikeDataBuffer, 0, 8);
|
|
||||||
}
|
}
|
||||||
if (this.username != null)
|
else if (payloadbytes.Length == 2)
|
||||||
this.communication.Doctor?.sendMessage(DataParser.GetRawBikeDataDoctor(payloadbytes, this.username));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (DataParser.isRawDataBPMServer(message))
|
|
||||||
{
|
|
||||||
//BPMdata = true;
|
|
||||||
saveData?.WriteDataRAWBPM(payloadbytes);
|
|
||||||
lock (token)
|
|
||||||
{
|
{
|
||||||
Array.Copy(payloadbytes, 0, this.BPMDataBuffer, 0, 2);
|
saveData?.WriteDataRAWBPM(payloadbytes);
|
||||||
}
|
|
||||||
if (this.username != null)
|
|
||||||
this.communication.Doctor?.sendMessage(DataParser.GetRawBPMDataDoctor(payloadbytes, this.username));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getClientBikeData(byte[] payloadbytes)
|
|
||||||
{
|
|
||||||
//ugly
|
|
||||||
//get the raw bike data of the user with the specified username
|
|
||||||
string username = DataParser.GetUsernameFromGetFileBytes(payloadbytes);
|
|
||||||
string path = Directory.GetCurrentDirectory() + "/" + username + "/";
|
|
||||||
string bytes = string.Empty;
|
|
||||||
StringBuilder sb = new StringBuilder(bytes);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
DirectoryInfo dirInf = new DirectoryInfo(Directory.GetCurrentDirectory() + "/" + username + "/");
|
|
||||||
DirectoryInfo[] directoryInfos = dirInf.GetDirectories();
|
|
||||||
DirectoryInfo latest = directoryInfos[directoryInfos.Length - 1];
|
|
||||||
path = path + latest.Name + "/rawBike.bin";
|
|
||||||
FileInfo fi = new FileInfo(path);
|
|
||||||
|
|
||||||
if ((int)fi.Length >= 1024) return;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Debug.WriteLine("[SERVER CLIENT] excetion while trying to get raw bike data: " + e.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
Debug.WriteLine("[SERVER CLIENT] about to send " + sb.ToString());
|
|
||||||
communication.Doctor.sendMessage(DataParser.GetFileMessage(File.ReadAllBytes(path)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool 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"));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sendMessage(DataParser.getLoginResponse("wrong username or password"));
|
Console.WriteLine("received raw data with weird lenght " + BitConverter.ToString(payloadbytes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
sendMessage(DataParser.getLoginResponse("invalid json"));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(byte[] message)
|
public void sendMessage(byte[] message)
|
||||||
@@ -248,7 +168,6 @@ namespace Server
|
|||||||
|
|
||||||
private bool verifyLogin(string username, string password)
|
private bool verifyLogin(string username, string password)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Got username {username} and password {password}");
|
|
||||||
|
|
||||||
|
|
||||||
if (!File.Exists(fileName))
|
if (!File.Exists(fileName))
|
||||||
@@ -263,23 +182,27 @@ namespace Server
|
|||||||
{
|
{
|
||||||
Console.WriteLine("file exists, located at " + Path.GetFullPath(fileName));
|
Console.WriteLine("file exists, located at " + Path.GetFullPath(fileName));
|
||||||
string[] usernamesPasswords = File.ReadAllLines(fileName);
|
string[] usernamesPasswords = File.ReadAllLines(fileName);
|
||||||
|
if (usernamesPasswords.Length == 0)
|
||||||
|
{
|
||||||
|
newUsers(username, password);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (string s in usernamesPasswords)
|
foreach (string s in usernamesPasswords)
|
||||||
{
|
{
|
||||||
string[] combo = s.Split(" ");
|
string[] combo = s.Split(" ");
|
||||||
if (combo[0] == username)
|
if (combo[0] == username)
|
||||||
{
|
{
|
||||||
Console.WriteLine("username found in file");
|
Console.WriteLine("correct info");
|
||||||
return combo[1] == password;
|
return combo[1] == password;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Console.WriteLine("username not found in file");
|
Console.WriteLine("combo was not found in file");
|
||||||
newUsers(username, password);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Console.WriteLine("false");
|
||||||
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,27 +223,5 @@ namespace Server
|
|||||||
hex.AppendFormat("{0:x2}", b);
|
hex.AppendFormat("{0:x2}", b);
|
||||||
return hex.ToString();
|
return hex.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartSession()
|
|
||||||
{
|
|
||||||
this.saveData = new SaveData(Directory.GetCurrentDirectory() + "/" + this.username + "/" + sessionStart.ToString("yyyy-MM-dd HH-mm-ss"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void StopSession()
|
|
||||||
{
|
|
||||||
this.saveData = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SendDataToDoctor(object sender, ElapsedEventArgs e)
|
|
||||||
{
|
|
||||||
lock (token)
|
|
||||||
{
|
|
||||||
this.communication.Doctor?.sendMessage(DataParser.GetRawBikeDataDoctor(this.BikeDataBuffer.Take(8).ToArray(), this.username));
|
|
||||||
this.communication.Doctor?.sendMessage(DataParser.GetRawBikeDataDoctor(this.BikeDataBuffer.Skip(8).ToArray(), this.username));
|
|
||||||
this.communication.Doctor?.sendMessage(DataParser.GetRawBPMDataDoctor(this.BPMDataBuffer, this.username));
|
|
||||||
}
|
|
||||||
this.timer.Start();
|
|
||||||
Debug.WriteLine("[serverclient] send bike and bpm data timer");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
using System;
|
using ClientApp;
|
||||||
|
using ClientApp.Utils;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO.Pipes;
|
||||||
|
using System.Linq;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using Util;
|
using System.Text;
|
||||||
|
|
||||||
namespace Server
|
namespace Server
|
||||||
{
|
{
|
||||||
@@ -9,24 +13,8 @@ namespace Server
|
|||||||
{
|
{
|
||||||
private TcpListener listener;
|
private TcpListener listener;
|
||||||
private List<Client> clients;
|
private List<Client> clients;
|
||||||
private Client mDoctor;
|
private Client doctor;
|
||||||
public Client Doctor
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return this.mDoctor;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
this.mDoctor = value;
|
|
||||||
if (this.mDoctor != null)
|
|
||||||
this.clients.ForEach((client) =>
|
|
||||||
{
|
|
||||||
this.mDoctor.sendMessage(DataParser.getNewConnectionJson(client.username));
|
|
||||||
client.sendMessage(DataParser.getNewConnectionJson(this.mDoctor.username));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public Communication(TcpListener listener)
|
public Communication(TcpListener listener)
|
||||||
{
|
{
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
@@ -47,68 +35,22 @@ namespace Server
|
|||||||
|
|
||||||
var tcpClient = listener.EndAcceptTcpClient(ar);
|
var tcpClient = listener.EndAcceptTcpClient(ar);
|
||||||
Console.WriteLine($"Client connected from {tcpClient.Client.RemoteEndPoint}");
|
Console.WriteLine($"Client connected from {tcpClient.Client.RemoteEndPoint}");
|
||||||
new Client(this, tcpClient);
|
clients.Add(new Client(this, tcpClient));
|
||||||
|
if (doctor == null)
|
||||||
|
{
|
||||||
|
doctor = clients.ElementAt(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
doctor.sendMessage(DataParser.getLoginResponse("new client"));
|
||||||
|
}
|
||||||
listener.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null);
|
listener.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NewLogin(Client client)
|
internal void Disconnect(Client client)
|
||||||
{
|
{
|
||||||
this.clients.Add(client);
|
clients.Remove(client);
|
||||||
if (this.Doctor != null)
|
|
||||||
{
|
|
||||||
Doctor.sendMessage(DataParser.getNewConnectionJson(client.username));
|
|
||||||
client.sendMessage(DataParser.getNewConnectionJson(Doctor.username));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LogOff(Client client)
|
|
||||||
{
|
|
||||||
if (this.Doctor == client)
|
|
||||||
{
|
|
||||||
this.clients.ForEach((client) =>
|
|
||||||
{
|
|
||||||
client.sendMessage(DataParser.getDisconnectJson(this.mDoctor.username));
|
|
||||||
});
|
|
||||||
this.Doctor = null;
|
|
||||||
}
|
|
||||||
Doctor?.sendMessage(DataParser.getDisconnectJson(client.username));
|
|
||||||
this.clients.Remove(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void StartSessionUser(string user)
|
|
||||||
{
|
|
||||||
foreach (Client client in clients)
|
|
||||||
{
|
|
||||||
if (client.username == user)
|
|
||||||
{
|
|
||||||
client.sendMessage(DataParser.getStartSessionJson(user));
|
|
||||||
client.StartSession();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void StopSessionUser(string user)
|
|
||||||
{
|
|
||||||
foreach (Client client in clients)
|
|
||||||
{
|
|
||||||
if (client.username == user)
|
|
||||||
{
|
|
||||||
client.sendMessage(DataParser.getStopSessionJson(user));
|
|
||||||
client.StopSession();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SendMessageToClient(string user, byte[] message)
|
|
||||||
{
|
|
||||||
foreach (Client c in clients)
|
|
||||||
{
|
|
||||||
if (c.username == user)
|
|
||||||
{
|
|
||||||
c.sendMessage(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ClientApp\ClientApp.csproj" />
|
<ProjectReference Include="..\ClientApp\ClientApp.csproj" />
|
||||||
<ProjectReference Include="..\DoctorApp\DoctorApp.csproj" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
|
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
|
||||||
|
|||||||
@@ -1,418 +0,0 @@
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using ProftaakRH;
|
|
||||||
using RH_Engine;
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace UnitTestRH
|
|
||||||
{
|
|
||||||
[TestClass]
|
|
||||||
public class CommandTest
|
|
||||||
{
|
|
||||||
[TestMethod]
|
|
||||||
public void TerrainAdd_TestMethod()
|
|
||||||
{
|
|
||||||
string testTunnelID = "dummyTunnelID";
|
|
||||||
string testSerial = "dummySerialCode";
|
|
||||||
|
|
||||||
string payloadId = "tunnel/send";
|
|
||||||
string messageId = "scene/terrain/add";
|
|
||||||
|
|
||||||
Command command = new Command(testTunnelID);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int[] terrainSizeArray = new int[2] { 4, 4 };
|
|
||||||
float[] terrainHeightsArray = new float[16] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
||||||
string terrainAddCommand = command.TerrainAdd(terrainSizeArray, terrainHeightsArray, testSerial);
|
|
||||||
|
|
||||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
|
||||||
|
|
||||||
//Test payload
|
|
||||||
Assert.AreEqual(payloadId, (string)json.id);
|
|
||||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
|
||||||
|
|
||||||
//Test message
|
|
||||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
|
||||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
|
||||||
|
|
||||||
//Test terrain
|
|
||||||
JArray jArrayTerrainSize = (JArray)json.data.data.data.size;
|
|
||||||
JArray jArrayTerrainHeights = (JArray)json.data.data.data.heights;
|
|
||||||
|
|
||||||
int[] outSizeArray = jArrayTerrainSize.Select(ja => (int)ja).ToArray();
|
|
||||||
float[] outHeightsArray = jArrayTerrainHeights.Select(ja => (float)ja).ToArray();
|
|
||||||
|
|
||||||
CollectionAssert.AreEqual(terrainSizeArray, outSizeArray);
|
|
||||||
CollectionAssert.AreEqual(terrainHeightsArray, json.data.data.data.heights.ToObject<float[]>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public void AddLayer_TestMethod()
|
|
||||||
{
|
|
||||||
string testTunnelID = "dummyTunnelID";
|
|
||||||
string testSerial = "dummySerialCode";
|
|
||||||
|
|
||||||
string payloadId = "tunnel/send";
|
|
||||||
string messageId = "scene/node/addlayer";
|
|
||||||
|
|
||||||
|
|
||||||
string testUuid = "dummyUuid";
|
|
||||||
string diffuseExpected = @"data\NetworkEngine\textures\terrain\grass_green_d.jpg";
|
|
||||||
string normalExpected = @"data\NetworkEngine\textures\terrain\grass_green_n.jpg";
|
|
||||||
int minHeightExpected = 0;
|
|
||||||
int maxHeightExpected = 10;
|
|
||||||
int fadeDistExpected = 1;
|
|
||||||
|
|
||||||
|
|
||||||
Command command = new Command(testTunnelID);
|
|
||||||
|
|
||||||
string terrainAddCommand = command.AddLayer(testUuid, testSerial);
|
|
||||||
|
|
||||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
|
||||||
|
|
||||||
//Test payload
|
|
||||||
Assert.AreEqual(payloadId, (string)json.id);
|
|
||||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
|
||||||
|
|
||||||
//Test message
|
|
||||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
|
||||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
|
||||||
|
|
||||||
//Test AddLayer
|
|
||||||
Assert.AreEqual(testUuid, (string)json.data.data.data.id);
|
|
||||||
Assert.AreEqual(diffuseExpected, (string)json.data.data.data.diffuse);
|
|
||||||
Assert.AreEqual(normalExpected, (string)json.data.data.data.normal);
|
|
||||||
Assert.AreEqual(minHeightExpected, (int)json.data.data.data.minHeight);
|
|
||||||
Assert.AreEqual(maxHeightExpected, (int)json.data.data.data.maxHeight);
|
|
||||||
Assert.AreEqual(fadeDistExpected, (int)json.data.data.data.fadeDist);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public void UpdateTerrain_TestMethod()
|
|
||||||
{
|
|
||||||
string testTunnelID = "dummyTunnelID";
|
|
||||||
|
|
||||||
string payloadId = "tunnel/send";
|
|
||||||
string messageId = "scene/terrain/update";
|
|
||||||
|
|
||||||
Command command = new Command(testTunnelID);
|
|
||||||
|
|
||||||
string terrainAddCommand = command.UpdateTerrain();
|
|
||||||
|
|
||||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
|
||||||
|
|
||||||
//Test payload
|
|
||||||
Assert.AreEqual(payloadId, (string)json.id);
|
|
||||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
|
||||||
|
|
||||||
//Test message
|
|
||||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public void renderTerrain_TestMethod()
|
|
||||||
{
|
|
||||||
string testTunnelID = "dummyTunnelID";
|
|
||||||
string testSerial = "dummySerialCode";
|
|
||||||
|
|
||||||
string payloadId = "tunnel/send";
|
|
||||||
string messageId = "scene/node/add";
|
|
||||||
|
|
||||||
|
|
||||||
string nameExpected = "newNode";
|
|
||||||
int[] positionExpected = new int[] { -80, 0, -80 };
|
|
||||||
float scaleExpected = 1f;
|
|
||||||
int[] rotationExpected = new int[] { 0, 0, 0 };
|
|
||||||
|
|
||||||
bool smoothnormalsExpected = true;
|
|
||||||
|
|
||||||
|
|
||||||
Command command = new Command(testTunnelID);
|
|
||||||
|
|
||||||
string terrainAddCommand = command.renderTerrain(testSerial);
|
|
||||||
|
|
||||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
|
||||||
|
|
||||||
|
|
||||||
//Test payload
|
|
||||||
Assert.AreEqual(payloadId, (string)json.id);
|
|
||||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
|
||||||
|
|
||||||
//Test message
|
|
||||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
|
||||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
|
||||||
|
|
||||||
//Test data
|
|
||||||
Assert.AreEqual(nameExpected, (string)json.data.data.data.name);
|
|
||||||
|
|
||||||
//Test data components
|
|
||||||
|
|
||||||
//Test transform
|
|
||||||
JArray jArrayPosition = (JArray)json.data.data.data.components.transform.position;
|
|
||||||
JArray jArrayRotation = (JArray)json.data.data.data.components.transform.rotation;
|
|
||||||
|
|
||||||
int[] outPositionArray = jArrayPosition.Select(ja => (int)ja).ToArray();
|
|
||||||
int[] outRotationArray = jArrayRotation.Select(ja => (int)ja).ToArray();
|
|
||||||
|
|
||||||
CollectionAssert.AreEqual(positionExpected, outPositionArray);
|
|
||||||
CollectionAssert.AreEqual(rotationExpected, outRotationArray);
|
|
||||||
|
|
||||||
|
|
||||||
//Test terrain
|
|
||||||
Assert.AreEqual(smoothnormalsExpected, (bool)json.data.data.data.components.terrain.smoothnormals);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public void DeleteNode_TestMethod()
|
|
||||||
{
|
|
||||||
string testTunnelID = "dummyTunnelID";
|
|
||||||
string testSerial = "dummySerialCode";
|
|
||||||
|
|
||||||
string payloadId = "tunnel/send";
|
|
||||||
string messageId = "scene/node/delete";
|
|
||||||
|
|
||||||
string uuid = "dummyUuid";
|
|
||||||
|
|
||||||
|
|
||||||
Command command = new Command(testTunnelID);
|
|
||||||
|
|
||||||
string terrainAddCommand = command.DeleteNode(uuid, testSerial);
|
|
||||||
|
|
||||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
|
||||||
|
|
||||||
//Test payload
|
|
||||||
Assert.AreEqual(payloadId, (string)json.id);
|
|
||||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
|
||||||
|
|
||||||
//Test message
|
|
||||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
|
||||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
|
||||||
|
|
||||||
//Test data
|
|
||||||
Assert.AreEqual(uuid, (string)json.data.data.data.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public void addPanel_TestMethod()
|
|
||||||
{
|
|
||||||
string testTunnelID = "dummyTunnelID";
|
|
||||||
string testSerial = "dummySerialCode";
|
|
||||||
|
|
||||||
string payloadId = "tunnel/send";
|
|
||||||
string messageId = "scene/node/add";
|
|
||||||
|
|
||||||
string uuidBike = "dummyUuidBike";
|
|
||||||
|
|
||||||
string nameExpected = "dashboard";
|
|
||||||
|
|
||||||
//components
|
|
||||||
//transform
|
|
||||||
float[] positionExpected = new float[] { -1.5f, 1f, 0f };
|
|
||||||
int scaleExpected = 1;
|
|
||||||
int[] rotationExpected = new int[] { -30, 90, 0 };
|
|
||||||
|
|
||||||
//panel
|
|
||||||
int[] sizeExpected = new int[] { 1, 1 };
|
|
||||||
int[] resolutionExpected = new int[] { 512, 512 };
|
|
||||||
int[] backgroundExpected = new int[] { 1, 1, 1, 1 };
|
|
||||||
bool castShadowExpected = false;
|
|
||||||
|
|
||||||
Command command = new Command(testTunnelID);
|
|
||||||
|
|
||||||
string terrainAddCommand = command.addPanel(testSerial, uuidBike);
|
|
||||||
|
|
||||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
|
||||||
|
|
||||||
//Test payload
|
|
||||||
Assert.AreEqual(payloadId, (string)json.id);
|
|
||||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
|
||||||
|
|
||||||
//Test message
|
|
||||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
|
||||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
|
||||||
|
|
||||||
//Test data
|
|
||||||
Assert.AreEqual(nameExpected, (string)json.data.data.data.name);
|
|
||||||
Assert.AreEqual(uuidBike, (string)json.data.data.data.parent);
|
|
||||||
|
|
||||||
//Test components
|
|
||||||
|
|
||||||
//Test transform
|
|
||||||
JArray jArrayPosition = (JArray)json.data.data.data.components.transform.position;
|
|
||||||
JArray jArrayRotation = (JArray)json.data.data.data.components.transform.rotation;
|
|
||||||
|
|
||||||
float[] outPositionArray = jArrayPosition.Select(ja => (float)ja).ToArray();
|
|
||||||
int[] outRotationArray = jArrayRotation.Select(ja => (int)ja).ToArray();
|
|
||||||
|
|
||||||
CollectionAssert.AreEqual(positionExpected, outPositionArray);
|
|
||||||
CollectionAssert.AreEqual(rotationExpected, outRotationArray);
|
|
||||||
|
|
||||||
Assert.AreEqual(scaleExpected, (int)json.data.data.data.components.transform.scale);
|
|
||||||
|
|
||||||
//Test panel
|
|
||||||
CollectionAssert.AreEqual(sizeExpected, ((JArray)json.data.data.data.components.panel.size).Select(ja => (int)ja).ToArray());
|
|
||||||
CollectionAssert.AreEqual(resolutionExpected, ((JArray)json.data.data.data.components.panel.resolution).Select(ja => (int)ja).ToArray());
|
|
||||||
CollectionAssert.AreEqual(backgroundExpected, ((JArray)json.data.data.data.components.panel.background).Select(ja => (int)ja).ToArray());
|
|
||||||
Assert.AreEqual(castShadowExpected, (bool)json.data.data.data.components.panel.castShadow);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public void ColorPanel_TestMethod()
|
|
||||||
{
|
|
||||||
string testTunnelID = "dummyTunnelID";
|
|
||||||
|
|
||||||
string payloadId = "tunnel/send";
|
|
||||||
string messageId = "scene/panel/setclearcolor";
|
|
||||||
|
|
||||||
string uuidPanel = "dummyUuidPanel";
|
|
||||||
|
|
||||||
float[] colorExpected = new float[] { 0f, 0f, 0f, 0f };
|
|
||||||
|
|
||||||
|
|
||||||
Command command = new Command(testTunnelID);
|
|
||||||
|
|
||||||
string terrainAddCommand = command.ColorPanel(uuidPanel);
|
|
||||||
|
|
||||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
|
||||||
|
|
||||||
//Test payload
|
|
||||||
Assert.AreEqual(payloadId, (string)json.id);
|
|
||||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
|
||||||
|
|
||||||
//Test message
|
|
||||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
|
||||||
|
|
||||||
//Test data
|
|
||||||
Assert.AreEqual(uuidPanel, (string)json.data.data.data.id);
|
|
||||||
CollectionAssert.AreEqual(colorExpected, ((JArray)json.data.data.data.color).Select(ja => (float)ja).ToArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public void SwapPanel_TestMethod()
|
|
||||||
{
|
|
||||||
string testTunnelID = "dummyTunnelID";
|
|
||||||
|
|
||||||
string payloadId = "tunnel/send";
|
|
||||||
string messageId = "scene/panel/swap";
|
|
||||||
|
|
||||||
string uuid = "dummyUuid";
|
|
||||||
|
|
||||||
|
|
||||||
Command command = new Command(testTunnelID);
|
|
||||||
|
|
||||||
string terrainAddCommand = command.SwapPanel(uuid);
|
|
||||||
|
|
||||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
|
||||||
|
|
||||||
//Test payload
|
|
||||||
Assert.AreEqual(payloadId, (string)json.id);
|
|
||||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
|
||||||
|
|
||||||
//Test message
|
|
||||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
|
||||||
|
|
||||||
//Test data
|
|
||||||
Assert.AreEqual(uuid, (string)json.data.data.data.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public void showOnPanel_TestMethod()
|
|
||||||
{
|
|
||||||
string testTunnelID = "dummyTunnelID";
|
|
||||||
string testSerial = "dummySerialCode";
|
|
||||||
|
|
||||||
string payloadId = "tunnel/send";
|
|
||||||
string messageId = "scene/panel/drawtext";
|
|
||||||
|
|
||||||
string uuidPanel = "dummyUuidPanel";
|
|
||||||
string text = "dummyText";
|
|
||||||
int index = 3;
|
|
||||||
int[] positionExpected = new int[] { 4, 24 + index * 32 };
|
|
||||||
double sizeExpected = 32.0;
|
|
||||||
int[] colorExpected = new int[] { 0, 0, 0, 1 };
|
|
||||||
string fontExpected = "segoeui";
|
|
||||||
|
|
||||||
|
|
||||||
Command command = new Command(testTunnelID);
|
|
||||||
|
|
||||||
string terrainAddCommand = command.showOnPanel(uuidPanel, testSerial, text, index);
|
|
||||||
|
|
||||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
|
||||||
|
|
||||||
//Test payload
|
|
||||||
Assert.AreEqual(payloadId, (string)json.id);
|
|
||||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
|
||||||
|
|
||||||
//Test message
|
|
||||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
|
||||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
|
||||||
|
|
||||||
//Test data
|
|
||||||
Assert.AreEqual(uuidPanel, (string)json.data.data.data.id);
|
|
||||||
Assert.AreEqual(text, (string)json.data.data.data.text);
|
|
||||||
CollectionAssert.AreEqual(positionExpected, ((JArray)json.data.data.data.position).Select(ja => (int)ja).ToArray());
|
|
||||||
Assert.AreEqual(sizeExpected, (double)json.data.data.data.size);
|
|
||||||
CollectionAssert.AreEqual(colorExpected, ((JArray)json.data.data.data.color).Select(ja => (int)ja).ToArray());
|
|
||||||
Assert.AreEqual(fontExpected, (string)json.data.data.data.font);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public void SwapPanelCommand_TestMethod()
|
|
||||||
{
|
|
||||||
string testTunnelID = "dummyTunnelID";
|
|
||||||
|
|
||||||
string payloadId = "tunnel/send";
|
|
||||||
string messageId = "scene/panel/swap";
|
|
||||||
|
|
||||||
string uuid = "dummyUuid";
|
|
||||||
|
|
||||||
|
|
||||||
Command command = new Command(testTunnelID);
|
|
||||||
|
|
||||||
string terrainAddCommand = command.SwapPanelCommand(uuid);
|
|
||||||
|
|
||||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
|
||||||
|
|
||||||
//Test payload
|
|
||||||
Assert.AreEqual(payloadId, (string)json.id);
|
|
||||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
|
||||||
|
|
||||||
//Test message
|
|
||||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
|
||||||
|
|
||||||
//Test data
|
|
||||||
Assert.AreEqual(uuid, (string)json.data.data.data.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public void ClearPanel_TestMethod()
|
|
||||||
{
|
|
||||||
string testTunnelID = "dummyTunnelID";
|
|
||||||
|
|
||||||
string payloadId = "tunnel/send";
|
|
||||||
string messageId = "scene/panel/clear";
|
|
||||||
|
|
||||||
string uuid = "dummyUuid";
|
|
||||||
|
|
||||||
|
|
||||||
Command command = new Command(testTunnelID);
|
|
||||||
|
|
||||||
string terrainAddCommand = command.ClearPanel(uuid);
|
|
||||||
|
|
||||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
|
||||||
|
|
||||||
//Test payload
|
|
||||||
Assert.AreEqual(payloadId, (string)json.id);
|
|
||||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
|
||||||
|
|
||||||
//Test terrain
|
|
||||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
|
||||||
|
|
||||||
//Test data
|
|
||||||
Assert.AreEqual(uuid, (string)json.data.data.data.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using RH_Engine;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using Util;
|
|
||||||
|
|
||||||
namespace UnitTestRH
|
|
||||||
{
|
|
||||||
[TestClass]
|
|
||||||
public class DataParserTest
|
|
||||||
{
|
|
||||||
|
|
||||||
public byte[] GetPayload(byte[] message)
|
|
||||||
{
|
|
||||||
byte[] payload = new byte[message.Length - 5];
|
|
||||||
Array.Copy(message, 5, payload, 0, message.Length - 5);
|
|
||||||
return payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public void TestGetMessageToSend()
|
|
||||||
{
|
|
||||||
byte[] toTest = DataParser.GetMessageToSend("test");
|
|
||||||
|
|
||||||
dynamic res = JsonConvert.DeserializeObject(Encoding.ASCII.GetString((toTest)));
|
|
||||||
Assert.AreEqual("MESSAGE", (string)res.identifier);
|
|
||||||
Assert.AreEqual("test", (string)res.data.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public void TestIsRawDataBikeServer()
|
|
||||||
{
|
|
||||||
byte[] testArr = { 0x34,0x00,0x00,0x00,0x02};
|
|
||||||
byte[] testArr2 = { 0x34, 0x00, 0x00, 0x00, 0x02,0x49,0x65 };
|
|
||||||
Assert.ThrowsException<ArgumentException>(() => DataParser.isRawDataBikeServer(testArr));
|
|
||||||
Assert.IsTrue(DataParser.isRawDataBikeServer(testArr2));
|
|
||||||
}
|
|
||||||
[TestMethod]
|
|
||||||
public void TestIsRawDataBikeDoctor()
|
|
||||||
{
|
|
||||||
byte[] testArr = { 0x34, 0x00, 0x00, 0x00, 0x04 };
|
|
||||||
byte[] testArr2 = { 0x34, 0x00, 0x00, 0x00, 0x04, 0x49, 0x65 };
|
|
||||||
Assert.ThrowsException<ArgumentException>(() => DataParser.isRawDataBikeDoctor(testArr));
|
|
||||||
Assert.IsTrue(DataParser.isRawDataBikeDoctor(testArr2));
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public void TestIsRawDataBPMServer()
|
|
||||||
{
|
|
||||||
byte[] testArr = { 0x34, 0x00, 0x00, 0x00, 0x03};
|
|
||||||
byte[] testArr2 = { 0x34, 0x00, 0x00, 0x00, 0x03, 0x49, 0x65 };
|
|
||||||
Assert.ThrowsException<ArgumentException>(() => DataParser.isRawDataBPMServer(testArr));
|
|
||||||
Assert.IsTrue(DataParser.isRawDataBPMServer(testArr2));
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public void TestIsRawDataBPMDoctor()
|
|
||||||
{
|
|
||||||
byte[] testArr = { 0x34, 0x00, 0x00, 0x00, 0x05 };
|
|
||||||
byte[] testArr2 = { 0x34, 0x00, 0x00, 0x00, 0x05, 0x49, 0x65 };
|
|
||||||
Assert.ThrowsException<ArgumentException>(() => DataParser.isRawDataBPMDoctor(testArr));
|
|
||||||
Assert.IsTrue(DataParser.isRawDataBPMDoctor(testArr2));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
|
||||||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
|
|
||||||
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
|
|
||||||
<PackageReference Include="coverlet.collector" Version="1.2.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\ClientApp\ClientApp.csproj" />
|
|
||||||
<ProjectReference Include="..\DoctorApp\DoctorApp.csproj" />
|
|
||||||
<ProjectReference Include="..\ProftaakRH\ProftaakRH.csproj" />
|
|
||||||
<ProjectReference Include="..\RH-Engine\RH-Engine.csproj" />
|
|
||||||
<ProjectReference Include="..\Server\Server.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
|
|
||||||
|
|
||||||
</Project>
|
|
||||||