コード例 #1
0
        public async Task SendTwinMessageAsync(
            AmqpTwinMessageType amqpTwinMessageType,
            string correlationId,
            TwinCollection reportedProperties,
            CancellationToken cancellationToken)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, nameof(SendTwinMessageAsync));
            }

            await EnableTwinLinksAsync(cancellationToken).ConfigureAwait(false);

            Debug.Assert(_twinSendingLink != null);

            try
            {
                AmqpIotOutcome amqpIotOutcome;
                switch (amqpTwinMessageType)
                {
                case AmqpTwinMessageType.Get:
                    amqpIotOutcome = await _twinSendingLink.SendTwinGetMessageAsync(correlationId, cancellationToken).ConfigureAwait(false);

                    amqpIotOutcome?.ThrowIfNotAccepted();
                    break;

                case AmqpTwinMessageType.Patch:
                    amqpIotOutcome = await _twinSendingLink.SendTwinPatchMessageAsync(correlationId, reportedProperties, cancellationToken).ConfigureAwait(false);

                    amqpIotOutcome?.ThrowIfNotAccepted();
                    break;

                case AmqpTwinMessageType.Put:
                    amqpIotOutcome = await _twinSendingLink.SubscribeToDesiredPropertiesAsync(correlationId, cancellationToken).ConfigureAwait(false);

                    amqpIotOutcome?.ThrowIfNotAccepted();
                    break;
                }
            }
            finally
            {
                if (Logging.IsEnabled)
                {
                    Logging.Exit(this, nameof(SendTwinMessageAsync));
                }
            }
        }