public async Task ProcessMessage(DeviceMessage message)
        {
            if (null == this.lastMessage || this.lastMessage.Latitude != message.Latitude || this.lastMessage.Longitude != message.Longitude)
            {
                // only sent a notification if the position has changed
                var notifier = PushNotifierGrainFactory.GetGrain(0);
                var speed    = GetSpeed(this.lastMessage, message);

                // record the last message
                this.lastMessage = message;

                // forward the message to the notifier grain
                var statusMessage = new DeviceStatusMessage(message, speed, description);
                await notifier.SendMessage(statusMessage);
            }
            else
            {
                // the position has not changed, just record the last message
                this.lastMessage = message;
            }
        }
Exemple #2
0
        async Task Move()
        {
            var        directions = new string[] { "north", "south", "west", "east" };
            var        rand       = new Random().Next(0, 4);
            IRoomGrain nextRoom   = await this.State.roomGrain.ExitTo(directions[rand], this);

            if (null == nextRoom)
            {
                return;
            }
            await this.State.roomGrain.Exit(this);

            await nextRoom.Enter(this);

            //Get Push grain
            var notifier = PushNotifierGrainFactory.GetGrain(0);
            //loop through players in the room grain
            var playersInRoom = await this.State.roomGrain.GetPlayersInRoom();

            for (int i = 0; i < playersInRoom.Length; i++)
            {
                Guid playerId = playersInRoom[i].GetPrimaryKey();
                await notifier.SendMessage(this.State.npcInfo.Name + " has left the room", playerId.ToString());
            }

            this.State.roomGrain = nextRoom;
            //Send messages to players in new room
            playersInRoom = await this.State.roomGrain.GetPlayersInRoom();

            for (int i = 0; i < playersInRoom.Length; i++)
            {
                Guid playerId = playersInRoom[i].GetPrimaryKey();
                await notifier.SendMessage(this.State.npcInfo.Name + " has entered room", playerId.ToString());
            }

            await State.WriteStateAsync();
        }
Exemple #3
0
 public async Task ProcessMessage(string message)
 {
     Trace.TraceInformation("ProcessMessage: " + message);
     var notifier = PushNotifierGrainFactory.GetGrain(0);
     await notifier.SendMessage(message);
 }