Develop #10
@@ -139,12 +139,12 @@ namespace ClientApp.Utils
|
||||
Console.WriteLine("Session started!");
|
||||
this.sessionRunning = true;
|
||||
if (engineConnection.Connected && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
|
||||
sendMessage(DataParser.getStartSessionJson());
|
||||
Debug.WriteLine("start");
|
||||
break;
|
||||
case DataParser.STOP_SESSION:
|
||||
Console.WriteLine("Stop session identifier");
|
||||
this.sessionRunning = false;
|
||||
sendMessage(DataParser.getStopSessionJson());
|
||||
Debug.WriteLine("stop");
|
||||
break;
|
||||
case DataParser.SET_RESISTANCE:
|
||||
Console.WriteLine("Set resistance identifier");
|
||||
@@ -181,7 +181,7 @@ namespace ClientApp.Utils
|
||||
/// starts sending a message to the server
|
||||
/// </summary>
|
||||
/// <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);
|
||||
}
|
||||
@@ -297,6 +297,7 @@ namespace ClientApp.Utils
|
||||
public void Dispose()
|
||||
{
|
||||
Debug.WriteLine("client dispose called");
|
||||
sendMessage(DataParser.getDisconnectJson(LoginViewModel.Username));
|
||||
this.stream.Dispose();
|
||||
this.client.Dispose();
|
||||
this.handler.stop();
|
||||
|
||||
@@ -10,7 +10,7 @@ using Util;
|
||||
namespace DoctorApp.Utils
|
||||
{
|
||||
public delegate void EngineCallback();
|
||||
public class Client : IDataReceiver
|
||||
public class Client
|
||||
{
|
||||
private TcpClient client;
|
||||
private NetworkStream stream;
|
||||
@@ -18,8 +18,6 @@ namespace DoctorApp.Utils
|
||||
private bool connected;
|
||||
private byte[] totalBuffer = new byte[1024];
|
||||
private int totalBufferReceived = 0;
|
||||
private bool sessionRunning = false;
|
||||
private IHandler handler = null;
|
||||
private LoginViewModel LoginViewModel;
|
||||
private MainViewModel MainViewModel;
|
||||
private ClientInfoViewModel ClientInfoViewModel;
|
||||
@@ -83,6 +81,8 @@ namespace DoctorApp.Utils
|
||||
|
||||
string identifier;
|
||||
bool isJson = DataParser.getJsonIdentifier(messageBytes, out identifier);
|
||||
|
||||
Debug.WriteLine("doctor " + Encoding.ASCII.GetString(payloadbytes));
|
||||
if (isJson)
|
||||
{
|
||||
switch (identifier)
|
||||
@@ -104,32 +104,19 @@ namespace DoctorApp.Utils
|
||||
break;
|
||||
case DataParser.START_SESSION:
|
||||
Console.WriteLine("Session started!");
|
||||
this.sessionRunning = true;
|
||||
sendMessage(DataParser.getStartSessionJson());
|
||||
break;
|
||||
case DataParser.STOP_SESSION:
|
||||
Console.WriteLine("Stop session identifier");
|
||||
this.sessionRunning = false;
|
||||
sendMessage(DataParser.getStopSessionJson());
|
||||
break;
|
||||
case DataParser.SET_RESISTANCE:
|
||||
Console.WriteLine("Set resistance identifier");
|
||||
if (this.handler == null)
|
||||
{
|
||||
Console.WriteLine("handler is null");
|
||||
sendMessage(DataParser.getSetResistanceResponseJson(false));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.handler.setResistance(DataParser.getResistanceFromJson(payloadbytes));
|
||||
sendMessage(DataParser.getSetResistanceResponseJson(true));
|
||||
}
|
||||
break;
|
||||
case DataParser.NEW_CONNECTION:
|
||||
Debug.WriteLine("doctor client new connection");
|
||||
this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
|
||||
break;
|
||||
case DataParser.DISCONNECT:
|
||||
this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
|
||||
this.MainViewModel.DisconnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
||||
@@ -153,7 +140,7 @@ namespace DoctorApp.Utils
|
||||
/// starts sending a message to the server
|
||||
/// </summary>
|
||||
/// <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);
|
||||
}
|
||||
@@ -167,63 +154,6 @@ namespace DoctorApp.Utils
|
||||
this.stream.EndWrite(ar);
|
||||
}
|
||||
|
||||
#region interface
|
||||
//maybe move this to other place
|
||||
/// <summary>
|
||||
/// bpm method for receiving the BPM value from the bluetooth bike or the simulation
|
||||
/// </summary>
|
||||
/// <param name="bytes">the message</param>
|
||||
public void BPM(byte[] bytes)
|
||||
{
|
||||
if (!sessionRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (bytes == null)
|
||||
{
|
||||
throw new ArgumentNullException("no bytes");
|
||||
}
|
||||
byte[] message = DataParser.GetRawDataMessage(bytes);
|
||||
|
||||
|
||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// method for receiving the bike message from the bluetooth bike or the simulation
|
||||
/// </summary>
|
||||
/// <param name="bytes">the message</param>
|
||||
public void Bike(byte[] bytes)
|
||||
{
|
||||
|
||||
if (!sessionRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (bytes == null)
|
||||
{
|
||||
throw new ArgumentNullException("no bytes");
|
||||
}
|
||||
byte[] message = DataParser.GetRawDataMessage(bytes);
|
||||
|
||||
/* switch (bytes[0])
|
||||
{
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// wether or not the client stream is connected
|
||||
/// </summary>
|
||||
@@ -246,15 +176,6 @@ namespace DoctorApp.Utils
|
||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sets the handler for the client, so either the bike simulator or the bluetooth bike handler
|
||||
/// </summary>
|
||||
/// <param name="handler"></param>
|
||||
public void SetHandler(IHandler handler)
|
||||
{
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
internal void SetLoginViewModel(LoginViewModel loginViewModel)
|
||||
{
|
||||
this.LoginViewModel = loginViewModel;
|
||||
@@ -275,7 +196,6 @@ namespace DoctorApp.Utils
|
||||
Debug.WriteLine("client dispose called");
|
||||
this.stream.Dispose();
|
||||
this.client.Dispose();
|
||||
this.handler?.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,81 @@
|
||||
using System;
|
||||
using DoctorApp.Utils;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Util;
|
||||
|
||||
namespace DoctorApp.ViewModels
|
||||
{
|
||||
|
||||
class ClientInfoViewModel
|
||||
class ClientInfoViewModel : ObservableObject
|
||||
{
|
||||
public ObservableCollection<string> ChatLog { 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
|
||||
{
|
||||
public ObservableCollection<object> Tabs { get; set; }
|
||||
public ObservableCollection<ClientInfoViewModel> Tabs { get; set; }
|
||||
public int Selected { get; set; }
|
||||
public MainWindowViewModel MainWindowViewModel { get; set; }
|
||||
|
||||
@@ -21,26 +21,37 @@ namespace DoctorApp.ViewModels
|
||||
{
|
||||
this.MainWindowViewModel = mainWindowViewModel;
|
||||
client = this.MainWindowViewModel.client;
|
||||
Tabs= new ObservableCollection<object>();
|
||||
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
|
||||
Tabs.Add(new ClientInfoViewModel(MainWindowViewModel)
|
||||
{
|
||||
Username = username,
|
||||
TabName = username
|
||||
Status = "Waiting to start"
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
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"/>
|
||||
</Style>
|
||||
</StackPanel.Resources>
|
||||
<Label Content="UserName" Name="Username_Label"/>
|
||||
<Label Content="Status: " Name="Status_Label"/>
|
||||
<Label Content="{Binding Path=Username}"/>
|
||||
<Label Content="{Binding Path=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="" 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_CurrentBPM" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
|
||||
<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"/>
|
||||
</DockPanel>
|
||||
<DockPanel Height="26" LastChildFill="False">
|
||||
<Label Content="Distance Covered" Width="110" DockPanel.Dock="Right"/>
|
||||
@@ -49,20 +49,19 @@
|
||||
<Label Content="Acc. Power" Width="110" DockPanel.Dock="Top"/>
|
||||
</DockPanel>
|
||||
<DockPanel Height="26" LastChildFill="False">
|
||||
<TextBox Name="textBox_DistanceCovered" Text="" 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_AccPower" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
|
||||
<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"/>
|
||||
</DockPanel>
|
||||
</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"/>
|
||||
<Button Content="Button" Grid.Column="1" HorizontalAlignment="Left" Margin="59,33,0,0" Grid.Row="3" VerticalAlignment="Top" />
|
||||
<Button Content="Start Session" Grid.Column="1" HorizontalAlignment="Left" Margin="69,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" />
|
||||
<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=""/>
|
||||
<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"/>
|
||||
<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>
|
||||
</UserControl>
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
|
||||
<Grid>
|
||||
<TabControl ItemsSource="{Binding Tabs}" SelectedItem="{Binding Selected}">
|
||||
<TabControl TabStripPlacement="Left" ItemsSource="{Binding Tabs}" SelectedItem="{Binding Selected}">
|
||||
<TabControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding TabName}"/>
|
||||
<TextBlock Text="{Binding Username}"/>
|
||||
</DataTemplate>
|
||||
</TabControl.ItemTemplate>
|
||||
<TabControl.ContentTemplate>
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:DoctorApp"
|
||||
mc:Ignorable="d"
|
||||
Background="Transparent"
|
||||
WindowStyle="None"
|
||||
AllowsTransparency="True"
|
||||
Title="MainWindow" Height="450" Width="800">
|
||||
<Window.Resources>
|
||||
<Style TargetType="{x:Type local:MainWindow}">
|
||||
|
||||
@@ -195,20 +195,29 @@ namespace Util
|
||||
return getMessage(payload, 0x01);
|
||||
}
|
||||
|
||||
public static byte[] getStartSessionJson()
|
||||
{
|
||||
return getJsonMessage(START_SESSION);
|
||||
}
|
||||
|
||||
public static byte[] getStopSessionJson()
|
||||
{
|
||||
return getJsonMessage(STOP_SESSION);
|
||||
}
|
||||
|
||||
public static byte[] getSetResistanceJson(float mResistance)
|
||||
public static byte[] getStartSessionJson(string user)
|
||||
{
|
||||
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
|
||||
};
|
||||
return getJsonMessage(SET_RESISTANCE, data);
|
||||
@@ -258,6 +267,26 @@ namespace Util
|
||||
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,9 +3,9 @@ using System.IO;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using ClientApp.Utils;
|
||||
using System.Diagnostics;
|
||||
using Util;
|
||||
using System.Linq;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
@@ -92,6 +92,8 @@ namespace Server
|
||||
|
||||
string identifier;
|
||||
bool isJson = DataParser.getJsonIdentifier(message, out identifier);
|
||||
|
||||
Debug.WriteLine("server " + Encoding.ASCII.GetString(payloadbytes));
|
||||
if (isJson)
|
||||
{
|
||||
switch (identifier)
|
||||
@@ -111,18 +113,18 @@ namespace Server
|
||||
}
|
||||
break;
|
||||
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;
|
||||
case DataParser.STOP_SESSION:
|
||||
this.saveData = null;
|
||||
this.communication.StopSessionUser(DataParser.getUsernameFromJson(payloadbytes));
|
||||
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.MESSAGE:
|
||||
//TODO send message to clients
|
||||
case DataParser.DISCONNECT:
|
||||
communication.Disconnect(this);
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
||||
@@ -168,7 +170,7 @@ namespace Server
|
||||
Console.WriteLine("Log in");
|
||||
this.username = username;
|
||||
sendMessage(DataParser.getLoginResponse("OK"));
|
||||
sendMessage(DataParser.getStartSessionJson());
|
||||
//sendMessage(DataParser.getStartSessionJson());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -185,6 +187,7 @@ 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);
|
||||
}
|
||||
|
||||
@@ -242,5 +245,15 @@ namespace Server
|
||||
hex.AppendFormat("{0:x2}", b);
|
||||
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.Net.Sockets;
|
||||
using System.Text;
|
||||
using DoctorApp.Utils;
|
||||
using Util;
|
||||
|
||||
namespace Server
|
||||
@@ -26,8 +25,9 @@ namespace Server
|
||||
this.mDoctor = value;
|
||||
this.clients.ForEach((client) =>
|
||||
{
|
||||
var dinges = DataParser.getNewConnectionJson(client.username);
|
||||
Debug.WriteLine("foreach " + Encoding.ASCII.GetString(dinges));
|
||||
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);
|
||||
});
|
||||
}
|
||||
@@ -59,11 +59,13 @@ namespace Server
|
||||
internal void Disconnect(Client client)
|
||||
{
|
||||
clients.Remove(client);
|
||||
Doctor.sendMessage(DataParser.getDisconnectJson(client.username));
|
||||
}
|
||||
|
||||
public void NewLogin(Client client)
|
||||
{
|
||||
clients.Add(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);
|
||||
@@ -77,5 +79,30 @@ namespace Server
|
||||
}
|
||||
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