mirror of
https://github.com/jwetzell/QControlKit.git
synced 2026-08-07 00:13:51 +00:00
Add WorkspaceConnectionError Event
This commit is contained in:
@@ -93,7 +93,7 @@ namespace QControlKit
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug($"[client] unhandled reply from cue: Type: {data.Type} value: {message.response}");
|
||||
Log.Warning($"[client] unhandled reply from cue: Type: {data.Type} value: {message.response}");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -107,6 +107,7 @@ namespace QControlKit
|
||||
}
|
||||
else if (message.IsConnect)
|
||||
{
|
||||
//Log.Debug($"[client] Connection message received: {message.response}");
|
||||
if (message.response.ToString() == "ok")
|
||||
OnWorkspaceConnected();
|
||||
else
|
||||
@@ -114,7 +115,7 @@ namespace QControlKit
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug($"[client] unhandled reply message: {message.address}");
|
||||
Log.Warning($"[client] unhandled reply message: {message.address}");
|
||||
}
|
||||
}
|
||||
else if(message.IsUpdate) {
|
||||
@@ -154,17 +155,16 @@ namespace QControlKit
|
||||
}
|
||||
else if (message.IsDisconnect)
|
||||
{
|
||||
Log.Debug($"[client] disconnect message received: {message.address}");
|
||||
OnWorkspaceDisconnected();
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug($"[client] unhandled update message: {message.address}");
|
||||
Log.Warning($"[client] unhandled update message: {message.address}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug($"[client] unhandled message: {message.address}");
|
||||
Log.Warning($"[client] unhandled message: {message.address}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<Authors>Joel Wetzell</Authors>
|
||||
<Version>1.0.0-devel</Version>
|
||||
<PackOnBuild>true</PackOnBuild>
|
||||
<PackageVersion>0.0.1</PackageVersion>
|
||||
<PackageVersion>0.0.3</PackageVersion>
|
||||
<PackageId>QControlKit</PackageId>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
//General information about a QLab Workspace
|
||||
using Serilog;
|
||||
using System.Collections.Concurrent;
|
||||
using Serilog;
|
||||
using System.Collections.Generic;
|
||||
using Zeroconf;
|
||||
|
||||
|
||||
+27
-11
@@ -1,4 +1,4 @@
|
||||
//TODO: connect methods, cue property fetch methods, everything else
|
||||
//TODO: workspace connection error handlers
|
||||
using Newtonsoft.Json;
|
||||
using Serilog;
|
||||
using System;
|
||||
@@ -32,6 +32,8 @@ namespace QControlKit
|
||||
|
||||
public event QWorkspaceUpdatedHandler WorkspaceUpdated;
|
||||
public event QCueListChangedPlaybackPositionHandler CueListChangedPlaybackPosition;
|
||||
public event QWorkspaceConnectionErrorHandler WorkspaceConnectionError;
|
||||
|
||||
private void Init()
|
||||
{
|
||||
name = "";
|
||||
@@ -52,9 +54,6 @@ namespace QControlKit
|
||||
|
||||
public QWorkspace(QWorkspaceInfo workspaceInfo, QServer server)
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (workspaceInfo.version.Length > 0)
|
||||
version = workspaceInfo.version;
|
||||
|
||||
@@ -143,19 +142,30 @@ namespace QControlKit
|
||||
|
||||
#region Connection/reconnection
|
||||
|
||||
public void connectWithPasscode(string passcode)
|
||||
public void connect(string passcode = null)
|
||||
{
|
||||
//TODO
|
||||
Log.Debug($"[workspace] connecting to {this.server.host} with passcode: {passcode}");
|
||||
|
||||
if(hasPasscode && passcode == null)
|
||||
{
|
||||
Log.Error($"[workspace] *** workspace <{name}> requires a passcode but none was supplied.");
|
||||
OnWorkspaceConnectionError(this, new QWorkspaceConnectionErrorArgs { status = "badpass" });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!client.connect())
|
||||
{
|
||||
Log.Error($"[workspace] *** Error: couldn't connect to server client is not connected");
|
||||
Log.Error($"[workspace] *** couldn't connect to server client is not connected");
|
||||
return;
|
||||
}
|
||||
|
||||
//save password for reuse
|
||||
this.passcode = passcode;
|
||||
Log.Information("[workspace] connecting...");
|
||||
client.sendMessage($"{workspacePrefix}/connect",passcode);
|
||||
if (passcode != null)
|
||||
client.sendMessage($"{workspacePrefix}/connect", passcode);
|
||||
else
|
||||
client.sendMessage($"{workspacePrefix}/connect");
|
||||
}
|
||||
|
||||
private void finishConnection()
|
||||
@@ -173,7 +183,10 @@ namespace QControlKit
|
||||
{
|
||||
if (connected)
|
||||
return;
|
||||
connectWithPasscode(passcode);
|
||||
if(hasPasscode)
|
||||
connect(passcode);
|
||||
else
|
||||
connect();
|
||||
|
||||
//todo
|
||||
}
|
||||
@@ -384,12 +397,15 @@ namespace QControlKit
|
||||
if (args.status.Equals("badpass"))
|
||||
{
|
||||
//clear passcode if there was one set in the connect() method
|
||||
this.passcode = "";
|
||||
this.passcode = null;
|
||||
Log.Error($"[workspace] *** Password for workspace {name} was incorrect!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error($"[workspace] *** Unable to connect to workspace: {name} on server: {server.name}");
|
||||
}
|
||||
|
||||
WorkspaceConnectionError?.Invoke(this, new QWorkspaceConnectionErrorArgs { status = args.status });
|
||||
}
|
||||
|
||||
private void OnWorkspaceConnected(object source, QWorkspaceConnectedArgs args)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using QControlKit;
|
||||
using QControlKitXamDemo.ViewModels;
|
||||
@@ -12,17 +11,39 @@ namespace QControlKitXamDemo
|
||||
{
|
||||
private QWorkspace connectedWorkspace;
|
||||
private Dictionary<string, Grid> cueGridDict = new Dictionary<string, Grid>();
|
||||
public CueListPage(QWorkspace workspace)
|
||||
public CueListPage(QWorkspace workspace, string passcode = null)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
connectedWorkspace = workspace;
|
||||
connectedWorkspace.WorkspaceUpdated += Workspace_WorkspaceUpdated;
|
||||
connectedWorkspace.connectWithPasscode("1234");
|
||||
connectedWorkspace.WorkspaceConnectionError += ConnectedWorkspace_WorkspaceConnectionError;
|
||||
connectedWorkspace.connect(passcode);
|
||||
connectedWorkspace.defaultSendUpdatesOSC = true;
|
||||
connectedWorkspace.CueListChangedPlaybackPosition += ConnectedWorkspace_CueListChangedPlaybackPosition;
|
||||
}
|
||||
|
||||
protected override void OnDisappearing()
|
||||
{
|
||||
base.OnDisappearing();
|
||||
connectedWorkspace.disconnect();
|
||||
connectedWorkspace.WorkspaceUpdated -= Workspace_WorkspaceUpdated;
|
||||
connectedWorkspace.WorkspaceConnectionError -= ConnectedWorkspace_WorkspaceConnectionError;
|
||||
connectedWorkspace.CueListChangedPlaybackPosition -= ConnectedWorkspace_CueListChangedPlaybackPosition;
|
||||
}
|
||||
|
||||
private async void ConnectedWorkspace_WorkspaceConnectionError(object source, QWorkspaceConnectionErrorArgs args)
|
||||
{
|
||||
System.Console.WriteLine("WorkspaceConnectionError Called");
|
||||
if (args.status.Equals("badpass"))
|
||||
{
|
||||
string passcode = await DisplayPromptAsync("Passcode was incorrect.", "Try Again", maxLength: 4, keyboard: Keyboard.Numeric);
|
||||
if (passcode != null)
|
||||
{
|
||||
connectedWorkspace.connect(passcode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectedWorkspace_CueListChangedPlaybackPosition(object source, QCueListChangedPlaybackPositionArgs args)
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
|
||||
@@ -25,9 +25,26 @@ namespace QControlKitXamDemo
|
||||
|
||||
async void ServerListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
|
||||
{
|
||||
QWorkspace selectedWorkspace = e.SelectedItem as QWorkspace;
|
||||
Console.WriteLine($"[demo] workspace: {selectedWorkspace.nameWithoutPathExtension} has been selected");
|
||||
await Navigation.PushAsync(new CueListPage(selectedWorkspace));
|
||||
if(e.SelectedItem != null)
|
||||
{
|
||||
QWorkspace selectedWorkspace = e.SelectedItem as QWorkspace;
|
||||
Console.WriteLine($"[demo] workspace: {selectedWorkspace.nameWithoutPathExtension} has been selected");
|
||||
if (selectedWorkspace.hasPasscode)
|
||||
{
|
||||
string passcode = await DisplayPromptAsync("Workspace has passcode", "Enter Passcode", maxLength: 4, keyboard: Keyboard.Numeric);
|
||||
if (passcode != null)
|
||||
{
|
||||
|
||||
await Navigation.PushAsync(new CueListPage(selectedWorkspace, passcode));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await Navigation.PushAsync(new CueListPage(selectedWorkspace));
|
||||
|
||||
}
|
||||
serverListView.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void Browser_ServerUpdatedWorkspaces(object source, QServerUpdatedArgs args)
|
||||
|
||||
Reference in New Issue
Block a user