예제 #1
0
        public async Task <AmqpIotOutcome> DisposeMessageAsync(string lockToken, AmqpIotDisposeActions disposeAction, TimeSpan timeout)
        {
            Logging.Enter(this, lockToken, nameof(DisposeMessageAsync));

            AmqpIotOutcome disposeOutcome;

            if (_deviceIdentity.IotHubConnectionString.ModuleId.IsNullOrWhiteSpace())
            {
                await EnsureMessageReceivingLinkIsOpenAsync(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);
            }
            Logging.Exit(this, lockToken, nameof(DisposeMessageAsync));

            return(disposeOutcome);
        }
        private async Task DisposeMessageAsync(string lockToken, AmqpIotDisposeActions outcome, CancellationToken cancellationToken)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, outcome, nameof(DisposeMessageAsync));
            }

            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.
                using var ctb = new CancellationTokenBundle(_operationTimeout, cancellationToken);

                AmqpIotOutcome disposeOutcome = await _amqpUnit.DisposeMessageAsync(lockToken, outcome, ctb.Token).ConfigureAwait(false);

                disposeOutcome.ThrowIfError();
            }
            finally
            {
                if (Logging.IsEnabled)
                {
                    Logging.Exit(this, outcome, nameof(DisposeMessageAsync));
                }
            }
        }
예제 #3
0
 internal static Outcome GetResult(AmqpIotDisposeActions amqpIotConstants)
 {
     return(amqpIotConstants switch
     {
         AmqpIotDisposeActions.Accepted => new Accepted(),
         AmqpIotDisposeActions.Released => new Released(),
         AmqpIotDisposeActions.Rejected => new Rejected(),
         _ => throw new ArgumentOutOfRangeException(nameof(amqpIotConstants)),
     });