Ejemplo n.º 1
0
        public async Task ExchangeService(MasterSerialPort port, CancellationToken ct)
        {
            if (port == null)
            {
                return;
            }

            foreach (var devCashier in _deviceCashiers)              //Запуск опроса кассиров
            {
                var readProvider = new Server2CashierReadDataProvider {
                    InputData = devCashier.Cashier.Id
                };
                devCashier.DataExchangeSuccess = await port.DataExchangeAsync(_timeRespone, readProvider, ct);

                if (!devCashier.IsConnect)
                {
                    devCashier.Cashier.DisconectHandling();
                    continue;
                }

                if (readProvider.IsOutDataValid)
                {
                    TicketItem item;
                    var        cashierInfo = readProvider.OutputData;

                    if (!cashierInfo.IsWork)
                    {
                        continue;
                    }

                    switch (cashierInfo.Handling)
                    {
                    case CashierHandling.IsSuccessfulHandling:
                        devCashier.Cashier.SuccessfulHandling();
                        break;

                    case CashierHandling.IsErrorHandling:
                        devCashier.Cashier.ErrorHandling();
                        break;

                    case CashierHandling.IsStartHandling:
                        item = devCashier.Cashier.StartHandling();
                        var writeProvider = new Server2CashierWriteDataProvider {
                            InputData = item
                        };
                        await port.DataExchangeAsync(_timeRespone, writeProvider, ct);

                        if (writeProvider.IsOutDataValid)                    //завершение транзакции ( успешная передача билета кассиру)
                        {
                            devCashier.Cashier.SuccessfulStartHandling();
                        }
                        break;

                    case CashierHandling.IsSuccessfulAndStartHandling:
                        devCashier.Cashier.SuccessfulHandling();

                        item          = devCashier.Cashier.StartHandling();
                        writeProvider = new Server2CashierWriteDataProvider {
                            InputData = item
                        };
                        await port.DataExchangeAsync(_timeRespone, writeProvider, ct);

                        if (writeProvider.IsOutDataValid)                    //завершение транзакции ( успешная передача билета кассиру)
                        {
                            devCashier.Cashier.SuccessfulStartHandling();
                        }
                        break;

                    case CashierHandling.IsErrorAndStartHandling:
                        devCashier.Cashier.ErrorHandling();

                        item          = devCashier.Cashier.StartHandling();
                        writeProvider = new Server2CashierWriteDataProvider {
                            InputData = item
                        };
                        await port.DataExchangeAsync(_timeRespone, writeProvider, ct);

                        if (writeProvider.IsOutDataValid)                    //завершение транзакции ( успешная передача билета кассиру)
                        {
                            devCashier.Cashier.SuccessfulStartHandling();
                        }
                        break;

                    default:
                        item = null;
                        break;
                    }
                }
            }

            //Отправка запроса синхронизации времени раз в час
            if (_lastSyncLabel != DateTime.Now.Hour)
            {
                _lastSyncLabel = DateTime.Now.Hour;

                var syncTimeProvider = new Server2CashierSyncTimeDataProvider();
                await port.DataExchangeAsync(_timeRespone, syncTimeProvider, ct);
            }
        }
