Esempio n. 1
0
        /// <summary>
        /// Execute the asynchronous action for the channel.
        /// </summary>
        /// <typeparam name="TResult">The action result type.</typeparam>
        /// <param name="channelAction">The action handler</param>
        public async Task <TResult> Execute <TResult>(Func <T, TResult> channelAction)
        {
            // Start the async object
            AsyncClientExecute <T, TResult> ret = new AsyncClientExecute <T, TResult>(channelAction, _instance, null, null);

            // Start the action asynchronously
            Task <TResult> data = Task <TResult> .Factory.FromAsync(ret.BeginActionResult(), ret.EndActionResult);

            object actionAsyncResult = await data;

            // Return the result.
            return((TResult)actionAsyncResult);
        }
Esempio n. 2
0
        /// <summary>
        /// Execute the asynchronous action for the channel.
        /// </summary>
        /// <param name="channelAction">The action handler</param>
        public async Task <Boolean> Execute(Action <T> channelAction)
        {
            // Start the async object
            AsyncClientExecute <T, Boolean> ret = new AsyncClientExecute <T, Boolean>(channelAction, _instance, null, null);

            // Start the action asynchronously
            Task <Boolean> data = Task <Boolean> .Factory.FromAsync(ret.BeginActionNoResult(), ret.EndActionNoResult);

            object actionAsyncResult = await data;

            // Return the result.
            return((Boolean)actionAsyncResult);
        }
Esempio n. 3
0
        /// <summary>
        /// Execute the asynchronous action for the channel.
        /// </summary>
        /// <typeparam name="TResult">The action result type.</typeparam>
        /// <param name="channelAction">The action handler</param>
        /// <param name="actionName">The unique action name; passed to the object sender of the AsyncExecuteComplete handler.</param>
        /// <param name="callback">The callback action handler.</param>
        /// <param name="state">The action state.</param>
        public async void Execute <TResult>(Func <T, TResult> channelAction, object actionName, Action <Nequeo.Threading.AsyncOperationResult <Object> > callback = null, object state = null)
        {
            try
            {
                // Start the async object
                AsyncClientExecute <T, TResult> ret = new AsyncClientExecute <T, TResult>(channelAction, _instance, null, null);

                // Start the action asynchronously
                Task <TResult> data = Task <TResult> .Factory.FromAsync(ret.BeginActionResult(), ret.EndActionResult);

                object actionAsyncResult = await data;

                // Get the current error.
                Exception exception = ret.GetCurrentError();
                if (exception != null)
                {
                    _exception = exception;
                    _exceptionMessage[actionName]         = exception;
                    _executionExceptionResult[actionName] = true;
                }
                else
                {
                    _exceptionMessage[actionName]         = null;
                    _executionExceptionResult[actionName] = false;
                }

                // Set the async value.
                _results[actionName] = actionAsyncResult;

                // Send the result back to the client
                if (AsyncExecuteComplete != null)
                {
                    AsyncExecuteComplete(this, actionName, _executionExceptionResult[actionName], _exceptionMessage[actionName]);
                }

                // If sending the result to a callback method.
                if (callback != null)
                {
                    callback(new AsyncOperationResult <Object>(_results[actionName], state, actionName));
                }
            }
            catch { }
        }
Esempio n. 4
0
        /// <summary>
        /// Execute the asynchronous action for the channel.
        /// </summary>
        /// <typeparam name="TResult">The action result type.</typeparam>
        /// <param name="channelAction">The action handler</param>
        /// <param name="actionName">The unique action name; passed to the object sender of the AsyncExecuteComplete handler.</param>
        /// <param name="callback">The callback action handler.</param>
        /// <param name="state">The action state.</param>
        internal async void ExecuteInternal <TResult>(Func <T, TResult> channelAction, object actionName,
                                                      Action <Nequeo.Threading.AsyncOperationResult <TResult> > callback, object state = null)
        {
            try
            {
                // Start the async object
                AsyncClientExecute <T, TResult> ret = new AsyncClientExecute <T, TResult>(channelAction, _instance, null, null);

                // Start the action asynchronously
                Task <TResult> data = Task <TResult> .Factory.FromAsync(ret.BeginActionResult(), ret.EndActionResult);

                object actionAsyncResult = await data;

                // If sending the result to a callback method.
                if (callback != null)
                {
                    callback(new AsyncOperationResult <TResult>((TResult)actionAsyncResult, state, actionName));
                }
            }
            catch { }
        }