private async Task DisposeMessageAsync(string lockToken, AmqpIoTDisposeActions outcome, CancellationToken cancellationToken)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, outcome, $"{nameof(DisposeMessageAsync)}");
            }
            AmqpIoTOutcome disposeOutcome;

            try
            {
                // Currently, the same mechanism is used for sending feedback for C2D messages and events received by modules.
                // However, devices only support C2D messages (they cannot receive events), and modules only support receiving events
                // (they cannot receive C2D messages). So we use this to distinguish whether to dispose the message (i.e. send outcome on)
                // the DeviceBoundReceivingLink or the EventsReceivingLink.
                // If this changes (i.e. modules are able to receive C2D messages, or devices are able to receive telemetry), this logic
                // will have to be updated.
                disposeOutcome = await _amqpUnit.DisposeMessageAsync(lockToken, outcome, _operationTimeout).ConfigureAwait(false);

                disposeOutcome.ThrowIfError();
            }
            finally
            {
                if (Logging.IsEnabled)
                {
                    Logging.Exit(this, outcome, $"{nameof(DisposeMessageAsync)}");
                }
            }
        }
Пример #2
0
        public async Task <AmqpIoTOutcome> DisposeMessageAsync(string lockToken, AmqpIoTDisposeActions disposeAction, TimeSpan timeout)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, lockToken, $"{nameof(DisposeMessageAsync)}");
            }
            AmqpIoTOutcome disposeOutcome;

            if (_deviceIdentity.IotHubConnectionString.ModuleId.IsNullOrWhiteSpace())
            {
                await EnsureMessageReceivingLinkAsync(timeout).ConfigureAwait(false);

                disposeOutcome = await _messageReceivingLink.DisposeMessageAsync(lockToken, AmqpIoTResultAdapter.GetResult(disposeAction), timeout).ConfigureAwait(false);
            }
            else
            {
                await EnableEventReceiveAsync(timeout).ConfigureAwait(false);

                disposeOutcome = await _eventReceivingLink.DisposeMessageAsync(lockToken, AmqpIoTResultAdapter.GetResult(disposeAction), timeout).ConfigureAwait(false);
            }
            if (Logging.IsEnabled)
            {
                Logging.Exit(this, lockToken, $"{nameof(DisposeMessageAsync)}");
            }
            return(disposeOutcome);
        }
Пример #3
0
        internal static Outcome GetResult(AmqpIoTDisposeActions amqpIoTConstants)
        {
            switch (amqpIoTConstants)
            {
            case AmqpIoTDisposeActions.Accepted:
                return(new Accepted());

            case AmqpIoTDisposeActions.Released:
                return(new Released());

            case AmqpIoTDisposeActions.Rejected:
                return(new Rejected());

            default:
                throw new ArgumentOutOfRangeException(nameof(amqpIoTConstants));
            }
        }