diff --git a/DokterApp/UserControlForTab.xaml b/DokterApp/UserControlForTab.xaml
index f45a03f..f54c028 100644
--- a/DokterApp/UserControlForTab.xaml
+++ b/DokterApp/UserControlForTab.xaml
@@ -1,11 +1,13 @@
+ d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance constantChanges:UserControlForTab}">
@@ -60,8 +62,31 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DokterApp/UserControlForTab.xaml.cs b/DokterApp/UserControlForTab.xaml.cs
index 443fa92..8e47cb0 100644
--- a/DokterApp/UserControlForTab.xaml.cs
+++ b/DokterApp/UserControlForTab.xaml.cs
@@ -1,6 +1,12 @@
-using System;
+using LiveCharts;
+using LiveCharts.Configurations;
+using LiveCharts.Wpf;
+using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
@@ -16,13 +22,122 @@ namespace DokterApp
///
/// Interaction logic for UserControlForTab.xaml
///
- public partial class UserControlForTab : UserControl
+ public partial class UserControlForTab : UserControl, INotifyPropertyChanged
{
+
+ private double _axisMax;
+ private double _axisMin;
+ private double _trend;
public UserControlForTab()
{
InitializeComponent();
Username_Label.Content = "Bob";
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()
+ .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(mapper);
+
+ //the values property will store our values array
+ ChartValues = new ChartValues();
+
+ //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; }
+
+ async private void Read()
+ {
+ var r = new Random();
+
+ while (IsReading)
+ {
+ await Task.Delay(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)
@@ -51,9 +166,25 @@ namespace DokterApp
private void ClientInfo_Click(object sender, RoutedEventArgs e)
{
- MessageBox.Show("firstname:\tBob\n" +
- "surname:\t\tde Bouwer");
+ MessageBox.Show("Firstname:\tBob\n" +
+ "Lastname:\t\tde Bouwer");
}
+ private void DropBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ //TODO
+ //Andere graph
+ }
+
+ public ChartValues ChartValues { get; set; }
+ public Func 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; }
}
}
diff --git a/Server/Communication.cs b/Server/Communication.cs
index f3432c8..3bc7d90 100644
--- a/Server/Communication.cs
+++ b/Server/Communication.cs
@@ -1,4 +1,5 @@
-using Client;
+using ClientApp;
+using ClientApp.Utils;
using System;
using System.Collections.Generic;
using System.IO.Pipes;