GetTransactionalStateAsync() static private method

static private GetTransactionalStateAsync ( SenderLink sender ) : Task
sender SenderLink
return Task
Beispiel #1
0
        /// <summary>
        /// Sends a message asynchronously.
        /// </summary>
        /// <param name="sender">The link.</param>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public static async Task SendAsync(this SenderLink sender, Message message)
        {
            DeliveryState txnState = null;

#if NETFX || NETFX40
            txnState = await TaskExtensions.GetTransactionalStateAsync(sender);
#endif
            TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();
            sender.Send(
                message,
                txnState,
                (m, o, s) =>
            {
                var t = (TaskCompletionSource <object>)s;
                if (o.Descriptor.Code == Codec.Accepted.Code)
                {
                    t.SetResult(null);
                }
                else if (o.Descriptor.Code == Codec.Rejected.Code)
                {
                    t.SetException(new AmqpException(((Rejected)o).Error));
                }
                else
                {
                    t.SetException(new AmqpException(ErrorCode.InternalError, o.Descriptor.Name));
                }
            },
                tcs);

            await tcs.Task;
        }
Beispiel #2
0
        internal async Task SendInternalAsync(Message message, int timeoutMilliseconds)
        {
            DeliveryState txnState = null;

#if NETFX || NETFX40
            txnState = await TaskExtensions.GetTransactionalStateAsync(this);
#endif
            TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();
            this.Send(
                message,
                txnState,
                (l, m, o, s) =>
            {
                var t = (TaskCompletionSource <object>)s;
                if (o.Descriptor.Code == Codec.Accepted.Code)
                {
                    t.SetResult(null);
                }
                else if (o.Descriptor.Code == Codec.Rejected.Code)
                {
                    t.SetException(new AmqpException(((Rejected)o).Error));
                }
                else if (o.Descriptor.Code == Codec.Released.Code)
                {
                    t.SetException(new AmqpException(ErrorCode.MessageReleased, null));
                }
                else
                {
                    t.SetException(new AmqpException(ErrorCode.InternalError, o.Descriptor.Name));
                }
            },
                tcs);

            await tcs.Task;
        }
Beispiel #3
0
        /// <summary>
        /// Sends a message asynchronously.
        /// </summary>
        /// <param name="message">The message to send.</param>
        /// <param name="timeout">The time to wait for the task to complete.</param>
        /// <returns>A Task for the asynchronous send operation.</returns>
        public async Task SendAsync(Message message, TimeSpan timeout)
        {
            DeliveryState txnState = null;

#if NETFX || NETFX40
            txnState = await TaskExtensions.GetTransactionalStateAsync(this);
#endif

            try
            {
                await new SendTask(this, message, txnState, timeout).Task;
            }
            catch (TimeoutException)
            {
                this.OnTimeout(message);
                throw;
            }
        }