Fix random active sessions showing up

This commit is contained in:
2015-11-03 21:51:01 +01:00
parent 363b20778a
commit ae3084a61a
5 changed files with 65 additions and 2 deletions
@@ -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);
@@ -26,6 +26,8 @@ namespace ErgometerDoctorApplication
public static List<NetCommand> backlog;
public static MainWindow Window;
//Server information
public static List<ClientThread> clients;
@@ -52,6 +54,11 @@ namespace ErgometerDoctorApplication
backlog = new List<NetCommand>();
}
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<string, double, int>(command.DisplayName, command.Timestamp, command.Session));
@@ -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)
+35 -1
View File
@@ -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;
+1 -1
View File
@@ -83,7 +83,7 @@ namespace ErgometerServer
sendToDoctor(new NetCommand(NetCommand.LengthType.SESSIONS, sessions.Count, input.Session));
foreach(Tuple<int,string,double> 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;