示例#1
0
        public IntentExecutorContext Execute(IntentExecutorContext intentExecutorContext, Intent intent, IAlexaProxyService alexaProxyService)
        {
            intentExecutorContext = EnsureContexto(intentExecutorContext, intent);

            LocateMissingPorts(intentExecutorContext, alexaProxyService);

            if (intentExecutorContext.TargetPorts == null)
            {
                intentExecutorContext.Response = $"Não foi possível localizar o dispositivo {intentExecutorContext.PortsQuery}";
            }
            else if (!intentExecutorContext.NeedConfirmation)
            {
                var changePortStateRequests = intentExecutorContext.TargetPorts.Select(p => new ChangePortStateRequest(p)).ToArray();

                foreach (var changePortStateRequest in changePortStateRequests)
                {
                    changePortStateRequest.StateChanged = alexaProxyService.PulsePort(changePortStateRequest.PortName);
                }

                intentExecutorContext.Response = BuildResponseMessage(changePortStateRequests);
            }
            else if (intentExecutorContext.NeedConfirmation)
            {
                intentExecutorContext.Response = BuildConfirmationMessage(intentExecutorContext);
            }

            return(intentExecutorContext);
        }
 private void LocateMissingPorts(IntentExecutorContext intentExecutorContext, IAlexaProxyService alexaProxyService)
 {
     if (intentExecutorContext.TargetPorts == null)
     {
         LocatePorts(intentExecutorContext, alexaProxyService);
     }
 }
        public IntentExecutorContext Execute(IntentExecutorContext intentExecutorContext, Intent intent, IAlexaProxyService alexaProxyService)
        {
            intentExecutorContext = EnsureContexto(intentExecutorContext, intent);

            LocateMissingPorts(intentExecutorContext, alexaProxyService);

            var portStatesMessages = intentExecutorContext.TargetPorts.Select(p => GetStatusMessageForPort(p, alexaProxyService));

            IntentExecutorContext result;

            if (portStatesMessages.Any())
            {
                result = new IntentExecutorContext()
                {
                    NeedConfirmation = false,
                    Response         = BuildResponseMessage(portStatesMessages)
                };
            }
            else
            {
                result = new IntentExecutorContext()
                {
                    NeedConfirmation = false,
                    Response         = "Não foi possível determinar os dispositivos requisitados"
                };
            }
            return(result);
        }
示例#4
0
        private string BuildConfirmationMessage(IntentExecutorContext intentExecutorContext)
        {
            var activateWord   = "ligar";
            var deactivateWord = "desligar";

            string word;

            switch (intentExecutorContext.TargetPortState)
            {
            case PortStates.Actived:
                word = activateWord;
                break;

            case PortStates.Deactived:
                word = deactivateWord;
                break;

            default:
                throw new SpeechletException($"TargetStates '{intentExecutorContext.TargetPortState}' não é suportado");
            }

            var portsText = string.Join(" e ", intentExecutorContext.TargetPorts);
            var message   = $"Deseja {word} os dispositivos {portsText} ?";

            return(message);
        }
        public IntentExecutorContext Execute(IntentExecutorContext intentExecutorContext, Intent intent, IAlexaProxyService alexaProxyService)
        {
            var intentExecutor = IntentExecutorLocator.GetExecutorForIntent(intentExecutorContext.Intent);

            intentExecutorContext.NeedConfirmation = false;

            return(intentExecutor.Execute(intentExecutorContext, intent, alexaProxyService));
        }
