Esempio n. 1
0
        public void DisconnectFromClient()
        {

            if (QueryRunner != null)
                QueryRunner.Dispose();
            QueryDispatcher = null;
            QueryRunner = null;
        }
        private void QueryDispatcher_ReadyForSendingCommands(object sender, System.EventArgs e)
        {
            Model.ConnectionState = ConnectionState.Connected;
            // you can only run commands on the queryrunner when this event has been raised first!
            QueryRunner = new QueryRunner(QueryDispatcher);
            QueryRunner.Notifications.ChannelTalkStatusChanged += Notifications_ChannelTalkStatusChanged;
            QueryRunner.RegisterForNotifications(ClientNotifyRegisterEvent.Any);

            MessageBox.Show("Ready");
        }
        protected void RunQueries(Action<QueryRunner> action)
        {
            if (action == null)
                throw new ArgumentNullException("action");


            using (QueryRunner queryRunner = new QueryRunner(new SyncTcpDispatcher("localhost", 25639)))  // host and port
            {
                // connection to the TS3-Server is established with the first query command

                action(queryRunner);
            }
        }
Esempio n. 4
0
        private void QueryDispatcher_ReadyForSendingCommands(object sender, System.EventArgs e)
        {
            try
            {
                QueryRunner = new QueryRunner(QueryDispatcher);
                QueryRunner.Notifications.ChannelTalkStatusChanged += Notifications_ChannelTalkStatusChanged;
                QueryRunner.RegisterForNotifications(ClientNotifyRegisterEvent.Any);
                this.state = State.Connected;
                setupClientAndChannel();
                state = State.Connected;
            }
            catch
            {
                state = State.Disconnected;
                Reconnect();
            }


        }
Esempio n. 5
0
        /// <summary>
        /// Handler for the ReadyForSendingCommands event
        /// </summary>
        private void EventQueryDispatcher_ReadyForSendingCommands(object sender, EventArgs e)
        {
            logger.Info("Event - Ready For Sending Commands");
            this.ConnectionState = ConnectionState.Connected;

            // you can only run commands on the queryrunner when this event has been raised first!
            this.EventQueryRunner = new QueryRunner(this.EventQueryDispatcher);
            this.EventQueryRunner.Notifications.TalkStatusChanged += Notifications_TalkStatusChanged;

            Task.Factory.StartNew(() =>
            {
                this.EventQueryRunner.RegisterForNotifications(ClientNotifyRegisterEvent.Any);

                // Start a timer to send a message every so often, keeping the connection open
                logger.Info("Starting poll timer");
                this.pollTimer.Start();
            });
        }
Esempio n. 6
0
        /// <summary>
        /// Disconnects from the Teamspeak Client Query interface
        /// </summary>
        public void Disconnect()
        {
            lock (this.pollLock)
            {
                logger.Debug("Disconnecting and cleaning up");

                // Stop the poll timer
                this.pollTimer.Stop();
                this.clients.Clear();

                // QueryRunner disposes the Dispatcher too
                if (this.CommandQueryRunner != null)
                    this.CommandQueryRunner.Dispose();
                if (this.EventQueryRunner != null)
                    this.EventQueryRunner.Dispose();

                this.CommandQueryDispatcher = null;
                this.CommandQueryRunner = null;
                this.EventQueryDispatcher = null;
                this.EventQueryRunner = null;
                this.ConnectionState = ConnectionState.Disconnected;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Ready for sending commands
        /// </summary>
        private void QueryDispatcher_ReadyForSendingCommands(object sender, System.EventArgs e)
        {
            if (!Keep_Alive_Timer.Enabled)
                Keep_Alive_Timer.Start();
            // you can only run commands on the queryrunner when this event has been raised first!
            try
            {
                QueryRunner = new QueryRunner(QueryDispatcher);
                //check if whoami returns a valid user, if erroneous teamspeak is not connected to a server
                //try connecting again later.
                if ((currentUser = QueryRunner.SendWhoAmI()).IsErroneous)
                {
                    Disconnect();
                    return;
                }
                Retry_Connection_Timer.Stop();
                Connected = ConnectionState.Connected;
                //QueryRunner.Notifications.ChannelTalkStatusChanged += Notifications_ChannelTalkStatusChanged;
                //QueryRunner.Notifications.ClientMoved += Notifications_ClientMoved;
                QueryRunner.Notifications.MessageReceived += Notifications_MessageReceived;

                QueryRunner.RegisterForNotifications(ClientNotifyRegisterEvent.Any);

            }
            catch (Exception)
            {
                Disconnect();
            }
        }