Exemplo n.º 1
0
        /// <summary>
        ///     <para>
        ///         Initializes a new instance of the <see cref="DataCommand{T}"/> class using the specified name and options.
        ///     </para>
        /// </summary>
        /// <remarks>
        ///     <para>
        ///         Usually, the data command's name is passed by child classes to identify themselves.
        ///         It is an ID for the command, that will be found on logs and statistics.
        ///     </para>
        /// </remarks>
        /// <param name="name">The name of this data command.</param>
        /// <param name="options">The options to use.</param>
        /// <param name="loggerFactory">The Factory Service to be used when creating loggers for this command.</param>
        protected DataCommand(string name, DataCommandOptions options, ILoggerFactory loggerFactory)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }
            if (null == options)
            {
                throw new ArgumentNullException("options");
            }
            if (null == loggerFactory)
            {
                throw new ArgumentNullException("loggerFactory");
            }

            // Test if a connection string was provided
            if (string.IsNullOrWhiteSpace(options.ConnectionString))
            {
                throw new ArgumentException("A connection string must be supplied within options parameter.");
            }

            //Setup command's name
            Name = name;

            //Setup internal command options
            _options = options;

            //Creates the default logger, that can be used by child classes
            Logger = loggerFactory.CreateLogger(GetType());

            //Creates the command statistics
            Statistics = new CommandStatistics()
            {
                Name = Name
            };
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instace of <see cref="BatchDataCommand{T}"/>
 /// </summary>
 /// <param name="name"></param>
 /// <param name="batchSize">The size for the batch operations (i.e., the size of objects to be hold before an execution happens)</param>
 /// <param name="options"></param>
 /// <param name="loggerFactory">The Factory Service to be used when creating loggers for this command.</param>
 public BatchDataCommand(string name, int batchSize, DataCommandOptions options, ILoggerFactory loggerFactory)
     : base(name, options, loggerFactory)
 {
     BatchSize = batchSize;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Executes the data command inside the provided connection.
 /// </summary>
 /// <param name="connection">The connection to the database to be used.</param>
 /// <param name="options">The options for this command execution.</param>
 /// <returns>A <see cref="T"/> instance, result from the execution within this connection.</returns>
 protected abstract T Execute(IDbConnection connection, DataCommandOptions options);