Exemplo n.º 1
0
        /// <param name="connection">May be null, in which case a new connection will be created</param>
        protected void ConnectToServer(IXenConnection conn, string hostname, int port, string username, string password, string version)
        {
            if (conn == null)
            {
                XenConnection connection = new XenConnection();
                connection.CachePopulated += conn_CachePopulated;
                connection.fromDialog      = true;
                conn = connection;
            }
            else if (!_changedPass)
            {
                conn.EndConnect(); // in case we're already connected
            }

            conn.Hostname = hostname;
            conn.Port     = port;
            conn.Username = username;
            conn.Password = password;
            conn.ExpectPasswordIsCorrect = false;
            conn.Version = version;

            if (!_changedPass)
            {
                XenConnectionUI.BeginConnect(conn, true, Owner, false);
            }
        }
Exemplo n.º 2
0
 void t_Elapsed(object sender, ElapsedEventArgs e)
 {
     Program.Invoke(Program.MainWindow, delegate
     {
         xc.CachePopulated += new EventHandler <EventArgs>(xc_CachePopulated);
         XenConnectionUI.BeginConnect(xc, true, Program.MainWindow, true);
     });
 }
Exemplo n.º 3
0
        private void WaitForBootTimeToBeGreaterThanBefore(bool master, Session session, MetricDelegate metricDelegate, double metric)
        {
            DateTime waitForMetric   = DateTime.Now;
            int      lastMetricDebug = 0;

            log.DebugFormat("{0}._WaitForReboot waiting for metric to update... (metric='{1}')", GetType().Name, metric);

            double currentMetric;

            do
            {
                currentMetric = metricDelegate(session);

                if (_cancelled)
                {
                    throw new CancelledException();
                }

                Thread.Sleep(1000);

                // Debug message once a minute

                int currMin = (int)((DateTime.Now - waitForMetric).TotalSeconds) / 60;
                if (currMin <= lastMetricDebug)
                {
                    continue;
                }

                lastMetricDebug = currMin;

                log.DebugFormat("{0}._WaitForReboot still waiting for metric after {1}... (old metric='{2}', current metric='{3}')",
                                GetType().Name, DateTime.Now - waitForMetric, metric, currentMetric);
            }while (metric == currentMetric);

            Thread.Sleep(1000);

            log.DebugFormat("{0}._WaitForReboot metric now up to date... (old metric='{1}', current metric='{2}')",
                            GetType().Name, metric, currentMetric);

            if (master)
            {
                //
                // Force a reconnect to prime the cache for the next actions
                //

                log.DebugFormat("{0}._WaitForReboot connecting up...", GetType().Name);

                Program.Invoke(Program.MainWindow, delegate()
                {
                    XenConnectionUI.BeginConnect(Connection, false, null, false);
                });
            }
        }
Exemplo n.º 4
0
 protected override void ExecuteCore(SelectedItemCollection selection)
 {
     foreach (SelectedItem item in selection)
     {
         if (item.Connection != null && !item.Connection.IsConnected)
         {
             if (selection.Count == 1)
             {
                 item.Connection.CachePopulated += Connection_CachePopulated;
             }
             XenConnectionUI.BeginConnect(item.Connection, true, Program.MainWindow, false);
         }
     }
 }
