async void SendD2CMessage(DeviceDataPacket dataPacket) { Contract.Requires(this.identity != null); if (identity?.Id != dataPacket.DeviceId) { if (this.stateFlags == StateFlags.ProcessingConnect || this.stateFlags == StateFlags.Connected) { this.stateFlags = StateFlags.InvalidConfiguration; this.Shutdown(this.capturedContext, new SocketIoTGatewayException(ErrorCode.UnResolvedSendingClient, "Invalid device identity")); return; } } if (this.ConnectedToService) { PreciseTimeSpan startedTimestamp = PreciseTimeSpan.FromStart; IMessage message = null; try { ITcpIoTHubMessagingServiceClient sendingClient = null; if (this.messagingBridge.TryResolveClient("Events", out sendingClient)) { message = sendingClient.CreateMessage(dataPacket.EventTopicAddress, dataPacket.Payload); message.Properties[this.settings.ServicePropertyPrefix + "MessageType"] = dataPacket.PacketType.ToString(); await sendingClient.SendAsync(message); message = null; } else { throw new SocketIoTGatewayException(ErrorCode.UnResolvedSendingClient, $"Could not resolve a sending client based on topic name `Events`."); } } finally { message?.Dispose(); } } else { dataPacket.Release(); } }
public bool TryResolveClient(string topicName, out ITcpIoTHubMessagingServiceClient sendingClient) { sendingClient = this.messagingClient; return(true); }
public SingleClientMessagingBridge(IDeviceIdentity deviceIdentity, ITcpIoTHubMessagingServiceClient messagingClient) { this.deviceIdentity = deviceIdentity; this.messagingClient = messagingClient; }