示例#1
0
        private void ExecuteDriverCommand(ExecuteCommandDelegate executeCommandDelegate)
        {
            ErrorCode = new ServerErrorCode(this, GeneralError.Success);
            try
            {
                if (!Active)
                {
                    ErrorCode = new ServerErrorCode(this, GeneralError.Inactive);
                    return;
                }

                executeCommandDelegate();

                if (_errorCode < 0x1000)
                {
                    ErrorCode = new ServerErrorCode(this, _errorCode, GetSpecificDescription(_errorCode));
                }
                else
                {
                    ErrorCode = new ServerErrorCode(this, (GeneralError)_errorCode);
                }
            }
            catch (TimeoutException)
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Timeout);
            }
            catch (Exception E)
            {
                ErrorCode = new ServerErrorCode(this, E);
            }
            finally
            {
            }
        }
示例#2
0
        private void ExecuteDriverCommand(ExecuteCommandDelegate executeCommandDelegate)
        {
            ErrorCode = new ServerErrorCode(this, GeneralError.Success);
            try
            {
                if (!Active)
                {
                    ErrorCode = new ServerErrorCode(this, GeneralError.Inactive);
                    return;
                }

                executeCommandDelegate();
            }
            catch (TimeoutException)
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Timeout);
            }
            catch (Exception E)
            {
                ErrorCode = new ServerErrorCode(this, E);
            }
            finally
            {
            }
        }
示例#3
0
 public Command(string name, ExecuteCommandDelegate commandDelegate)
 {
     _commandName        = name;
     _commandDelegate    = commandDelegate;
     _commandDescription = "";
     _argumentMap        = new Dictionary <String, CommandArgument>();
 }
示例#4
0
        //***************************************************************************
        // Thread Methods
        //
        private void ExecuteCommandCallback(IAsyncResult state)
        {
            ExecuteCommandDelegate del = (ExecuteCommandDelegate)state.AsyncState;

            this._qryRslt = del.EndInvoke(state);

            this.ReadCompleteEvent();
        }
示例#5
0
        public DelegateCommand(ExecuteCommandDelegate <T> executeCommand, CanExecuteCommandDelegate <T> canExecuteCommand)
        {
            Check.NotNull(executeCommand, "executeCommand");
            Check.NotNull(canExecuteCommand, "canExecuteCommand");

            _executeCommand    = executeCommand;
            _canExecuteCommand = canExecuteCommand;
        }
示例#6
0
        /// <summary>
        /// Adds the specified command handler associated with the command type.
        /// </summary>
        /// <param name="commandType">The command type.</param>
        /// <param name="handler">The command handler.</param>
        /// <exception cref="CommandTypeAlreadyRegisteredException">Thrown when a command with the specified handler is already registered.</exception>
        public void AddCommandHandler(CommandType commandType, ExecuteCommandDelegate handler)
        {
            if (_commandHandles.ContainsKey(commandType))
            {
                throw new CommandTypeAlreadyRegisteredException();
            }

            _commandHandles.Add(commandType, handler);
        }
示例#7
0
        private void ExecuteDriverCommand(bool printerMode, ExecuteCommandDelegate executeCommandDelegate)
        {
            ErrorCode = new ServerErrorCode(this, GeneralError.Success);
            try
            {
                if (!Active)
                {
                    ErrorCode = new ServerErrorCode(this, GeneralError.Inactive);
                    return;
                }

                if (!IsPrim02)
                {
                    // проверяем текущий режим
                    if (_deviceProtocol.IsPrinterMode != printerMode)
                    {
                        // устанавливаем нужный режим
                        _deviceProtocol.IsPrinterMode = printerMode;
                    }
                }

                executeCommandDelegate();
            }
            catch (TimeoutException)
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Timeout, _deviceProtocol.GetCommandDump());
                if (_deviceProtocol.IsPrinterMode)
                {
                    _deviceProtocol.IsPrinterMode = false;
                }
            }
            catch (PrintableErrorException)
            {
                // Ошибка печатающего устройства. Документ не отменяется
                ErrorCode = new ServerErrorCode(this, 0x18, GetSpecificDescription(0x18), _deviceProtocol.GetCommandDump());
            }
            catch (DeviceErrorException E)
            {
                // Протокольная ошибка. Документ нужно попробовать отменить
                ErrorCode = new ServerErrorCode(this, E.ErrorCode, GetSpecificDescription(E.ErrorCode), _deviceProtocol.GetCommandDump());
                CancelDocument(_deviceProtocol.IsPrinterMode);
            }
            catch (Exception E)
            {
                ErrorCode = new ServerErrorCode(this, E);
            }
            finally
            {
                if (!ErrorCode.Succeeded && Logger.DebugInfo && !string.IsNullOrEmpty(_deviceProtocol.DebugInfo))
                {
                    Logger.SaveDebugInfo(this, _deviceProtocol.DebugInfo);
                }
//                _deviceProtocol.ClearDebugInfo();
            }
        }
