Merge remote-tracking branch 'origin/develop' into newDoctor

This commit is contained in:
fabjuuuh
2020-10-16 12:51:42 +02:00
35 changed files with 1269 additions and 113 deletions

View File

@@ -6,17 +6,27 @@
xmlns:views="clr-namespace:DoctorApp.Views"
StartupUri="Views/MainWindow.xaml">
<Application.Resources>
<DataTemplate DataType="{x:Type viewModels:MainViewModel}">
<views:MainView />
<!-- This is a UserControl -->
</DataTemplate>
<DataTemplate DataType="{x:Type viewModels:LoginViewModel}">
<views:LoginView />
<!-- This is a UserControl -->
</DataTemplate>
<DataTemplate DataType="{x:Type viewModels:ClientInfoViewModel}">
<views:ClientInfoView/>
</DataTemplate>
<ResourceDictionary>
<DataTemplate DataType="{x:Type viewModels:MainViewModel}">
<views:MainView />
<!-- This is a UserControl -->
</DataTemplate>
<DataTemplate DataType="{x:Type viewModels:LoginViewModel}">
<views:LoginView />
<!-- This is a UserControl -->
</DataTemplate>
<DataTemplate DataType="{x:Type viewModels:ClientInfoViewModel}">
<views:ClientInfoView/>
</DataTemplate>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/Fonts.xaml"/>
<ResourceDictionary Source="Styles/Colors.xaml"/>
<ResourceDictionary Source="Styles/Buttons.xaml"/>
<ResourceDictionary Source="Styles/Texts.xaml"/>
<ResourceDictionary Source="Styles/Windows.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@@ -57,6 +57,9 @@ namespace DoctorApp.Utils
/// <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)
@@ -91,7 +94,7 @@ namespace DoctorApp.Utils
Debug.WriteLine("Username and password correct!");
this.LoginViewModel.setLoginStatus(true);
this.connected = true;
}
else
{
@@ -192,7 +195,7 @@ namespace DoctorApp.Utils
/// <param name="bytes">the message</param>
public void Bike(byte[] bytes)
{
if (!sessionRunning)
{
return;
@@ -202,18 +205,18 @@ namespace DoctorApp.Utils
throw new ArgumentNullException("no bytes");
}
byte[] message = DataParser.GetRawDataMessage(bytes);
/* switch (bytes[0])
{
case 0x10:
/* switch (bytes[0])
{
if (canSendToEngine) engineConnection.BikeSpeed = (bytes[4] | (bytes[5] << 8)) * 0.01f;
break;
case 0x19:
if (canSendToEngine) engineConnection.BikePower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
break;
}*/
case 0x10:
if (canSendToEngine) engineConnection.BikeSpeed = (bytes[4] | (bytes[5] << 8)) * 0.01f;
break;
case 0x19:
if (canSendToEngine) engineConnection.BikePower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
break;
}*/
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
@@ -234,8 +237,8 @@ namespace DoctorApp.Utils
/// </summary>
public void tryLogin(string username, string password)
{
string hashUser = Hasher.HashString(username);
string hashPassword = Hasher.HashString(password);
string hashPassword = Util.Hasher.HashString(password);
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(hashUser, hashPassword));
@@ -266,5 +269,13 @@ namespace DoctorApp.Utils
{
this.ClientInfoViewModel = clientInfoViewModel;
}
public void Dispose()
{
Debug.WriteLine("client dispose called");
this.stream.Dispose();
this.client.Dispose();
this.handler?.stop();
}
}
}

View File

@@ -1,26 +1,134 @@
using DoctorApp.Models;
using DoctorApp.Utils;
using System;
using System.Collections.Generic;
using System.Text;
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; }
public MainWindowViewModel(Client client)
/// <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
}
}

View File

@@ -5,10 +5,113 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DoctorApp"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"
WindowState="Maximized">
Title="MainWindow" Height="450" Width="800">
<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="/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>
<ContentControl Content="{Binding SelectedViewModel}" Focusable="False" />
<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>

View File

@@ -26,7 +26,7 @@ namespace DoctorApp
{
Client client = new Client();
InitializeComponent();
DataContext = new MainWindowViewModel(client);
DataContext = new MainWindowViewModel(this, client);
}
}
}