/// <summary>
        /// Actually send a message.
        /// </summary>
        private void SendMessageInternal(CommunicationMessage message, Identity to = null)
        {
            try
            {
                var senderId   = message.From.Equals(ClientDevice.Identity) ? message.From : _hostId;
                var receiverId = to ?? _hostId;
                //var uri = to?.Role == IdentityRole.Client && !to.Equals(HostDevice.Identity) ? HostDevice.GetUri(to) : HostDevice.Uri;
                var uri     = to?.Address ?? HostDevice.Uri;
                var binding = HostDevice.CreateBinding();
                var proxy   = ChannelFactory <ITransmissionService> .CreateChannel(binding, new EndpointAddress(uri));

                message.Sent = DateTime.UtcNow;
                message.To   = receiverId;

                Task.Run(() =>
                {
                    DebugMessage?.Invoke($"{senderId.Name} >> Sending {message.Name} ({message.Type}) to {receiverId.Name}");
                    CurrentStatus.LastSendTime = DateTime.UtcNow;
                    try
                    {
                        proxy.SendData(TransmissionService.PrepareMessage(message));
                    }
                    //catch (EndpointNotFoundException ex)
                    catch (Exception ex)
                    {
                        DebugMessage?.Invoke($"Exception: {ex.GetType().Name} {ex.Message}");
                    }
                });
            }
            catch (Exception ex)
            {
                DebugMessage?.Invoke($"Exception: {ex.GetType().Name} {ex.Message}");
            }
        }
Beispiel #2
0
 protected CommunicationDevice(Identity id, Uri baseUri, string channel)
 {
     Identity              = id;
     Service               = new TransmissionService();
     Service.DataReceived += ServiceOnDataReceived;
     BaseUri               = baseUri.AbsoluteUri;
     Channel               = channel;
 }