示例#8
0
        public void BeginExecuteCommand()
        {
            if (string.IsNullOrEmpty(this._connStr) || string.IsNullOrEmpty(this._cmndStr))
            {
                throw new Exception("Connection and command strings must be populated in order for data read thread to complete.");
            }

            ExecuteCommandDelegate del = new ExecuteCommandDelegate(this.ExecuteCommand);

            del.BeginInvoke(this._connStr, this._cmndStr, this._prvType, new AsyncCallback(this.ExecuteCommandCallback), del);
        }
        private void ExecuteDriverCommand(ExecuteCommandDelegate executeCommandDelegate)
        {
            ErrorCode = new ServerErrorCode(this, GeneralError.Success);
            try
            {
                if (!Active)
                {
                    ErrorCode = new ServerErrorCode(this, GeneralError.Inactive);
                    return;
                }

                executeCommandDelegate();
            }
            catch (TimeoutException)
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Timeout);
            }
            catch (Exception E)
            {
                debugInfo.AppendLine();
                debugInfo.AppendLine("Full exception info:");
                debugInfo.AppendLine();

                var currentException = E;
                var level            = 0;
                do
                {
                    debugInfo.AppendFormat("[{0}]", level);
                    debugInfo.AppendLine();
                    debugInfo.AppendFormat("Exception: {0}", currentException.Message);
                    debugInfo.AppendFormat("Type: {0}", currentException.GetType());
                    debugInfo.AppendFormat("Stack trace: {0}", currentException.StackTrace);
                    debugInfo.AppendLine();

                    level++;
                    currentException = currentException.InnerException;
                }while (currentException != null);

                Logger.SaveDebugInfo(this, debugInfo.ToString());
                ClearDebugInfo();

                ErrorCode = new ServerErrorCode(this, E);
            }
            finally
            {
                if (!ErrorCode.Succeeded && Logger.DebugInfo && !string.IsNullOrEmpty(debugInfo.ToString()))
                {
                    Logger.SaveDebugInfo(this, debugInfo.ToString());
                }
                ClearDebugInfo();
            }
        }
示例#10
0
        public virtual T Select <T>(string query, object parameters = null, QueryOptions options = null)
        {
            ExecuteCommandDelegate <T> selectFunc = command =>
            {
                var dataReader = command.ExecuteReader();
                using (var dataReaderAdapter = new DataReaderAdapter(dataReader))
                {
                    return((T)_objectBuilderInvoker.CreateInstance(new ObjectBuilderContext(typeof(T), dataReaderAdapter)));
                }
            };

            return(InvokeFlow(query, parameters, options, InvokeMethod.Select, selectFunc));
        }
示例#11
0
 /// <inheritdoc/>
 public void Enlist(PrepareCommandDelegate command,
   ExecuteCommandDelegate executor) {
   var enlisted = new EnlistedCommand(delegate(ITransactionContext context)
   {
     var cmd = command(context);
     if (cmd.Connection != connection_) {
       throw new ArgumentException(
         Resources.Resources.Arg_TransactionContext_Command_Connection);
     }
     return cmd;
   }, executor);
   commands_.Enqueue(enlisted);
 }
