Example #1
0
 private Task ExceptionReceivedHandler(ExceptionReceivedEventArgs exceptionReceivedEventArgs)
 {
     OnListenerError?.Invoke(this, new GamePacketErrorArgs
     {
         Exception = exceptionReceivedEventArgs.Exception,
         Message   = "Exception Received Event"
     });
     return(Task.CompletedTask);
 }
Example #2
0
        private async Task ProcessMessages(Message message, CancellationToken token)
        {
            try
            {
                var packet = message.GetBody <GamePacket>(new DataContractSerializer(typeof(GamePacket)));

                if (packet == null)
                {
                    OnListenerError?.Invoke(this,
                                            new GamePacketErrorArgs {
                        Message = "Message body was not serialized as a GamePacket."
                    });
                    await _client.DeadLetterAsync(message.SystemProperties.LockToken,
                                                  "Message body was not serialized as a GamePacket.");
                }
                else
                {
                    if (HandleGamePacket(packet))
                    {
                        OnGamePacketCompleted?.Invoke(this, new GamePacketArgs {
                            GamePacket = packet
                        });
                        await _client.CompleteAsync(message.SystemProperties.LockToken);
                    }
                    else
                    {
                        OnListenerError?.Invoke(this,
                                                new GamePacketErrorArgs
                        {
                            GameEvent = packet,
                            Message   = "Message was not handled completely."
                        });

                        await _client.DeadLetterAsync(message.SystemProperties.LockToken,
                                                      "Message was not handled completely.");
                    }
                }
            }
            catch (Exception e)
            {
                OnListenerError?.Invoke(this, new GamePacketErrorArgs
                {
                    Exception = e,
                    Message   = "GamePacketReceiver failed to ProcessMessage"
                });
            }
        }