public async override Task SendAsync(string deviceId, Message message, TimeSpan?timeout = null) { if (string.IsNullOrWhiteSpace(deviceId)) { throw new ArgumentNullException(nameof(deviceId)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } timeout ??= OperationTimeout; using AmqpMessage amqpMessage = message.ToAmqpMessage(); amqpMessage.Properties.To = "/devices/" + WebUtility.UrlEncode(deviceId) + "/messages/deviceBound"; try { SendingAmqpLink sendingLink = await GetSendingLinkAsync().ConfigureAwait(false); Outcome outcome = await sendingLink .SendMessageAsync(amqpMessage, IotHubConnection.GetNextDeliveryTag(ref _sendingDeliveryTag), AmqpConstants.NullBinary, timeout.Value) .ConfigureAwait(false); if (outcome.DescriptorCode != Accepted.Code) { throw AmqpErrorMapper.GetExceptionFromOutcome(outcome); } } catch (Exception ex) when(!(ex is TimeoutException) && !ex.IsFatal()) { throw AmqpClientHelper.ToIotHubClientContract(ex); } }
public async override Task SendAsync(string deviceId, Message message, TimeSpan?timeout = null) { if (string.IsNullOrWhiteSpace(deviceId)) { throw new ArgumentException("Value should be non null and non empty", "deviceId"); } if (message == null) { throw new ArgumentNullException("message"); } Outcome outcome; using (AmqpMessage amqpMessage = message.ToAmqpMessage()) { amqpMessage.Properties.To = "/devices/" + WebUtility.UrlEncode(deviceId) + "/messages/deviceBound"; try { SendingAmqpLink sendingLink = await GetSendingLinkAsync().ConfigureAwait(false); if (timeout != null) { outcome = await sendingLink.SendMessageAsync(amqpMessage, IotHubConnection.GetNextDeliveryTag(ref sendingDeliveryTag), AmqpConstants.NullBinary, (TimeSpan)timeout).ConfigureAwait(false); } else { outcome = await sendingLink.SendMessageAsync(amqpMessage, IotHubConnection.GetNextDeliveryTag(ref sendingDeliveryTag), AmqpConstants.NullBinary, OperationTimeout).ConfigureAwait(false); } } catch (TimeoutException exception) { throw exception; } catch (Exception exception) { if (exception.IsFatal()) { throw; } throw AmqpClientHelper.ToIotHubClientContract(exception); } } if (outcome.DescriptorCode != Accepted.Code) { throw AmqpErrorMapper.GetExceptionFromOutcome(outcome); } }
public override async Task SendAsync(string deviceId, string moduleId, Message message) { if (string.IsNullOrWhiteSpace(deviceId)) { throw new ArgumentNullException(nameof(deviceId)); } if (string.IsNullOrWhiteSpace(moduleId)) { throw new ArgumentNullException(nameof(moduleId)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } Outcome outcome; using (AmqpMessage amqpMessage = message.ToAmqpMessage()) { amqpMessage.Properties.To = "/devices/" + WebUtility.UrlEncode(deviceId) + "/modules/" + WebUtility.UrlEncode(moduleId) + "/messages/deviceBound"; try { SendingAmqpLink sendingLink = await this.GetSendingLinkAsync().ConfigureAwait(false); outcome = await sendingLink.SendMessageAsync(amqpMessage, IotHubConnection.GetNextDeliveryTag(ref this.sendingDeliveryTag), AmqpConstants.NullBinary, this.OperationTimeout).ConfigureAwait(false); } catch (Exception exception) { if (exception.IsFatal()) { throw; } throw AmqpClientHelper.ToIotHubClientContract(exception); } } if (outcome.DescriptorCode != Accepted.Code) { throw AmqpErrorMapper.GetExceptionFromOutcome(outcome); } }