Esempio n. 1
0
        async Task ProcessLocalBuildingCommandAsync(
            VoiceCommandServiceConnection voiceConnection,
            BuildingCommandDetails commandDetails)
        {
            if (string.IsNullOrEmpty(commandDetails.Room))
            {
                commandDetails.Room = await this.DisambiguateRoomAsync(
                    voiceConnection,
                    BuildingPersistence.Instance.Rooms);
            }
            // Local building, relatively easy.
            if (string.IsNullOrEmpty(commandDetails.Room))
            {
                BuildingPersistence.Instance.SwitchAllLights(commandDetails.OnOff.Value);
            }
            else
            {
                var room = BuildingPersistence.Instance.GetRoomByName(commandDetails.Room);

                if (room != null)
                {
                    room.SwitchLights(commandDetails.OnOff.Value);
                }
            }
            await BuildingPersistence.SaveAsync(BuildingPersistence.Instance);
        }
Esempio n. 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);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        async Task ProcessRemoteBuildingCommandAsync(
            VoiceCommandServiceConnection voiceConnection,
            BuildingCommandDetails commandDetails)
        {
            // We're on a remote building. Do we know it or not?
            var remoteConsumer = await RemoteLightControlManager.GetConsumerForRemoteBuildingAsync(
                commandDetails.Building, 5);

            if (remoteConsumer != null)
            {
                // If we've not been given a room, let the user choose one if they want to.
                if (string.IsNullOrEmpty(commandDetails.Room))
                {
                    // We need to grab the room details - involves a network call and some
                    // deserialization :-S
                    var remoteBuildingJson = await remoteConsumer.GetBuildingDefinitionJsonAsync();

                    var remoteBuilding = JsonConvert.DeserializeObject <Building>(remoteBuildingJson.Json);

                    commandDetails.Room = await this.DisambiguateRoomAsync(
                        voiceConnection,
                        remoteBuilding.Rooms);
                }
                // We've found the building, this is a good sign!
                if (string.IsNullOrEmpty(commandDetails.Room))
                {
                    await remoteConsumer.SwitchBuildingAsync(commandDetails.OnOff.Value);
                }
                else
                {
                    await remoteConsumer.SwitchRoomAsync(
                        commandDetails.Room, commandDetails.OnOff.Value);
                }
            }
            else
            {
                await ReportErrorAsync(
                    voiceConnection,
                    $"Sorry, I could not find a connection to the {commandDetails.Building}");
            }
        }