示例#1
0
        /// <summary>
        /// Sends the packet to the network.
        /// </summary>
        /// <param name="packet">The packet to send.</param>
        protected override Task <bool> Publish(IrisPacket packet)
        {
            return(Task.Factory.StartNew(() =>
            {
                try
                {
                    if (packet is IrisSubscribe)
                    {
                        var subscribeCommand = packet as IrisSubscribe;
                        _pubSubRouter.Subscribe(this, subscribeCommand.Channel);
                    }
                    else if (packet is IrisUnsubscribe)
                    {
                        var unsubscribeCommand = packet as IrisUnsubscribe;
                        _pubSubRouter.Unsubscribe(this, unsubscribeCommand.Channel);
                    }
                    else
                    {
                        var message = packet as IrisMessage;
                        _pubSubRouter.SubmitMessage(this, message);
                    }

                    return true;
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                    return false;
                }
            }));
        }
示例#2
0
        /// <summary>
        /// Handler for a packet received from the IrisListener.
        /// If the data is valid, it's given to the IPubSubRouter to be handled.
        /// If the data is valid, it sends an IrisMeta packet with positive ACK.
        /// </summary>
        /// <param name="packet">The packet received.</param>
        protected override void OnClientSubmittedPacketReceived(IrisPacket packet)
        {
            try
            {
                bool?result = null;

                if (packet is IrisMessage)
                {
                    result = _pubSubRouter.SubmitMessage(this, packet as IrisMessage);
                }
                else if (packet is IrisSubscribe)
                {
                    result = _pubSubRouter.Subscribe(this, (packet as IrisSubscribe).Channel);
                }
                else if (packet is IrisUnsubscribe)
                {
                    result = _pubSubRouter.Unsubscribe(this, (packet as IrisUnsubscribe).Channel);
                }
                else
                {
                    OnInvalidDataReceived(packet);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
示例#3
0
 private void InvokeAsyncOnClientSubmittedPacketReceived(IrisPacket packet) => OnClientSubmittedPacketReceived?.GetInvocationList().ForEach(e => ((MessageHandler)e).BeginInvoke(packet, EndAsyncEventForMessageHandler, EventArgs.Empty));
 /// <summary>
 /// Publishes the packet to the network.
 /// </summary>
 /// <param name="packet">The packet to publish.</param>
 protected override Task <bool> Publish(IrisPacket packet) => _networkWorker.SendAsync(packet);