// this function looks up the remote connections and for each one open // queries it for the API, target (usually executable name) and if any user is already connected private static void LookupHostConnections(object o) { { lookupMutex.WaitOne(); lookupsInProgress++; lookupMutex.ReleaseMutex(); } TreelistView.Node node = o as TreelistView.Node; Control p = node.OwnerView; while (p.Parent != null) { p = p.Parent; } RemoteHostSelect rhs = p as RemoteHostSelect; string hostname = node["Hostname"] as string; string username = System.Security.Principal.WindowsIdentity.GetCurrent().Name; StaticExports.EnumerateRemoteConnections(hostname, (UInt32 i) => { try { var conn = StaticExports.CreateRemoteAccessConnection(hostname, i, username, false); if (node.OwnerView.Visible) { string target = conn.Target; string api = conn.API; string busy = conn.BusyClient; node.OwnerView.BeginInvoke((MethodInvoker) delegate { node.OwnerView.BeginUpdate(); node.Nodes.Add(new TreelistView.Node(new object[] { target, api, busy })).Tag = new RemoteConnect(hostname, i); node.OwnerView.EndUpdate(); node.Expand(); }); } conn.Shutdown(); } catch (ApplicationException) { } }); if (node.OwnerView.Visible) { node.OwnerView.BeginInvoke((MethodInvoker) delegate { node.OwnerView.BeginUpdate(); node.Italic = false; node.Image = null; node.OwnerView.EndUpdate(); }); } { lookupMutex.WaitOne(); lookupsInProgress--; lookupMutex.ReleaseMutex(); } if (!rhs.IsDisposed && rhs.Visible) { rhs.BeginInvoke((MethodInvoker) delegate { rhs.LookupComplete(); }); } }
private void ConnectionThreadEntry() { try { string username = System.Security.Principal.WindowsIdentity.GetCurrent().Name; m_Connection = StaticExports.CreateRemoteAccessConnection(m_Host, m_RemoteIdent, username, true); if (m_Connection.Connected) { string api = "..."; if (m_Connection.API.Length > 0) { api = m_Connection.API; } this.BeginInvoke((MethodInvoker) delegate { if (m_Connection.PID == 0) { connectionStatus.Text = String.Format("Connection established to {0} ({1})", m_Connection.Target, api); Text = String.Format("{0} ({1})", m_Connection.Target, api); } else { connectionStatus.Text = String.Format("Connection established to {0} [PID {1}] ({2})", m_Connection.Target, m_Connection.PID, api); Text = String.Format("{0} [PID {1}] ({2})", m_Connection.Target, m_Connection.PID, api); } connectionIcon.Image = global::renderdocui.Properties.Resources.connect; }); } else { throw new ApplicationException(); } while (m_Connection.Connected) { m_Connection.ReceiveMessage(); if (m_TriggerCapture) { m_Connection.TriggerCapture(); m_TriggerCapture = false; } if (m_QueueCapture) { m_Connection.QueueCapture((uint)m_CaptureFrameNum); m_QueueCapture = false; m_CaptureFrameNum = 0; } if (m_Disconnect) { m_Connection.Shutdown(); m_Connection = null; return; } if (m_Connection.InfoUpdated) { this.BeginInvoke((MethodInvoker) delegate { connectionStatus.Text = String.Format("Connection established to {0} ({1})", m_Connection.Target, m_Connection.API); Text = String.Format("{0} ({1})", m_Connection.Target, m_Connection.API); connectionIcon.Image = global::renderdocui.Properties.Resources.connect; }); m_Connection.InfoUpdated = false; } if (m_Connection.CaptureExists) { uint capID = m_Connection.CaptureFile.ID; DateTime timestamp = new DateTime(1970, 1, 1, 0, 0, 0); timestamp = timestamp.AddSeconds(m_Connection.CaptureFile.timestamp).ToLocalTime(); byte[] thumb = m_Connection.CaptureFile.thumbnail; string path = m_Connection.CaptureFile.localpath; if (path.Length == 0 || File.Exists(path)) { this.BeginInvoke((MethodInvoker) delegate { CaptureAdded(capID, m_Connection.Target, m_Connection.API, thumb, timestamp); if (path.Length > 0) { CaptureRetrieved(capID, path); } }); m_Connection.CaptureExists = false; if (path.Length == 0) { m_Connection.CopyCapture(capID, m_Core.TempLogFilename("remotecopy_" + m_Connection.Target)); } } } if (m_Connection.CaptureCopied) { uint capID = m_Connection.CaptureFile.ID; string path = m_Connection.CaptureFile.localpath; this.BeginInvoke((MethodInvoker) delegate { CaptureRetrieved(capID, path); }); m_Connection.CaptureCopied = false; } if (m_Connection.ChildAdded) { if (m_Connection.NewChild.PID != 0) { try { ChildProcess c = new ChildProcess(); c.PID = (int)m_Connection.NewChild.PID; c.ident = m_Connection.NewChild.ident; c.name = Process.GetProcessById((int)m_Connection.NewChild.PID).ProcessName; lock (m_Children) { m_Children.Add(c); } } catch (Exception) { // process expired/doesn't exist anymore } } m_Connection.ChildAdded = false; } } this.BeginInvoke((MethodInvoker) delegate { connectionStatus.Text = "Connection closed"; connectionIcon.Image = global::renderdocui.Properties.Resources.disconnect; ConnectionClosed(); }); } catch (ApplicationException) { this.BeginInvoke((MethodInvoker) delegate { Text = (m_Host.Length > 0 ? (m_Host + " - ") : "") + "Connection failed"; connectionStatus.Text = "Connection failed"; connectionIcon.Image = global::renderdocui.Properties.Resources.delete; ConnectionClosed(); }); } }
// this function looks up the remote connections and for each one open // queries it for the API, target (usually executable name) and if any user is already connected private static void LookupHostConnections(object o) { { lookupMutex.WaitOne(); lookupsInProgress++; lookupMutex.ReleaseMutex(); } TreelistView.Node node = o as TreelistView.Node; Control p = node.OwnerView; while (p.Parent != null) { p = p.Parent; } RemoteHostSelect rhs = p as RemoteHostSelect; string hostname = node["Hostname"] as string; var idents = StaticExports.EnumerateRemoteConnections(hostname); var remotes = new Dictionary <UInt32, AvailableRemote>(); string username = System.Security.Principal.WindowsIdentity.GetCurrent().Name; foreach (var i in idents) { if (i != 0) { try { var conn = StaticExports.CreateRemoteAccessConnection(hostname, i, username, false); var data = new AvailableRemote(conn.Target, conn.API, conn.BusyClient); conn.Shutdown(); remotes.Add(i, data); } catch (ApplicationException) { } } } if (node.OwnerView.Visible) { node.OwnerView.BeginInvoke((MethodInvoker) delegate { node.OwnerView.BeginUpdate(); node.Italic = false; node.Image = null; foreach (var kv in remotes) { node.Nodes.Add(new TreelistView.Node(new object[] { kv.Value.Target, kv.Value.API, kv.Value.Busy })).Tag = new RemoteConnect(hostname, kv.Key); node.Bold = true; } node.OwnerView.EndUpdate(); }); } { lookupMutex.WaitOne(); lookupsInProgress--; lookupMutex.ReleaseMutex(); } if (!rhs.IsDisposed && rhs.Visible) { rhs.BeginInvoke((MethodInvoker) delegate { rhs.LookupComplete(); }); } }