Example #1
0
 public void Receive(ArraySegment <byte> buffer)
 {
     AssertIsPersistencePayload(buffer);
     PayloadReceived?.Invoke(
         this,
         new ArraySegment <byte>(buffer.Array, buffer.Offset + 1, buffer.Count - 1));
 }
Example #2
0
        public MiniUDPConnection(NetPeer peer)
        {
            _peer = peer;
            _peer.PayloadReceived += (peer_, data, length) =>
            {
                if (peer_ != _peer)
                {
                    throw new InvalidOperationException("Peer wrapper mismatch");
                }

                PayloadReceived.Invoke(data, length);
            };
        }
        private void HandlePayload(OSNotification notification)
        {
            var payload = new NotificationPayload();

            payload.EventType = GetPayloadItem(notification, eventTypeKey);
            payload.Event     = GetPayloadItem(notification, eventKey);
            payload.Message   = GetPayloadItem(notification, messageKey);

            bool payloadCompleted = !string.IsNullOrEmpty(payload.Event) && !string.IsNullOrEmpty(payload.EventType);

            if (payloadCompleted)
            {
                PayloadReceived?.Invoke(this, new PayloadReceivedEventArgs()
                {
                    Payload = payload
                });
            }
        }
Example #4
0
        private void ProcessData()
        {
            byte msgType = payloadBuff[3];

            switch (msgType)
            {
            case 0:
                StatusMessageReceived?.Invoke(StatusMessage.InitFailed);
                break;

            case 1:
                StatusMessageReceived?.Invoke(StatusMessage.InitOk);
                break;

            case 2:
                StatusMessageReceived?.Invoke(StatusMessage.CrcError);
                break;

            case 3:
                byte[] buffer = new byte[payloadLen];

                Buffer.BlockCopy(payloadBuff, 4, buffer, 0, payloadLen);
                try
                {
                    TxRxPayload trp = new TxRxPayload(buffer);
                    PayloadReceived?.Invoke(trp);
                }
                catch (Exception e)
                {
                    UnrecognizedPayloadReceived?.Invoke(buffer);
                }
                break;

            case 4:
                StatusMessageReceived?.Invoke(StatusMessage.GetFifoError);
                break;

            case 5:
                StatusMessageReceived?.Invoke(StatusMessage.GetIntError);
                break;
            }
        }
Example #5
0
        private bool Host_DispatchPayload(IConnection connection, object payload, Type type,
                                          Action <object> responseSender, int?requestId)
        {
            if (!ContainsClient(connection))
            {
                return(false);
            }

            var ret = ProcessPayloadHandlers(connection, payload, type, responseSender, requestId);


            try
            {
                PayloadReceived?.Invoke(connection, payload, type);
            }
            catch
            {
            }


            if (DispatchPayload != null)
            {
                foreach (var handler in DispatchPayload)
                {
                    try
                    {
                        ret |= handler.Invoke(connection, payload, type, responseSender, requestId);
                    }
                    catch
                    {
                    }
                }
            }

            return(ret);
        }
Example #6
0
 // #region Events
 internal void OnPayloadReceived(byte[] data, int dataLength)
 {
     PayloadReceived?.Invoke(this, data, dataLength);
 }
Example #7
0
 public void PollEvents()
 {
     receivedBuffer.ForEach(buffer => PayloadReceived?.Invoke(this, buffer));
     receivedBuffer.Clear();
 }
 /// <summary>
 ///     Invokes the <see cref="PayloadReceived"/> event asynchronously. (Can be override for
 ///     event catching)
 /// </summary>
 /// <param name="eventArgs">the event arguments for the event</param>
 /// <returns>a task that represents the asynchronous operation</returns>
 protected virtual Task OnPayloadReceived(PayloadReceivedEventArgs eventArgs)
 => PayloadReceived.InvokeAsync(this, eventArgs);