示例#6
0
        private string BuildConfirmationMessage(IntentExecutorContext intentExecutorContext)
        {
            string word = "ativar";

            var portsText = string.Join(" e ", intentExecutorContext.TargetPorts);
            var message   = intentExecutorContext.TargetPorts.Length > 1 ? $"Deseja {word} os dispositivos {portsText} ?" : $"Deseja {word} o dispositivo {portsText} ?";

            return(message);
        }
        private void LocatePorts(IntentExecutorContext intentExecutorContext, IAlexaProxyService alexaProxyService)
        {
            var query = intentExecutorContext.PortsQuery;
            var ports = alexaProxyService.GetAllPorts(PortTypes.Switch);

            var querys    = query.Split(" e ");
            var portInfos = querys.Select(p => PortInfo.Locate(ports, p)).ToArray();

            intentExecutorContext.TargetPorts = portInfos.Select(p => p.TargetPort).ToArray();
        }
        private static IntentExecutorContext EnsureContexto(IntentExecutorContext intentExecutorContext, Intent intent)
        {
            if (intentExecutorContext == null)
            {
                intentExecutorContext = new IntentExecutorContext()
                {
                    Intent     = intent.Name,
                    PortsQuery = PortsQueryProcessor.GetQueryFromIntent(intent)
                };
            }

            return(intentExecutorContext);
        }
        public IntentExecutorContext Execute(IntentExecutorContext intentExecutorContext, Intent intent, IAlexaProxyService alexaProxyService)
        {
            var modoRave = new ModoRave(alexaProxyService);
            var thread   = new Thread(() => modoRave.Execute());

            thread.Start();

            return(new IntentExecutorContext()
            {
                Response = "Vamos começar a rave!",
                NeedConfirmation = false,
            });
        }
示例#10
0
 private TargetStates GetTargetState(IntentExecutorContext intentExecutorContext)
 {
     if (string.Equals(intentExecutorContext.Intent, AlexaIntents.ActivateIntent.Name, StringComparison.InvariantCultureIgnoreCase))
     {
         return(TargetStates.Activate);
     }
     else if (string.Equals(intentExecutorContext.Intent, AlexaIntents.DeactivateIntent.Name, StringComparison.InvariantCultureIgnoreCase))
     {
         return(TargetStates.Deactivate);
     }
     else
     {
         throw new SpeechletException($"Intent '{intentExecutorContext.Intent}' não é suportada");
     }
 }
示例#11
0
        private static IntentExecutorContext EnsureContexto(IntentExecutorContext intentExecutorContext, Intent intent)
        {
            if (intentExecutorContext == null)
            {
                intentExecutorContext = new IntentExecutorContext()
                {
                    Intent          = intent.Name,
                    PortsQuery      = PortsQueryProcessor.GetQueryFromIntent(intent),
                    TargetPortState = string.Equals(AlexaIntents.ActivateIntent.Name, intent.Name, StringComparison.InvariantCultureIgnoreCase) ?
                                      PortStates.Actived : PortStates.Deactived
                };
            }

            return(intentExecutorContext);
        }
示例#12
0
        public IntentExecutorContext Execute(IntentExecutorContext intentExecutorContext, Intent intent, IAlexaProxyService alexaProxyService)
        {
            intentExecutorContext = EnsureContexto(intentExecutorContext, intent);

            LocateMissingPorts(intentExecutorContext, alexaProxyService);

            if (intentExecutorContext.TargetPorts == null)
            {
                intentExecutorContext.Response = $"Não foi possível localizar o dispositivo {intentExecutorContext.PortsQuery}";
            }
            else if (!intentExecutorContext.NeedConfirmation)
            {
                var changePortStateRequests = intentExecutorContext.TargetPorts.Select(p => new ChangePortStateRequest(p)).ToArray();
                var targetState             = GetTargetState(intentExecutorContext);
                Func <string, bool> changeStateFunc;
                switch (targetState)
                {
                case TargetStates.Activate:
                    changeStateFunc = alexaProxyService.ActivatePort;
                    break;

                case TargetStates.Deactivate:
                    changeStateFunc = alexaProxyService.DeactivatePort;
                    break;

                default:
                    throw new SpeechletException($"TargetStates '{targetState}' não é suportado");
                }

                foreach (var changePortStateRequest in changePortStateRequests)
                {
                    changePortStateRequest.StateChanged = changeStateFunc(changePortStateRequest.PortName);
                }

                intentExecutorContext.Response = BuildResponseMessage(changePortStateRequests, targetState);
            }
            else if (intentExecutorContext.NeedConfirmation)
            {
                intentExecutorContext.Response = BuildConfirmationMessage(intentExecutorContext);
            }

            return(intentExecutorContext);
        }