Example #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Sends a ringing event. </summary>
        ///
        /// <param name="evt">  The event. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public void SendRingingEvent(RingingEvent evt)
        {
            if (IsValidCommand(evt))
            {
                SendKeystroke(evt.ToChar());
            }
        }
Example #2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Applies the mapping from keypress to ringing event. </summary>
        ///
        /// <param name="e">    Key event information. </param>
        ///
        /// <returns>   A RingingEvent. </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private RingingEvent ApplyMapping(KeyEventArgs e)
        {
            if (AdvancedMode.Checked)
            {
                Keys mappedKey = CustomMapKeypress(e.KeyCode);
                return(simulator.FindEventForKey(mappedKey.ToString()));
            }

            RingingEvent res = null;

            switch (e.KeyCode)
            {
            case Keys.F:     // LH bell
                res = simulator.FindEventForCommand((LHBell.SelectedIndex + 1).ToString());
                break;

            case Keys.J:     // RH bell
                res = simulator.FindEventForCommand((RHBell.SelectedIndex + 1).ToString());
                break;

            case Keys.G:     // Go
                res = simulator.FindEventForCommand("Go");
                break;

            case Keys.A:     // Bob
                res = simulator.FindEventForCommand("Bob");
                break;

            case Keys.OemSemicolon:     // Single
                res = simulator.FindEventForCommand("Single");
                break;

            case Keys.T:     // That's all
                res = simulator.FindEventForCommand("ThatsAll");
                break;

            case Keys.R:     // Rounds
                res = simulator.FindEventForCommand("Rounds");
                break;

            case Keys.Q:     // Stand
                res = simulator.FindEventForCommand("Stand");
                break;

            case Keys.F4:     // Reset all bells
                res = simulator.FindEventForCommand("ResetBells");
                break;
            }

            return(res);
        }
Example #3
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Process the keystroke. </summary>
        ///
        /// <param name="e">    Key event information. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private void ProcessKeystroke(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Space)
            {
                logger.Debug($"Key press ignored: {e.KeyCode}");
                e.SuppressKeyPress = true;
                return;
            }

            RingingEvent evt = ApplyMapping(e);

            if (evt != null)
            {
                logger.Debug("Key press: {in} -> {out}", e.KeyCode, evt);
                peerConnectionManager.SendAndRingKeyStroke(evt);
            }
            else
            {
                logger.Debug($"Key press ignored: {e.KeyCode}");
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Sends and rings a key stroke. </summary>
        ///
        /// <param name="ringingEvent"> The ringing event. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public void SendAndRingKeyStroke(RingingEvent ringingEvent)
        {
            if (simulator.IsValidCommand(ringingEvent))
            {
                var txBytes = Encoding.ASCII.GetBytes($"{ringingEvent.ToChar()}");
                foreach (var _socket in peerSockets)
                {
                    if (_socket.Connected)
                    {
                        logger.Debug("Sending message to: {dest}", _socket.RemoteEndPoint.ToString());
                        Task.Factory.StartNew(() => { _socket.Send(txBytes); });
                    }
                }
            }

            if (SendKeepAlives)
            {
                TimeSinceLastTX.Restart();
            }

            simulator.SendRingingEvent(ringingEvent);
        }
Example #5
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Query if 'ringingEvent' is a valid simulator command. </summary>
        ///
        /// <param name="ringingEvent"> The ringing event. </param>
        ///
        /// <returns>   True if a valid simulator command, false if not. </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public bool IsValidCommand(RingingEvent ringingEvent)
        {
            return(RingingCommandToChar.ContainsKey(ringingEvent.ToString()));
        }