From ae3084a61a090f486a660ff1da75fac36c22c8c0 Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Tue, 3 Nov 2015 21:51:01 +0100 Subject: [PATCH] Fix random active sessions showing up --- .../ErgometerApplication/MainClient.cs | 5 +++ .../ErgometerDoctorApplication/MainClient.cs | 14 ++++++++ .../ErgometerDoctorApplication/MainWindow.cs | 10 ++++++ ErgometerIPR/ErgometerLibrary/NetCommand.cs | 36 ++++++++++++++++++- ErgometerIPR/ErgometerServer/DoctorThread.cs | 2 +- 5 files changed, 65 insertions(+), 2 deletions(-) diff --git a/ErgometerIPR/ErgometerApplication/MainClient.cs b/ErgometerIPR/ErgometerApplication/MainClient.cs index 22265f0..a002edc 100644 --- a/ErgometerIPR/ErgometerApplication/MainClient.cs +++ b/ErgometerIPR/ErgometerApplication/MainClient.cs @@ -52,6 +52,11 @@ namespace ErgometerApplication Console.Beep(1000, 50); } + public static void QuickBeepAudio() + { + Console.Beep(1200, 150); + } + public static void SwitchWorkloadAudio() { Console.Beep(1000, 200); diff --git a/ErgometerIPR/ErgometerDoctorApplication/MainClient.cs b/ErgometerIPR/ErgometerDoctorApplication/MainClient.cs index 9abc19d..f541ebc 100644 --- a/ErgometerIPR/ErgometerDoctorApplication/MainClient.cs +++ b/ErgometerIPR/ErgometerDoctorApplication/MainClient.cs @@ -26,6 +26,8 @@ namespace ErgometerDoctorApplication public static List backlog; + public static MainWindow Window; + //Server information public static List clients; @@ -52,6 +54,11 @@ namespace ErgometerDoctorApplication backlog = new List(); } + public static void Init(MainWindow client) + { + Window = client; + } + public static bool Connect(string password, out string error) { error = "Succes"; @@ -195,10 +202,17 @@ namespace ErgometerDoctorApplication if (ActiveSessionsBeingSent) { activesessions.Add(command.Session, command.DisplayName); + Console.WriteLine(command.Session + " | " + command.DisplayName); ActiveSessionsSent++; if (ActiveSessionsSent >= ActiveSessionsLength) + { ActiveSessionsBeingSent = false; + if (Window.HeaderLabel.Text == "Actieve Sessies") + Window.updateSession = true; + } } + break; + case NetCommand.CommandType.OLDSESSIONDATA: if (SessionsBeingSent) { oldSessionsData.Add(new Tuple(command.DisplayName, command.Timestamp, command.Session)); diff --git a/ErgometerIPR/ErgometerDoctorApplication/MainWindow.cs b/ErgometerIPR/ErgometerDoctorApplication/MainWindow.cs index 550854a..4ce2481 100644 --- a/ErgometerIPR/ErgometerDoctorApplication/MainWindow.cs +++ b/ErgometerIPR/ErgometerDoctorApplication/MainWindow.cs @@ -14,10 +14,14 @@ namespace ErgometerDoctorApplication public partial class MainWindow : Form { private int request; + public bool updateSession; public MainWindow() { InitializeComponent(); + MainClient.Init(this); + + updateSession = false; conPanelLogin.BringToFront(); request = 2; updateTimer.Start(); @@ -130,6 +134,12 @@ namespace ErgometerDoctorApplication private void updateTimer_tick(object sender, EventArgs e) { + if (updateSession) + { + BtnActiveSessions_Click(this, new EventArgs()); + updateSession = false; + } + if (request == 0) MainClient.SendNetCommand(new NetCommand(NetCommand.RequestType.USERS, MainClient.Session)); else if (request == 1) diff --git a/ErgometerIPR/ErgometerLibrary/NetCommand.cs b/ErgometerIPR/ErgometerLibrary/NetCommand.cs index 5d64b22..cf28957 100644 --- a/ErgometerIPR/ErgometerLibrary/NetCommand.cs +++ b/ErgometerIPR/ErgometerLibrary/NetCommand.cs @@ -9,7 +9,7 @@ namespace ErgometerLibrary { public class NetCommand { - public enum CommandType { LOGIN, DATA, CHAT, LOGOUT, SESSION, VALUESET, USER, RESPONSE, REQUEST, LENGTH, SESSIONDATA, ERROR, BROADCAST, UITLEG, PERSONDATA, TESTRESULT} + public enum CommandType { LOGIN, DATA, CHAT, LOGOUT, SESSION, VALUESET, USER, RESPONSE, REQUEST, LENGTH, SESSIONDATA, OLDSESSIONDATA, ERROR, BROADCAST, UITLEG, PERSONDATA, TESTRESULT} public enum RequestType { USERS, ALLSESSIONS, OLDDATA, SESSIONDATA, CHAT, PERSONALDATA, TESTRESULT } public enum ResponseType { LOGINOK, LOGINWRONG, ERROR, NOTLOGGEDIN } public enum ValueType { TIME, POWER, ENERGY, DISTANCE } @@ -96,6 +96,25 @@ namespace ErgometerLibrary DisplayName = name; } + //SESSIONDATA + public NetCommand(string name, double timestamp, int session, bool old) + { + if (old) + { + Type = CommandType.OLDSESSIONDATA; + Session = session; + Timestamp = timestamp; + DisplayName = name; + } + else + { + Type = CommandType.SESSIONDATA; + Session = session; + Timestamp = timestamp; + DisplayName = name; + } + } + //RESPONSE public NetCommand(ResponseType response, int session) { @@ -251,11 +270,23 @@ namespace ErgometerLibrary return ParsePersonData(session, args); case 15: return ParseTestResult(session, args); + case 16: + return ParseOldSessionData(session, args); default: throw new FormatException("Error in NetCommand: " + comType + " is not a valid command type."); } } + private static NetCommand ParseOldSessionData(int session, string[] args) + { + if (args.Length != 2) + throw new MissingFieldException("Error in NetCommand: OLD Session Data is missing arguments"); + + NetCommand temp = new NetCommand(args[0], double.Parse(args[1]), session, true); + + return temp; + } + private static NetCommand ParseTestResult(int session, string[] args) { if (args.Length != 5) @@ -509,6 +540,9 @@ namespace ErgometerLibrary case CommandType.TESTRESULT: command += "15»ses" + Session + "»" + VO2Max + "»" + MET + "»" + PopulationAvg + "»" + ZScore + "»" + Rating; break; + case CommandType.OLDSESSIONDATA: + command += "16»ses" + Session + "»" + DisplayName + "»" + Timestamp; + break; case CommandType.ERROR: command += "ERROR IN NETCOMMAND"; break; diff --git a/ErgometerIPR/ErgometerServer/DoctorThread.cs b/ErgometerIPR/ErgometerServer/DoctorThread.cs index 991079e..6916910 100644 --- a/ErgometerIPR/ErgometerServer/DoctorThread.cs +++ b/ErgometerIPR/ErgometerServer/DoctorThread.cs @@ -83,7 +83,7 @@ namespace ErgometerServer sendToDoctor(new NetCommand(NetCommand.LengthType.SESSIONS, sessions.Count, input.Session)); foreach(Tuple session in sessions) { - sendToDoctor(new NetCommand(session.Item2, session.Item3, session.Item1)); + sendToDoctor(new NetCommand(session.Item2, session.Item3, session.Item1, true)); Thread.Sleep(10); } break;