Esempio n. 1
0
        private void ReaderEnabled(bool enabled)
        {
            tbReadData.Enabled = enabled;
            try
            {
                if (enabled)
                {
                    _dmClient = new DeviceManagerClient("localhost");
                    _dmClient.Login();
                    if (_dmClient.Capture(deviceId, 5))
                    {
                        _device = (IGenericReader)_dmClient[deviceId];
                    }
                    else
                    {
                        MessageBox.Show(
                            string.Format("Не удалось получить доступ к устройству \"{0}\"",
                                          deviceId), "Тест устройства", MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                }
                else
                {
                    if (_dmClient != null && _dmClient.Logged)
                    {
                        if (_device != null)
                        {
                            _dmClient.Release(deviceId);
                        }
                        _dmClient = null;
                        _device   = null;
                    }
                }
            }
            catch (Exception E)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(string.Format("Ошибка тестирования устройства \"{0}\".",
                                            deviceId));
                sb.AppendLine(string.Format("Тип: {0}.", E.GetType().Name));
                sb.AppendLine(string.Format("Сообщение: {0}.", E.Message));
                sb.AppendLine("Трассировка стека:");
                sb.Append(E.StackTrace);

                MessageBox.Show(sb.ToString(), "Тест устройства", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                Close();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Захват устройства
        /// </summary>
        private void CaptureDevice()
        {
            if (_client != null && _device != null)
            {
                // устройство уже захвачено
                return;
            }

            // подключаемся к диспетчеру устройств
            _client = new DeviceManagerClient(_unitSettings.HostOrIp, _unitSettings.Port);
            _client.Login();
            // захватываем турникет
            _client.Capture(_unitSettings.DeviceId, Timeout.Infinite);
            _device = (ITurnstileDevice)_client[_unitSettings.DeviceId];
            // подключение установлено
            _eventLink.Post(TsGlobalConst.EventSource, string.Format(
                                "[0] Подключение к диспетчеру устройств установлено", _unitSettings));
        }
Esempio n. 3
0
        /// <summary>
        /// Выполнение теста
        /// </summary>
        public void Execute()
        {
            try
            {
                using (DeviceManagerClient dmClient = new DeviceManagerClient("localhost"))
                {
                    dmClient.Login();
                    if (dmClient.Capture(_deviceId, 5))
                    {
                        try
                        {
                            if (_testCallback != null)
                            {
                                _testCallback((TIntf)dmClient[_deviceId]);
                            }
                        }
                        finally
                        {
                            dmClient.Release(_deviceId);
                        }
                    }
                    else
                    {
                        MessageBox.Show(
                            string.Format("Не удалось получить доступ к устройству \"{0}\"",
                                          _deviceId), "Тест устройства", MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                }
            }
            catch (Exception e)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(string.Format("Ошибка тестирования устройства \"{0}\".",
                                            _deviceId));
                sb.AppendLine(string.Format("Тип: {0}.", e.GetType().Name));
                sb.AppendLine(string.Format("Сообщение: {0}.", e.Message));
                sb.AppendLine("Трассировка стека:");
                sb.Append(e.StackTrace);

                MessageBox.Show(sb.ToString(), "Тест устройства", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Освобождаем устройство
        /// </summary>
        private void ReleaseDevice()
        {
            if (_client == null)
            {
                // устройство свободно
                return;
            }

            try
            {
                // освобождаем устройство
                _client.Release(_unitSettings.DeviceId);
                // закрываем клиентскую сессию
                _client.Dispose();
            }
            catch (LoginToDeviceManagerException)
            {
            }
            catch (DeviceManagerException)
            {
            }
            catch (DeviceNoFoundException)
            {
            }
            catch (SocketException)
            {
            }
            catch (RemotingException)
            {
            }
            finally
            {
                _client = null;
                _device = null;

                // подключение закрыто
                _eventLink.Post(TsGlobalConst.EventSource, string.Format(
                                    "[0] Подключение к диспетчеру устройств закрыто", _unitSettings));
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("POS device manager test utility");
            Console.WriteLine("version 2.0");
            Console.WriteLine();

            try
            {
                if (args.Length == 0)
                {
                    ViewHelp();
                }
                else
                {
                    string host = args.Length > 0 ? args[0] : "localhost";
                    using (DeviceManagerClient dmc = new DeviceManagerClient(host))
                    {
                        dmc.Login();
                        string deviceID = args.Length > 1 ? args[1] : "”стройство1";
                        dmc.Capture(deviceID, WaitConstant.Infinite);
                        try
                        {
                            IPrintableDevice device = (IPrintableDevice)dmc[deviceID];
                            Console.WriteLine(string.Format("Device status: {0}",
                                                            device.Active ? "active" : "inactive"));

                            if (!device.Active)
                            {
                                Console.WriteLine("Trying to re-activate.");
                                device.Active = true;
                                if (!device.Active)
                                {
                                    Console.WriteLine("Re-activate failed.");
                                }
                                else
                                {
                                    Console.WriteLine("Re-activate succeeded.");
                                }
                            }

                            if (device.Active)
                            {
                                PaperOutStatus paperStatus = device.PrinterStatus.PaperOut;
                                if (ProcessErrorCode(device.ErrorCode, false))
                                {
                                    Console.WriteLine(string.Format("Paper: {0}", paperStatus));
                                    if (paperStatus == PaperOutStatus.Present || paperStatus == PaperOutStatus.OutAfterActive)
                                    {
                                        XmlDocument xmlDoc = new XmlDocument();
                                        xmlDoc.Load(args.Length > 2 ? args[2] : "receipt.xml");
                                        device.Print(xmlDoc.OuterXml);
                                        ProcessErrorCode(device.ErrorCode, true);
                                    }
                                    else
                                    {
                                        Console.WriteLine("Printer not ready.");
                                    }
                                }
                            }
                        }
                        finally
                        {
                            dmc.Release(deviceID);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception.");
                Console.WriteLine(e.Message);
                Console.WriteLine("View stack trace (y/n)?:");
                ConsoleKeyInfo info = Console.ReadKey(true);
                Console.WriteLine();
                if (info.Key == ConsoleKey.Y)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }

            Console.WriteLine("Done. Press any key.");
            Console.ReadKey(true);
        }