From 0207c74b9001bbfcbd1355526eb45a0adbd5999f Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 4 Aug 2016 15:48:22 +0200 Subject: [PATCH] Check remote server status at startup to pre-populate context chooser --- renderdocui/Code/PersistantConfig.cs | 27 +++++++++- renderdocui/Windows/Dialogs/RemoteManager.cs | 16 +----- renderdocui/Windows/MainWindow.cs | 55 +++++++++----------- 3 files changed, 52 insertions(+), 46 deletions(-) diff --git a/renderdocui/Code/PersistantConfig.cs b/renderdocui/Code/PersistantConfig.cs index a6edbce79..91ff29350 100644 --- a/renderdocui/Code/PersistantConfig.cs +++ b/renderdocui/Code/PersistantConfig.cs @@ -29,6 +29,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; +using System.Threading; using System.Xml; using System.Xml.Serialization; using renderdoc; @@ -44,13 +45,35 @@ namespace renderdocui.Code [XmlIgnore] public bool ServerRunning = false; - [XmlIgnore] public bool Connected = false; - [XmlIgnore] public bool Busy = false; + public void CheckStatus() + { + try + { + RemoteServer server = StaticExports.CreateRemoteServer(Hostname, 0); + ServerRunning = true; + Busy = false; + server.ShutdownConnection(); + } + catch (ReplayCreateException ex) + { + if (ex.Status == ReplayCreateStatus.NetworkRemoteBusy) + { + ServerRunning = true; + Busy = true; + } + else + { + ServerRunning = false; + Busy = false; + } + } + } + public void Launch() { try diff --git a/renderdocui/Windows/Dialogs/RemoteManager.cs b/renderdocui/Windows/Dialogs/RemoteManager.cs index 591b46bb0..43636a08f 100644 --- a/renderdocui/Windows/Dialogs/RemoteManager.cs +++ b/renderdocui/Windows/Dialogs/RemoteManager.cs @@ -170,23 +170,9 @@ namespace renderdocui.Windows.Dialogs string hostname = node["hostname"] as string; - RemoteHost host = node.Tag as RemoteHost; - string username = System.Security.Principal.WindowsIdentity.GetCurrent().Name; - try - { - RemoteServer server = StaticExports.CreateRemoteServer(hostname, 0); - SetRemoteServerLive(node, true, false); - server.ShutdownConnection(); - } - catch (ReplayCreateException ex) - { - if (ex.Status == ReplayCreateStatus.NetworkRemoteBusy) - SetRemoteServerLive(node, true, true); - else - SetRemoteServerLive(node, false, false); - } + (node.Tag as RemoteHost).CheckStatus(); StaticExports.EnumerateRemoteTargets(hostname, (UInt32 i) => { try diff --git a/renderdocui/Windows/MainWindow.cs b/renderdocui/Windows/MainWindow.cs index 3b1c991f4..a1a9671a9 100644 --- a/renderdocui/Windows/MainWindow.cs +++ b/renderdocui/Windows/MainWindow.cs @@ -175,6 +175,13 @@ namespace renderdocui.Windows CheckUpdates(); + Thread remoteStatusThread = Helpers.NewThread(new ThreadStart(() => + { + for (int i = 0; i < m_Core.Config.RemoteHosts.Count; i++) + m_Core.Config.RemoteHosts[i].CheckStatus(); + })); + remoteStatusThread.Start(); + sendErrorReportToolStripMenuItem.Enabled = OfficialVersion || BetaVersion; // create default layout if layout failed to load @@ -912,13 +919,13 @@ namespace renderdocui.Windows private void switchContext(object sender, EventArgs e) { + m_Core.Renderer.DisconnectFromRemoteServer(); + if(sender == localContext) { contextChooser.Image = global::renderdocui.Properties.Resources.house; contextChooser.Text = "Replay Context: Local"; - m_Core.Renderer.DisconnectFromRemoteServer(); - injectIntoProcessToolStripMenuItem.Enabled = true; statusText.Text = ""; @@ -945,17 +952,7 @@ namespace renderdocui.Windows Thread th = Helpers.NewThread(new ThreadStart(() => { // see if the server is up - try - { - RemoteServer server = StaticExports.CreateRemoteServer(host.Hostname, 0); - server.ShutdownConnection(); - - // if we got this far without an exception, the server is running - host.ServerRunning = true; - } - catch (ReplayCreateException) - { - } + host.CheckStatus(); if (!host.ServerRunning && host.RunCommand != "") { @@ -964,35 +961,35 @@ namespace renderdocui.Windows host.Launch(); // check if it's running now - try - { - RemoteServer server = StaticExports.CreateRemoteServer(host.Hostname, 0); - server.ShutdownConnection(); - - // if we got this far without an exception, the server is running - host.ServerRunning = true; - } - catch (ReplayCreateException) - { - } + host.CheckStatus(); } - if (host.ServerRunning) + if (host.ServerRunning && !host.Busy) { - m_Core.Renderer.DisconnectFromRemoteServer(); m_Core.Renderer.ConnectToRemoteServer(host); } this.BeginInvoke(new Action(() => { - contextChooser.Image = host.ServerRunning + contextChooser.Image = (host.ServerRunning && !host.Busy) ? global::renderdocui.Properties.Resources.connect : global::renderdocui.Properties.Resources.disconnect; - if (host.ServerRunning) + if (host.Busy) + { + statusText.Text = "Remote server in use elsewhere"; + } + else if (host.ServerRunning) + { statusText.Text = "Remote server ready"; + } else - statusText.Text = "Remote server not running or failed"; + { + if(host.RunCommand != "") + statusText.Text = "Remote server not running or failed to start"; + else + statusText.Text = "Remote server not running - no start command configured"; + } contextChooser.Enabled = true; }));