示例#12
0
        public Command(string name, ExecuteCommandDelegate commandDelegate, CommandArgument[] arguments, string description)
        {
            _commandName        = name;
            _commandDelegate    = commandDelegate;
            _commandDescription = description;
            _argumentMap        = new Dictionary <String, CommandArgument>();

            if (arguments != null)
            {
                foreach (CommandArgument argument in arguments)
                {
                    _argumentMap.Add(argument.ArgumentName, argument);
                }
            }
        }
示例#13
0
        /// <inheritdoc/>
        public void Enlist(PrepareCommandDelegate command,
                           ExecuteCommandDelegate executor)
        {
            var enlisted = new EnlistedCommand(delegate(ITransactionContext context)
            {
                var cmd = command(context);
                if (cmd.Connection != connection_)
                {
                    throw new ArgumentException(
                        Resources.Resources.Arg_TransactionContext_Command_Connection);
                }
                return(cmd);
            }, executor);

            commands_.Enqueue(enlisted);
        }
示例#14
0
        protected virtual T InvokeFlow <T>(string query, object parameters, QueryOptions options, InvokeMethod invokeMethod,
                                           ExecuteCommandDelegate <T> executeCommandFunc)
        {
            var resultType = typeof(T);

            using (var command = _configuration.DataObjectFactory.CreateCommand())
            {
                command.CommandText = query;
                command.Connection  = Connection;
                command.Transaction = _transaction;

                _optionsConfigurator.ConfigureCommand(command, options);

                _interceptoInvoker.OnEntry(new AdoExecutorContext(query, parameters, resultType, invokeMethod, Connection,
                                                                  command, _configuration));

                _parameterExtractorInvoker.ExtractParameter(new AdoExecutorContext(query, parameters, resultType, invokeMethod,
                                                                                   Connection, command, _configuration));

                System.Exception exception = null;
                var result = default(T);

                try
                {
                    TryOpenConnection();
                    result = executeCommandFunc(command);

                    _interceptoInvoker.OnSuccess(new InterceptorSuccessContext(query, parameters, resultType,
                                                                               invokeMethod, Connection, command, _configuration, result));
                }
                catch (System.Exception ex)
                {
                    exception = ex;

                    _interceptoInvoker.OnError(new InterceptorErrorContext(query, parameters, resultType, invokeMethod,
                                                                           Connection, command, _configuration, ex));
                    throw;
                }
                finally
                {
                    _interceptoInvoker.OnExit(new InterceptorExitContext(query, parameters, resultType, invokeMethod,
                                                                         Connection, command, _configuration, result, exception));
                }

                return(result);
            }
        }
 /// <inheritdoc/>
 public void Enlist(PrepareCommandDelegate preparing,
   ExecuteCommandDelegate executor) {
   bool should_close_connection = false;
   try {
     if (connection_.State != ConnectionState.Open) {
       should_close_connection = true;
       connection_.Open();
     }
     executor(preparing(this));
   } catch (Exception e) {
     throw new ProviderException(e);
   } finally {
     if (should_close_connection) {
       connection_.Close();
     }
   }
 }
示例#16
0
        private void ExecuteDriverCommand(bool printable, ExecuteCommandDelegate executeCommandDelegate)
        {
            ErrorCode = new ServerErrorCode(this, GeneralError.Success);

            if (!Active)
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Inactive);
                return;
            }

            try
            {
                if (_spProtocol == null)
                {
                    _spProtocol = new SPProtocol(Port, PASSWORD);
                }
                executeCommandDelegate(_spProtocol);
                if (printable)
                {
                    _paperStatus = PaperOutStatus.Present;
                }
            }
            catch (TimeoutException)
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Timeout, _spProtocol.GetCommandDump());
            }
            catch (DeviceErrorException E)
            {
                // отлавливаем ошибки принтера
                if (E.ErrorCode == 8 || E.ErrorCode == 9)
                {
                    _paperStatus = PaperOutStatus.OutPassive;
                }
                else if (E.ErrorCode == 1 && _paperStatus != PaperOutStatus.Present)
                {
                }

                ErrorCode = new ServerErrorCode(this, E.ErrorCode, GetSpecificDescription(E.ErrorCode),
                                                _spProtocol.GetCommandDump());
            }
            catch (Exception E)
            {
                ErrorCode = new ServerErrorCode(this, E);
            }
        }
