Fixed old client data

This commit is contained in:
2015-10-20 11:19:08 +02:00
parent af684d2986
commit 48b9e1365e
5 changed files with 97 additions and 103 deletions
@@ -43,14 +43,11 @@ namespace ErgometerDoctorApplication
switch (command.Type)
{
case NetCommand.CommandType.DATA:
if (!IsOldData)
lock (Metingen)
{
lock (Metingen)
{
Metingen.Add(command.Meting);
}
window.Invoke(window.updateMetingen, new Object[] { command.Meting });
Metingen.Add(command.Meting);
}
window.Invoke(window.updateMetingen, new Object[] { command.Meting });
break;
case NetCommand.CommandType.CHAT:
ChatMessage chat = new ChatMessage(command.DisplayName, command.ChatMessage, false);
@@ -76,12 +73,6 @@ namespace ErgometerDoctorApplication
if(! IsOldData)
MainClient.SendNetCommand(command);
}
public void HandMetingen(List<Meting> metingen)
{
Metingen = metingen;
window.Invoke(window.updateMetingen, new Object[] { new Meting(0,0,0,0,0,0,0,0,0) });
}
}
}
@@ -25,6 +25,9 @@ namespace ErgometerDoctorApplication
public delegate void UpdateMetingen(Meting m);
public UpdateMetingen updateMetingen;
public delegate void UpdateGraph();
public UpdateGraph updateGraph;
public SessionWindow(string ClientName, bool old, int session, ClientThread parentthread)
{
this.ActiveSession = !old;
@@ -35,6 +38,7 @@ namespace ErgometerDoctorApplication
count = 0;
updateMetingen = new UpdateMetingen(this.SaveMeting);
updateGraph = new UpdateGraph(this.LoadGraph);
InitializeComponent();
@@ -85,5 +89,10 @@ namespace ErgometerDoctorApplication
count++;
}
public void LoadGraph()
{
panelGraphView.updateAllCharts(client.Metingen);
}
}
}
@@ -64,7 +64,7 @@ namespace ErgometerDoctorApplication
this.labelActiveSessions.Anchor = System.Windows.Forms.AnchorStyles.None;
this.labelActiveSessions.AutoSize = true;
this.labelActiveSessions.Font = new System.Drawing.Font("Segoe UI Semibold", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.labelActiveSessions.Location = new System.Drawing.Point(0, 0);
this.labelActiveSessions.Location = new System.Drawing.Point(0, 50);
this.labelActiveSessions.Name = "labelActiveSessions";
this.labelActiveSessions.Size = new System.Drawing.Size(103, 21);
this.labelActiveSessions.TabIndex = 3;
+81 -88
View File
@@ -96,6 +96,7 @@ namespace ErgometerDoctorApplication
loggedin = true;
}
SendNetCommand(new NetCommand(NetCommand.RequestType.USERS, Session));
SendNetCommand(new NetCommand(NetCommand.RequestType.SESSIONDATA, Session));
return true;
@@ -118,85 +119,11 @@ namespace ErgometerDoctorApplication
{
while (running)
{
if (Server.Connected && Server.Available > 0)
if (loggedin && Server.Connected && Server.Available > 0)
{
NetCommand command = NetHelper.ReadNetCommand(Server);
Console.WriteLine(command.Type.ToString());
switch (command.Type)
{
case NetCommand.CommandType.LENGTH:
Console.WriteLine(command.Length.ToString() + " : " + command.LengthValue);
switch (command.Length)
{
case NetCommand.LengthType.USERS:
lock (users)
{
users.Clear();
for (int i = 0; i < command.LengthValue; i++)
{
NetCommand c = NetHelper.ReadNetCommand(Server);
if (c.Type == NetCommand.CommandType.USER)
{
try
{
users.Add(c.DisplayName, c.Password);
}
catch (ArgumentException e)
{
// ignore double username
}
}
}
}
break;
case NetCommand.LengthType.SESSIONS:
oldsessions.Clear();
for (int i = 0; i < command.LengthValue; i++)
{
NetCommand c = NetHelper.ReadNetCommand(Server);
if (c.Type == NetCommand.CommandType.SESSION)
{
oldsessions.Add(c.Session);
}
}
break;
case NetCommand.LengthType.SESSIONDATA:
activesessions.Clear();
for (int i = 0; i < command.LengthValue; i++)
{
NetCommand c = NetHelper.ReadNetCommand(Server);
if (c.Type == NetCommand.CommandType.SESSIONDATA)
{
activesessions.Add(c.Session, c.DisplayName);
}
}
break;
case NetCommand.LengthType.DATA:
Console.WriteLine(command);
List<Meting> metingen = new List<Meting>();
for (int i = 0; i < command.LengthValue; i++)
{
NetCommand c = NetHelper.ReadNetCommand(Server);
Console.WriteLine(c);
if (c.Type == NetCommand.CommandType.DATA)
{
metingen.Add(c.Meting);
}
}
HandMetingenToClient(metingen, command.Session);
break;
default:
throw new FormatException("Error in NetCommand: Length type is not recognised");
}
break;
case NetCommand.CommandType.ERROR:
Console.WriteLine("An error occured, ignoring");
break;
default:
HandToClient(command);
break;
}
Console.WriteLine(command.Type.ToString() + " # " + command);
HandleNetCommand(command);
}
}
@@ -204,6 +131,83 @@ namespace ErgometerDoctorApplication
Server.Close();
}
private static bool UsersBeingSent = false;
private static int UsersSent = 0;
private static int UsersLength = 0;
private static bool SessionsBeingSent = false;
private static int SessionsSent = 0;
private static int SessionsLength = 0;
private static bool ActiveSessionsBeingSent = false;
private static int ActiveSessionsSent = 0;
private static int ActiveSessionsLength = 0;
private static void HandleNetCommand(NetCommand command)
{
switch (command.Type)
{
case NetCommand.CommandType.LENGTH:
switch (command.Length)
{
case NetCommand.LengthType.USERS:
users.Clear();
UsersBeingSent = true;
UsersSent = 0;
UsersLength = command.LengthValue;
break;
case NetCommand.LengthType.SESSIONS:
oldsessions.Clear();
SessionsBeingSent = true;
SessionsSent = 0;
SessionsLength = command.LengthValue;
break;
case NetCommand.LengthType.SESSIONDATA:
activesessions.Clear();
ActiveSessionsBeingSent = true;
ActiveSessionsSent = 0;
ActiveSessionsLength = command.LengthValue;
break;
default:
throw new FormatException("Error in NetCommand: Length type is not recognised");
}
break;
case NetCommand.CommandType.ERROR:
Console.WriteLine("An error occured, ignoring");
break;
case NetCommand.CommandType.USER:
if(UsersBeingSent)
{
users.Add(command.DisplayName, command.Password);
UsersSent++;
if (UsersSent >= UsersLength)
UsersBeingSent = false;
}
break;
case NetCommand.CommandType.SESSION:
if (SessionsBeingSent)
{
oldsessions.Add(command.Session);
SessionsSent++;
if (SessionsSent >= SessionsLength)
SessionsBeingSent = false;
}
break;
case NetCommand.CommandType.SESSIONDATA:
if (ActiveSessionsBeingSent)
{
activesessions.Add(command.Session, command.DisplayName);
ActiveSessionsSent++;
if (ActiveSessionsSent >= ActiveSessionsLength)
ActiveSessionsBeingSent = false;
}
break;
default:
HandToClient(command);
break;
}
}
private static void HandToClient(NetCommand command)
{
foreach (ClientThread cl in clients)
@@ -215,17 +219,6 @@ namespace ErgometerDoctorApplication
}
}
private static void HandMetingenToClient(List<Meting> metingen, int session)
{
foreach (ClientThread cl in clients)
{
if (cl.Session == session)
{
cl.HandMetingen(metingen);
}
}
}
public static void SendNetCommand(NetCommand command)
{
NetHelper.SendNetCommand(Server, command);
+3 -2
View File
@@ -20,7 +20,7 @@ namespace ErgometerDoctorApplication
InitializeComponent();
conPanelLogin.BringToFront();
request = false;
//updateTimer.Start();
updateTimer.Start();
}
@@ -37,6 +37,7 @@ namespace ErgometerDoctorApplication
}
else
{
conActiveSessions.updateActiveSessions(MainClient.activesessions);
conActiveSessions.labelActiveSessions.Text = "Er zijn geen actieve sessies.";
}
@@ -66,7 +67,7 @@ namespace ErgometerDoctorApplication
this.HeaderLabel.Text = "Sessie geschiedenis";
conSessionHistory.BringToFront();
MainClient.StartOldCLient("Test", 2001739555);
MainClient.StartOldCLient("Test", 1148735907);
}
public void validateLogin()
{