Develop #10
25
DoctorApp/Models/PatientInfo.cs
Normal file
25
DoctorApp/Models/PatientInfo.cs
Normal 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; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,6 @@ namespace DoctorApp.Utils
|
||||
string identifier;
|
||||
bool isJson = DataParser.getJsonIdentifier(messageBytes, out identifier);
|
||||
|
||||
Debug.WriteLine("doctor " + Encoding.ASCII.GetString(payloadbytes));
|
||||
if (isJson)
|
||||
{
|
||||
switch (identifier)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using DoctorApp.Utils;
|
||||
using DoctorApp.Models;
|
||||
using DoctorApp.Utils;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -11,25 +12,10 @@ using Util;
|
||||
|
||||
namespace DoctorApp.ViewModels
|
||||
{
|
||||
|
||||
|
||||
class ClientInfoViewModel : 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; }
|
||||
|
||||
public PatientInfo PatientInfo { get; set; }
|
||||
public ICommand StartSession { get; set; }
|
||||
|
||||
public ICommand StopSession { get; set; }
|
||||
@@ -45,33 +31,36 @@ namespace DoctorApp.ViewModels
|
||||
public MainWindowViewModel MainWindowViewModel { get; set; }
|
||||
private Client client;
|
||||
|
||||
public ClientInfoViewModel(MainWindowViewModel mainWindowViewModel)
|
||||
public ClientInfoViewModel(MainWindowViewModel mainWindowViewModel, string username)
|
||||
{
|
||||
MainWindowViewModel = mainWindowViewModel;
|
||||
ChatLog = new ObservableCollection<string>();
|
||||
this.PatientInfo = new PatientInfo() { Username = username, Status = "Waiting to start" };
|
||||
PatientInfo.ChatLog = new ObservableCollection<string>();
|
||||
client = mainWindowViewModel.client;
|
||||
|
||||
StartSession = new RelayCommand(()=>{
|
||||
client.sendMessage(DataParser.getStartSessionJson(Username));
|
||||
Status = "Session started";
|
||||
StartSession = new RelayCommand(() =>
|
||||
{
|
||||
client.sendMessage(DataParser.getStartSessionJson(PatientInfo.Username));
|
||||
PatientInfo.Status = "Session started";
|
||||
});
|
||||
|
||||
StopSession = new RelayCommand(() => {
|
||||
client.sendMessage(DataParser.getStopSessionJson(Username));
|
||||
Status = "Session stopped, waiting to start again.";
|
||||
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(Username, ((TextBox)parameter).Text));
|
||||
ChatLog.Add(DateTime.Now+": "+ ((TextBox)parameter).Text);
|
||||
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) =>
|
||||
{
|
||||
client.sendMessage(DataParser.getSetResistanceJson(Username, float.Parse(((TextBox)parameter).Text)));
|
||||
client.sendMessage(DataParser.getSetResistanceJson(PatientInfo.Username, float.Parse(((TextBox)parameter).Text)));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -21,19 +21,14 @@ namespace DoctorApp.ViewModels
|
||||
{
|
||||
this.MainWindowViewModel = mainWindowViewModel;
|
||||
client = this.MainWindowViewModel.client;
|
||||
Tabs= new ObservableCollection<ClientInfoViewModel>();
|
||||
Tabs = new ObservableCollection<ClientInfoViewModel>();
|
||||
}
|
||||
|
||||
public void NewConnectedUser(string username)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("CREATING TAB FOR " + username);
|
||||
App.Current.Dispatcher.Invoke((Action)delegate
|
||||
{
|
||||
Tabs.Add(new ClientInfoViewModel(MainWindowViewModel)
|
||||
{
|
||||
Username = username,
|
||||
Status = "Waiting to start"
|
||||
});
|
||||
Tabs.Add(new ClientInfoViewModel(MainWindowViewModel, username));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -43,7 +38,7 @@ namespace DoctorApp.ViewModels
|
||||
{
|
||||
foreach (ClientInfoViewModel item in Tabs)
|
||||
{
|
||||
if (item.Username == username)
|
||||
if (item.PatientInfo.Username == username)
|
||||
{
|
||||
Tabs.Remove(item);
|
||||
break;
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
<Setter Property="Margin" Value="0,0,20,0"/>
|
||||
</Style>
|
||||
</StackPanel.Resources>
|
||||
<Label Content="{Binding Path=Username}"/>
|
||||
<Label Content="{Binding Path=Status}"/>
|
||||
<Label Content="{Binding Path=PatientInfo.Username}"/>
|
||||
<Label Content="{Binding Path=PatientInfo.Status}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Margin="0,10,0,0" Grid.RowSpan="2" Grid.Row="1">
|
||||
<StackPanel.Resources>
|
||||
@@ -39,9 +39,9 @@
|
||||
<Label Content="Current BPM" Width="110" DockPanel.Dock="Top"/>
|
||||
</DockPanel>
|
||||
<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_CurrentSpeed" Text="{Binding Path=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_Resistance" Text="{Binding Path=PatientInfo.Resistance}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" 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=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"/>
|
||||
@@ -49,18 +49,18 @@
|
||||
<Label Content="Acc. Power" Width="110" DockPanel.Dock="Top"/>
|
||||
</DockPanel>
|
||||
<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_CurrentPower" Text="{Binding Path=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_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 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"/>
|
||||
<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=""/>
|
||||
<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 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 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"/>
|
||||
<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"/>
|
||||
<ComboBox Name="DropBox" HorizontalAlignment="Left" Margin="0,6,0,0" Grid.Row="3" VerticalAlignment="Top" Width="190"/>
|
||||
</Grid>
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
Background="Transparent"
|
||||
WindowStyle="None"
|
||||
AllowsTransparency="True"
|
||||
MinHeight="{Binding MinimumHeight}"
|
||||
MinWidth="{Binding MinimumWidth}"
|
||||
Title="MainWindow" Height="450" Width="800">
|
||||
<Window.Resources>
|
||||
<Style TargetType="{x:Type local:MainWindow}">
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using System.Diagnostics;
|
||||
using Util;
|
||||
using System.Linq;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
@@ -93,7 +93,6 @@ namespace Server
|
||||
string identifier;
|
||||
bool isJson = DataParser.getJsonIdentifier(message, out identifier);
|
||||
|
||||
Debug.WriteLine("server " + Encoding.ASCII.GetString(payloadbytes));
|
||||
if (isJson)
|
||||
{
|
||||
switch (identifier)
|
||||
@@ -109,7 +108,6 @@ namespace Server
|
||||
if (handleLogin(payloadbytes))
|
||||
{
|
||||
communication.Doctor = this;
|
||||
Console.WriteLine("Set doctor to " + communication.Doctor + " , this is " + this);
|
||||
}
|
||||
break;
|
||||
case DataParser.START_SESSION:
|
||||
@@ -120,7 +118,6 @@ namespace Server
|
||||
break;
|
||||
case DataParser.SET_RESISTANCE:
|
||||
bool worked = DataParser.getResistanceFromResponseJson(payloadbytes);
|
||||
Console.WriteLine($"set resistance worked is " + worked);
|
||||
//set resistance on doctor GUI
|
||||
break;
|
||||
case DataParser.DISCONNECT:
|
||||
@@ -170,7 +167,6 @@ namespace Server
|
||||
Console.WriteLine("Log in");
|
||||
this.username = username;
|
||||
sendMessage(DataParser.getLoginResponse("OK"));
|
||||
//sendMessage(DataParser.getStartSessionJson());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -187,7 +183,6 @@ namespace Server
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO.Pipes;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using Util;
|
||||
|
||||
namespace Server
|
||||
@@ -25,10 +21,7 @@ namespace Server
|
||||
this.mDoctor = value;
|
||||
this.clients.ForEach((client) =>
|
||||
{
|
||||
Debug.WriteLine("foreach called for " + client.username);
|
||||
byte[] dinges = DataParser.getNewConnectionJson(client.username);
|
||||
Debug.WriteLine("foreach " + Encoding.ASCII.GetString(dinges.Skip(5).ToArray()));
|
||||
this.mDoctor.sendMessage(dinges);
|
||||
this.mDoctor.sendMessage(DataParser.getNewConnectionJson(client.username));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -65,10 +58,7 @@ namespace Server
|
||||
public void NewLogin(Client client)
|
||||
{
|
||||
this.clients.Add(client);
|
||||
Debug.WriteLine("amount of clients is now " + this.clients.Count);
|
||||
var dinges = DataParser.getNewConnectionJson(client.username);
|
||||
Debug.WriteLine("new login" + Encoding.ASCII.GetString(dinges));
|
||||
Doctor?.sendMessage(dinges);
|
||||
Doctor?.sendMessage(DataParser.getNewConnectionJson(client.username));
|
||||
}
|
||||
|
||||
public void LogOff(Client client)
|
||||
@@ -82,9 +72,9 @@ namespace Server
|
||||
|
||||
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.StartSession();
|
||||
|
||||
Reference in New Issue
Block a user