예제 #1
0
        async Task ProcessCommandAsync(
            VoiceCommandServiceConnection voiceConnection,
            SpeechRecognitionResult speechRecognitionResult)
        {
            // Extract the details of the building, room, and onOff value.
            var commandDetails =
                BuildingVoiceCommandParser.Parse(speechRecognitionResult);

            if ((commandDetails?.RulePath != null) &&
                (!string.IsNullOrEmpty(commandDetails.Building)) &&
                (commandDetails.OnOff.HasValue))
            {
                // We may still not have a room, that's fine if we get this far without one.
                if (commandDetails.Building == BuildingPersistence.Instance.Name)
                {
                    await ProcessLocalBuildingCommandAsync(voiceConnection, commandDetails);
                }
                else
                {
                    await ProcessRemoteBuildingCommandAsync(voiceConnection, commandDetails);
                }
            }
            else
            {
                await ReportErrorAsync(voiceConnection,
                                       "we got a result from the speech parser that we were not expecting");
            }
        }
예제 #2
0
        protected async override void OnActivated(IActivatedEventArgs args)
        {
            base.OnActivated(args);

            if (args.Kind == ActivationKind.VoiceCommand)
            {
                // Create the UI. We assume that the configuration has been done
                // before any voice commands are issued. Wouldn't be ok for a real
                // app but it's ok for us.
                await CreateUIAndLoadBuildingDataAsync(false);

                VoiceCommandActivatedEventArgs voiceArgs =
                    (VoiceCommandActivatedEventArgs)args;

                // Which rule were we invoked with?
                BuildingCommandDetails commandDetails =
                    BuildingVoiceCommandParser.Parse(voiceArgs.Result);

                if (!string.IsNullOrEmpty(commandDetails?.RulePath))
                {
                    if ((commandDetails.RulePath == "switchLights") ||
                        (commandDetails.RulePath == "showLights") &&
                        !string.IsNullOrEmpty(commandDetails.Building))
                    {
                        await MonitorPage.Instance.SwitchToBuildingAsync(commandDetails.Building);
                    }
                    if (!string.IsNullOrEmpty(commandDetails.Building) &&
                        commandDetails.OnOff.HasValue)
                    {
                        if (string.IsNullOrEmpty(commandDetails.Room))
                        {
                            await MonitorPage.Instance.SwitchLightsInBuildingAsync(
                                commandDetails.OnOff.Value);
                        }
                        else
                        {
                            await MonitorPage.Instance.SwitchLightsInRoomAsync(
                                (RoomType)Enum.Parse(typeof(RoomType), commandDetails.Room),
                                commandDetails.OnOff.Value);
                        }
                    }
                }
            }
        }