private void Adapter_OnObserve(object sender, ObserveMessageEventArgs e)
        {
            MessageAuditRecord record = null;
            int      length           = 0;
            DateTime sendTime         = DateTime.UtcNow;

            try
            {
                byte[] message = ProtocolTransition.ConvertToMqtt(session, e.Message);
                Send(message).LogExceptions();

                MqttMessage mm = MqttMessage.DecodeMessage(message);

                length = mm.Payload.Length;
                record = new MessageAuditRecord(e.Message.MessageId, session.Identity, Channel.TypeId, "MQTT", length,
                                                MessageDirectionType.Out, true, sendTime);
            }
            catch (Exception ex)
            {
                string msg = string.Format("{0} - MQTT adapter observe error on channel '{1}' with '{2}'",
                                           DateTime.UtcNow.ToString("yyyy-MM-ddTHH-MM-ss.fffff"), Channel.Id, ex.Message);
                logger?.LogErrorAsync(ex, $"MQTT adapter observe error on channel '{Channel.Id}'.").GetAwaiter();
                record = new MessageAuditRecord(e.Message.MessageId, session.Identity, Channel.TypeId, "MQTT", length,
                                                MessageDirectionType.Out, true, sendTime, msg);
            }
            finally
            {
                if (e.Message.Audit)
                {
                    messageAuditor?.WriteAuditRecordAsync(record).Ignore();
                }
            }
        }
        private void Adapter_OnObserve(object sender, ObserveMessageEventArgs e)
        {
            MessageAuditRecord record = null;
            int      length           = 0;
            DateTime sendTime         = DateTime.UtcNow;

            try
            {
                byte[] message = ProtocolTransition.ConvertToHttp(e.Message);
                Send(message).LogExceptions();
                OnObserve?.Invoke(this,
                                  new ChannelObserverEventArgs(Channel.Id, e.Message.ResourceUri, e.Message.ContentType,
                                                               e.Message.Message));

                length = message.Length;
                record = new MessageAuditRecord(e.Message.MessageId, identity, Channel.TypeId, "WSN", length,
                                                MessageDirectionType.Out, true, sendTime);
            }
            catch (Exception ex)
            {
                string msg = string.Format("{0} - WSN adapter observe error on channel '{1}' with '{2}'",
                                           DateTime.UtcNow.ToString("yyyy-MM-ddTHH-MM-ss.fffff"), Channel.Id, ex.Message);
                logger?.LogError(ex, $"WSN adapter observe error on channel '{Channel.Id}'.");
                record = new MessageAuditRecord(e.Message.MessageId, identity, Channel.TypeId, "WSN", length,
                                                MessageDirectionType.Out, true, sendTime, msg);
            }
            finally
            {
                if (e.Message.Audit)
                {
                    messageAuditor?.WriteAuditRecordAsync(record).Ignore();
                }
            }
        }
        private void Adapter_OnObserve(object sender, ObserveMessageEventArgs e)
        {
            logger?.LogDebugAsync("REST adapter received observed message");
            OnObserve?.Invoke(this, new ChannelObserverEventArgs(channel.Id, e.Message.ResourceUri, e.Message.ContentType, e.Message.Message));
            AuditRecord record = new UserAuditRecord(channel.Id, identity, DateTime.UtcNow);

            userAuditor?.UpdateAuditRecordAsync(record).Ignore();
            AuditRecord messageRecord = new MessageAuditRecord(e.Message.MessageId, identity, channel.TypeId, protocolType.ToString(), e.Message.Message.Length, MessageDirectionType.Out, true, DateTime.UtcNow);

            messageAuditor?.WriteAuditRecordAsync(messageRecord);
        }
        private void Adapter_OnObserve(object sender, ObserveMessageEventArgs e)
        {
            byte[] message = null;

            if (coapObserved.ContainsKey(e.Message.ResourceUri))
            {
                message = ProtocolTransition.ConvertToCoap(session, e.Message, coapObserved[e.Message.ResourceUri]);
            }
            else
            {
                message = ProtocolTransition.ConvertToCoap(session, e.Message);
            }

            Send(message, e).LogExceptions();
        }
        private void Adapter_OnObserve(object sender, ObserveMessageEventArgs e)
        {
            byte[] message = null;

            if (coapObserved.ContainsKey(e.Message.ResourceUri))
            {
                message = ProtocolTransition.ConvertToCoap(session, e.Message, coapObserved[e.Message.ResourceUri]);
            }
            else
            {
                message = ProtocolTransition.ConvertToCoap(session, e.Message);
            }

            logger?.LogDebugAsync($"Converted observed CoAP message '{e.Message.ResourceUri}'.");

            Send(message, e).LogExceptions(logger).GetAwaiter();
        }
        private async Task Send(byte[] message, ObserveMessageEventArgs e)
        {
            AuditRecord record = null;

            try
            {
                await channel.SendAsync(message);

                record = new MessageAuditRecord(e.Message.MessageId, session.Identity, this.channel.TypeId, "COAP", e.Message.Message.Length, MessageDirectionType.Out, true, DateTime.UtcNow);
            }
            catch (Exception ex)
            {
                record = new MessageAuditRecord(e.Message.MessageId, session.Identity, this.channel.TypeId, "COAP", e.Message.Message.Length, MessageDirectionType.Out, false, DateTime.UtcNow, ex.Message);
            }
            finally
            {
                if (e.Message.Audit)
                {
                    await auditor?.WriteAuditRecordAsync(record);
                }
            }
        }
Exemple #7
0
 private void Adapter_OnObserve(object sender, ObserveMessageEventArgs e)
 {
     byte[] payload = ProtocolTransition.ConvertToHttp(e.Message);
     OnObserve?.Invoke(this, new ChannelObserverEventArgs(e.Message.ResourceUri, e.Message.ContentType, payload));
 }