Develop #10
@@ -139,12 +139,12 @@ namespace ClientApp.Utils
|
|||||||
Console.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();
|
||||||
sendMessage(DataParser.getStartSessionJson());
|
Debug.WriteLine("start");
|
||||||
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;
|
||||||
sendMessage(DataParser.getStopSessionJson());
|
Debug.WriteLine("stop");
|
||||||
break;
|
break;
|
||||||
case DataParser.SET_RESISTANCE:
|
case DataParser.SET_RESISTANCE:
|
||||||
Console.WriteLine("Set resistance identifier");
|
Console.WriteLine("Set resistance identifier");
|
||||||
@@ -181,7 +181,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>
|
||||||
private void sendMessage(byte[] message)
|
public void sendMessage(byte[] message)
|
||||||
{
|
{
|
||||||
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||||
}
|
}
|
||||||
@@ -297,6 +297,7 @@ namespace ClientApp.Utils
|
|||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Debug.WriteLine("client dispose called");
|
Debug.WriteLine("client dispose called");
|
||||||
|
sendMessage(DataParser.getDisconnectJson(LoginViewModel.Username));
|
||||||
this.stream.Dispose();
|
this.stream.Dispose();
|
||||||
this.client.Dispose();
|
this.client.Dispose();
|
||||||
this.handler.stop();
|
this.handler.stop();
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ namespace DoctorApp.Utils
|
|||||||
this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
|
this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
|
||||||
break;
|
break;
|
||||||
case DataParser.DISCONNECT:
|
case DataParser.DISCONNECT:
|
||||||
this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
|
this.MainViewModel.DisconnectedUser(DataParser.getUsernameFromResponseJson(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)}");
|
||||||
@@ -140,7 +140,7 @@ namespace DoctorApp.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>
|
||||||
private void sendMessage(byte[] message)
|
public void sendMessage(byte[] message)
|
||||||
{
|
{
|
||||||
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||||
}
|
}
|
||||||
@@ -170,7 +170,7 @@ namespace DoctorApp.Utils
|
|||||||
|
|
||||||
string hashPassword = Util.Hasher.HashString(password);
|
string hashPassword = Util.Hasher.HashString(password);
|
||||||
|
|
||||||
byte[] message = DataParser.getJsonMessage(DataParser.LoginAsDoctor(username, 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);
|
||||||
|
|||||||
@@ -1,13 +1,81 @@
|
|||||||
using System;
|
using DoctorApp.Utils;
|
||||||
|
using GalaSoft.MvvmLight.Command;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using Util;
|
||||||
|
|
||||||
namespace DoctorApp.ViewModels
|
namespace DoctorApp.ViewModels
|
||||||
{
|
{
|
||||||
|
|
||||||
class ClientInfoViewModel
|
class ClientInfoViewModel : ObservableObject
|
||||||
{
|
{
|
||||||
|
public ObservableCollection<string> ChatLog { get; set; }
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
public string TabName { 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 StopSession { get; set; }
|
||||||
|
|
||||||
|
public ICommand Chat { get; set; }
|
||||||
|
|
||||||
|
public ICommand ChatToAll { get; set; }
|
||||||
|
|
||||||
|
public ICommand ClientInfo { get; set; }
|
||||||
|
|
||||||
|
public ICommand SetResistance { get; set; }
|
||||||
|
|
||||||
|
public MainWindowViewModel MainWindowViewModel { get; set; }
|
||||||
|
private Client client;
|
||||||
|
|
||||||
|
public ClientInfoViewModel(MainWindowViewModel mainWindowViewModel)
|
||||||
|
{
|
||||||
|
MainWindowViewModel = mainWindowViewModel;
|
||||||
|
ChatLog = new ObservableCollection<string>();
|
||||||
|
client = mainWindowViewModel.client;
|
||||||
|
|
||||||
|
StartSession = new RelayCommand(()=>{
|
||||||
|
client.sendMessage(DataParser.getStartSessionJson(Username));
|
||||||
|
Status = "Session started";
|
||||||
|
});
|
||||||
|
|
||||||
|
StopSession = new RelayCommand(() => {
|
||||||
|
client.sendMessage(DataParser.getStopSessionJson(Username));
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
//TODO RelayCommand ChatToAll
|
||||||
|
|
||||||
|
SetResistance = new RelayCommand<object>((parameter) =>
|
||||||
|
{
|
||||||
|
client.sendMessage(DataParser.getSetResistanceJson(Username, float.Parse(((TextBox)parameter).Text)));
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace DoctorApp.ViewModels
|
|||||||
{
|
{
|
||||||
class MainViewModel : ObservableObject
|
class MainViewModel : ObservableObject
|
||||||
{
|
{
|
||||||
public ObservableCollection<object> Tabs { get; set; }
|
public ObservableCollection<ClientInfoViewModel> Tabs { get; set; }
|
||||||
public int Selected { get; set; }
|
public int Selected { get; set; }
|
||||||
public MainWindowViewModel MainWindowViewModel { get; set; }
|
public MainWindowViewModel MainWindowViewModel { get; set; }
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ namespace DoctorApp.ViewModels
|
|||||||
{
|
{
|
||||||
this.MainWindowViewModel = mainWindowViewModel;
|
this.MainWindowViewModel = mainWindowViewModel;
|
||||||
client = this.MainWindowViewModel.client;
|
client = this.MainWindowViewModel.client;
|
||||||
Tabs = new ObservableCollection<object>();
|
Tabs= new ObservableCollection<ClientInfoViewModel>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NewConnectedUser(string username)
|
public void NewConnectedUser(string username)
|
||||||
@@ -29,17 +29,27 @@ namespace DoctorApp.ViewModels
|
|||||||
System.Diagnostics.Debug.WriteLine("CREATING TAB FOR " + 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
|
Tabs.Add(new ClientInfoViewModel(MainWindowViewModel)
|
||||||
{
|
{
|
||||||
Username = username,
|
Username = username,
|
||||||
TabName = username
|
Status = "Waiting to start"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DisconnectedUser(string username)
|
public void DisconnectedUser(string username)
|
||||||
{
|
{
|
||||||
|
App.Current.Dispatcher.Invoke((Action)delegate
|
||||||
|
{
|
||||||
|
foreach (ClientInfoViewModel item in Tabs)
|
||||||
|
{
|
||||||
|
if (item.Username == username)
|
||||||
|
{
|
||||||
|
Tabs.Remove(item);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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="UserName" Name="Username_Label"/>
|
<Label Content="{Binding Path=Username}"/>
|
||||||
<Label Content="Status: " Name="Status_Label"/>
|
<Label Content="{Binding Path=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="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
|
<TextBox Name="textBox_Resistance" Text="{Binding Path=Resistance}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
|
||||||
<TextBox Name="textBox_CurrentSpeed" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
|
<TextBox Name="textBox_CurrentSpeed" Text="{Binding Path=Speed}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
|
||||||
<TextBox Name="textBox_CurrentBPM" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
|
<TextBox Name="textBox_CurrentBPM" Text="{Binding Path=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,20 +49,19 @@
|
|||||||
<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="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
|
<TextBox Name="textBox_DistanceCovered" Text="{Binding Path=Distance}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
|
||||||
<TextBox Name="textBox_CurrentPower" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" 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="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
|
<TextBox Name="textBox_AccPower" Text="{Binding Path=Acc_Power}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<ListBox Name="ChatBox" Grid.Column="1" Margin="59,41,0,0" Grid.RowSpan="3"/>
|
<ListBox Name="ChatBox" ItemsSource="{Binding 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 Content="Button" Grid.Column="1" HorizontalAlignment="Left" Margin="59,33,0,0" Grid.Row="3" VerticalAlignment="Top" />
|
<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"/>
|
<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" />
|
<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"/>
|
<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"/>
|
<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}"/>
|
||||||
<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"/>
|
||||||
<Button Content="Client Info" Grid.Column="1" HorizontalAlignment="Left" Margin="207,6,0,0" VerticalAlignment="Top" Height="26" Width="82"/>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -8,10 +8,10 @@
|
|||||||
d:DesignHeight="450" d:DesignWidth="800">
|
d:DesignHeight="450" d:DesignWidth="800">
|
||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<TabControl ItemsSource="{Binding Tabs}" SelectedItem="{Binding Selected}">
|
<TabControl TabStripPlacement="Left" ItemsSource="{Binding Tabs}" SelectedItem="{Binding Selected}">
|
||||||
<TabControl.ItemTemplate>
|
<TabControl.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<TextBlock Text="{Binding TabName}"/>
|
<TextBlock Text="{Binding Username}"/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</TabControl.ItemTemplate>
|
</TabControl.ItemTemplate>
|
||||||
<TabControl.ContentTemplate>
|
<TabControl.ContentTemplate>
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:DoctorApp"
|
xmlns:local="clr-namespace:DoctorApp"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
|
Background="Transparent"
|
||||||
|
WindowStyle="None"
|
||||||
|
AllowsTransparency="True"
|
||||||
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}">
|
||||||
|
|||||||
@@ -195,20 +195,29 @@ namespace Util
|
|||||||
return getMessage(payload, 0x01);
|
return getMessage(payload, 0x01);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] getStartSessionJson()
|
public static byte[] getStartSessionJson(string user)
|
||||||
{
|
|
||||||
return getJsonMessage(START_SESSION);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] getStopSessionJson()
|
|
||||||
{
|
|
||||||
return getJsonMessage(STOP_SESSION);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] getSetResistanceJson(float mResistance)
|
|
||||||
{
|
{
|
||||||
dynamic data = new
|
dynamic data = new
|
||||||
{
|
{
|
||||||
|
username = user
|
||||||
|
};
|
||||||
|
return getJsonMessage(START_SESSION, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] getStopSessionJson(string user)
|
||||||
|
{
|
||||||
|
dynamic data = new
|
||||||
|
{
|
||||||
|
username = user
|
||||||
|
};
|
||||||
|
return getJsonMessage(STOP_SESSION, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] getSetResistanceJson(string user,float mResistance)
|
||||||
|
{
|
||||||
|
dynamic data = new
|
||||||
|
{
|
||||||
|
username = user,
|
||||||
resistance = mResistance
|
resistance = mResistance
|
||||||
};
|
};
|
||||||
return getJsonMessage(SET_RESISTANCE, data);
|
return getJsonMessage(SET_RESISTANCE, data);
|
||||||
@@ -258,6 +267,26 @@ namespace Util
|
|||||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username;
|
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string getChatMessageFromJson(byte[] json)
|
||||||
|
{
|
||||||
|
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.chat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string getUsernameFromJson(byte[] json)
|
||||||
|
{
|
||||||
|
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] getChatJson(string user, string message)
|
||||||
|
{
|
||||||
|
dynamic data = new
|
||||||
|
{
|
||||||
|
username = user,
|
||||||
|
chat = message
|
||||||
|
};
|
||||||
|
return getJsonMessage(MESSAGE, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using System.IO;
|
|||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using ClientApp.Utils;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Util;
|
using Util;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -112,18 +111,18 @@ namespace Server
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DataParser.START_SESSION:
|
case DataParser.START_SESSION:
|
||||||
this.saveData = new SaveData(Directory.GetCurrentDirectory() + "/" + this.username + "/" + sessionStart.ToString("yyyy-MM-dd HH-mm-ss"));
|
this.communication.StartSessionUser(DataParser.getUsernameFromJson(payloadbytes));
|
||||||
break;
|
break;
|
||||||
case DataParser.STOP_SESSION:
|
case DataParser.STOP_SESSION:
|
||||||
this.saveData = null;
|
this.communication.StopSessionUser(DataParser.getUsernameFromJson(payloadbytes));
|
||||||
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);
|
Console.WriteLine($"set resistance worked is " + worked);
|
||||||
//set resistance on doctor GUI
|
//set resistance on doctor GUI
|
||||||
break;
|
break;
|
||||||
case DataParser.MESSAGE:
|
case DataParser.DISCONNECT:
|
||||||
//TODO send message to clients
|
communication.Disconnect(this);
|
||||||
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)}");
|
||||||
@@ -244,5 +243,15 @@ 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ using System.IO.Pipes;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using DoctorApp.Utils;
|
|
||||||
using Util;
|
using Util;
|
||||||
|
|
||||||
namespace Server
|
namespace Server
|
||||||
@@ -60,6 +59,7 @@ namespace Server
|
|||||||
internal void Disconnect(Client client)
|
internal void Disconnect(Client client)
|
||||||
{
|
{
|
||||||
clients.Remove(client);
|
clients.Remove(client);
|
||||||
|
Doctor.sendMessage(DataParser.getDisconnectJson(client.username));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NewLogin(Client client)
|
public void NewLogin(Client client)
|
||||||
@@ -79,5 +79,30 @@ namespace Server
|
|||||||
}
|
}
|
||||||
this.clients.Remove(client);
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user