private void ErrorHandler(object sender, Exception exn) { Program.AssertOffEventThread(); if (this.Disposing || this.IsDisposed) { return; } Program.Invoke(this, delegate() { VNCGraphicsClient v = (VNCGraphicsClient)sender; if (exn is VNCAuthenticationException || exn is CryptographicException) { Log.Debug(exn, exn); // Clear the stored VNC password for this server. Settings.SetVNCPassword(sourceVM.uuid, null); RetryConnection(v, exn); } else if (exn is IOException || exn is Failure) { Log.Debug(exn, exn); SleepAndRetryConnection_(v); } else { Log.Warn(exn, exn); this.errorMessage = exn.Message; } }); }
private void RetryConnection(VNCGraphicsClient v, Exception exn) { if (vncClient == v && !v.Terminated && Source.power_state == vm_power_state.Running) { ThreadPool.QueueUserWorkItem(new WaitCallback(Connect), new KeyValuePair <VNCGraphicsClient, Exception>(v, exn)); } }
private void ConnectHostedConsole(VNCGraphicsClient v, Console console) { Program.AssertOffEventThread(); Host host = console.Connection.Resolve(Source.resident_on); if (host == null) { throw new Failure(Failure.INTERNAL_ERROR, Messages.VNC_HOST_GONE); } Uri uri = new Uri(console.location); String SessionUUID; lock (activeSessionLock) { // use the elevated credentials, if provided, for connecting to the console (CA-91132) activeSession = (string.IsNullOrEmpty(ElevatedUsername) || string.IsNullOrEmpty(ElevatedPassword)) ? console.Connection.DuplicateSession() : console.Connection.ElevatedSession(ElevatedUsername, ElevatedPassword); SessionUUID = activeSession.uuid; } Stream stream = HTTPHelper.CONNECT(uri, console.Connection, SessionUUID, false, true); InvokeConnection(v, stream, console); }
private void ConnectHostedConsole(VNCGraphicsClient v, XenAPI.Console console, string session_uuid) { //Program.AssertOffEventThread(); Uri uri = new Uri(console.location); Stream stream = HTTP.CONNECT(uri, null, session_uuid, 0); InvokeConnection(v, stream, console, m_vncPassword); }
private void SleepAndRetryConnection(object o) { VNCGraphicsClient v = (VNCGraphicsClient)o; Program.AssertOffEventThread(); ConnectionRetries++; Thread.Sleep(ConnectionRetries < SHORT_RETRY_COUNT ? SHORT_RETRY_SLEEP_TIME : RETRY_SLEEP_TIME); RetryConnection(v, null); }
private void InvokeConnection(VNCGraphicsClient v, Stream stream, Console console) { Program.Invoke(this, delegate() { // This is the last chance that we have to make sure that we've not already // connected this VNCGraphicsClient. Now that we are back on the event thread, // we're guaranteed that no-one will beat us to the v.connect() call. We // hand over responsibility for closing the stream at that point, so we have to // close it ourselves if the client is already connected. if (v.Connected || v.Terminated) { stream.Close(); } else { v.SendScanCodes = UseSource && !this.sourceIsPV; v.SourceVM = sourceVM; v.Console = console; v.connect(stream, this.vncPassword); } }); }
private void Connect(object o) { if (Program.RunInAutomatedTestMode) { return; } Program.AssertOffEventThread(); KeyValuePair <VNCGraphicsClient, Exception> kvp = (KeyValuePair <VNCGraphicsClient, Exception>)o; VNCGraphicsClient v = kvp.Key; Exception error = kvp.Value; try { if (UseSource) { List <Console> consoles; lock (hostedConsolesLock) { consoles = sourceVM.Connection.ResolveAll(hostedConsoles); } foreach (Console console in consoles) { if (vncClient != v) { // We've been replaced. Give up. return; } if (console.protocol == console_protocol.rfb) { try { ConnectHostedConsole(v, console); return; } catch (Exception exn) { Failure failure = exn as Failure; bool isHostGoneMessage = failure != null && failure.ErrorDescription.Count == 2 && failure.ErrorDescription[0] == Failure.INTERNAL_ERROR && failure.ErrorDescription[1] == Messages.VNC_HOST_GONE; if (isHostGoneMessage) { if (!_suppressHostGoneMessage) { Log.Debug(exn, exn); _suppressHostGoneMessage = true; } } else { Log.Debug(exn, exn); _suppressHostGoneMessage = false; } } } } Log.Debug("Did not find any hosted consoles"); SleepAndRetryConnection(v); } else { if (vncIP == null) { Log.DebugFormat("vncIP is null. Abort VNC connection attempt"); OnVncConnectionAttemptCancelled(); return; } this.vncPassword = Settings.GetVNCPassword(sourceVM.uuid); if (this.vncPassword == null) { bool lifecycleOperationInProgress = sourceVM.current_operations.Values.Any(VM.is_lifecycle_operation); if (haveTriedLoginWithoutPassword && !lifecycleOperationInProgress) { Program.Invoke(this, delegate { promptForPassword(ignoreNextError ? null : error); }); ignoreNextError = false; if (this.vncPassword == null) { Log.Debug("User cancelled VNC password prompt: aborting connection attempt"); OnUserCancelledAuth(); return; } } else { Log.Debug("Attempting passwordless VNC login"); this.vncPassword = new char[0]; ignoreNextError = true; haveTriedLoginWithoutPassword = true; } } Stream s; lock (pendingVNCConnectionLock) { s = pendingVNCConnection; Log.DebugFormat("Using pending VNC connection"); pendingVNCConnection = null; } if (s == null) { Log.DebugFormat("Connecting to vncIP={0}, port={1}", this.vncIP, VNC_PORT); s = connectGuest(this.vncIP, VNC_PORT, sourceVM.Connection); Log.DebugFormat("Connected to vncIP={0}, port={1}", this.vncIP, VNC_PORT); } InvokeConnection(v, s, null); // store the empty vnc password after a successful passwordless login if (haveTriedLoginWithoutPassword && this.vncPassword.Length == 0) { Program.Invoke(this, () => Settings.SetVNCPassword(sourceVM.uuid, this.vncPassword)); } } } catch (Exception exn) { Log.Warn(exn, exn); SleepAndRetryConnection(v); } }
/// <summary> /// Creates the actual VNC or RDP client control. /// </summary> private void initSubControl() { Program.AssertOnEventThread(); //When switch to RDP from VNC, if RDP IP is empty, do not try to switch. if (String.IsNullOrEmpty(rdpIP) && !UseVNC && RemoteConsole != null) { return; } bool wasFocused = false; this.Controls.Clear(); Size oldSize = new Size(1024, 768); // Kill the old client. if (RemoteConsole != null) { oldSize = RemoteConsole.DesktopSize; wasFocused = RemoteConsole.ConsoleControl != null && RemoteConsole.ConsoleControl.Focused; RemoteConsole.DisconnectAndDispose(); RemoteConsole = null; this.vncPassword = null; } // Reset haveTriedLoginWithoutPassword = false; if (UseVNC || String.IsNullOrEmpty(rdpIP)) { this.AutoScroll = false; this.AutoScrollMinSize = new Size(0, 0); vncClient = new VNCGraphicsClient(this); vncClient.UseSource = UseSource; vncClient.DesktopResized += ResizeHandler; vncClient.Resize += ResizeHandler; vncClient.ErrorOccurred += ErrorHandler; vncClient.ConnectionSuccess += ConnectionSuccess; vncClient.Dock = DockStyle.Fill; } else { if (rdpClient == null) { if (this.ParentForm is FullScreenForm) { oldSize = ((FullScreenForm)ParentForm).contentPanel.Size; } this.AutoScroll = true; this.AutoScrollMinSize = oldSize; rdpClient = new RdpClient(this, oldSize, ResizeHandler); rdpClient.OnDisconnected += new EventHandler(parentVNCTabView.RdpDisconnectedHandler); } } if (RemoteConsole != null && RemoteConsole.ConsoleControl != null) { RemoteConsole.KeyHandler = this.KeyHandler; RemoteConsole.SendScanCodes = !this.sourceIsPV; RemoteConsole.Scaling = Scaling; RemoteConsole.DisplayBorder = this.displayFocusRectangle; SetKeyboardAndMouseCapture(autoCaptureKeyboardAndMouse); if (wasPaused) { RemoteConsole.Pause(); } else { RemoteConsole.Unpause(); } ConnectToRemoteConsole(); if (wasFocused) { RemoteConsole.Activate(); } } parentVNCTabView.ShowGpuWarningIfRequired(); }
private void SleepAndRetryConnection_(VNCGraphicsClient v) { ThreadPool.QueueUserWorkItem(new WaitCallback(SleepAndRetryConnection), v); }
/// <summary> /// Creates the actual VNC client control. /// </summary> private void initSubControl(int width, int height, bool scaling, bool show_border) { Program.MainWindow = this; bool wasFocused = m_vncClient != null && m_vncClient.Focused; this.Controls.Clear(); Size newSize; Size oldSize = new Size(1024, 768); if (width == 0 || height == 0) { newSize = new Size(1024, 768); } else { newSize = new Size(width, height); } // Kill the old client. if (m_vncClient != null) { oldSize = m_vncClient.DesktopSize; m_vncClient.Disconnect(); m_vncClient.Dispose(); m_vncClient = null; } // Reset this.AutoScroll = false; this.AutoScrollMinSize = new Size(0, 0); m_vncClient = new VNCGraphicsClient(this); m_vncClient.Size = newSize; this.Size = newSize; m_vncClient.UseSource = true; m_vncClient.SendScanCodes = !this.m_sourceIsPV; m_vncClient.Dock = DockStyle.Fill; this.m_vncClient.Scaling = scaling; // SCVMM requires a scaled image m_vncClient.DisplayBorder = show_border; m_vncClient.AutoScaleDimensions = newSize; m_vncClient.AutoScaleMode = AutoScaleMode.Inherit; this.m_vncClient.DesktopResized += ResolutionChangeHandler; //this.m_vncClient.Resize += ResizeHandler; //this.m_vncClient.ErrorOccurred += ErrorHandler; //this.m_vncClient.ConnectionSuccess += ConnectionSuccess; //this.m_vncClient.ErrorOccurred //this.m_vncClient.MouseDown += new MouseEventHandler(vncClient_MouseDown); //this.m_vncClient.KeyDown += new KeyEventHandler(vncClient_KeyDown); m_vncClient.KeyHandler = new ConsoleKeyHandler(); this.m_vncClient.Unpause(); foreach (Set <Keys> keys in extraCodes.Keys) { m_vncClient.KeyHandler.AddKeyHandler(keys, extraCodes[keys]); } foreach (Set <int> keys in extraScans.Keys) { m_vncClient.KeyHandler.AddKeyHandler(keys, extraScans[keys]); } }