Example #1
0
        public void destroy()
        {
            try {
                lock (this) {
                    if (null == currentSession)
                    {
                        return;
                    }

                    ReleaseEventHandlers();
                    currentSession.Close();
                    currentSession = null;
                    controlString  = null;

                    isSessionAlive = false;

                    countControlClient = 0;
                    countViewClient    = 0;
                    ReleaseEventHandlers();
                }
            } catch (Exception Ex) {
                // MessageBox.Show("Error Connecting", "Error connecting to remote desktop " + " Error:  " + Ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Console.WriteLine("error disconnecting" + Ex);
                throw Ex;
            }
        }
Example #2
0
        private void Button_Begin_Click(object sender, EventArgs e)
        {
            if (Button_Begin.Text == "Initiate")
            {
                session = new RDPSession();

                session.OnAttendeeConnected += Incoming;
                session.Open();

                var info = new ConnectInfo();
                info.ShowDialog();

                IRDPSRAPIInvitation invitation = session.Invitations.CreateInvitation(auth, group, pass, 10);
                Text_Key.Text = invitation.ConnectionString;

                Buttons(Setting.Basic, true);
            }
            else if (Button_Begin.Text == "Begin")
            {
                var info = new Credentials();
                info.ShowDialog();

                Screen.key = Text_Key.Text;
                var screen = new Screen();
                screen.Start();
                screen.ShowDialog();

                Buttons(Setting.Basic, true);
            }
        }
        /**
         * starts a new RDP session and a new invitation, and returns the corresponding invite string.
         * returns the empty string if the start failed.
         * */
        private String CreateNewTicklet()
        {
            try
            {
                StartRDPSession();
                String invite = connectionString == null?GetInviteString() : connectionString;

                Console.WriteLine("Ticklet Creation Succeeded!");
                return(invite);
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                Console.WriteLine("Ticklet Creation Failed :(");
                Console.WriteLine(e.Message);
                if (rdpSession != null)
                {
                    Action TickletFail = () => {
                        textBox1.Text        = "Ticklet was rejected, please try again";
                        submitButton.Enabled = true;
                    };
                    this.Invoke(TickletFail);
                    rdpSession.Close();
                    rdpSession = null;
                }
            }

            return("");
        }
Example #4
0
        private void HostTabEnterStartConnection()
        {
            RDPSession x = new RDPSession();

            x.OnAttendeeConnected += Incoming;
            x.Open();
        }
Example #5
0
        private void StopButton_Click(object sender, EventArgs e)
        {
            StartButton.Enabled = true;
            StopButton.Enabled  = false;

            try
            {
                MessagesClass propTest = new MessagesClass();
                propTest.netShutdown();
                m_pRdpSession.Close();
                //LogTextBox.Text += "Presentation Stopped." + Environment.NewLine;
                LogTextBox.AppendText("Presentation Stopped." + Environment.NewLine);
                Marshal.ReleaseComObject(m_pRdpSession);
                m_pRdpSession = null;
            }
            catch (Exception ex)
            {
                //LogTextBox.Text += "Error occured while stopping presentation. Error: " + ex.ToString();
                LogTextBox.AppendText("Error occured while stopping presentation. Error: " + ex.ToString() + Environment.NewLine);

                StartButton.Enabled = false;
                StopButton.Enabled  = false;
                checkBox1.Enabled   = false;

                LogTextBox.AppendText("Please exit the program." + Environment.NewLine);
            }
        }
Example #6
0
        public void Dispose()
        {
            ConnectionString = string.Empty;
            Connected        = false;
            ListenOn         = false;
            try
            {
                if (RdpSession != null)
                {
                    foreach (IRDPSRAPIAttendee attendees in RdpSession.Attendees)
                    {
                        attendees.TerminateConnection();
                    }

                    RdpSession.Close();
                    RdpSession = null;
                }
            }
            catch { }
            try
            {
                TcpClient.GetStream().Close();
            }
            catch { }
            MessageBroker = null;
            TcpClient.Close();
            TcpClient       = null;
            Settings        = null;
            User            = null;
            AuthData        = null;
            MessageListener = null;
        }
