Tortuga.Chain.PostgreSqlDataSource.Execute C# (CSharp) Method

Execute() protected method

Executes the specified operation.
executionToken;executionToken is null. /// or /// implementation;implementation is null.
protected Execute ( NpgsqlParameter>.CommandExecutionToken executionToken, CommandImplementation implementation, object state ) : int?
executionToken NpgsqlParameter>.CommandExecutionToken The execution token.
implementation CommandImplementation The implementation that handles processing the result of the command.
state object User supplied state.
return int?
        protected override int? Execute(CommandExecutionToken<NpgsqlCommand, NpgsqlParameter> executionToken, CommandImplementation<NpgsqlCommand> implementation, object state)
        {
            if (executionToken == null)
                throw new ArgumentNullException("executionToken", "executionToken is null.");
            if (implementation == null)
                throw new ArgumentNullException("implementation", "implementation is null.");

            var startTime = DateTimeOffset.Now;
            OnExecutionStarted(executionToken, startTime, state);

            try
            {
                using (var con = CreateConnection())
                {
                    using (var cmd = new NpgsqlCommand())
                    {
                        cmd.Connection = con;
                        if (DefaultCommandTimeout.HasValue)
                            cmd.CommandTimeout = (int)DefaultCommandTimeout.Value.TotalSeconds;
                        cmd.CommandText = executionToken.CommandText;
                        cmd.CommandType = executionToken.CommandType;
                        foreach (var param in executionToken.Parameters)
                            cmd.Parameters.Add(param);

                        executionToken.ApplyCommandOverrides(cmd);

                        int? rows;

                        if (((PostgreSqlCommandExecutionToken)executionToken).DereferenceCursors)
                            rows = DereferenceCursors(cmd, implementation);
                        else
                            rows = implementation(cmd);

                        executionToken.RaiseCommandExecuted(cmd, rows);
                        OnExecutionFinished(executionToken, startTime, DateTimeOffset.Now, rows, state);
                        return rows;
                    }
                }
            }
            catch (Exception ex)
            {
                OnExecutionError(executionToken, startTime, DateTimeOffset.Now, ex, state);
                throw;
            }
        }

Same methods

PostgreSqlDataSource::Execute ( NpgsqlTransaction>.OperationExecutionToken executionToken, NpgsqlTransaction>.OperationImplementation implementation, object state ) : int?