Exemplo n.º 5
0
        private void WaitForReboot(object o)
        {
            while (true)
            {
                IXenConnection connection = (IXenConnection)o;
                Thread.Sleep(30 * 1000);           // wait 30s for server to shutdown
                int i   = 0;
                int max = 27;                      // giveup after 5 mins
                while (true)
                {
                    if (i > max)
                    {
                        MainWindowCommandInterface.Invoke(delegate
                        {
                            using (var dlg = new ThreeButtonDialog(
                                       new ThreeButtonDialog.Details(
                                           SystemIcons.Exclamation,
                                           string.Format(Messages.MESSAGEBOX_RECONNECT_FAIL, connection.Hostname),
                                           Messages.MESSAGEBOX_RECONNECT_FAIL_TITLE)))
                            {
                                dlg.ShowDialog(Parent);
                            }
                        });
                        return;
                    }

                    Socket socket = new Socket(System.Net.Sockets.AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    try
                    {
                        socket.Connect(connection.Hostname, connection.Port);
                    }
                    catch (Exception)
                    {
                    }

                    if (socket.Connected)
                    {
                        MainWindowCommandInterface.Invoke(delegate
                        {
                            XenConnectionUI.BeginConnect(connection, false, null, false);
                            MainWindowCommandInterface.RequestRefreshTreeView();
                        });
                        return;
                    }
                    i++;
                    Thread.Sleep(15 * 1000);
                }
            }
        }
        protected IXenConnection LoadDB(string name, string username)
        {
            string fileName = TestResource(name);

            IXenConnection connection = new XenConnection(fileName, name);

            connection.Username = username;
            connection.Password = "";
            lock (ConnectionsManager.ConnectionsLock)
            {
                ConnectionsManager.XenConnections.Add(connection);
            }
            XenConnectionUI.BeginConnect(connection, false, null, false);
            return(connection);
        }
Exemplo n.º 7
0
        protected override void ExecuteCore(SelectedItemCollection selection)
        {
            foreach (SelectedItem item in selection)
            {
                if (item.Connection != null && !item.Connection.IsConnected)
                {
                    if (selection.Count == 1)
                    {
                        item.Connection.CachePopulated += Connection_CachePopulated;
                    }
                    XenConnectionUI.BeginConnect(item.Connection, true, null, false);
                }
            }

            MainWindowCommandInterface.RequestRefreshTreeView();
        }
Exemplo n.º 8
0
        private void Connection_ConnectionResult(object sender, ConnectionResultEventArgs e)
        {
            CloseConnectingDialog();

            // show connection error
            if (e.Connected || e.Error == null)
            {
                return;
            }

            IXenConnection connection = (IXenConnection)sender;

            Program.Invoke(Program.MainWindow,
                           delegate()
            {
                XenConnectionUI.ShowConnectingDialogError_(getOwnerForm(), connection, e.Error);
            });
        }
Exemplo n.º 9
0
        private void WaitForReboot(object o)
        {
            while (true)
            {
                IXenConnection connection = (IXenConnection)o;
                Thread.Sleep(30 * 1000); // wait 30s for server to shutdown
                int i   = 0;
                int max = 27;            // give up after 5 mins
                while (true)
                {
                    if (i > max)
                    {
                        MainWindowCommandInterface.Invoke(delegate
                        {
                            using (var dlg = new WarningDialog(string.Format(Messages.MESSAGEBOX_RECONNECT_FAIL, connection.Hostname))
                            {
                                WindowTitle = Messages.MESSAGEBOX_RECONNECT_FAIL_TITLE
                            })
                            {
                                dlg.ShowDialog(Parent);
                            }
                        });
                        return;
                    }

                    Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    try
                    {
                        socket.Connect(connection.Hostname, connection.Port);
                    }
                    catch (Exception)
                    {
                    }

                    if (socket.Connected)
                    {
                        MainWindowCommandInterface.Invoke(() => XenConnectionUI.BeginConnect(connection, false, Program.MainWindow, false));
                        return;
                    }
                    i++;
                    Thread.Sleep(15 * 1000);
                }
            }
        }
Exemplo n.º 10
0
        private IXenConnection LoadDB(string name, string username)
        {
            var connection = new XenConnection
            {
                Username         = username,
                Password         = "",
                Hostname         = TestResource(name),
                FriendlyName     = name,
                Port             = 443,
                SaveDisconnected = true
            };

            lock (ConnectionsManager.ConnectionsLock)
            {
                ConnectionsManager.XenConnections.Add(connection);
            }
            XenConnectionUI.BeginConnect(connection, false, null, false);
            return(connection);
        }
Exemplo n.º 11
0
        protected override void ExecuteCore(SelectedItemCollection selection)
        {
            bool expand = MainWindowCommandInterface.GetXenConnectionsCopy().Count < 30;

            foreach (IXenConnection c in MainWindowCommandInterface.GetXenConnectionsCopy())
            {
                if (!c.IsConnected && !c.InProgress)
                {
                    MainWindowCommandInterface.Invoke(delegate
                    {
                        if (expand)
                        {
                            c.CachePopulated += c_CachePopulated;
                        }
                        XenConnectionUI.BeginConnect(c, false, null, false);
                    });
                }
            }
        }
Exemplo n.º 12
0
 private void _action_RequestReconnection(IXenConnection conn)
 {
     Program.Invoke(Program.MainWindow, () => XenConnectionUI.BeginConnect(conn, false, null, false));
 }