Basic workspace connection and Cue Lists fetching working

This commit is contained in:
Joel Wetzell
2020-06-09 19:03:33 -05:00
parent 830e905300
commit 130366acad
14 changed files with 1716 additions and 147 deletions
+33 -19
View File
@@ -1,53 +1,67 @@
//General information about a QLab Workspace
using System.Collections.Concurrent;
using System.Collections.Generic;
using Zeroconf;
namespace QSharp
{
public class QServer
{
private QClient qClient;
private QClient client;
public string host;
public int port;
public string name;
public IZeroconfHost zeroconfHost;
List<QWorkspace> workspaces = new List<QWorkspace>();
public QServer(string host, int port, string name)
public QServer(string host, int port)
{
this.host = host;
this.port = port;
this.name = name;
qClient = new QClient(host, port);
qClient.WorkspacesUpdated += OnWorkspacesUpdated;
client = new QClient(host, port);
client.WorkspacesUpdated += OnWorkspacesUpdated;
}
private void OnWorkspacesUpdated(object source, QClient.WorkspacesUpdatedArgs args)
{
foreach(var workspace in args.Workspaces)
{
QWorkspace existingWorkspace = workspaceWithID(workspace.uniqueID);
if(existingWorkspace == null)
{
QWorkspace workspaceToAdd = new QWorkspace(workspace, this);
workspaces.Add(workspaceToAdd);
}
}
}
public string description { get { return $"{name} - {host} - {port}"; } }
public void refreshWorkspaces()
{
qClient.sendMessage("/workspaces");
if (!client.connect())
{
System.Console.WriteLine($"Error: QServer unable to connect to QLab Server: {host}:{port}");
return;
}
client.sendMessage("/workspaces");
}
public QWorkspace workspaceWithID(string uniqueID)
{
foreach(var workspace in workspaces)
{
if (workspace.getUniqueID().Equals(uniqueID))
if (workspace.uniqueID.Equals(uniqueID))
return workspace;
}
return null;
}
#region EventHandlers
private void OnWorkspacesUpdated(object source, QWorkspacesUpdatedArgs args)
{
foreach (var workspace in args.Workspaces)
{
QWorkspace existingWorkspace = workspaceWithID(workspace.uniqueID);
if (existingWorkspace == null)
{
QWorkspace workspaceToAdd = new QWorkspace(workspace, this);
workspaces.Add(workspaceToAdd);
workspaceToAdd.connectWithPasscode("1234");
}
}
}
#endregion
}
}