Rebuilt core client code
This commit is contained in:
Binary file not shown.
@@ -33,7 +33,6 @@ namespace ErgometerApplication
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.updateTimer = new System.Windows.Forms.Timer(this.components);
|
||||
this.writeTimer = new System.Windows.Forms.Timer(this.components);
|
||||
this.panelClientContainer = new System.Windows.Forms.Panel();
|
||||
this.panelDataViewLeft = new System.Windows.Forms.Panel();
|
||||
this.panelGraphView = new ErgometerApplication.PanelGraphView();
|
||||
@@ -58,11 +57,8 @@ namespace ErgometerApplication
|
||||
//
|
||||
// updateTimer
|
||||
//
|
||||
this.updateTimer.Interval = 1500;
|
||||
//
|
||||
// writeTimer
|
||||
//
|
||||
this.writeTimer.Interval = 10000;
|
||||
this.updateTimer.Interval = 350;
|
||||
this.updateTimer.Tick += new System.EventHandler(this.updateTimer_Tick);
|
||||
//
|
||||
// panelClientContainer
|
||||
//
|
||||
|
||||
@@ -20,281 +20,32 @@ namespace ErgometerApplication
|
||||
{
|
||||
public partial class ClientApplicatie : Form
|
||||
{
|
||||
private ComPort comPort;
|
||||
private TcpClient doctor;
|
||||
//private List<Meting> _data;
|
||||
//private int i = 0;
|
||||
//NetCommand command;
|
||||
//private ServerCommunicator communicator = new ServerCommunicator();
|
||||
//List<Meting> readFile = new List<Meting>();
|
||||
|
||||
public ClientApplicatie()
|
||||
{
|
||||
InitializeComponent();
|
||||
comPort = new ComPort();
|
||||
|
||||
doctor = new TcpClient("127.0.0.1", 8888);
|
||||
|
||||
// _data = new List<Meting>();
|
||||
// communicator.data = _data;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
//private void connectButton_Click(object sender, EventArgs e)
|
||||
//{
|
||||
// if (!comPort.IsOpen())
|
||||
// {
|
||||
// if (comPort.Connect(ComPortBox.Text))
|
||||
// {
|
||||
// connectButton.Text = "Disconnect";
|
||||
// statusButton.Enabled = true;
|
||||
// resetButton.Enabled = true;
|
||||
// timerStatus.Enabled = true;
|
||||
// inputTextBox.Enabled = true;
|
||||
// timeButton.Enabled = true;
|
||||
// distanceButton.Enabled = true;
|
||||
// powerButton.Enabled = true;
|
||||
// energyButton.Enabled = true;
|
||||
// ComPortBox.Enabled = false;
|
||||
|
||||
// comPort.Write("RS");
|
||||
// comPort.Read();
|
||||
// Thread.Sleep(200);
|
||||
// comPort.Write("CM");
|
||||
// comPort.Read();
|
||||
// Thread.Sleep(200);
|
||||
|
||||
// comPort.Write("ST");
|
||||
// string response = comPort.Read();
|
||||
// Console.WriteLine(response);
|
||||
|
||||
// Meting m = Meting.Parse(response);
|
||||
// SaveData(m);
|
||||
// // richTextBox1.Text = m.ToString();
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (comPort.Disconnect())
|
||||
// {
|
||||
// connectButton.Text = "Connect";
|
||||
// timerStatus.Checked = false;
|
||||
// statusButton.Enabled = false;
|
||||
// resetButton.Enabled = false;
|
||||
// timerStatus.Enabled = false;
|
||||
// inputTextBox.Enabled = false;
|
||||
// timeButton.Enabled = false;
|
||||
// distanceButton.Enabled = false;
|
||||
// powerButton.Enabled = false;
|
||||
// energyButton.Enabled = false;
|
||||
// ComPortBox.Enabled = true;
|
||||
// richTextBox1.Text = "";
|
||||
|
||||
// WriteFile();
|
||||
|
||||
// }
|
||||
// }
|
||||
// communicator.client = new TcpClient();
|
||||
// communicator.client.Connect("127.0.0.1", 8888);
|
||||
// Thread thread = new Thread(ServerCommunication);
|
||||
// thread.Start(communicator);
|
||||
//}
|
||||
|
||||
//private void statusButton_Click(object sender, EventArgs e)
|
||||
//{
|
||||
// comPort.Write("ST");
|
||||
// string response = comPort.Read();
|
||||
// Console.WriteLine(response);
|
||||
// Meting m = Meting.Parse(response, '\t');
|
||||
// Console.WriteLine(m);
|
||||
// SaveData(m);
|
||||
// communicator.data.Add(m);
|
||||
// command = new NetCommand(m, communicator.sessionId);
|
||||
// NetHelper.SendNetCommand(communicator.client, command);
|
||||
// richTextBox1.Text = m.ToString();
|
||||
// WriteFile();
|
||||
//}
|
||||
|
||||
//static void ServerCommunication(object obj)
|
||||
//{
|
||||
// ServerCommunicator communicator = obj as ServerCommunicator;
|
||||
|
||||
// NetCommand net = NetHelper.ReadNetCommand(communicator.client);
|
||||
// if (net.Type == NetCommand.CommandType.SESSION)
|
||||
// communicator.sessionId = net.Session;
|
||||
|
||||
// NetCommand command = new NetCommand("name", false, "pass", communicator.sessionId);
|
||||
// NetHelper.SendNetCommand(communicator.client, command);
|
||||
//}
|
||||
|
||||
//private void resetButton_Click(object sender, EventArgs e)
|
||||
//{
|
||||
// comPort.Write("RS");
|
||||
// comPort.Read();
|
||||
// Thread.Sleep(200);
|
||||
// comPort.Write("CM");
|
||||
// comPort.Read();
|
||||
//}
|
||||
|
||||
//private void updateTimer_Tick(object sender, EventArgs e)
|
||||
//{
|
||||
// if (timerStatus.Checked)
|
||||
// {
|
||||
// comPort.Write("ST");
|
||||
// string response = comPort.Read();
|
||||
// Console.WriteLine(response);
|
||||
// Meting m = Meting.Parse(response);
|
||||
// SaveData(m);
|
||||
// communicator.data.Add(m);
|
||||
// command = new NetCommand(m, communicator.sessionId);
|
||||
// NetHelper.SendNetCommand(communicator.client, command);
|
||||
// richTextBox1.Text = m.ToString();
|
||||
// command = new NetCommand(communicator.data[0], communicator.sessionId);
|
||||
// NetHelper.SendNetCommand(communicator.client, command);
|
||||
// }
|
||||
//}
|
||||
|
||||
//private void timeButton_Click(object sender, EventArgs e)
|
||||
//{
|
||||
// comPort.Write("RS");
|
||||
// comPort.Read();
|
||||
// Thread.Sleep(200);
|
||||
// string[] temp = inputTextBox.Text.Split(':');
|
||||
// comPort.Write("PT " + temp[0] + temp[1]);
|
||||
// Console.WriteLine("PT " + temp[0] + temp[1]);
|
||||
// inputTextBox.Text = "";
|
||||
// comPort.Read();
|
||||
//}
|
||||
|
||||
//private void distanceButton_Click(object sender, EventArgs e)
|
||||
//{
|
||||
// comPort.Write("RS");
|
||||
// comPort.Read();
|
||||
// Thread.Sleep(200);
|
||||
// int temp = int.Parse(inputTextBox.Text);
|
||||
// comPort.Write("PD " + temp.ToString());
|
||||
// inputTextBox.Text = "";
|
||||
// comPort.Read();
|
||||
//}
|
||||
|
||||
//private void powerButton_Click(object sender, EventArgs e)
|
||||
//{
|
||||
// int temp = int.Parse(inputTextBox.Text);
|
||||
// comPort.Write("PW " + temp.ToString());
|
||||
// inputTextBox.Text = "";
|
||||
// comPort.Read();
|
||||
//}
|
||||
|
||||
//private void energyButton_Click(object sender, EventArgs e)
|
||||
//{
|
||||
// comPort.Write("RS");
|
||||
// comPort.Read();
|
||||
// Thread.Sleep(200);
|
||||
// int temp = int.Parse(inputTextBox.Text);
|
||||
// comPort.Write("PE " + temp.ToString());
|
||||
// inputTextBox.Text = "";
|
||||
// comPort.Read();
|
||||
//}
|
||||
|
||||
//private void timerStatus_CheckedChanged(object sender, EventArgs e)
|
||||
//{
|
||||
// if (timerStatus.Checked)
|
||||
// {
|
||||
// statusButton.Enabled = false;
|
||||
// updateTimer.Start();
|
||||
// writeTimer.Start();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// statusButton.Enabled = true;
|
||||
// updateTimer.Stop();
|
||||
// writeTimer.Stop();
|
||||
// }
|
||||
//}
|
||||
|
||||
//private void readButton_Click(object sender, EventArgs e)
|
||||
//{
|
||||
// ReadFile();
|
||||
// if (readFile != null)
|
||||
// {
|
||||
// metingNextButton.Enabled = true;
|
||||
// metingBackButton.Enabled = true;
|
||||
// }
|
||||
|
||||
//}
|
||||
|
||||
//private void metingBackButton_Click(object sender, EventArgs e)
|
||||
//{
|
||||
// if (i > 0)
|
||||
// { i--;
|
||||
// metingNextButton.Enabled = true;
|
||||
// }
|
||||
// if (i == 0)
|
||||
// {
|
||||
// metingBackButton.Enabled = false;
|
||||
// }
|
||||
// richTextBox1.Text = readFile.ElementAt(i).ToString();
|
||||
//}
|
||||
|
||||
//private void metingNextButton_Click(object sender, EventArgs e)
|
||||
//{
|
||||
// if (i < (readFile.Count - 1))
|
||||
// { i++;
|
||||
// metingBackButton.Enabled = true;
|
||||
// }
|
||||
// if (i == (readFile.Count - 1))
|
||||
// {
|
||||
// metingNextButton.Enabled = false;
|
||||
// }
|
||||
// richTextBox1.Text = readFile.ElementAt(i).ToString();
|
||||
//}
|
||||
|
||||
//private void writeTimer_Tick(object sender, EventArgs e)
|
||||
//{
|
||||
// WriteFile();
|
||||
//}
|
||||
|
||||
|
||||
//private void WriteFile()
|
||||
//{
|
||||
// string json = Newtonsoft.Json.JsonConvert.SerializeObject(_data);
|
||||
// string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "ErgometerSessionData.ergo");
|
||||
// System.IO.File.WriteAllText(path, json);
|
||||
// Console.WriteLine("Writing file: " + path);
|
||||
//}
|
||||
|
||||
//private void SaveData(Meting meting)
|
||||
//{
|
||||
// _data.Add(meting);
|
||||
//}
|
||||
|
||||
//private void ReadFile()
|
||||
//{
|
||||
// string path;
|
||||
// OpenFileDialog file = new OpenFileDialog();
|
||||
// file.Filter = "Ergometer files(*.ergo) | *.ergo | All files(*.*) | *.*";
|
||||
// if (file.ShowDialog() == DialogResult.OK)
|
||||
// {
|
||||
// path = file.FileName;
|
||||
// readFile = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Meting>>(System.IO.File.ReadAllText(path));
|
||||
// richTextBox1.Text = readFile.ElementAt(i).ToString();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// readFile = null;
|
||||
// }
|
||||
//}
|
||||
private void updateTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
if(MainClient.Doctor.Connected)
|
||||
{
|
||||
MainClient.ComPort.Write("ST");
|
||||
string response = MainClient.ComPort.Read();
|
||||
MainClient.SaveMeting(response);
|
||||
}
|
||||
}
|
||||
|
||||
public void validateLogin(string username, string password)
|
||||
{
|
||||
if(username.Length >= 4)
|
||||
if (username.Length >= 4)
|
||||
{
|
||||
if(password.Length == 0)
|
||||
if (password.Length == 0)
|
||||
{
|
||||
panelLogin.lblVerification.Text = "Vul een wachtwoord in.";
|
||||
panelLogin.lblVerification.ForeColor = Color.Red;
|
||||
panelLogin.lblVerification.Visible = true;
|
||||
}
|
||||
if (password.Length > 0 && password.Length < 9)
|
||||
if (password.Length > 0 && password.Length < 8)
|
||||
{
|
||||
panelLogin.lblVerification.Text = "Vul een wachtwoord in van minimaal 8 karakters.";
|
||||
panelLogin.lblVerification.ForeColor = Color.Red;
|
||||
@@ -302,7 +53,7 @@ namespace ErgometerApplication
|
||||
}
|
||||
if (password.Length >= 8)
|
||||
{
|
||||
//password checken
|
||||
MainClient.Connect(SerialPort.GetPortNames()[0], username, password);
|
||||
panelClientContainer.BringToFront();
|
||||
this.labelUsername.Text = panelLogin.textBoxUsername.Text;
|
||||
panelTopBar.Visible = true;
|
||||
@@ -319,7 +70,7 @@ namespace ErgometerApplication
|
||||
private void ClientApplicatie_Resize(object sender, System.EventArgs e)
|
||||
{
|
||||
Control control = (Control)sender;
|
||||
if(control.Size.Width < 980)
|
||||
if (control.Size.Width < 980)
|
||||
{
|
||||
panelGraphView.Visible = false;
|
||||
panelClientChat.Width = 400;
|
||||
@@ -343,7 +94,7 @@ namespace ErgometerApplication
|
||||
|
||||
public void sessionLogout()
|
||||
{
|
||||
|
||||
MainClient.Disconnect();
|
||||
}
|
||||
|
||||
private void buttonLogOff_Click(object sender, EventArgs e)
|
||||
@@ -352,7 +103,5 @@ namespace ErgometerApplication
|
||||
panelTopBar.Visible = false;
|
||||
sessionLogout();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -120,9 +120,6 @@
|
||||
<metadata name="updateTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="writeTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>147, 19</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>25</value>
|
||||
</metadata>
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="MainClient.cs" />
|
||||
<Compile Include="PanelClientData.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
using ErgometerLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ErgometerApplication
|
||||
{
|
||||
class MainClient
|
||||
{
|
||||
|
||||
public static ComPort ComPort { get; }
|
||||
public static TcpClient Doctor { get; }
|
||||
public static List<Meting> Metingen { get; }
|
||||
|
||||
public static int Session;
|
||||
|
||||
public static string HOST = "127.0.0.1";
|
||||
public static int PORT = 8888;
|
||||
|
||||
static MainClient()
|
||||
{
|
||||
ComPort = new ComPort();
|
||||
Doctor = new TcpClient();
|
||||
Metingen = new List<Meting>();
|
||||
|
||||
Session = 0;
|
||||
}
|
||||
|
||||
public static void Connect(string comport, string name, string password)
|
||||
{
|
||||
if (!ComPort.IsOpen())
|
||||
{
|
||||
if (ComPort.Connect(comport))
|
||||
{
|
||||
ComPort.Write("RS");
|
||||
ComPort.Read();
|
||||
Thread.Sleep(200);
|
||||
ComPort.Write("CM");
|
||||
ComPort.Read();
|
||||
Thread.Sleep(200);
|
||||
|
||||
ComPort.Write("ST");
|
||||
string response = ComPort.Read();
|
||||
Console.WriteLine(response);
|
||||
|
||||
SaveMeting(response);
|
||||
}
|
||||
else
|
||||
throw new Exception("Comport was unable to connect");
|
||||
}
|
||||
else
|
||||
throw new Exception("Comport is already connected");
|
||||
|
||||
|
||||
if(!Doctor.Connected)
|
||||
{
|
||||
Doctor.Connect(HOST, PORT);
|
||||
|
||||
NetCommand net = NetHelper.ReadNetCommand(Doctor);
|
||||
if (net.Type == NetCommand.CommandType.SESSION)
|
||||
Session = net.Session;
|
||||
else
|
||||
throw new Exception("Session not assigned");
|
||||
|
||||
NetCommand command = new NetCommand(name, false, password, Session);
|
||||
NetHelper.SendNetCommand(Doctor, command);
|
||||
}
|
||||
else
|
||||
throw new Exception("Client is already connected");
|
||||
}
|
||||
|
||||
public static void Disconnect()
|
||||
{
|
||||
if (ComPort.IsOpen())
|
||||
{
|
||||
if (ComPort.Disconnect())
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
throw new Exception("Comport was unable to disconnect");
|
||||
}
|
||||
else
|
||||
throw new Exception("Comport is already closed");
|
||||
|
||||
if (Doctor.Connected)
|
||||
{
|
||||
NetHelper.SendNetCommand(Doctor, new NetCommand(NetCommand.CommandType.LOGOUT, Session));
|
||||
Doctor.Close();
|
||||
}
|
||||
else
|
||||
throw new Exception("Client is already disconnected");
|
||||
}
|
||||
|
||||
public static void SaveMeting(string meting)
|
||||
{
|
||||
Meting m = Meting.Parse(meting);
|
||||
Metingen.Add(m);
|
||||
if (Doctor.Connected)
|
||||
{
|
||||
NetHelper.SendNetCommand(Doctor, new NetCommand(m, Session));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
Reference in New Issue
Block a user