示例#1
0
        /// <summary>
        /// Execute non query command asyncronously.
        /// </summary>
        /// <param name="command">The complete command</param>
        /// <param name="callback">The callback action handler.</param>
        /// <param name="callbackException">The callback action exception handler.</param>
        /// <param name="state">The action state.</param>
        public static async void ExecuteCommand(DbCommand command,
                                                Action <Nequeo.Threading.AsyncOperationResult <Int32> > callback,
                                                Action <Nequeo.Threading.AsyncOperationResult <System.Exception> > callbackException, object state = null)
        {
            // Check to see if the critical parameters
            // have been set, throw exception on each.
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            AsyncExecuteCommand ret = new AsyncExecuteCommand(command, null, null);

            System.Threading.Tasks.Task <Int32> data = Task <Int32> .Factory.FromAsync(ret.BeginExecute(), ret.EndExecute);

            Int32 commandAsyncResult = await data;

            if (callback != null)
            {
                callback(new Nequeo.Threading.AsyncOperationResult <Int32>(commandAsyncResult, state, "ExecuteCommand"));
            }

            if (callbackException != null)
            {
                callbackException(new Nequeo.Threading.AsyncOperationResult <System.Exception>(ret.Exception, state, "ExecuteCommand"));
            }
        }
示例#2
0
        /// <summary>
        /// Execute non query command.
        /// </summary>
        /// <param name="command">The complete command</param>
        /// <returns>The data table containing the data.</returns>
        public static Int32 ExecuteCommand(DbCommand command)
        {
            // Check to see if the critical parameters
            // have been set, throw exception on each.
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            // Create the new async operation
            AsyncExecuteCommand ret = new AsyncExecuteCommand(command, null, null);
            Int32 data = ret.FuncAsyncExecute();

            // If an error occures then thow the excption.
            if (ret.Exception != null)
            {
                throw new Exception(ret.Exception.Message, ret.Exception.InnerException);
            }

            return(data);
        }