예제 #1
0
        public Dictionary <BaseATCommand, bool> RunCommands(List <BaseATCommand> aCommands, CommandType aType, out string aErrorMessage, bool aForceSettings = true)
        {
            aErrorMessage = "";
            Dictionary <BaseATCommand, bool> zResult = new Dictionary <BaseATCommand, bool>();

            try
            {
                _communicatorInstance.Activate(aForceSettings);

                if (DeviceWakeUp())
                {
                    foreach (BaseATCommand zCommand in aCommands)
                    {
                        switch (aType)
                        {
                        case CommandType.ctRead:
                            _logger.Debug("readable command");
                            if (zCommand is IReadableCommand)
                            {
                                zResult[zCommand] = RunSingleReadableCommand((IReadableCommand)zCommand);
                            }
                            else
                            {
                                zResult[zCommand] = false;
                            }
                            break;

                        case CommandType.ctWrite:
                            _logger.Debug("writable command");
                            if (zCommand is IWritableCommand)
                            {
                                zResult[zCommand] = RunSingleWritableCommand((IWritableCommand)zCommand);
                            }
                            else
                            {
                                zResult[zCommand] = false;
                            }
                            break;

                        case CommandType.ctRun:
                            _logger.Debug("runnable command");
                            if (zCommand is IRunnableComand)
                            {
                                zResult[zCommand] = RunSingleRunnableCommand((IRunnableComand)zCommand);
                            }
                            else
                            {
                                zResult[zCommand] = false;
                            }
                            break;

                        default:
                            _logger.Debug("Unknown command type");
                            aErrorMessage = "Неизвестный тип команды";
                            break;
                        }
                    }

                    _communicatorInstance.Deactivate();
                    return(zResult);;
                }
                else
                {
                    _logger.Debug("No answer");
                    aErrorMessage = "Нет ответа от устройства";
                    return(zResult);
                }
            }
            catch (Exception zException)
            {
                _logger.WarnException("Handled exception", zException);
                aErrorMessage = zException.Message;
            }

            return(zResult);
        }