コード例 #1
0
        public static IRDPClient NewRDPClient(RDPClientVersion clientType)
        {
            bool designMode = (System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime);

            if (!designMode)
            {
                using (var process = Process.GetCurrentProcess())
                {
                    designMode = process.ProcessName.ToLowerInvariant().Contains("devenv");
                }
            }

            if (designMode)
            {
                clientType = RDPClientVersion.Stub;
            }

#if __MONO
            else
            {
                clientType = RDPClientVersion.FreeRDP;
            }
#endif

            IRDPClient client;

            if (clientType == RDPClientVersion.Stub)
            {
                client = new RDPClientStub();
            }
            else if (clientType == RDPClientVersion.FreeRDP)
            {
                client = new FreeRDPClient();
            }
#if !__MONO
            else if (clientType == RDPClientVersion.MsRDPClient ||
                     clientType == RDPClientVersion.MsRDPClient80 ||
                     clientType == RDPClientVersion.MsRDPClient70 ||
                     clientType == RDPClientVersion.MsRDPClient61 ||
                     clientType == RDPClientVersion.MsRDPClient60 ||
                     clientType == RDPClientVersion.MsRDPClient50
                     )
            {
                string   libPath             = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "AwakeCoding.MsRdpClient.dll");
                Assembly msRdpClientAssembly = Assembly.LoadFrom(libPath);
                client = msRdpClientAssembly.CreateInstance("AwakeCoding.MsRdpClient.MsRdpClientAdapter") as IRDPClient;
            }
#endif
            else
            {
                throw new ArgumentException("Unsupported RDPClientVersion");
            }

            return(client);
        }
コード例 #2
0
        private void TryVersion(RDPClientVersion clientVersion, MethodInvoker doApplyVersion)
        {
            try
            {
                if (lastDetectedVersion == RDPClientVersion.Unknown || lastDetectedVersion == clientVersion)
                {
                    doApplyVersion();
                    parent.Controls.Add((Control)client);                     // can throw a COMException

                    // Finish initialization - com object proxies
                    TrySetSecuredSettings(client.SecuredSettings, typeof(IMsTscSecuredSettings));
                    TrySetSecuredSettings(client.SecuredSettings2, typeof(IMsRdpClientSecuredSettings));

                    TrySetAdvancedSettings(client.AdvancedSettings9, typeof(MSTSCLib.IMsRdpClientAdvancedSettings8));
                    TrySetAdvancedSettings(client.AdvancedSettings8, typeof(MSTSCLib.IMsRdpClientAdvancedSettings7));
                    TrySetAdvancedSettings(client.AdvancedSettings7, typeof(MSTSCLib.IMsRdpClientAdvancedSettings6));
                    TrySetAdvancedSettings(client.AdvancedSettings6, typeof(MSTSCLib.IMsRdpClientAdvancedSettings5));
                    TrySetAdvancedSettings(client.AdvancedSettings5, typeof(MSTSCLib.IMsRdpClientAdvancedSettings4));
                    TrySetAdvancedSettings(client.AdvancedSettings3, typeof(MSTSCLib.IMsRdpClientAdvancedSettings2));
                    TrySetAdvancedSettings(client.AdvancedSettings2, typeof(MSTSCLib.IMsRdpClientAdvancedSettings));
                    TrySetAdvancedSettings(client.AdvancedSettings, typeof(MSTSCLib.IMsTscAdvancedSettings));

                    if (AdvancedSettings == null)
                    {
                        throw new NotSupportedException();
                    }

                    transportSettingsProxy = new InterfaceProxy <ITransportSettings>();
                    transportSettingsProxy.TargetInstance = client.TransportSettings2;
                    transportSettingsProxy.TargetType     = typeof(IMsRdpClientTransportSettings2);
                    TransportSettings = transportSettingsProxy.GetStrongTypedProxy();

                    host        = (AxHost)client;
                    host.Width  = host.Parent.ClientRectangle.Width;
                    host.Height = host.Parent.ClientRectangle.Height;

                    host.Visible = false;

                    lastDetectedVersion = clientVersion;
                }
            }
            catch (COMException ex)
            {
                if (parent.Controls.Contains((Control)client))
                {
                    parent.Controls.Remove((Control)client);                     // yes, this is required!
                }
                host   = null;
                client = null;
                System.Diagnostics.Debug.WriteLine(clientVersion + " failed to initialize: " + ex.Message);
                lastDetectedVersion = RDPClientVersion.Unknown;
            }
        }