private void Channel_OnReceive(object sender, ChannelReceivedEventArgs args) { CoapMessage message = CoapMessage.DecodeMessage(args.Message); CoapMessageHandler handler = CoapMessageHandler.Create(session, message, dispatcher); Task task = ReceiveAsync(handler); Task.WhenAll(task); }
private void Channel_OnReceive(object sender, ChannelReceivedEventArgs e) { try { CoapMessage message = CoapMessage.DecodeMessage(e.Message); if (!session.IsAuthenticated || forcePerReceiveAuthn) { session.EnsureAuthentication(message, forcePerReceiveAuthn); UserAuditRecord record = new UserAuditRecord(Channel.Id, session.Identity, session.Config.IdentityClaimType, Channel.TypeId, "COAP", "Granted", DateTime.UtcNow); userAuditor?.WriteAuditRecordAsync(record).Ignore(); } OnObserve?.Invoke(this, new ChannelObserverEventArgs(Channel.Id, message.ResourceUri.ToString(), MediaTypeConverter.ConvertFromMediaType(message.ContentType), message.Payload)); Task task = Task.Factory.StartNew(async() => { CoapMessageHandler handler = CoapMessageHandler.Create(session, message, dispatcher); CoapMessage msg = await handler.ProcessAsync(); if (msg != null) { byte[] payload = msg.Encode(); await Channel.SendAsync(payload); } }); task.LogExceptions(); } catch (Exception ex) { logger?.LogErrorAsync(ex, $"CoAP adapter receiveing on channel '{Channel.Id}'.").GetAwaiter(); OnError?.Invoke(this, new ProtocolAdapterErrorEventArgs(Channel.Id, ex)); Channel.CloseAsync().Ignore(); } }
private void Channel_OnReceive(object sender, ChannelReceivedEventArgs args) { CoapMessage message = CoapMessage.DecodeMessage(args.Message); CoapMessageHandler handler = CoapMessageHandler.Create(session, message, dispatcher); Task task = ReceiveAsync(handler); Task.WhenAll(task); //Task task = Task.Factory.StartNew(async () => //{ // CoapMessage msg = await handler.ProcessAsync(); // if (msg != null && pingId.Contains(msg.MessageId)) // { // pingId.Remove(msg.MessageId); // //ping complete // OnPingResponse?.Invoke(this, new CoapMessageEventArgs(msg)); // } //}); //Task.WaitAll(task); }