Rework workspace/client/tcpclient disconnection

This commit is contained in:
Joel Wetzell
2020-06-16 08:13:22 -05:00
parent 64e1cc787f
commit 549d1d7d08
7 changed files with 71 additions and 44 deletions
+1 -1
View File
@@ -99,7 +99,7 @@ namespace QSharp
{ {
foreach(var server in servers) foreach(var server in servers)
{ {
server.Close(); server.disconnect();
} }
zeroconfTCPBrowser.Dispose(); zeroconfTCPBrowser.Dispose();
} }
+1 -9
View File
@@ -241,14 +241,6 @@ namespace QSharp
} }
WorkspacesUpdated(this, new QWorkspacesUpdatedArgs { Workspaces = workspaces }); WorkspacesUpdated(this, new QWorkspacesUpdatedArgs { Workspaces = workspaces });
} }
} }
public void Close()
{
this.tcpClient.Close();
}
} }
} }
+7 -4
View File
@@ -71,14 +71,17 @@ namespace QSharp
} }
#endregion #endregion
public void Close() public void disconnect()
{ {
foreach (var workspace in workspaces) foreach (var workspace in workspaces)
{ {
if(workspace.connected) if (workspace.connected)
workspace.Close(); {
Log.Debug($"[server] Close Called For workspace: {workspace.name}");
workspace.disconnect();
}
} }
client.Close(); client.disconnect();
} }
} }
+4 -8
View File
@@ -180,15 +180,16 @@ namespace QSharp
public void disconnect() public void disconnect()
{ {
//TODO
Log.Information($"[workspace] disconnect: {name}"); Log.Information($"[workspace] disconnect: {name}");
stopHeartbeat(); if (heartbeatTimer != null)
stopHeartbeat();
stopReceivingUpdates(); stopReceivingUpdates();
disconnectFromWorkspace(); disconnectFromWorkspace();
connected = false; connected = false;
client.disconnect(); client.disconnect();
//TODO
//root.removeAllChildCues(); //root.removeAllChildCues();
} }
@@ -531,11 +532,6 @@ namespace QSharp
#endregion #endregion
public void Close()
{
client.Close();
}
#region Printing #region Printing
public void Print() public void Print()
{ {
+11 -7
View File
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Net.Sockets; using System.Net.Sockets;
using System.Threading; using System.Threading;
using Serilog;
namespace SharpOSC namespace SharpOSC
{ {
@@ -30,7 +31,7 @@ namespace SharpOSC
} }
public delegate void MessageReceivedHandler(object source, MessageEventArgs args); public delegate void MessageReceivedHandler(object source, MessageEventArgs args);
public event MessageReceivedHandler MessageReceived; public event MessageReceivedHandler MessageReceived;
private Thread receivingThread;
string _address; string _address;
TcpClient client; TcpClient client;
@@ -51,9 +52,9 @@ namespace SharpOSC
try try
{ {
client = new TcpClient(Address, Port); client = new TcpClient(Address, Port);
Thread receivingThread = new Thread(ReceiveLoop); receivingThread = new Thread(ReceiveLoop);
receivingThread.Start(); receivingThread.Start();
//Console.WriteLine($"TCPClient - connected to <{Address}:{Port}>"); Console.WriteLine($"[tcpclient] connected to <{Address}:{Port}>");
return true; return true;
} }
catch (Exception e) catch (Exception e)
@@ -94,7 +95,7 @@ namespace SharpOSC
{ {
Receive(); Receive();
} }
Console.WriteLine("TCPClient - Receive Loop has exited for some reason"); //Log.Debug("[tcpclient] - ReceiveLoop has exited");
} }
public void Receive() public void Receive()
@@ -164,10 +165,13 @@ namespace SharpOSC
public void Close() public void Close()
{ {
if(client != null || !client.Connected) if (client != null)
{ {
client.GetStream().Close(); if (client.Connected)
client.Close(); {
client.GetStream().Close();
client.Close();
}
} }
} }
+20 -6
View File
@@ -37,6 +37,7 @@
this.columnHeader3 = new System.Windows.Forms.ColumnHeader(); this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.columnHeader4 = new System.Windows.Forms.ColumnHeader(); this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
this.connectButton = new System.Windows.Forms.Button(); this.connectButton = new System.Windows.Forms.Button();
this.disconnectButton = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// workspaceListView // workspaceListView
@@ -47,10 +48,10 @@
this.workspaceListView.FullRowSelect = true; this.workspaceListView.FullRowSelect = true;
this.workspaceListView.GridLines = true; this.workspaceListView.GridLines = true;
this.workspaceListView.HideSelection = false; this.workspaceListView.HideSelection = false;
this.workspaceListView.Location = new System.Drawing.Point(208, 122); this.workspaceListView.Location = new System.Drawing.Point(246, 122);
this.workspaceListView.MultiSelect = false; this.workspaceListView.MultiSelect = false;
this.workspaceListView.Name = "workspaceListView"; this.workspaceListView.Name = "workspaceListView";
this.workspaceListView.Size = new System.Drawing.Size(580, 316); this.workspaceListView.Size = new System.Drawing.Size(542, 316);
this.workspaceListView.TabIndex = 0; this.workspaceListView.TabIndex = 0;
this.workspaceListView.UseCompatibleStateImageBehavior = false; this.workspaceListView.UseCompatibleStateImageBehavior = false;
this.workspaceListView.View = System.Windows.Forms.View.Details; this.workspaceListView.View = System.Windows.Forms.View.Details;
@@ -68,7 +69,7 @@
// //
// goButton // goButton
// //
this.goButton.Location = new System.Drawing.Point(208, 47); this.goButton.Location = new System.Drawing.Point(246, 47);
this.goButton.Name = "goButton"; this.goButton.Name = "goButton";
this.goButton.Size = new System.Drawing.Size(104, 69); this.goButton.Size = new System.Drawing.Size(104, 69);
this.goButton.TabIndex = 1; this.goButton.TabIndex = 1;
@@ -96,7 +97,7 @@
this.serverListView.HideSelection = false; this.serverListView.HideSelection = false;
this.serverListView.Location = new System.Drawing.Point(13, 47); this.serverListView.Location = new System.Drawing.Point(13, 47);
this.serverListView.Name = "serverListView"; this.serverListView.Name = "serverListView";
this.serverListView.Size = new System.Drawing.Size(189, 391); this.serverListView.Size = new System.Drawing.Size(227, 391);
this.serverListView.TabIndex = 4; this.serverListView.TabIndex = 4;
this.serverListView.UseCompatibleStateImageBehavior = false; this.serverListView.UseCompatibleStateImageBehavior = false;
this.serverListView.View = System.Windows.Forms.View.Details; this.serverListView.View = System.Windows.Forms.View.Details;
@@ -113,7 +114,7 @@
// //
// connectButton // connectButton
// //
this.connectButton.Location = new System.Drawing.Point(94, 21); this.connectButton.Location = new System.Drawing.Point(72, 21);
this.connectButton.Name = "connectButton"; this.connectButton.Name = "connectButton";
this.connectButton.Size = new System.Drawing.Size(75, 23); this.connectButton.Size = new System.Drawing.Size(75, 23);
this.connectButton.TabIndex = 5; this.connectButton.TabIndex = 5;
@@ -121,11 +122,23 @@
this.connectButton.UseVisualStyleBackColor = true; this.connectButton.UseVisualStyleBackColor = true;
this.connectButton.Click += new System.EventHandler(this.connectButton_Click); this.connectButton.Click += new System.EventHandler(this.connectButton_Click);
// //
// disconnectButton
//
this.disconnectButton.Enabled = false;
this.disconnectButton.Location = new System.Drawing.Point(153, 21);
this.disconnectButton.Name = "disconnectButton";
this.disconnectButton.Size = new System.Drawing.Size(75, 23);
this.disconnectButton.TabIndex = 5;
this.disconnectButton.Text = "Disconnect";
this.disconnectButton.UseVisualStyleBackColor = true;
this.disconnectButton.Click += new System.EventHandler(this.disconnectButton_Click);
//
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(842, 480);
this.Controls.Add(this.disconnectButton);
this.Controls.Add(this.connectButton); this.Controls.Add(this.connectButton);
this.Controls.Add(this.serverListView); this.Controls.Add(this.serverListView);
this.Controls.Add(this.label1); this.Controls.Add(this.label1);
@@ -152,6 +165,7 @@
private System.Windows.Forms.Button connectButton; private System.Windows.Forms.Button connectButton;
private System.Windows.Forms.ColumnHeader columnHeader4; private System.Windows.Forms.ColumnHeader columnHeader4;
private System.Windows.Forms.ColumnHeader cueNameHeader; private System.Windows.Forms.ColumnHeader cueNameHeader;
private System.Windows.Forms.Button disconnectButton;
} }
} }
+27 -9
View File
@@ -46,23 +46,41 @@ namespace QSharpDemoApp
private void connectButton_Click(object sender, EventArgs e) private void connectButton_Click(object sender, EventArgs e)
{ {
if(serverListView.SelectedItems.Count == 1) if(connectedWorkspace == null)
{ {
if (serverListView.SelectedItems.Count == 1)
QServer server = browser.serverForAddress(serverListView.SelectedItems[0].SubItems[3].Text);
string workspaceID = serverListView.SelectedItems[0].SubItems[2].Text;
if (server != null)
{ {
connectedWorkspace = server.workspaceWithID(workspaceID);
if(connectedWorkspace != null) QServer server = browser.serverForAddress(serverListView.SelectedItems[0].SubItems[3].Text);
string workspaceID = serverListView.SelectedItems[0].SubItems[2].Text;
if (server != null)
{ {
connectedWorkspace.WorkspaceUpdated += Workspace_WorkspaceUpdated; connectedWorkspace = server.workspaceWithID(workspaceID);
connectedWorkspace.connectWithPasscode(""); if (connectedWorkspace != null)
{
connectedWorkspace.WorkspaceUpdated += Workspace_WorkspaceUpdated;
connectedWorkspace.connectWithPasscode("");
connectButton.Enabled = false;
disconnectButton.Enabled = true;
}
} }
} }
} }
} }
private void disconnectButton_Click(object sender, EventArgs e)
{
if (connectedWorkspace != null)
{
connectedWorkspace.disconnect();
connectButton.Enabled = true;
disconnectButton.Enabled = false;
connectedWorkspace = null;
workspaceListView.Items.Clear();
}
}
private void Server_ServerUpdated(object source, QServerUpdatedArgs args) private void Server_ServerUpdated(object source, QServerUpdatedArgs args)
{ {
QServer server = args.server; QServer server = args.server;