Example #7
0
        private void StartButton_Click(object sender, EventArgs e)
        {
            if (!ongoingSession)
            {
                try
                {
                    if (m_pRdpSession == null)
                    {
                        m_pRdpSession = new RDPSession();
                    }

                    m_pRdpSession.OnAttendeeConnected         += new _IRDPSessionEvents_OnAttendeeConnectedEventHandler(OnAttendeeConnected);
                    m_pRdpSession.OnAttendeeDisconnected      += new _IRDPSessionEvents_OnAttendeeDisconnectedEventHandler(OnAttendeeDisconnected);
                    m_pRdpSession.OnControlLevelChangeRequest += new _IRDPSessionEvents_OnControlLevelChangeRequestEventHandler(OnControlLevelChangeRequest);
                    var properties = m_pRdpSession.Properties;
                    properties["EnableClipboardRedirect"] = true;
                    SetSharingMode();

                    m_pRdpSession.Open();
                    IRDPSRAPIInvitation pInvitation = m_pRdpSession.Invitations.CreateInvitation("WinPresenter", "PresentationGroup", "", 5);
                    string invitationString         = pInvitation.ConnectionString;
                    WriteToFile(invitationString);
                    LogTextBox.Text += $"Presentation Started. {this.SharingModeComboBox.GetItemText(this.SharingModeComboBox.SelectedItem)} is being shared." + Environment.NewLine;
                    ongoingSession   = true;
                }
                catch (Exception ex)
                {
                    LogTextBox.Text += "Error occured while starting presentation. Error: " + ex.ToString() + Environment.NewLine;
                }
            }
        }
Example #8
0
 private void ButtonHost_Click(object sender, RoutedEventArgs e)
 {
     if (x == null)
     {
         x = new RDPSession();
         x.OnAttendeeConnected += Incoming;
         x.Open();
         IRDPSRAPIInvitation Invitation = x.Invitations.CreateInvitation("Trial", "MyGroup", "", 10);
         //ButtonHost.Visibility = Visibility.Hidden;
         //ButtonStopHost.Visibility = Visibility.Visible;
         if (trafficController.GetState() == State.OpenedGate)
         {
             messageSendTime = DateTime.Now;
             /// Wysyłanie konkretnej wiadomości do kontaktu, z którym mamy otwartego gate'a
             TextBoxMessage.Text = "Ekran udostępniony";
             trafficController.SMSSend(nr.ToString(), null, szyfr2 + Invitation.ConnectionString, "", "" + messageSendTime);
             messageSend = true;
         }
     }
     else
     {
         x.Close();
         x = null;
         TextBoxMessage.Text = "Udostępnianie przerwane";
     }
 }
