Example #1
0
        /// <summary>
        /// Handler for a packet received from the network.
        /// If the packet is of IrisMessage type, invokes the ContentHandlers subscribed to the reception of the message.
        /// Fires a log event if LogMessagesEnable is true and the packet is of IrisMessage type.
        /// </summary>
        /// <param name="packet">The packet received.</param>
        protected virtual void OnClientSubmittedPacketReceived(IrisPacket packet)
        {
            if (packet is IrisMessage)
            {
                var message = packet as IrisMessage;
                IEnumerable <ContentHandler> handlers = null;

                if (message.TargetChannel != null)
                {
                    handlers = _channelsSubscriptions.GetSubscriptions(message.TargetChannel, message.PropagateThroughHierarchy);
                }
                else
                {
                    var broadcastHandlers = new List <ContentHandler>();
                    broadcastHandlers.AddRange(_broadcastHandlers);
                    handlers = broadcastHandlers;
                }

                if (handlers != null)
                {
                    var ctxHook = new IrisContextHook()
                    {
                        TargetChannel       = message.TargetChannel,
                        PublicationDateTime = message.PublicationDateTime
                    };

                    foreach (var hander in handlers)
                    {
                        hander.BeginInvoke(message.Content, ctxHook, null, null);
                    }
                }

                if (LogMessagesEnable)
                {
                    OnLog?.BeginInvoke(GetLogForMessageReceived(message), null, null);
                }

                // No subscription found for this message
                if (handlers == null)
                {
                    OnLog?.BeginInvoke(GetLogForError(new IrisError(Id)
                    {
                        Log = $"Unable to find subscriptions for the channel {message.TargetChannel}. [Message]{GetLogForMessageReceived(message)}."
                    }), null, null);
                }
            }
        }
Example #2
0
 /// <summary>
 /// Publishes the packet to the network.
 /// </summary>
 /// <param name="packet">The packet to publish.</param>
 protected abstract Task <bool> Publish(IrisPacket packet);