Ejemplo n.º 1
0
 /// <summary>
 /// Asynchronously open the store connection.
 /// </summary>
 /// <returns>A task to await completion of the Open</returns>
 public virtual Task OpenAsync()
 {
     return(SqlUtils.WithSqlExceptionHandlingAsync(() =>
     {
         return _conn.OpenAsync();
     }));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Asynchronously executes the given operation using the <paramref name="operationData"/> values
        /// as input to the operation.
        /// </summary>
        /// <param name="operationName">Operation to execute.</param>
        /// <param name="operationData">Input data for operation.</param>
        /// <returns>Task encapsulating storage results object.</returns>
        public virtual Task <IStoreResults> ExecuteOperationAsync(string operationName, XElement operationData)
        {
            return(SqlUtils.WithSqlExceptionHandlingAsync <IStoreResults>(async() =>
            {
                SqlResults results = new SqlResults();

                using (SqlCommand cmd = _conn.CreateCommand())
                    using (XmlReader input = operationData.CreateReader())
                    {
                        cmd.Transaction = _tran;
                        cmd.CommandText = operationName;
                        cmd.CommandType = CommandType.StoredProcedure;

                        SqlUtils.AddCommandParameter(cmd, "@input", SqlDbType.Xml, ParameterDirection.Input, -1, new SqlXml(input));

                        SqlParameter result = SqlUtils.AddCommandParameter(cmd, "@result", SqlDbType.Int, ParameterDirection.Output, 0, 0);

                        using (SqlDataReader reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false))
                        {
                            await results.FetchAsync(reader).ConfigureAwait(false);
                        }

                        // Output parameter will be used to specify the outcome.
                        results.Result = (StoreResult)result.Value;
                    }

                return results;
            }));
        }