Example #9
0
        private void btnStartCast_Click(object sender, EventArgs e)
        {
            var dlg = new CaptureScreen()
            {
                Owner = this
            };
            var result = dlg.ShowDialog();

            if (result == DialogResult.No)
            {
                return;
            }
            Rectangle rect = new Rectangle(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

            if (result == DialogResult.Yes)
            {
                rect = dlg.SelectedRectangle;
            }

            try
            {
                btnStartCast.Enabled = false;

                _rdpSession = new RDPSession();

                _attendees.Clear();

                _rdpSession.OnAttendeeConnected         += RdpSessionOnOnAttendeeConnected;
                _rdpSession.OnAttendeeDisconnected      += RdpSessionOnOnAttendeeDisconnected;
                _rdpSession.OnControlLevelChangeRequest += RdpSessionOnOnControlLevelChangeRequest;

                //_rdpSession.SetDesktopSharedRect(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
                _rdpSession.SetDesktopSharedRect(rect.X, rect.Y, rect.Right, rect.Bottom);

                _rdpSession.Open();


                IRDPSRAPIInvitation invitation = _rdpSession.Invitations.CreateInvitation("PalmaeTech", "CastGroup", "",
                                                                                          64);

                _hostCaster.StartCast(invitation.ConnectionString);

                btnStopCast.Enabled = true;
                notifyIcon1.Text    = "屏幕广播已启动";
                notifyIcon1.ShowBalloonTip(1000, "屏幕广播启动成功", "屏幕广播已启动,程序已最小化到右下角系统通知区域。", ToolTipIcon.Info);

                this.ShowInTaskbar = false;
                this.Hide();

                _isRunning = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                btnStartCast.Enabled = true;
                btnStopCast.Enabled  = false;
                _isRunning           = false;
            }
        }
Example #10
0
        /// <summary>
        /// Create the specified password.
        /// </summary>
        /// <param name="password">Password.</param>
        public void Create(string password)
        {
            currentSession = new RDPSession();
            Connect(currentSession);
            var invitation = DesktopInvitation = getConnectionString(currentSession, Environment.UserDomainName, "SharpView", password, 5);

            ConnectionId = invitation.ConnectionString;
        }
Example #11
0
 public static void Connect(RDPSession session)
 {
     session.ApplicationFilter.Enabled       = false;
     session.OnSharedDesktopSettingsChanged += Session_OnSharedDesktopSettingsChanged;
     session.colordepth           = 8;
     session.OnChannelDataSent   += Session_OnChannelDataSent;
     session.OnAttendeeConnected += Incoming;
     session.Open();
 }
Example #12
0
        public static string getConnectionString(RDPSession session, String authString,
                                                 string group, string password, int clientLimit)
        {
            IRDPSRAPIInvitation invitation =
                session.Invitations.CreateInvitation
                    (authString, group, password, clientLimit);

            return(invitation.ConnectionString);
        }
Example #13
0
 public static void Disconnect(RDPSession session)
 {
     try
     {
         session.Close();
     }
     catch (Exception)
     {
     }
 }
Example #14
0
 public void createSession()  //made it non-static
 {
     lock (_lock)
     {
         if (null == currentSession)
         {
             currentSession = new RDPSession();
         }
     }
 }
Example #15
0
 /// <summary>
 /// Constructor <see cref="RdpSessionServer"/>.
 /// </summary>
 public RdpSessionServer()
 {
     // Specifies the color depth of the session in bits per pixel (bpp). The color depth is always 32. If you specify any other value, the color depth is set to 32 bpp.
     // Windows Server 2008 R2: Possible values are 16 and 24.If you specify a value of 8, the color depth is set to 16 bpp.
     // Windows Server 2008 and Windows Vista: Possible values are 8, 16, and 24 bpp.
     _rdpSession = new RDPSession {
         colordepth = 8
     };
     _rdpSession.add_OnAttendeeConnected(OnAttendeeConnected);
 }
Example #16
0
 public static void Disconnect(RDPSession session)
 {
     try
     {
         session.Close();
     }
     catch (Exception Ex)
     {
         MessageBox.Show("Error Connecting", "Error connecting to remote desktop " + " Error:  " + Ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #17
0
 public static void Connect(RDPSession session)
 {
     try
     {
         session.OnAttendeeConnected += Incoming;
         session.Open();
     }
     catch (Exception)
     {
     }
 }
Example #18
0
        public string ConnectionString()
        {
            session = new RDPSession();
            session.Open();

            session.add_OnAttendeeConnected(OnAttendeeConnected);

            IRDPSRAPIInvitation invitation = session.Invitations.CreateInvitation(null, screenCommand.UserName, screenCommand.Password, 1);

            return(invitation.ConnectionString);
        }
Example #19
0
        private void Disconnect(RDPSession session)
        {
            session.Close();

            AxEventHandler <RemoteServerDisconnectEventArgs> handler = this.Disconnected;

            if (handler != null)
            {
                handler(new  RemoteServerDisconnectEventArgs(session));
            }
        }
Example #20
0
        private RemoteDesktopInvitation getConnectionString(RDPSession session, String authString,
                                                            string group, string password, int clientLimit)
        {
            IRDPSRAPIInvitation invitation =
                session.Invitations.CreateInvitation
                    (authString, group, password, clientLimit);

            return(new SharpViewCore.RemoteDesktopInvitation(invitation.ConnectionString, invitation.GroupName, invitation.Password)
            {
                AttendeeLimit = invitation.AttendeeLimit, Revoked = invitation.Revoked
            });
        }
Example #21
0
        private void Connect(RDPSession session)
        {
            session.OnAttendeeConnected += Incoming;
            session.Open();

            AxEventHandler <RemoteServerConnectedEventArgs> handler = this.Connected;

            if (handler != null)
            {
                handler(new RemoteServerConnectedEventArgs(session));
            }
        }
Example #22
0
 private void HostButton2_Click(object sender, EventArgs e)
 {
     if (counterDisconnector > 0)
     {
         MessageBox.Show("You have already Disconnected The Connection, Please Restart And Try Again");
     }
     else
     {
         counterDisconnector++;
         x.Close();
         x = null;
     }
 }
Example #23
0
        public Client(Settings settings, User user, AuthorizationData authData, ThreadMethod listening, bool firstRun)
        {
            this.Settings = settings;
            this.User     = user;
            this.AuthData = authData;
            if (firstRun)
            {
                RdpSession = new RDPSession();
            }
            ThreadStart threadDelegate = new ThreadStart(listening);

            MessageListener = new Thread(threadDelegate);
        }
 public void CloseShare()
 {
     try
     {
         m_pRdpSession.Close();
         Marshal.ReleaseComObject(m_pRdpSession);
         m_pRdpSession = null;
     }
     catch (Exception ex)
     {
         //LogTextBox.Text += "Error occured while stopping presentation. Error: " + ex.ToString();
     }
 }
Example #25
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            FriendData friend = ClientInformation.GetFriend(Partner);

            if (friend.Status && !ClientInformation.AnswerWindows.ContainsKey(friend.Username) && !ClientInformation.CallingWindows.ContainsKey(friend.Username))
            {
                RDPSession rdpSession = new RDPSession();
                rdpSession.OnAttendeeConnected += Incoming;
                rdpSession.Open();

                IRDPSRAPIInvitation Invitation = rdpSession.Invitations.CreateInvitation(ClientInformation.Username, Partner, "", 1);
                ClientInformation.ScreenShareService.InitShareScreen(ClientInformation.Username, Partner, Invitation.ConnectionString);
            }
        }
Example #26
0
 public void CreateSession(bool fullDesktop, string chosenApp = "")
 {
     if (RdpSession == null)
     {
         RdpSession = new RDPSession();
     }
     RdpSession.OnControlLevelChangeRequest += ChangeControl;
     RdpSession.OnAttendeeConnected         += Incoming;
     RdpSession.Open();
     if (!fullDesktop)
     {
         RdpSession.ApplicationFilter.Enabled = true;
         SetAppForSharing(chosenApp);
     }
 }
Example #27
0
        public Service(RDPSession session)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }

            // store the session
            this.session = session;

            // hook the session events
            session.OnAttendeeConnected         += OnAttendeeConnected;
            session.OnControlLevelChangeRequest += OnControlLevelChangeRequest;
            session.OnAttendeeDisconnected      += OnAttendeeDisconnected;
        }
Example #28
0
 private void StopButton_Click(object sender, EventArgs e)
 {
     try
     {
         m_Timer.Start();
         m_pRdpSession.Close();
         LogTextBox.Text += "停止共享." + Environment.NewLine;
         Marshal.ReleaseComObject(m_pRdpSession);
         m_pRdpSession = null;
     }
     catch (Exception ex)
     {
         LogTextBox.Text += "停止共享出错. 错误: " + ex.ToString();
     }
 }
Example #29
0
 private void StopButton_Click(object sender, EventArgs e)
 {
     try
     {
         m_pRdpSession.Close();
         LogTextBox.Text += "Presentation Stopped." + Environment.NewLine;
         Marshal.ReleaseComObject(m_pRdpSession);
         m_pRdpSession  = null;
         ongoingSession = false;
     }
     catch (Exception ex)
     {
         LogTextBox.Text += "Error occured while stopping presentation. Error: " + ex.ToString();
     }
 }
Example #30
0
 public RdpTcpClient()
 {
     try
     {
         m_pRdpSession            = new RDPSession();
         m_pRdpSession.colordepth = 8;
         m_pRdpSession.SetDesktopSharedRect(0, 0, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
         m_pRdpSession.OnAttendeeConnected         += new _IRDPSessionEvents_OnAttendeeConnectedEventHandler(OnAttendeeConnected);
         m_pRdpSession.OnAttendeeDisconnected      += new _IRDPSessionEvents_OnAttendeeDisconnectedEventHandler(OnAttendeeDisconnected);
         m_pRdpSession.OnControlLevelChangeRequest += new _IRDPSessionEvents_OnControlLevelChangeRequestEventHandler(OnControlLevelChangeRequest);
         m_pRdpSession.Open();
         IRDPSRAPIInvitation invitation = m_pRdpSession.Invitations.CreateInvitation("baseAuth", "groupName", "", 2);
         m_rdpConnectionString = invitation.ConnectionString;
         XmlDocument doc = new XmlDocument();
         doc.LoadXml(invitation.ConnectionString);
         XmlNodeList nlist = doc.SelectNodes("//L");
         if (nlist != null && nlist.Count > 0)
         {
             for (int i = 0; i < nlist.Count; i++)
             {
                 XmlAttribute attrhost = nlist[i].Attributes["N"];
                 if (attrhost != null)
                 {
                     if (attrhost.Value.IndexOf(":") > 0)
                     {
                         //ipv6
                     }
                     else if (attrhost.Value.IndexOf(".") > 0)
                     {
                         //ipv4
                         XmlAttribute attrport = nlist[i].Attributes["P"];
                         if (attrport != null)
                         {
                             int.TryParse(attrport.Value, out m_rdpport);
                             m_rdphost = attrhost.Value;
                             break;
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         Logger.Trace(e);
     }
     //<E><A KH="jebWL5nMyWOiBHyxcM08QPxhQ4E=" ID="baseAuth"/><C><T ID="1" SID="3344616568"><L P="5247" N="fe80::dc3d:7c76:b517:75fb%11"/><L P="5248" N="192.168.10.175"/></T></C></E>
 }
Example #31
0
 private void button3_Click(object sender, EventArgs e)
 {
     x.Close();
     x = null;
 }