mirror of
https://github.com/jwetzell/qController.git
synced 2026-08-07 08:23:49 +00:00
Don't crash when no tcp connection can be created.
This commit is contained in:
@@ -13,6 +13,7 @@ namespace qController.Communication
|
||||
public QParser qParser;
|
||||
string Address;
|
||||
int Port;
|
||||
public bool connected;
|
||||
|
||||
public QClient(string address, int port)
|
||||
{
|
||||
@@ -20,8 +21,7 @@ namespace qController.Communication
|
||||
Port = port;
|
||||
qParser = new QParser();
|
||||
tcpClient = new TCPClient(Address, Port);
|
||||
tcpClient.Connect();
|
||||
|
||||
connected = tcpClient.Connect();
|
||||
tcpClient.MessageReceived += OnMessageReceived;
|
||||
|
||||
}
|
||||
|
||||
@@ -8,70 +8,7 @@ using Serilog;
|
||||
|
||||
namespace qController.Communication
|
||||
{
|
||||
public class CueEventArgs : EventArgs
|
||||
{
|
||||
public QCue Cue
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
public class WorkspaceEventArgs : EventArgs
|
||||
{
|
||||
public QWorkspace UpdatedWorkspace
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
public class PlaybackPositionArgs : EventArgs
|
||||
{
|
||||
public string PlaybackPosition
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
public class ConnectEventArgs : EventArgs
|
||||
{
|
||||
public string Status
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string WorkspaceId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
public class WorkspaceInfoArgs : EventArgs
|
||||
{
|
||||
public List<QWorkspaceInfo> WorkspaceInfo
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
public class ChildrenEventArgs : EventArgs
|
||||
{
|
||||
public string cue_id
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public List<QCue> children
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class QParser
|
||||
{
|
||||
@@ -80,15 +17,7 @@ namespace qController.Communication
|
||||
|
||||
}
|
||||
|
||||
public delegate void SelectedCueUpdatedHandler(object source, CueEventArgs args);
|
||||
public delegate void WorkspaceUpdatedHandler(object source, WorkspaceEventArgs args);
|
||||
public delegate void CueInfoUpdatedHandler(object source, CueEventArgs args);
|
||||
public delegate void PlaybackPositionUpdatedHandler(object source, PlaybackPositionArgs args);
|
||||
public delegate void ConnectionStatusHandler(object source, ConnectEventArgs args);
|
||||
public delegate void ChildrenUpdateHandler(object source, ChildrenEventArgs args);
|
||||
public delegate void WorkspaceDisconnectHandler(object source, EventArgs args);
|
||||
public delegate void WorkspaceInfoHandler(object source, WorkspaceInfoArgs args);
|
||||
public delegate void WorkspaceLoadErrorHandler(object source, WorkspaceEventArgs args);
|
||||
|
||||
public event WorkspaceLoadErrorHandler WorkspaceLoadError;
|
||||
public event WorkspaceInfoHandler WorkspaceInfoReceived;
|
||||
public event WorkspaceDisconnectHandler WorkspaceDisconnect;
|
||||
@@ -214,50 +143,41 @@ namespace qController.Communication
|
||||
|
||||
protected virtual void OnWorkspaceUpdated(QWorkspace workspace)
|
||||
{
|
||||
if (WorkspaceUpdated != null)
|
||||
WorkspaceUpdated(this, new WorkspaceEventArgs() { UpdatedWorkspace = workspace });
|
||||
WorkspaceUpdated?.Invoke(this, new WorkspaceEventArgs() { UpdatedWorkspace = workspace });
|
||||
}
|
||||
protected virtual void OnSelectedCueUpdated(QCue cue)
|
||||
{
|
||||
if (SelectedCueUpdated != null)
|
||||
SelectedCueUpdated(this, new CueEventArgs() { Cue = cue });
|
||||
SelectedCueUpdated?.Invoke(this, new CueEventArgs() { Cue = cue });
|
||||
}
|
||||
|
||||
protected virtual void OnCueInfoUpdated(QCue cue)
|
||||
{
|
||||
if (CueInfoUpdated != null)
|
||||
CueInfoUpdated(this, new CueEventArgs() { Cue = cue });
|
||||
{
|
||||
CueInfoUpdated?.Invoke(this, new CueEventArgs() { Cue = cue });
|
||||
}
|
||||
|
||||
protected virtual void OnPlaybackPositionUpdated(string id)
|
||||
{
|
||||
if (PlaybackPositionUpdated != null)
|
||||
PlaybackPositionUpdated(this, new PlaybackPositionArgs() { PlaybackPosition = id });
|
||||
PlaybackPositionUpdated?.Invoke(this, new PlaybackPositionArgs() { PlaybackPosition = id });
|
||||
}
|
||||
protected virtual void OnConnectionStatusChanged(string status, string workspace_id)
|
||||
{
|
||||
if (ConnectionStatusChanged != null)
|
||||
ConnectionStatusChanged(this, new ConnectEventArgs() { Status = status, WorkspaceId = workspace_id });
|
||||
ConnectionStatusChanged?.Invoke(this, new ConnectEventArgs() { Status = status, WorkspaceId = workspace_id });
|
||||
}
|
||||
protected virtual void OnChildrenUpdated(string id, List<QCue> cues)
|
||||
{
|
||||
if (ChildrenUpdated != null)
|
||||
ChildrenUpdated(this, new ChildrenEventArgs() { cue_id = id, children = cues });
|
||||
ChildrenUpdated?.Invoke(this, new ChildrenEventArgs() { cue_id = id, children = cues });
|
||||
}
|
||||
protected virtual void OnWorkspaceDisconnect()
|
||||
{
|
||||
if (WorkspaceDisconnect != null)
|
||||
WorkspaceDisconnect(this, new EventArgs());
|
||||
WorkspaceDisconnect?.Invoke(this, new EventArgs());
|
||||
}
|
||||
protected virtual void OnWorkspaceInfoReceived(List<QWorkspaceInfo> workspaces)
|
||||
{
|
||||
if (WorkspaceInfoReceived != null)
|
||||
WorkspaceInfoReceived(this, new WorkspaceInfoArgs() { WorkspaceInfo = workspaces });
|
||||
WorkspaceInfoReceived?.Invoke(this, new WorkspaceInfoArgs() { WorkspaceInfo = workspaces });
|
||||
}
|
||||
protected virtual void OnWorkspaceLoadError(string id)
|
||||
{
|
||||
if (WorkspaceLoadError != null)
|
||||
WorkspaceLoadError(this, new WorkspaceEventArgs { UpdatedWorkspace = new QWorkspace(id) });
|
||||
WorkspaceLoadError?.Invoke(this, new WorkspaceEventArgs { UpdatedWorkspace = new QWorkspace(id) });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using Serilog;
|
||||
|
||||
namespace SharpOSC
|
||||
{
|
||||
@@ -47,12 +46,22 @@ namespace SharpOSC
|
||||
_address = address;
|
||||
}
|
||||
|
||||
public void Connect()
|
||||
public bool Connect()
|
||||
{
|
||||
client = new TcpClient(Address, Port);
|
||||
Log.Debug($"TCPClient - connect called for <{Address}:{Port}>");
|
||||
Thread receivingThread = new Thread(ReceiveLoop);
|
||||
receivingThread.Start();
|
||||
try
|
||||
{
|
||||
client = new TcpClient(Address, Port);
|
||||
Thread receivingThread = new Thread(ReceiveLoop);
|
||||
receivingThread.Start();
|
||||
//Console.WriteLine($"TCPClient - connected to <{Address}:{Port}>");
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Send(byte[] message)
|
||||
@@ -68,13 +77,21 @@ namespace SharpOSC
|
||||
Send(data);
|
||||
}
|
||||
|
||||
public bool IsConnected
|
||||
{
|
||||
get
|
||||
{
|
||||
return client.Connected;
|
||||
}
|
||||
}
|
||||
|
||||
public void ReceiveLoop()
|
||||
{
|
||||
while (client.Connected)
|
||||
{
|
||||
Receive();
|
||||
}
|
||||
Log.Debug("TCPClient - Receive Loop has exited for some reason");
|
||||
Console.WriteLine("TCPClient - Receive Loop has exited for some reason");
|
||||
}
|
||||
|
||||
public void Receive()
|
||||
@@ -102,15 +119,15 @@ namespace SharpOSC
|
||||
//Log.Debug("Thread " + num + ": Bytes read: " + bytesRead + " - " + Encoding.UTF8.GetString(buffer));
|
||||
} while (netStream.DataAvailable);
|
||||
|
||||
//Log.Debug("Raw TCP In: " + System.Text.Encoding.UTF8.GetString(responseData.ToArray()));
|
||||
//Console.WriteLine("Raw TCP In: " + System.Text.Encoding.UTF8.GetString(responseData.ToArray()));
|
||||
OscMessage response = (OscMessage)OscPacket.GetPacket(responseData.Skip(1).ToArray());
|
||||
//watch.Stop();
|
||||
//Log.Debug($"TCPCLient - message receive took {watch.ElapsedMilliseconds}ms and {reads} reads");
|
||||
//Console.WriteLine($"TCPCLient - message receive took {watch.ElapsedMilliseconds}ms and {reads} reads");
|
||||
OnMessageReceived(response);
|
||||
}
|
||||
} catch(Exception e)
|
||||
{
|
||||
//Log.Debug("TCPSENDER - Receive Exception: " + e.ToString());
|
||||
//Console.WriteLine("TCPSENDER - Receive Exception: " + e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,8 +167,7 @@ namespace SharpOSC
|
||||
|
||||
protected virtual void OnMessageReceived(OscMessage msg)
|
||||
{
|
||||
if (MessageReceived != null)
|
||||
MessageReceived(this, new MessageEventArgs() { Message = msg });
|
||||
MessageReceived?.Invoke(this, new MessageEventArgs() { Message = msg });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,11 @@ namespace qController
|
||||
|
||||
InitGUI();
|
||||
|
||||
if (!qController.qClient.connected)
|
||||
{
|
||||
App.showToast("Error connecting...make sure QLab is running");
|
||||
Back();
|
||||
}
|
||||
qController.KickOff();
|
||||
}
|
||||
|
||||
@@ -220,7 +225,8 @@ namespace qController
|
||||
|
||||
void Back()
|
||||
{
|
||||
qController.Kill();
|
||||
if(qController.qClient.connected)
|
||||
qController.Kill();
|
||||
App.rootPage.MenuItemSelected -= OnMenuItemSelected;
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
|
||||
@@ -83,11 +83,9 @@
|
||||
<EmbeddedResource Include="App.xaml" />
|
||||
</ItemGroup>-->
|
||||
<ItemGroup>
|
||||
<Folder Include="Classes\" />
|
||||
<Folder Include="Pages\" />
|
||||
<Folder Include="Classes\QItems\" />
|
||||
<Folder Include="Classes\Cell\" />
|
||||
<Folder Include="Classes\Communication\" />
|
||||
<Folder Include="Classes\Settings\" />
|
||||
<Folder Include="Classes\Dialogs\" />
|
||||
<Folder Include="Classes\Buttons\" />
|
||||
|
||||
Reference in New Issue
Block a user