Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DatabaseQuery{T}"/> class.
        /// </summary>
        /// <param name="database">The <see cref="DatabaseBase"/>.</param>
        /// <param name="queryArgs">The <see cref="IDatabaseArgs"/>.</param>
        /// <param name="queryParams">The query <see cref="DatabaseParameters"/> action/delegate.</param>
        internal DatabaseQuery(DatabaseBase database, DatabaseArgs <T> queryArgs, Action <DatabaseParameters> queryParams)
        {
            var db = database ?? throw new ArgumentNullException(nameof(database));

            QueryArgs = queryArgs ?? throw new ArgumentNullException(nameof(queryArgs));
            Command   = db.StoredProcedure(QueryArgs.StoredProcedure).Params(queryParams);
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DatabaseCommand"/> class.
        /// </summary>
        /// <param name="database">The <see cref="DatabaseBase"/>.</param>
        /// <param name="commandText">The command text.</param>
        /// <param name="commandType">The <see cref="CommandType"/>.</param>
        public DatabaseCommand(DatabaseBase database, string commandText, CommandType commandType = CommandType.StoredProcedure)
        {
            if (string.IsNullOrEmpty(commandText))
            {
                throw new ArgumentNullException(nameof(commandText));
            }

            Database              = database ?? throw new ArgumentNullException(nameof(database));
            DbCommand             = Database.Provider.CreateCommand();
            DbCommand.CommandText = commandText;
            DbCommand.CommandType = commandType;
            Parameters            = new DatabaseParameters(this);
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DatabaseCommand"/> class.
        /// </summary>
        /// <param name="database">The <see cref="DatabaseBase"/>.</param>
        /// <param name="commandText">The command text.</param>
        /// <param name="commandType">The <see cref="CommandType"/>.</param>
        public DatabaseCommand(DatabaseBase database, string commandText, CommandType commandType = CommandType.StoredProcedure)
        {
            if (string.IsNullOrEmpty(commandText))
            {
                throw new ArgumentNullException(nameof(commandText));
            }

            Database  = database ?? throw new ArgumentNullException(nameof(database));
            DbCommand = Database.Provider.CreateCommand();
#pragma warning disable CA2100 // Review SQL queries for security vulnerabilities; by-design, trusts that the consumer has validated the command text where applicable.
            DbCommand.CommandText = commandText;
#pragma warning restore CA2100
            DbCommand.CommandType = commandType;
            Parameters            = new DatabaseParameters(this);
        }
Beispiel #4
0
 /// <summary>
 /// Invokes an <paramref name="action"/> synchronously.
 /// </summary>
 /// <param name="caller">The calling (invoking) object.</param>
 /// <param name="action">The function to invoke.</param>
 /// <param name="param">The optional parameter passed to the invoke.</param>
 /// <param name="memberName">The method or property name of the caller to the method.</param>
 /// <param name="filePath">The full path of the source file that contains the caller.</param>
 /// <param name="lineNumber">The line number in the source file at which the method is called.</param>
 protected override void WrapInvoke(object caller, Action action, DatabaseBase param = null, [CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int lineNumber = 0)
 {
     CreateSyncPolicy().Execute(() => base.WrapInvoke(caller, action, param, memberName, filePath, lineNumber));
 }
Beispiel #5
0
 /// <summary>
 /// Invokes a <paramref name="func"/> with a <typeparamref name="TResult"/> asynchronously.
 /// </summary>
 /// <typeparam name="TResult">The result <see cref="Type"/>.</typeparam>
 /// <param name="caller">The calling (invoking) object.</param>
 /// <param name="func">The function to invoke.</param>
 /// <param name="param">The optional parameter passed to the invoke.</param>
 /// <param name="memberName">The method or property name of the caller to the method.</param>
 /// <param name="filePath">The full path of the source file that contains the caller.</param>
 /// <param name="lineNumber">The line number in the source file at which the method is called.</param>
 /// <returns>The result.</returns>
 protected override Task <TResult> WrapInvokeAsync <TResult>(object caller, Func <Task <TResult> > func, DatabaseBase param = null, [CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int lineNumber = 0)
 {
     return(CreateAsyncPolicy().ExecuteAsync(() => base.WrapInvokeAsync(caller, func, param, memberName, filePath, lineNumber)));
 }