2017-01-16 20:59:50 +01:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
2013-11-26 12:19:34 +01:00
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using DotNetVnc;
|
2017-11-17 02:04:45 +01:00
|
|
|
|
using XenCenterLib;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.RDP;
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.ConsoleView
|
|
|
|
|
{
|
|
|
|
|
class RdpClient: IRemoteConsole
|
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
|
|
|
|
private Size size;
|
|
|
|
|
|
2017-04-20 18:51:49 +02:00
|
|
|
|
private bool allowDisplayUpdate;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private readonly ContainerControl parent;
|
|
|
|
|
|
2017-11-13 17:51:56 +01:00
|
|
|
|
public bool needsRdpVersionWarning = false;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// http://msdn2.microsoft.com/en-us/library/aa383022(VS.85).aspx
|
|
|
|
|
/// </summary>
|
2017-06-20 12:33:52 +02:00
|
|
|
|
private MsRdpClient9 rdpClient9 = null;
|
|
|
|
|
|
2017-11-06 12:28:07 +01:00
|
|
|
|
private MsRdpClient6 rdpClient6 = null;
|
|
|
|
|
|
2017-06-20 12:33:52 +02:00
|
|
|
|
/// <summary>
|
2017-11-06 12:28:07 +01:00
|
|
|
|
/// This will be equal to rdpClient9, if the DLL that we've got is version 8, otherwise equal to
|
|
|
|
|
/// rdpClient6.
|
2017-06-20 12:33:52 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
private AxHost rdpControl = null;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public event EventHandler OnDisconnected = null;
|
|
|
|
|
|
|
|
|
|
internal RdpClient(ContainerControl parent, Size size, EventHandler resizeHandler)
|
|
|
|
|
{
|
|
|
|
|
this.parent = parent;
|
|
|
|
|
this.size = size;
|
2013-11-26 12:19:34 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-06-20 12:33:52 +02:00
|
|
|
|
rdpControl = rdpClient9 = new MsRdpClient9();
|
2013-11-26 12:19:34 +01:00
|
|
|
|
RDPConfigure(size);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2017-04-20 18:51:49 +02:00
|
|
|
|
//add event handler for when RDP display is resized
|
2017-06-20 12:33:52 +02:00
|
|
|
|
rdpClient9.OnRemoteDesktopSizeChange += rdpClient_OnRemoteDesktopSizeChange;
|
|
|
|
|
|
2013-11-26 12:19:34 +01:00
|
|
|
|
// CA-96135: Try adding rdpControl to parent.Controls list; this will throw exception when
|
2017-11-06 12:28:07 +01:00
|
|
|
|
// MsRdpClient8 control cannot be created (there is no appropriate version of dll present)
|
2017-06-20 12:33:52 +02:00
|
|
|
|
parent.Controls.Add(rdpControl);
|
2017-04-20 18:51:49 +02:00
|
|
|
|
allowDisplayUpdate = true;
|
2017-11-13 17:51:56 +01:00
|
|
|
|
needsRdpVersionWarning = false;
|
2013-11-26 12:19:34 +01:00
|
|
|
|
}
|
2017-11-06 12:28:07 +01:00
|
|
|
|
catch
|
2013-11-26 12:19:34 +01:00
|
|
|
|
{
|
2017-11-13 17:51:56 +01:00
|
|
|
|
//any problems: fall back without thinking too much
|
2017-06-20 12:33:52 +02:00
|
|
|
|
if (parent.Controls.Contains(rdpControl))
|
|
|
|
|
parent.Controls.Remove(rdpControl);
|
|
|
|
|
rdpClient9 = null;
|
2017-11-06 12:28:07 +01:00
|
|
|
|
rdpControl = rdpClient6 = new MsRdpClient6();
|
|
|
|
|
RDPConfigure(size);
|
|
|
|
|
parent.Controls.Add(rdpControl);
|
2017-11-13 17:51:56 +01:00
|
|
|
|
needsRdpVersionWarning = true;
|
2013-11-26 12:19:34 +01:00
|
|
|
|
}
|
2017-06-20 12:33:52 +02:00
|
|
|
|
rdpControl.Resize += resizeHandler;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-27 19:00:46 +01:00
|
|
|
|
private void RDPConfigure(Size currentConsoleSize)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-06-20 12:33:52 +02:00
|
|
|
|
rdpControl.BeginInit();
|
2017-11-06 12:28:07 +01:00
|
|
|
|
rdpLocationOffset = new Point(3, 3); //small offset to accomodate focus rectangle
|
2017-06-20 12:33:52 +02:00
|
|
|
|
rdpControl.Dock = DockStyle.None;
|
|
|
|
|
rdpControl.Anchor = AnchorStyles.None;
|
|
|
|
|
rdpControl.Size = currentConsoleSize;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
RDPAddOnDisconnected();
|
2017-06-20 12:33:52 +02:00
|
|
|
|
rdpControl.Enter += RdpEnter;
|
|
|
|
|
rdpControl.Leave += rdpClient_Leave;
|
|
|
|
|
rdpControl.GotFocus += rdpClient_GotFocus;
|
|
|
|
|
rdpControl.EndInit();
|
2017-02-27 19:00:46 +01:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
|
2017-02-27 19:00:46 +01:00
|
|
|
|
public Point rdpLocationOffset
|
|
|
|
|
{
|
2017-04-07 12:41:59 +02:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-06-20 12:33:52 +02:00
|
|
|
|
if (rdpControl == null)
|
2017-04-07 12:41:59 +02:00
|
|
|
|
return;
|
|
|
|
|
|
2017-06-20 12:33:52 +02:00
|
|
|
|
rdpControl.Location = value;
|
2017-04-07 12:41:59 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RDPAddOnDisconnected()
|
|
|
|
|
{
|
2017-06-20 12:33:52 +02:00
|
|
|
|
if (rdpControl == null)
|
2014-06-10 18:12:16 +02:00
|
|
|
|
return;
|
|
|
|
|
|
2017-11-06 12:28:07 +01:00
|
|
|
|
if (rdpClient9 == null)
|
|
|
|
|
rdpClient6.OnDisconnected += rdpClient_OnDisconnected;
|
|
|
|
|
else
|
|
|
|
|
rdpClient9.OnDisconnected += rdpClient_OnDisconnected;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RDPSetSettings()
|
|
|
|
|
{
|
2017-06-20 12:33:52 +02:00
|
|
|
|
if (rdpControl == null)
|
2014-06-10 18:12:16 +02:00
|
|
|
|
return;
|
2017-11-06 12:28:07 +01:00
|
|
|
|
|
|
|
|
|
if (rdpClient9 == null)
|
|
|
|
|
{
|
|
|
|
|
rdpClient6.SecuredSettings2.KeyboardHookMode = Properties.Settings.Default.WindowsShortcuts ? 1 : 0;
|
|
|
|
|
rdpClient6.SecuredSettings2.AudioRedirectionMode = Properties.Settings.Default.ReceiveSoundFromRDP ? 0 : 1;
|
|
|
|
|
rdpClient6.AdvancedSettings3.DisableRdpdr = Properties.Settings.Default.ClipboardAndPrinterRedirection ? 0 : 1;
|
|
|
|
|
rdpClient6.AdvancedSettings7.ConnectToAdministerServer = Properties.Settings.Default.ConnectToServerConsole;
|
|
|
|
|
//CA-103910 - enable NLA
|
|
|
|
|
rdpClient6.AdvancedSettings5.AuthenticationLevel = 2;
|
|
|
|
|
rdpClient6.AdvancedSettings7.EnableCredSspSupport = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rdpClient9.SecuredSettings2.KeyboardHookMode = Properties.Settings.Default.WindowsShortcuts ? 1 : 0;
|
|
|
|
|
rdpClient9.SecuredSettings2.AudioRedirectionMode = Properties.Settings.Default.ReceiveSoundFromRDP ? 0 : 1;
|
|
|
|
|
rdpClient9.AdvancedSettings3.DisableRdpdr = Properties.Settings.Default.ClipboardAndPrinterRedirection ? 0 : 1;
|
|
|
|
|
rdpClient9.AdvancedSettings7.ConnectToAdministerServer = Properties.Settings.Default.ConnectToServerConsole;
|
|
|
|
|
//CA-103910 - enable NLA
|
|
|
|
|
rdpClient9.AdvancedSettings5.AuthenticationLevel = 2;
|
|
|
|
|
rdpClient9.AdvancedSettings7.EnableCredSspSupport = true;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RDPConnect(string rdpIP, int w, int h)
|
|
|
|
|
{
|
2017-06-20 12:33:52 +02:00
|
|
|
|
if (rdpControl == null)
|
2014-06-10 18:12:16 +02:00
|
|
|
|
return;
|
|
|
|
|
|
2017-11-06 12:28:07 +01:00
|
|
|
|
Log.DebugFormat("Connecting RDPClient{0} using server '{1}', width '{2}' and height '{3}'",
|
|
|
|
|
rdpClient9 == null ? "6" : "9",
|
|
|
|
|
rdpIP,
|
|
|
|
|
w,
|
|
|
|
|
h);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2017-11-06 12:28:07 +01:00
|
|
|
|
if (rdpClient9 == null)
|
|
|
|
|
{
|
|
|
|
|
rdpClient6.Server = rdpIP;
|
|
|
|
|
rdpClient6.DesktopWidth = w;
|
|
|
|
|
rdpClient6.DesktopHeight = h;
|
|
|
|
|
rdpClient6.Connect();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rdpClient9.Server = rdpIP;
|
|
|
|
|
rdpClient9.DesktopWidth = w;
|
|
|
|
|
rdpClient9.DesktopHeight = h;
|
|
|
|
|
rdpClient9.Connect();
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-25 15:07:29 +02:00
|
|
|
|
public void UpdateDisplay(int width, int height, Point locationOffset)
|
2017-02-27 19:00:46 +01:00
|
|
|
|
{
|
2017-06-20 12:33:52 +02:00
|
|
|
|
if (rdpControl == null)
|
2017-02-27 19:00:46 +01:00
|
|
|
|
return;
|
|
|
|
|
|
2017-11-06 12:28:07 +01:00
|
|
|
|
if (Connected && rdpClient9 != null && allowDisplayUpdate)
|
2017-02-27 19:00:46 +01:00
|
|
|
|
{
|
2017-04-20 18:51:49 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-04-25 15:07:29 +02:00
|
|
|
|
Log.DebugFormat("Updating display settings using width '{0}' and height '{1}'", width, height);
|
2017-06-20 12:33:52 +02:00
|
|
|
|
rdpClient9.UpdateSessionDisplaySettings((uint)width, (uint)height, (uint)width, (uint)height, 1, 1, 1);
|
|
|
|
|
rdpClient9.Size = new Size(width, height);
|
2017-04-25 15:07:29 +02:00
|
|
|
|
rdpLocationOffset = locationOffset;
|
|
|
|
|
parent.AutoScroll = false;
|
2017-04-20 18:51:49 +02:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
allowDisplayUpdate = false;
|
2017-04-25 15:07:29 +02:00
|
|
|
|
parent.AutoScroll = true;
|
2017-06-20 12:33:52 +02:00
|
|
|
|
parent.AutoScrollMinSize = rdpClient9.Size;
|
2017-04-20 18:51:49 +02:00
|
|
|
|
}
|
2017-02-27 19:00:46 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-12 16:06:09 +02:00
|
|
|
|
private bool Connected
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-11-06 12:28:07 +01:00
|
|
|
|
get { return rdpControl == null ? false : (rdpClient9 == null ? rdpClient6.Connected == 1 : rdpClient9.Connected == 1); }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int DesktopHeight
|
|
|
|
|
{
|
2017-11-06 12:28:07 +01:00
|
|
|
|
get { return rdpControl == null ? 0 : (rdpClient9 == null ? rdpClient6.DesktopHeight : rdpClient9.DesktopHeight); }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int DesktopWidth
|
|
|
|
|
{
|
2017-11-06 12:28:07 +01:00
|
|
|
|
get { return rdpControl == null ? 0 : (rdpClient9 == null ? rdpClient6.DesktopWidth : rdpClient9.DesktopWidth); }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static readonly List<System.Windows.Forms.Timer> RdpCleanupTimers = new List<System.Windows.Forms.Timer>();
|
|
|
|
|
void rdpClient_OnDisconnected(object sender, AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEvent e)
|
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
|
|
|
|
|
if (OnDisconnected != null)
|
|
|
|
|
OnDisconnected(this, null);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-20 18:51:49 +02:00
|
|
|
|
//refresh to draw focus border in correct position after display is updated
|
|
|
|
|
void rdpClient_OnRemoteDesktopSizeChange(object sender, AxMSTSCLib.IMsTscAxEvents_OnRemoteDesktopSizeChangeEvent e)
|
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
|
2017-06-20 12:33:52 +02:00
|
|
|
|
if (rdpControl == null || parent == null)
|
2017-04-25 15:07:29 +02:00
|
|
|
|
return;
|
|
|
|
|
|
2017-06-20 12:33:52 +02:00
|
|
|
|
rdpControl.Size = DesktopSize;
|
2017-04-25 15:07:29 +02:00
|
|
|
|
parent.Refresh();
|
2017-04-20 18:51:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public void Connect(string rdpIP)
|
|
|
|
|
{
|
2014-06-10 18:12:16 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
RDPSetSettings();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2017-06-20 12:33:52 +02:00
|
|
|
|
if (parent.Controls.Contains(rdpControl))
|
|
|
|
|
parent.Controls.Remove(rdpControl);
|
|
|
|
|
rdpControl.Dispose();
|
|
|
|
|
rdpControl = null;
|
2014-06-10 18:12:16 +02:00
|
|
|
|
Log.Error("Setting the RDP client properties caused an exception.", ex);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
RDPConnect(rdpIP, size.Width, size.Height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Disconnect()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-12 16:06:09 +02:00
|
|
|
|
if (Connected)
|
2014-06-10 18:12:16 +02:00
|
|
|
|
{
|
2017-11-06 12:28:07 +01:00
|
|
|
|
if (rdpClient9 == null)
|
|
|
|
|
rdpClient6.Disconnect();
|
|
|
|
|
else
|
|
|
|
|
rdpClient9.Disconnect();
|
2014-06-10 18:12:16 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
catch(InvalidComObjectException ex)
|
|
|
|
|
{
|
|
|
|
|
Log.ErrorFormat("Disconnecting RdpClient caused an exception: {0}, {1}", ex.Message, ex.StackTrace);
|
|
|
|
|
}
|
|
|
|
|
catch(AccessViolationException ex)
|
|
|
|
|
{
|
|
|
|
|
//We seem (often unpredictably) to get a read/write into protected memory while disposing the client eg: CA-91482
|
|
|
|
|
Log.ErrorFormat("Disconnecting RdpClient caused an AccessViolationException: {0}, {1}", ex.Message, ex.StackTrace);
|
|
|
|
|
}
|
|
|
|
|
catch(NullReferenceException ex)
|
|
|
|
|
{
|
|
|
|
|
//Sometimes rdpClient.Disconnect() crashes with NullReferenceException eg: CA-94062
|
|
|
|
|
Log.ErrorFormat("Disconnecting RdpClient caused a NullReferenceException: {0}, {1}", ex.Message, ex.StackTrace);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal Set<int> pressedScans = new Set<int>();
|
|
|
|
|
private bool modifierKeyPressedAlone = false;
|
|
|
|
|
|
2017-05-02 18:16:23 +02:00
|
|
|
|
private void handleRDPKey(bool pressed, int scancode, int keysym)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
bool containsFocus = parent.ParentForm != null && parent.ParentForm.ContainsFocus;
|
|
|
|
|
|
2017-06-20 12:33:52 +02:00
|
|
|
|
if (rdpControl == null || !containsFocus)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (KeyHandler.handleExtras<int>(pressed, pressedScans, KeyHandler.ExtraScans, scancode, KeyHandler.ModifierScans, ref modifierKeyPressedAlone))
|
|
|
|
|
parent.Focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void rdpClient_Leave(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-10-01 18:01:59 +02:00
|
|
|
|
Program.MainWindow.MenuShortcutsEnabled = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
InterceptKeys.releaseKeys();
|
|
|
|
|
pressedScans = new Set<int>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RdpEnter(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Activate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void rdpClient_GotFocus(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Activate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region IRemoteConsole implementation
|
|
|
|
|
|
|
|
|
|
public ConsoleKeyHandler KeyHandler
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Control ConsoleControl
|
|
|
|
|
{
|
2017-06-20 12:33:52 +02:00
|
|
|
|
get { return rdpControl; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Activate()
|
|
|
|
|
{
|
2018-10-01 18:01:59 +02:00
|
|
|
|
Program.MainWindow.MenuShortcutsEnabled = false;
|
2017-06-20 12:33:52 +02:00
|
|
|
|
if (rdpControl != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-06-20 12:33:52 +02:00
|
|
|
|
if (!rdpControl.Focused)
|
|
|
|
|
rdpControl.Select();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
InterceptKeys.releaseKeys();
|
|
|
|
|
InterceptKeys.grabKeys(new InterceptKeys.KeyEvent(handleRDPKey), true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DisconnectAndDispose()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Disconnect();
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Dispose();
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool disposed;
|
|
|
|
|
public void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if(!disposed)
|
|
|
|
|
{
|
|
|
|
|
if(disposing)
|
|
|
|
|
{
|
2017-06-20 12:33:52 +02:00
|
|
|
|
if (rdpControl != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
// We need to dispose the rdp control. However, doing it immediately (in the control's own
|
|
|
|
|
// OnDisconnected event) will cause a horrible crash. Instead, start a timer that will
|
|
|
|
|
// call the dispose method on the GUI thread at the next available opportunity. CA-12902
|
|
|
|
|
Timer t = new Timer();
|
|
|
|
|
t.Tick += delegate
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Log.Debug("RdpClient Dispose(): rdpControl.Dispose() in delegate");
|
2017-06-20 12:33:52 +02:00
|
|
|
|
rdpControl.Dispose();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
// We often get NullReferenceException here
|
|
|
|
|
}
|
|
|
|
|
t.Stop();
|
|
|
|
|
RdpCleanupTimers.Remove(t);
|
|
|
|
|
Log.Debug("RdpClient Dispose(): Timer stopped and removed in delegate");
|
|
|
|
|
};
|
|
|
|
|
t.Interval = 1;
|
|
|
|
|
RdpCleanupTimers.Add(t);
|
|
|
|
|
Log.DebugFormat("RdpClient Dispose(): Start timer (timers count {0})", RdpCleanupTimers.Count);
|
|
|
|
|
t.Start();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Log.Debug("RdpClient Dispose(): rdpControl == null");
|
|
|
|
|
}
|
2017-06-20 12:33:52 +02:00
|
|
|
|
rdpControl = null;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Log.Debug("RdpClient Dispose(): disposed = true");
|
|
|
|
|
disposed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Pause()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Unpause()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SendCAD()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Image Snapshot()
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SendScanCodes
|
|
|
|
|
{
|
|
|
|
|
set { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Scaling
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool DisplayBorder
|
|
|
|
|
{
|
|
|
|
|
set { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Size DesktopSize
|
|
|
|
|
{
|
2017-06-20 12:33:52 +02:00
|
|
|
|
get { return rdpControl != null ? new Size(DesktopWidth, DesktopHeight) /*rdpControl.Size*/ : Size.Empty; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
set { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Rectangle ConsoleBounds
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-06-20 12:33:52 +02:00
|
|
|
|
return rdpControl != null ? new Rectangle(rdpControl.Location.X, rdpControl.Location.Y, DesktopWidth, DesktopHeight) : Rectangle.Empty;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|