Esempio n. 1
0
        private void ConnectionThreadEntry()
        {
            try
            {
                string username = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

                m_Connection = StaticExports.CreateTargetControl(m_Host, m_RemoteIdent, username, true);

                if (m_Connection.Connected)
                {
                    string api = "No API detected";
                    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);
                            SetText(String.Format("{0}", m_Connection.Target));
                        }
                        else
                        {
                            connectionStatus.Text = String.Format("Connection established to {0} [PID {1}] ({2})",
                                                                  m_Connection.Target, m_Connection.PID, api);
                            SetText(String.Format("{0} [PID {1}]", m_Connection.Target, m_Connection.PID));
                        }
                        connectionIcon.Image = global::renderdocui.Properties.Resources.connect;
                    });
                }
                else
                {
                    throw new ReplayCreateException(ReplayCreateStatus.NetworkIOFailed);
                }

                while (m_Connection.Connected)
                {
                    m_Connection.ReceiveMessage();

                    if (m_TriggerCapture)
                    {
                        m_Connection.TriggerCapture((uint)m_CaptureNumFrames);
                        m_TriggerCapture = false;
                    }

                    if (m_QueueCapture)
                    {
                        m_Connection.QueueCapture((uint)m_CaptureFrameNum);
                        m_QueueCapture    = false;
                        m_CaptureFrameNum = 0;
                    }

                    if (m_CopyLogLocalPath != "")
                    {
                        m_Connection.CopyCapture(m_CopyLogID, m_CopyLogLocalPath);
                        m_CopyLogLocalPath = "";
                        m_CopyLogID        = uint.MaxValue;
                    }

                    List <uint> dels = new List <uint>();
                    lock (m_DeleteLogs)
                    {
                        dels.AddRange(m_DeleteLogs);
                        m_DeleteLogs.Clear();
                    }

                    foreach (var del in dels)
                    {
                        m_Connection.DeleteCapture(del);
                    }

                    if (m_Disconnect)
                    {
                        m_Connection.Shutdown();
                        m_Connection = null;
                        return;
                    }

                    if (m_Connection.InfoUpdated)
                    {
                        this.BeginInvoke((MethodInvoker) delegate
                        {
                            if (m_Connection.PID == 0)
                            {
                                connectionStatus.Text = String.Format("Connection established to {0} ({1})", m_Connection.Target, m_Connection.API);
                                SetText(String.Format("{0}", m_Connection.Target));
                            }
                            else
                            {
                                connectionStatus.Text = String.Format("Connection established to {0} [PID {1}] ({2})",
                                                                      m_Connection.Target, m_Connection.PID, m_Connection.API);
                                SetText(String.Format("{0} [PID {1}]", m_Connection.Target, m_Connection.PID));
                            }
                            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;
                        int    thumbWidth  = m_Connection.CaptureFile.thumbWidth;
                        int    thumbHeight = m_Connection.CaptureFile.thumbHeight;
                        string path        = m_Connection.CaptureFile.path;
                        bool   local       = m_Connection.CaptureFile.local;

                        this.BeginInvoke((MethodInvoker) delegate
                        {
                            CaptureAdded(capID, m_Connection.Target, m_Connection.API, thumb, thumbWidth, thumbHeight, timestamp, path, local);
                        });
                        m_Connection.CaptureExists = false;
                    }

                    if (m_Connection.CaptureCopied)
                    {
                        uint   capID = m_Connection.CaptureFile.ID;
                        string path  = m_Connection.CaptureFile.path;

                        this.BeginInvoke((MethodInvoker) delegate
                        {
                            CaptureCopied(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;

                    numFrames.Enabled          = captureDelay.Enabled = captureFrame.Enabled =
                        triggerCapture.Enabled = queueCap.Enabled = false;

                    ConnectionClosed();
                });
            }
            catch (ReplayCreateException)
            {
                this.BeginInvoke((MethodInvoker) delegate
                {
                    SetText("Connection failed");
                    connectionStatus.Text = "Connection failed";
                    connectionIcon.Image  = global::renderdocui.Properties.Resources.delete;

                    ConnectionClosed();
                });
            }
        }
Esempio n. 2
0
        // 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;
            }

            RemoteManager rhs = p as RemoteManager;

            string hostname = node["hostname"] as string;

            string username = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

            RemoteHost host = node.Tag as RemoteHost;

            host.CheckStatus();

            SetRemoteServerLive(node, host.ServerRunning, host.Busy);

            StaticExports.EnumerateRemoteTargets(hostname, (UInt32 i) => {
                try
                {
                    var conn = StaticExports.CreateTargetControl(hostname, i, username, false);

                    if (node.OwnerView.Visible)
                    {
                        string target = conn.Target;
                        string api    = conn.API;
                        string busy   = conn.BusyClient;

                        string running;

                        if (busy != "")
                        {
                            running = String.Format("Running {0}, {1} is connected", api, busy);
                        }
                        else
                        {
                            running = String.Format("Running {0}", api);
                        }

                        node.OwnerView.BeginInvoke((MethodInvoker) delegate
                        {
                            node.OwnerView.BeginUpdate();
                            node.Nodes.Add(new TreelistView.Node(new object[] { target, running })).Tag = new RemoteConnect(hostname, i);
                            node.OwnerView.EndUpdate();
                            node.Expand();
                        });
                    }

                    conn.Shutdown();
                }
                catch (ReplayCreateException)
                {
                }
            });

            if (node.OwnerView.Visible)
            {
                node.OwnerView.BeginInvoke((MethodInvoker) delegate
                {
                    node.OwnerView.BeginUpdate();
                    node.Italic = false;
                    node.OwnerView.EndUpdate();
                });
            }

            {
                lookupMutex.WaitOne();
                lookupsInProgress--;
                lookupMutex.ReleaseMutex();
            }

            if (!rhs.IsDisposed && rhs.Visible)
            {
                rhs.BeginInvoke((MethodInvoker) delegate { rhs.LookupComplete(); });
            }
        }