示例#17
0
        /// <inheritdoc/>
        public void Enlist(PrepareCommandDelegate preparing,
                           ExecuteCommandDelegate executor)
        {
            bool should_close_connection = false;

            try {
                if (connection_.State != ConnectionState.Open)
                {
                    should_close_connection = true;
                    connection_.Open();
                }
                executor(preparing(this));
            } catch (Exception e) {
                throw new ProviderException(e);
            } finally {
                if (should_close_connection)
                {
                    connection_.Close();
                }
            }
        }
示例#18
0
 public DelegateCommand(ExecuteCommandDelegate execute, CanExecuteCommandDelegate canExecute)
 {
     this.execute = execute;
     this.canExecute = canExecute;
 }
示例#19
0
 public DelegateCommand(ExecuteCommandDelegate execute)
     : this(execute, null)
 {
 }
 public RelayCommand(ExecuteCommandDelegate execute, CanExecuteCommandDelegate canExecute)
 {
     this.execute    = execute;
     this.canExecute = canExecute;
 }
 public RelayCommand(ExecuteCommandDelegate execute) : this(execute, null)
 {
 }
 public DelegateCommand(ExecuteCommandDelegate <T> execute, CanExecuteCommandDelegate <T> canExecute)
 {
     this.execute    = execute;
     this.canExecute = canExecute;
 }
 public DelegateCommand(ExecuteCommandDelegate <T> execute) : this(execute, null)
 {
 }
示例#24
0
 public EnlistedCommand(PrepareCommandDelegate preparing,
   ExecuteCommandDelegate executor) {
   executor_ = executor;
   preparing_ = preparing;
 }
示例#25
0
        /// <summary>
        /// Adds the specified command handler associated with the command type.
        /// </summary>
        /// <param name="commandType">The command type.</param>
        /// <param name="commandGroup">The command group.</param>
        /// <param name="handler">The command handler.</param>
        public void AddCommandHandler(CommandType commandType, CommandGroup commandGroup, ExecuteCommandDelegate handler)
        {
            var commandHandle = new CommandHandle(commandType, commandGroup, handler);

            _commandHandles.Add(commandHandle);
        }
示例#26
0
        public void BeginExecuteCommand()
        {
            if (string.IsNullOrEmpty(this._connStr) || string.IsNullOrEmpty(this._cmndStr))
                throw new Exception("Connection and command strings must be populated in order for data read thread to complete.");

            ExecuteCommandDelegate del = new ExecuteCommandDelegate(this.ExecuteCommand);
            del.BeginInvoke(this._connStr, this._cmndStr, this._prvType, new AsyncCallback(this.ExecuteCommandCallback), del);
        }
示例#27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandHandle"/> class.
 /// </summary>
 /// <param name="commandType">The command type.</param>
 /// <param name="commandGroup">The command group.</param>
 /// <param name="executeCommandDelegate">The execute command delegate.</param>
 public CommandHandle(CommandType commandType, CommandGroup commandGroup, ExecuteCommandDelegate executeCommandDelegate)
 {
     CommandType            = commandType;
     CommandGroup           = commandGroup;
     ExecuteCommandDelegate = executeCommandDelegate;
 }
示例#28
0
 public RelayCommand(ExecuteCommandDelegate execute, CanExecuteCommandDelegate canExecute)
 {
     this._execute = execute;
     this._canExecute = canExecute;
 }
示例#29
0
 public DelegateCommand(ExecuteCommandDelegate <T> executeCommand) : this(executeCommand, x => true)
 {
 }
示例#30
0
        public virtual int Execute(string query, object parameters = null, QueryOptions options = null)
        {
            ExecuteCommandDelegate <int> executeFunc = command => command.ExecuteNonQuery();

            return(InvokeFlow(query, parameters, options, InvokeMethod.Execute, executeFunc));
        }
示例#31
0
 private void ExecuteDriverCommand(ExecuteCommandDelegate executeCommandDelegate)
 {
     ExecuteDriverCommand(false, executeCommandDelegate);
 }
示例#32
0
 public EnlistedCommand(PrepareCommandDelegate preparing,
                        ExecuteCommandDelegate executor)
 {
     executor_  = executor;
     preparing_ = preparing;
 }