Ejemplo n.º 1
0
        /// <summary>
        /// Every time the Proxy sends telemetry, forward the payload to the SCENE step state machine
        /// It returns the Collection of commands for the step
        /// </summary>

        public async Task <List <Command> > OnBeaconChange(string lanternId, string beaconId)
        {
            Debug.WriteLine($"Beacon Trigger {lanternId} {beaconId}");

            List <Command> scriptResponse = null;

            if (!Lantern2Character.TryGetValue(lanternId, out string character))
            {
                throw new Exception("Lantern not mapped");
            }

            //Check the When All condition, if it is true it will trigger the callback
            string triggerNext = _currentStep.OnBeaconOccurred(character, beaconId);

            if (string.IsNullOrEmpty(triggerNext))
            {
                if (beaconId == _scenes[CurrentSceneName].RequiredAVA)
                {
                    //for the character condition to stop roaming
                    beaconId = "AVA";
                }

                if (!Characters.TryGetValue(character, out Character cs))
                {
                    return(null);
                }

                var characterCommands = cs.OnBeaconChange(beaconId);
                if (null != characterCommands)
                {
                    //command to the device
                    await _downlink.SendCloudToLanternMethodAsync(lanternId, characterCommands);

                    scriptResponse = characterCommands;
                }

                //this is roaming but also move the step
                if (_currentStep.RequiredBeacons != null && _currentStep.RequiredBeacons.Contains(beaconId))
                {
                    TriggerJumpTo(_currentStep.OnTriggerNext);
                }
            }
            else if (triggerNext != "BLOCKED")
            {
                TriggerJumpTo(triggerNext);
            }

            return(scriptResponse);
        }
Ejemplo n.º 2
0
 public void Reset()
 {
     Characters.Clear();
     Lantern2Character.Clear();
     _scenes.Clear();
 }