Ejemplo n.º 2
0
        public async Task ExchangeService(MasterSerialPort port, CancellationToken ct)
        {
            if (port == null)
            {
                return;
            }

            try
            {
                foreach (var devCashier in _deviceCashiers)                                                                                                                                                                                                                                                                        //Запуск опроса кассиров
                {
                    _loggerCashierInfo.Info($"---------------------------КАССИР: Id= {devCashier.Cashier.Id}   CurrentTicket= {(devCashier.Cashier.CurrentTicket != null ? devCashier.Cashier.CurrentTicket.Prefix + devCashier.Cashier.CurrentTicket.NumberElement.ToString("000") : "НЕТ")}----------------------------------"); //LOG;

                    var readProvider = new Server2CashierReadDataProvider(devCashier.AddresDevice, _logName);
                    devCashier.DataExchangeSuccess = await port.DataExchangeAsync(_timeRespone, readProvider, ct);

                    if (!devCashier.IsConnect)
                    {
                        _loggerCashierInfo.Info($"кассир НЕ на связи: Id= {devCashier.Cashier.Id}");//LOG;
                        devCashier.LastSyncLabel = 0;
                        continue;
                    }

                    if (readProvider.IsOutDataValid)
                    {
                        TicketItem item;
                        var        cashierInfo = readProvider.OutputData;

                        //Если устойство было не на связи, то Отправка запроса синхронизации времени раз в час, будет произведенна мгновенно.
                        if (devCashier.LastSyncLabel != DateTime.Now.Hour)
                        {
                            devCashier.LastSyncLabel = DateTime.Now.Hour;
                            var syncTimeProvider = new Server2CashierSyncTimeDataProvider(_logName);
                            await port.DataExchangeAsync(_timeRespone, syncTimeProvider, ct);
                        }

                        //TODO: проверить
                        if (!cashierInfo.IsWork)
                        {
                            //Если кассир быстро закрыла сессию (до того как опрос порта дошел до нее), то билет из обработки надо убрать.
                            if (devCashier.Cashier.CurrentTicket != null)
                            {
                                _loggerCashierInfo.Info($"Команда от кассира: Id= {devCashier.Cashier.Id}   Handling=\"Если кассир быстро закрыла сессию(до того как опрос порта дошел до нее). НО У НЕЕ БЫЛ ТЕКУЩИЙ ОБРАБАТЫВАЕМЫЙ БИЛЕТ\"    NameTicket= {cashierInfo.NameTicket}");//LOG;
                                //devCashier.Cashier.SuccessfulHandling();
                            }
                            continue;
                        }

                        switch (cashierInfo.Handling)
                        {
                        case CashierHandling.IsSuccessfulHandling:
                            if (!devCashier.Cashier.CanHandling)
                            {
                                break;
                            }
                            devCashier.Cashier.SuccessfulHandling();
                            break;


                        case CashierHandling.IsErrorHandling:
                            if (!devCashier.Cashier.CanHandling)
                            {
                                break;
                            }
                            devCashier.Cashier.ErrorHandling();
                            break;


                        case CashierHandling.IsStartHandling:
                            await WriteTicketTransaction(devCashier, cashierInfo.Handling, port, ct);

                            break;


                        case CashierHandling.IsSuccessfulAndStartHandling:
                            devCashier.Cashier.SuccessfulHandling();
                            await WriteTicketTransaction(devCashier, cashierInfo.Handling, port, ct);

                            break;


                        case CashierHandling.IsRedirectAndStartHandling:
                            if (_adminCashier != null)
                            {
                                var redirectTicket = devCashier.Cashier.CurrentTicket;
                                if (redirectTicket != null)
                                {
                                    _adminCashier.Cashier.AddRedirectedTicket(redirectTicket);
                                }

                                devCashier.Cashier.SuccessfulHandling();
                                await WriteTicketTransaction(devCashier, cashierInfo.Handling, port, ct);
                            }
                            break;


                        case CashierHandling.IsErrorAndStartHandling:
                            devCashier.Cashier.ErrorHandling();
                            await WriteTicketTransaction(devCashier, cashierInfo.Handling, port, ct);

                            break;


                        case CashierHandling.IsRedirectHandling:
                            if (_adminCashier != null)
                            {
                                if (!devCashier.Cashier.CanHandling)
                                {
                                    break;
                                }
                                var redirectTicket = devCashier.Cashier.CurrentTicket;
                                if (redirectTicket != null)
                                {
                                    _adminCashier.Cashier.AddRedirectedTicket(redirectTicket);
                                }
                                devCashier.Cashier.SuccessfulHandling();
                            }
                            break;

                        default:
                            item = null;
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _loggerCashierInfo.Info($"EXCEPTION CashierExchangeService:   {ex.ToString()}");
            }
        }