예제 #1
0
        /// <summary>
        /// This method runs in an endless cycle in the Azure Worker Role.
        /// Its task is to periodically poll the player's status and call the ShipLanded() and ShipFlying()
        /// methods to execute the player's code.
        /// </summary>
        private static async Task Run(AndromedaServiceClient client, Guid playerGuid)
        {
            //This call tells the Andromeda server whether the player is running his code from the
            //emulator or from Azure.
            //As stated in the game's rules, only code running from Azure is eligible for the competition's prizes.
            //Naturally this call can be faked very easily, but we'll manually check the winners by their IP
            //addresses, so this is not worth doing. :)
            await client.RegisterRunLocationAsync(playerGuid, false); //TODO: RoleEnvironment.IsEmulated);

            //Load all the ships of the player
            var spaceshipGuids = await client.GetOwnedShipsAsync(playerGuid);

            //Check the status of each ship and call the appropriate control method
            foreach (var spaceshipGuid in spaceshipGuids)
            {
                //We try to download the list of the player's ships (the server will throw an exception
                //if the player ID is invalid
                var spaceship = await client.GetSpaceshipStatusAsync(spaceshipGuid);

                //Ship list successfully downloaded. If the ship is on a planet, call ShipLanded(); otherwise
                //call ShipFlying().
                NavigationComputer.CommandedShip = spaceshipGuid; //Point the NavigationComputer to this ship
                if (!spaceship.IsInTransit)
                {
                    await SpaceshipController.ShipLandedAsync(spaceshipGuid);
                }
                else
                {
                    await SpaceshipController.ShipFlying(spaceshipGuid);
                }
            }
        }
예제 #2
0
        public static async Task Run([TimerTrigger("*/10 * * * * *")] TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

            //Create the service reference
            var client = new AndromedaServiceClient();

            var playerGuid = GetPlayerGuid();

            await Run(client, playerGuid);
        }