示例#1
0
        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();
            }
        }
示例#2
0
 public bool TryResolveClient(string topicName, out ITcpIoTHubMessagingServiceClient sendingClient)
 {
     sendingClient = this.messagingClient;
     return(true);
 }
示例#3
0
 public SingleClientMessagingBridge(IDeviceIdentity deviceIdentity, ITcpIoTHubMessagingServiceClient messagingClient)
 {
     this.deviceIdentity  = deviceIdentity;
     this.messagingClient = messagingClient;
 }