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 { } }
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 { } }
public Command(string name, ExecuteCommandDelegate commandDelegate) { _commandName = name; _commandDelegate = commandDelegate; _commandDescription = ""; _argumentMap = new Dictionary <String, CommandArgument>(); }
//*************************************************************************** // Thread Methods // private void ExecuteCommandCallback(IAsyncResult state) { ExecuteCommandDelegate del = (ExecuteCommandDelegate)state.AsyncState; this._qryRslt = del.EndInvoke(state); this.ReadCompleteEvent(); }
public DelegateCommand(ExecuteCommandDelegate <T> executeCommand, CanExecuteCommandDelegate <T> canExecuteCommand) { Check.NotNull(executeCommand, "executeCommand"); Check.NotNull(canExecuteCommand, "canExecuteCommand"); _executeCommand = executeCommand; _canExecuteCommand = canExecuteCommand; }
/// <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); }
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(); } }
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(); } }
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)); }
/// <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); }
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); } } }
/// <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); }
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(); } } }
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); } }
public DelegateCommand(ExecuteCommandDelegate execute, CanExecuteCommandDelegate canExecute) { this.execute = execute; this.canExecute = canExecute; }
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) { }
public EnlistedCommand(PrepareCommandDelegate preparing, ExecuteCommandDelegate executor) { executor_ = executor; preparing_ = preparing; }
/// <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); }
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); }
/// <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; }
public RelayCommand(ExecuteCommandDelegate execute, CanExecuteCommandDelegate canExecute) { this._execute = execute; this._canExecute = canExecute; }
public DelegateCommand(ExecuteCommandDelegate <T> executeCommand) : this(executeCommand, x => true) { }
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)); }
private void ExecuteDriverCommand(ExecuteCommandDelegate executeCommandDelegate) { ExecuteDriverCommand(false, executeCommandDelegate); }