Ejemplo n.º 1
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(); });
            }
        }