Пример #1
0
            /// <summary>
            ///  Translates the protocol event args to value event args.
            /// </summary>
            /// <param name="sender">Event sender.</param>
            /// <param name="args">Event arguments.</param>
            private void HandleButtonPressEvent(object sender, DeviceButtonPressEventArgs args)
            {
                var    deviceForm      = this.GetDeviceForm(args.FormName);
                string buttonName      = deviceForm.GetControlName(args.ControlId);
                var    buttonPressArgs = new ButtonPressEventArgs {
                    ButtonName = buttonName
                };

                this.ButtonPressEvent(sender, buttonPressArgs);
            }
            /// <summary>
            ///  Handles the button press and keypad event types.
            /// </summary>
            /// <param name="responseMessage">Event message.</param>
            private void HandleFormEvent(ResponseMessage responseMessage)
            {
                // Check for invalid form event message.
                if (responseMessage.ResponseValues == null || responseMessage.ResponseValues.Count < 2)
                {
                    return;
                }

                var controlType = (ControlType)Enum.Parse(typeof(ControlType), responseMessage.ResponseValues[0]);
                var controlId   = int.Parse(responseMessage.ResponseValues[1], CultureInfo.InvariantCulture.NumberFormat);

                switch (controlType)
                {
                case ControlType.Button:
                    if (this.ButtonPressEvent != null)
                    {
                        var args = new DeviceButtonPressEventArgs()
                        {
                            ControlId = controlId, FormName = this.currentForm
                        };
                        this.ButtonPressEvent(this, args);
                    }

                    break;

                case ControlType.Keypad:
                    if (this.EnterKeypadEvent != null)
                    {
                        // Check for invalid key press event message.
                        if (responseMessage.ResponseValues.Count < 3)
                        {
                            return;
                        }

                        var keyPress = (KeyPressEvent)Enum.Parse(typeof(KeyPressEvent), responseMessage.ResponseValues[2]);

                        if (keyPress == KeyPressEvent.EnterPressed || keyPress == KeyPressEvent.Timeout || keyPress == KeyPressEvent.Cancel)
                        {
                            bool   isCancel = keyPress == KeyPressEvent.Cancel;
                            string value    = isCancel ? string.Empty : responseMessage.ResponseValues[3];
                            var    args     = new DeviceKeypadEventArgs()
                            {
                                ControlId = controlId, FormName = this.currentForm, Value = value, IsCanceled = isCancel
                            };
                            this.EnterKeypadEvent(this, args);
                        }
                    }

                    break;

                default:
                    // Unhandled event type.
                    break;
                }
            }