This commit is contained in:
shinichi
2020-10-16 16:24:07 +02:00
parent e8a4901f09
commit cc046d6611
8 changed files with 67 additions and 72 deletions

View File

@@ -0,0 +1,25 @@
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 int Speed { get; set; }
public int BPM { get; set; }
public int Resistance { get; set; }
public int Acc_Power { get; set; }
public int Curr_Power { get; set; }
public int Distance { get; set; }
}
}

View File

@@ -82,7 +82,6 @@ namespace DoctorApp.Utils
string identifier; string identifier;
bool isJson = DataParser.getJsonIdentifier(messageBytes, out identifier); bool isJson = DataParser.getJsonIdentifier(messageBytes, out identifier);
Debug.WriteLine("doctor " + Encoding.ASCII.GetString(payloadbytes));
if (isJson) if (isJson)
{ {
switch (identifier) switch (identifier)

View File

@@ -1,4 +1,5 @@
using DoctorApp.Utils; using DoctorApp.Models;
using DoctorApp.Utils;
using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Command;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -11,25 +12,10 @@ using Util;
namespace DoctorApp.ViewModels namespace DoctorApp.ViewModels
{ {
class ClientInfoViewModel : ObservableObject class ClientInfoViewModel : ObservableObject
{ {
public ObservableCollection<string> ChatLog { get; set; } public PatientInfo PatientInfo { get; set; }
public string Username { get; set; }
public string Status { get; set; }
public int Speed { get; set; }
public int BPM { get; set; }
public int Resistance { get; set; }
public int Acc_Power { get; set; }
public int Curr_Power { get; set; }
public int Distance { get; set; }
public ICommand StartSession { get; set; } public ICommand StartSession { get; set; }
public ICommand StopSession { get; set; } public ICommand StopSession { get; set; }
@@ -45,33 +31,36 @@ namespace DoctorApp.ViewModels
public MainWindowViewModel MainWindowViewModel { get; set; } public MainWindowViewModel MainWindowViewModel { get; set; }
private Client client; private Client client;
public ClientInfoViewModel(MainWindowViewModel mainWindowViewModel) public ClientInfoViewModel(MainWindowViewModel mainWindowViewModel, string username)
{ {
MainWindowViewModel = mainWindowViewModel; MainWindowViewModel = mainWindowViewModel;
ChatLog = new ObservableCollection<string>(); this.PatientInfo = new PatientInfo() { Username = username, Status = "Waiting to start" };
PatientInfo.ChatLog = new ObservableCollection<string>();
client = mainWindowViewModel.client; client = mainWindowViewModel.client;
StartSession = new RelayCommand(()=>{ StartSession = new RelayCommand(() =>
client.sendMessage(DataParser.getStartSessionJson(Username)); {
Status = "Session started"; client.sendMessage(DataParser.getStartSessionJson(PatientInfo.Username));
PatientInfo.Status = "Session started";
}); });
StopSession = new RelayCommand(() => { StopSession = new RelayCommand(() =>
client.sendMessage(DataParser.getStopSessionJson(Username)); {
Status = "Session stopped, waiting to start again."; client.sendMessage(DataParser.getStopSessionJson(PatientInfo.Username));
PatientInfo.Status = "Session stopped, waiting to start again.";
}); });
Chat = new RelayCommand<object>((parameter) => Chat = new RelayCommand<object>((parameter) =>
{ {
client.sendMessage(DataParser.getChatJson(Username, ((TextBox)parameter).Text)); client.sendMessage(DataParser.getChatJson(PatientInfo.Username, ((TextBox)parameter).Text));
ChatLog.Add(DateTime.Now+": "+ ((TextBox)parameter).Text); PatientInfo.ChatLog.Add(DateTime.Now + ": " + ((TextBox)parameter).Text);
}); });
//TODO RelayCommand ChatToAll //TODO RelayCommand ChatToAll
SetResistance = new RelayCommand<object>((parameter) => SetResistance = new RelayCommand<object>((parameter) =>
{ {
client.sendMessage(DataParser.getSetResistanceJson(Username, float.Parse(((TextBox)parameter).Text))); client.sendMessage(DataParser.getSetResistanceJson(PatientInfo.Username, float.Parse(((TextBox)parameter).Text)));
}); });
} }

View File

@@ -21,19 +21,14 @@ namespace DoctorApp.ViewModels
{ {
this.MainWindowViewModel = mainWindowViewModel; this.MainWindowViewModel = mainWindowViewModel;
client = this.MainWindowViewModel.client; client = this.MainWindowViewModel.client;
Tabs= new ObservableCollection<ClientInfoViewModel>(); Tabs = new ObservableCollection<ClientInfoViewModel>();
} }
public void NewConnectedUser(string username) public void NewConnectedUser(string username)
{ {
System.Diagnostics.Debug.WriteLine("CREATING TAB FOR " + username);
App.Current.Dispatcher.Invoke((Action)delegate App.Current.Dispatcher.Invoke((Action)delegate
{ {
Tabs.Add(new ClientInfoViewModel(MainWindowViewModel) Tabs.Add(new ClientInfoViewModel(MainWindowViewModel, username));
{
Username = username,
Status = "Waiting to start"
});
}); });
} }
@@ -43,7 +38,7 @@ namespace DoctorApp.ViewModels
{ {
foreach (ClientInfoViewModel item in Tabs) foreach (ClientInfoViewModel item in Tabs)
{ {
if (item.Username == username) if (item.PatientInfo.Username == username)
{ {
Tabs.Remove(item); Tabs.Remove(item);
break; break;

View File

@@ -24,8 +24,8 @@
<Setter Property="Margin" Value="0,0,20,0"/> <Setter Property="Margin" Value="0,0,20,0"/>
</Style> </Style>
</StackPanel.Resources> </StackPanel.Resources>
<Label Content="{Binding Path=Username}"/> <Label Content="{Binding Path=PatientInfo.Username}"/>
<Label Content="{Binding Path=Status}"/> <Label Content="{Binding Path=PatientInfo.Status}"/>
</StackPanel> </StackPanel>
<StackPanel Margin="0,10,0,0" Grid.RowSpan="2" Grid.Row="1"> <StackPanel Margin="0,10,0,0" Grid.RowSpan="2" Grid.Row="1">
<StackPanel.Resources> <StackPanel.Resources>
@@ -39,9 +39,9 @@
<Label Content="Current BPM" Width="110" DockPanel.Dock="Top"/> <Label Content="Current BPM" Width="110" DockPanel.Dock="Top"/>
</DockPanel> </DockPanel>
<DockPanel Height="26" LastChildFill="False" HorizontalAlignment="Stretch"> <DockPanel Height="26" LastChildFill="False" HorizontalAlignment="Stretch">
<TextBox Name="textBox_Resistance" Text="{Binding Path=Resistance}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/> <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=Speed}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/> <TextBox Name="textBox_CurrentSpeed" Text="{Binding Path=PatientInfo.Speed}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
<TextBox Name="textBox_CurrentBPM" Text="{Binding Path=BPM}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/> <TextBox Name="textBox_CurrentBPM" Text="{Binding Path=PatientInfo.BPM}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
</DockPanel> </DockPanel>
<DockPanel Height="26" LastChildFill="False"> <DockPanel Height="26" LastChildFill="False">
<Label Content="Distance Covered" Width="110" DockPanel.Dock="Right"/> <Label Content="Distance Covered" Width="110" DockPanel.Dock="Right"/>
@@ -49,18 +49,18 @@
<Label Content="Acc. Power" Width="110" DockPanel.Dock="Top"/> <Label Content="Acc. Power" Width="110" DockPanel.Dock="Top"/>
</DockPanel> </DockPanel>
<DockPanel Height="26" LastChildFill="False"> <DockPanel Height="26" LastChildFill="False">
<TextBox Name="textBox_DistanceCovered" Text="{Binding Path=Distance}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/> <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=Curr_Power}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" 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=Acc_Power}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/> <TextBox Name="textBox_AccPower" Text="{Binding Path=PatientInfo.Acc_Power}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
</DockPanel> </DockPanel>
</StackPanel> </StackPanel>
<ListBox Name="ChatBox" ItemsSource="{Binding ChatLog}" Grid.Column="1" Margin="59,41,0,0" Grid.RowSpan="3"/> <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="TextBox" TextWrapping="Wrap" VerticalAlignment="Top" Width="235"/> <TextBox Name="textBox_Chat" Grid.Column="1" HorizontalAlignment="Left" Margin="59,10,0,0" Grid.Row="3" Text="TextBox" TextWrapping="Wrap" VerticalAlignment="Top" Width="235"/>
<Button 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 x:Name="Send" Content="Send" Grid.Column="1" HorizontalAlignment="Left" Margin="59,33,0,0" Grid.Row="3" VerticalAlignment="Top" Command="{Binding PatientInfo.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="Start Session" Grid.Column="1" HorizontalAlignment="Left" Margin="69,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Command="{Binding PatientInfo.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=""/> <Button Content="Stop Session" Grid.Column="1" HorizontalAlignment="Left" Margin="187,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Command="{Binding PatientInfo.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"/> <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}"/> <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 PatientInfo.SetResistance}" CommandParameter="{Binding ElementName=textBox_SetResistance}"/>
<Canvas Grid.Row="3" Background="White" Margin="0,33,0,0"/> <Canvas Grid.Row="3" Background="White" Margin="0,33,0,0"/>
<ComboBox Name="DropBox" HorizontalAlignment="Left" Margin="0,6,0,0" Grid.Row="3" VerticalAlignment="Top" Width="190"/> <ComboBox Name="DropBox" HorizontalAlignment="Left" Margin="0,6,0,0" Grid.Row="3" VerticalAlignment="Top" Width="190"/>
</Grid> </Grid>

View File

@@ -8,6 +8,8 @@
Background="Transparent" Background="Transparent"
WindowStyle="None" WindowStyle="None"
AllowsTransparency="True" AllowsTransparency="True"
MinHeight="{Binding MinimumHeight}"
MinWidth="{Binding MinimumWidth}"
Title="MainWindow" Height="450" Width="800"> Title="MainWindow" Height="450" Width="800">
<Window.Resources> <Window.Resources>
<Style TargetType="{x:Type local:MainWindow}"> <Style TargetType="{x:Type local:MainWindow}">

View File

@@ -1,11 +1,11 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text; using System.Text;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Diagnostics;
using Util; using Util;
using System.Linq;
namespace Server namespace Server
{ {
@@ -93,7 +93,6 @@ namespace Server
string identifier; string identifier;
bool isJson = DataParser.getJsonIdentifier(message, out identifier); bool isJson = DataParser.getJsonIdentifier(message, out identifier);
Debug.WriteLine("server " + Encoding.ASCII.GetString(payloadbytes));
if (isJson) if (isJson)
{ {
switch (identifier) switch (identifier)
@@ -109,7 +108,6 @@ namespace Server
if (handleLogin(payloadbytes)) if (handleLogin(payloadbytes))
{ {
communication.Doctor = this; communication.Doctor = this;
Console.WriteLine("Set doctor to " + communication.Doctor + " , this is " + this);
} }
break; break;
case DataParser.START_SESSION: case DataParser.START_SESSION:
@@ -120,7 +118,6 @@ namespace Server
break; break;
case DataParser.SET_RESISTANCE: case DataParser.SET_RESISTANCE:
bool worked = DataParser.getResistanceFromResponseJson(payloadbytes); bool worked = DataParser.getResistanceFromResponseJson(payloadbytes);
Console.WriteLine($"set resistance worked is " + worked);
//set resistance on doctor GUI //set resistance on doctor GUI
break; break;
case DataParser.DISCONNECT: case DataParser.DISCONNECT:
@@ -170,7 +167,6 @@ namespace Server
Console.WriteLine("Log in"); Console.WriteLine("Log in");
this.username = username; this.username = username;
sendMessage(DataParser.getLoginResponse("OK")); sendMessage(DataParser.getLoginResponse("OK"));
//sendMessage(DataParser.getStartSessionJson());
return true; return true;
} }
else else
@@ -187,7 +183,6 @@ namespace Server
public void sendMessage(byte[] message) public void sendMessage(byte[] message)
{ {
Debug.WriteLine("serverclient " + Encoding.ASCII.GetString(message.Skip(5).ToArray()));
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
} }

View File

@@ -1,10 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO.Pipes;
using System.Linq;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text;
using Util; using Util;
namespace Server namespace Server
@@ -25,10 +21,7 @@ namespace Server
this.mDoctor = value; this.mDoctor = value;
this.clients.ForEach((client) => this.clients.ForEach((client) =>
{ {
Debug.WriteLine("foreach called for " + client.username); this.mDoctor.sendMessage(DataParser.getNewConnectionJson(client.username));
byte[] dinges = DataParser.getNewConnectionJson(client.username);
Debug.WriteLine("foreach " + Encoding.ASCII.GetString(dinges.Skip(5).ToArray()));
this.mDoctor.sendMessage(dinges);
}); });
} }
} }
@@ -65,10 +58,7 @@ namespace Server
public void NewLogin(Client client) public void NewLogin(Client client)
{ {
this.clients.Add(client); this.clients.Add(client);
Debug.WriteLine("amount of clients is now " + this.clients.Count); Doctor?.sendMessage(DataParser.getNewConnectionJson(client.username));
var dinges = DataParser.getNewConnectionJson(client.username);
Debug.WriteLine("new login" + Encoding.ASCII.GetString(dinges));
Doctor?.sendMessage(dinges);
} }
public void LogOff(Client client) public void LogOff(Client client)
@@ -82,9 +72,9 @@ namespace Server
public void StartSessionUser(string user) public void StartSessionUser(string user)
{ {
foreach(Client client in clients) foreach (Client client in clients)
{ {
if(client.username == user) if (client.username == user)
{ {
client.sendMessage(DataParser.getStartSessionJson(user)); client.sendMessage(DataParser.getStartSessionJson(user));
client.StartSession(); client.StartSession();