示例#1
0
        private async Task ProcessSessionMessages(IMessageSession session, Message message, CancellationToken token)
        {
            var packet = message.GetBody <GamePacket>(new DataContractSerializer(typeof(GamePacket)));

            if (HandleGamePacket(packet))
            {
                OnGamePacketCompleted?.Invoke(this, new GamePacketArgs {
                    GamePacket = packet
                });
            }

            await session.CompleteAsync(message.SystemProperties.LockToken);
        }
示例#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"
                });
            }
        }
示例#3
0
        public async Task ProcessReceivedMessage(Task <IEnumerable <BrokeredMessage> > task)
        {
            foreach (var message in task.Result)
            {
                GamePacket packet = null;

                try
                {
                    Trace.TraceInformation("IGL.ServiceRole.EchoTask.ProcessReceivedMessage() processing message {0}", message.SequenceNumber);

                    if (!message.Properties.ContainsKey(GamePacket.VERSION))
                    {
                        throw new ApplicationException(string.Format("IGL.Service.GameEventsListenerTask.RunAsync() message {0} does not have a valid {1} property.", message.SequenceNumber, GamePacket.VERSION));
                    }

                    packet = message.GetBody <GamePacket>(new DataContractSerializer(typeof(GamePacket)));

                    EchoTheMessage(packet);

                    await message.CompleteAsync();

                    // alert any listeners
                    OnGamePacketCompleted?.Invoke(null, new GamePacketArgs {
                        GamePacket = packet
                    });

                    Trace.TraceInformation("IGL.ServiceRole.EchoTask.ProcessReceivedMessage() processed message {0}", message.SequenceNumber);
                }
                catch (Exception ex)
                {
                    message.DeadLetter(ex.Message, ex.GetFullMessage());

                    OnGamePacketError?.Invoke(null, new GamePacketErrorArgs
                    {
                        Message   = string.Format("Message {0} added to deadletter queue at UTC {1}.", message.SequenceNumber, DateTime.UtcNow.ToString()),
                        GameEvent = packet,
                        Exception = ex
                    });

                    Trace.TraceError(string.Format("IGL.ServiceRole.EchoTask.ProcessReceivedMessage() failed with {0}", ex.GetFullMessage()));
                }
            }

            Trace.TraceInformation("IGL.ServiceRole.EchoTask.ProcessReceivedMessage() completed");
        }