private void AcquireKey()
        {
            if (Ready)
            {
                return;
            }

            Instance instance = null;

            try
            {
                instance = CreateInstance();
                string result = EgateAPI.egAuthRequest(instance.ID, EgateAPI.ProtocolID, CreateRequest(OperationType.RequestWorkKey).ToString()).GetString();
                if (!IsValidResult(result))
                {
                    OnError(instance);
                    return;
                }

                OnMessage(String.Format("Ответ на запрос ключа : {0}", result), false);

                //int code = GetStatusCode(result);
                //if (!AuthResponse.IsValidCode(code))
                //{
                //  OnError(instance);
                //  return;
                //}

                result = EgateAPI.egGetAuthResult(instance.ID).GetString();
                if (!IsValidResult(result))
                {
                    OnError(instance);
                    return;
                }

                AuthResponse response = null;
                try
                {
                    response = AuthResponse.Parse(result, null);
                }
                catch (Exception x)
                {
                    OnMessage(x.Message, true);
                }

                if ((response == null) || !AuthResponse.IsValidCode(response.GCSCode))
                {
                    return;
                }

                _keyAcqiured = true;
                OnMessage(String.Format("Ключ получен успешно : {0}", response), false);
            }
            finally
            {
                ReleaseInstance(instance);
            }
        }
        private void ProcessTransaction(object sender, ElapsedEventArgs e)
        {
            string status = EgateAPI.egGetOpStatus(_current.ID, false).GetString();

            if (status[0] == EgateAPI.StatusResult)
            {
                _timer.Stop();
                OnMessage(String.Format("Запрос обработан : {0}", status.Substring(1)), false);

                AuthResponse response = null;
                try
                {
                    byte[] ba;
                    string result = EgateAPI.egGetAuthResult(_current.ID).GetString(out ba);
                    if (IsValidResult(result))
                    {
                        _lastTransactionResult = (_cancel == CancelState.Completed) ? TransactionResult.Cancelled : TransactionResult.OK;
                    }
                    else
                    {
                        _lastTransactionResult = TransactionResult.Error;
                        OnError(_current);
                    }

                    response = AuthResponse.Parse(result, ba);
                }
                catch (Exception x)
                {
                    OnMessage(x.Message, true);
                }
                finally
                {
                    OnTransactionCompleted(_lastTransactionResult, response);
                    _state = EquipmentState.CardTaken;
                    OnStateChanged(_state, status.Substring(1));
                }
            }
            else if (status[0] == EgateAPI.StatusBusy)
            {
                EquipmentState s = _state;
                switch (status[1])
                {
                case EgateAPI.StatusWaitCard:
                    //if (_state == EquipmentState.Started)
                    s = EquipmentState.WaitingForCard;
                    break;

                case EgateAPI.StatusCardEntered:
                    //if (_state == EquipmentState.WaitingForCard)
                    s = EquipmentState.CardInserted;
                    break;

                case EgateAPI.StatusPinEntered:
                    if (_state == EquipmentState.CardInserted)
                    {
                        s = EquipmentState.PinEntered;
                    }
                    break;

                case EgateAPI.StatusAuthCompleted:
                    if ((_state != EquipmentState.Started) && (_state != EquipmentState.WaitingForCard))
                    {
                        s = EquipmentState.AuthCompleted;
                    }
                    break;

                default:
                    s = _state;
                    break;
                }

                if (_state != s)
                {
                    _state = s;
                    OnStateChanged(_state, status.Substring(2));
                }
            }
        }