Added client windows
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using ErgometerLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ErgometerDoctorApplication
|
||||
{
|
||||
@@ -11,10 +13,44 @@ namespace ErgometerDoctorApplication
|
||||
public int Session { get; }
|
||||
public string Name { get; }
|
||||
|
||||
private SessionWindow window;
|
||||
|
||||
public ClientThread(string name, int session)
|
||||
{
|
||||
Name = name;
|
||||
Session = session;
|
||||
|
||||
window = new SessionWindow(Name, true);
|
||||
window.FormClosed += Window_FormClosed;
|
||||
}
|
||||
|
||||
private void Window_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
MainClient.RemoveActiveClient(this);
|
||||
}
|
||||
|
||||
public void HandleCommand(NetCommand command)
|
||||
{
|
||||
switch(command.Type)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
Application.Run(window);
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
window.Close();
|
||||
MainClient.RemoveActiveClient(this);
|
||||
}
|
||||
|
||||
private void sendCommand(NetCommand command)
|
||||
{
|
||||
MainClient.SendNetCommand(command);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace ErgometerDoctorApplication
|
||||
this.Size = new System.Drawing.Size(584, 459);
|
||||
this.TabIndex = 0;
|
||||
//
|
||||
// labelPassword
|
||||
// labelActiveSessions
|
||||
//
|
||||
this.labelActiveSessions.Anchor = System.Windows.Forms.AnchorStyles.None;
|
||||
this.labelActiveSessions.AutoSize = true;
|
||||
@@ -32,6 +32,8 @@ namespace ErgometerDoctorApplication
|
||||
this.labelActiveSessions.Size = new System.Drawing.Size(103, 21);
|
||||
this.labelActiveSessions.TabIndex = 3;
|
||||
this.labelActiveSessions.Text = "Geen actieve sessies.";
|
||||
|
||||
this.Controls.Add(labelActiveSessions);
|
||||
}
|
||||
|
||||
public System.Windows.Forms.Label labelActiveSessions;
|
||||
|
||||
@@ -29,6 +29,12 @@ namespace ErgometerDoctorApplication
|
||||
public static List<ClientThread> clients;
|
||||
public static Dictionary<string, string> users;
|
||||
public static List<int> oldsessions;
|
||||
|
||||
public static void RemoveActiveClient(ClientThread clientThread)
|
||||
{
|
||||
clients.Remove(clientThread);
|
||||
}
|
||||
|
||||
public static Dictionary<int, string> activesessions;
|
||||
|
||||
static MainClient()
|
||||
@@ -76,6 +82,8 @@ namespace ErgometerDoctorApplication
|
||||
loggedin = true;
|
||||
}
|
||||
|
||||
SendNetCommand(new NetCommand(NetCommand.RequestType.SESSIONDATA, Session));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -152,13 +160,43 @@ namespace ErgometerDoctorApplication
|
||||
|
||||
private static void HandToClient(NetCommand command)
|
||||
{
|
||||
//throw new NotImplementedException();
|
||||
Console.WriteLine(command);
|
||||
foreach(ClientThread cl in clients)
|
||||
{
|
||||
if(cl.Session == command.Session)
|
||||
{
|
||||
cl.HandleCommand(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendNetCommand(NetCommand command)
|
||||
{
|
||||
NetHelper.SendNetCommand(Server, command);
|
||||
}
|
||||
|
||||
private static bool IsSessionRunning(int session)
|
||||
{
|
||||
foreach(ClientThread cl in clients)
|
||||
{
|
||||
if (cl.Session == session)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void StartNewCLient(string name, int session)
|
||||
{
|
||||
if (IsSessionRunning(session))
|
||||
return;
|
||||
|
||||
//Start new client
|
||||
ClientThread cl = new ClientThread(name, session);
|
||||
clients.Add(cl);
|
||||
|
||||
//Run client on new thread
|
||||
Thread thread = new Thread(new ThreadStart(cl.run));
|
||||
thread.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,14 +21,14 @@ namespace ErgometerDoctorApplication
|
||||
|
||||
private void BtnActiveSessions_Click(object sender, EventArgs e)
|
||||
{
|
||||
MainClient.SendNetCommand(new NetCommand(NetCommand.RequestType.SESSIONDATA, MainClient.Session));
|
||||
this.HeaderLabel.Text = "Actieve Sessies";
|
||||
conActiveSessions.BringToFront();
|
||||
|
||||
string str = "";
|
||||
foreach(string name in MainClient.activesessions.Values)
|
||||
foreach(KeyValuePair<int, string> client in MainClient.activesessions)
|
||||
{
|
||||
str += name + ", ";
|
||||
str += client.Value + ", ";
|
||||
MainClient.StartNewCLient(client.Value, client.Key);
|
||||
}
|
||||
conActiveSessions.labelActiveSessions.Text = str;
|
||||
Console.WriteLine(str);
|
||||
|
||||
Reference in New Issue
Block a user