Develop #10
@@ -130,7 +130,7 @@ namespace ClientApp.Utils
|
||||
Debug.WriteLine($"login failed \"{responseStatus}\"");
|
||||
}
|
||||
break;
|
||||
case DataParser.START_SESSION:
|
||||
/*case DataParser.START_SESSION:
|
||||
Console.WriteLine("Session started!");
|
||||
this.sessionRunning = true;
|
||||
if (engineConnection.Connected && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
|
||||
@@ -140,7 +140,7 @@ namespace ClientApp.Utils
|
||||
Console.WriteLine("Stop session identifier");
|
||||
this.sessionRunning = false;
|
||||
sendMessage(DataParser.getStopSessionJson());
|
||||
break;
|
||||
break;*/
|
||||
case DataParser.SET_RESISTANCE:
|
||||
Console.WriteLine("Set resistance identifier");
|
||||
if (this.handler == null)
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace DoctorApp.Utils
|
||||
Debug.WriteLine($"login failed \"{responseStatus}\"");
|
||||
}
|
||||
break;
|
||||
case DataParser.START_SESSION:
|
||||
/*case DataParser.START_SESSION:
|
||||
Console.WriteLine("Session started!");
|
||||
this.sessionRunning = true;
|
||||
sendMessage(DataParser.getStartSessionJson());
|
||||
@@ -108,7 +108,7 @@ namespace DoctorApp.Utils
|
||||
Console.WriteLine("Stop session identifier");
|
||||
this.sessionRunning = false;
|
||||
sendMessage(DataParser.getStopSessionJson());
|
||||
break;
|
||||
break;*/
|
||||
case DataParser.SET_RESISTANCE:
|
||||
Console.WriteLine("Set resistance identifier");
|
||||
if (this.handler == null)
|
||||
|
||||
@@ -2,18 +2,34 @@
|
||||
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 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; }
|
||||
@@ -29,23 +45,38 @@ namespace DoctorApp.ViewModels
|
||||
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());
|
||||
client.sendMessage(DataParser.getStartSessionJson(Username));
|
||||
Status = "Session started";
|
||||
});
|
||||
|
||||
StopSession = new RelayCommand(() => {
|
||||
client.sendMessage(DataParser.getStopSessionJson());
|
||||
client.sendMessage(DataParser.getStopSessionJson(Username));
|
||||
Status = "Session stopped, waiting to start again.";
|
||||
});
|
||||
|
||||
Chat = new RelayCommand<object>((parameter) =>
|
||||
{
|
||||
/*client.sendMessage(DataParser.)*/
|
||||
client.sendMessage(DataParser.getChatJson(Username, ((TextBox)parameter).Text));
|
||||
ChatLog.Add(DateTime.Now+": "+ ((TextBox)parameter).Text);
|
||||
});
|
||||
|
||||
//TODO RelayCommand ChatToAll
|
||||
|
||||
ClientInfo = new RelayCommand(() =>
|
||||
{
|
||||
//TODO POPUP
|
||||
});
|
||||
|
||||
SetResistance = new RelayCommand<object>((parameter) =>
|
||||
{
|
||||
client.sendMessage(DataParser.getSetResistanceJson(Username, float.Parse(((TextBox)parameter).Text)));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
<Setter Property="Margin" Value="0,0,20,0"/>
|
||||
</Style>
|
||||
</StackPanel.Resources>
|
||||
<Label Content="{Binding Username}"/>
|
||||
<Label Content="{Binding Status}"/>
|
||||
<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,18 +49,18 @@
|
||||
<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"/>
|
||||
|
||||
@@ -182,20 +182,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);
|
||||
@@ -243,16 +252,25 @@ namespace Util
|
||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username;
|
||||
}
|
||||
|
||||
/*public static bool getChatMessageFronJson(byte[] json, out string username, out string chat)
|
||||
public static string getChatMessageFromJson(byte[] json)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.chat;
|
||||
}
|
||||
|
||||
}
|
||||
dynamic jsn = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json));
|
||||
username = jsn.data.username;
|
||||
chat = jsn.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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace Server
|
||||
Console.WriteLine("Log in");
|
||||
this.username = username;
|
||||
sendMessage(DataParser.getLoginResponse("OK"));
|
||||
sendMessage(DataParser.getStartSessionJson());
|
||||
//sendMessage(DataParser.getStartSessionJson());
|
||||
communication.NewLogin(this);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user