Example #1
0
        private bool OpenRDPView()
        {
            if (m_RdpListener != null)
            {
                try
                {
                    m_RdpListener.Stop();
                    m_RdpListener = null;
                }
                catch (Exception e)
                {
                }
            }

            int rdpport = 20000;

            for (int i = 0; i < 10; i++, rdpport++)
            {
                try
                {
                    m_RdpListener = new TcpListener(IPAddress.Any, rdpport);
                    break;
                }
                catch (Exception e)
                {
                    m_RdpListener = null;
                }
            }
            if (m_RdpListener == null)
            {
                return(false);
            }
            try
            {
                m_RdpListener.Start();
                m_RdpListener.BeginAcceptTcpClient(OnRdpConnect, this);
            }
            catch (Exception e)
            {
                m_RdpListener = null;
                return(false);
            }

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(m_rdpConnectionString);
            XmlNode node = doc.SelectSingleNode("//E/C/T");

            if (node == null)
            {
                m_RdpListener.Stop();
                m_RdpListener = null;
                return(false);
            }
            node.InnerXml = "";
            XmlElement   newele = doc.CreateElement("L");
            XmlAttribute attrp  = doc.CreateAttribute("P");

            attrp.Value = rdpport + "";
            newele.Attributes.Append(attrp);
            XmlAttribute attrn = doc.CreateAttribute("N");

            attrn.Value = "127.0.0.1";
            newele.Attributes.Append(attrn);
            node.AppendChild(newele);

            node = doc.SelectSingleNode("//rdptype");
            if (node != null)
            {
                int.TryParse(node.InnerText, out m_rdpviewtype);
            }

            try
            {
                if (m_rdpviewtype == 1)
                {
                    if (m_viewer2.Connected != 0)
                    {
                        m_viewer2.Disconnect();
                    }
                    m_viewer.Hide();
                    m_viewer2.Show();
                    m_viewer2.Server = "127.0.0.1";
                    m_viewer2.AdvancedSettings8.EnableCredSspSupport = true;
                    m_viewer2.AdvancedSettings8.RDPPort            = rdpport;
                    m_viewer2.AdvancedSettings8.RedirectDevices    = false;
                    m_viewer2.AdvancedSettings8.RedirectDrives     = false;
                    m_viewer2.AdvancedSettings8.RedirectPorts      = false;
                    m_viewer2.AdvancedSettings8.RedirectPOSDevices = false;
                    m_viewer2.AdvancedSettings8.RedirectPrinters   = false;
                    m_viewer2.AdvancedSettings8.RedirectSmartCards = false;
                    m_viewer2.Connect();
                    m_viewer2.Update();
                }
                else
                {
                    m_viewer.Show();
                    m_viewer2.Hide();
                    string connstr = doc.InnerXml;
                    m_viewer.Connect(connstr, "controller", "");
                }
            }
            catch (Exception e)
            {
                m_RdpListener.Stop();
                m_RdpListener = null;
                return(false);
            }
            return(true);
        }