Example #1
0
        void StartAllJoynActivity()
        {
            this.CreateBusAttachmentForAdvertisement();

            this.lightControlProducer = new LightControlProducer(
                this.advertisingBusAttachment)
            {
                Service = new LightControlService()
            };
            this.lightControlProducer.Start();

            RemoteLightControlManager.LightControlDiscovered += OnBuildingDiscovered;

            RemoteLightControlManager.Initialise(BuildingPersistence.Instance.Name);
        }
Example #2
0
        async Task SwitchToRemoteBuildingAsync(string otherBuilding,
                                               int timeoutInSeconds = 0)
        {
            this.currentConsumer =
                await RemoteLightControlManager.GetConsumerForRemoteBuildingAsync(
                    otherBuilding,
                    timeoutInSeconds);

            var json = await this.currentConsumer.GetBuildingDefinitionJsonAsync();

            if (json.Status == AllJoynStatus.Ok)
            {
                var building = JsonConvert.DeserializeObject <Building>(json.Json);

                this.Building = building;

                this.isLocalBuilding = false;
            }
        }
Example #3
0
        /// <summary>
        /// Big note - we do not deal with cancellation in this background task
        /// and we should. We should handle the situation both the background
        /// task being cancelled and also the voice command firing its
        /// Completed event to do things properly
        /// </summary>
        /// <param name="taskInstance"></param>
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails?.Name == "buildingCommandService")
            {
                var deferral = taskInstance.GetDeferral();

                // Load up our stored local building configuration if not already loaded.
                if (BuildingPersistence.Instance == null)
                {
                    BuildingPersistence.Instance = await BuildingPersistence.LoadAsync();
                }
                // Start building a list of remote building configurations if not already
                // started..
                RemoteLightControlManager.Initialise(BuildingPersistence.Instance.Name);

                // Get the connection to the 'Cortana' end of this conversation.
                var voiceConnection =
                    VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                // We should handle voiceConnection.VoiceCommandCompleted here, we
                // don't yet.

                // What command has been issued?
                var voiceCommand = await voiceConnection.GetVoiceCommandAsync();

                // Is this the command that we understand?
                if (voiceCommand.CommandName == "backgroundSwitchLights")
                {
                    await this.ProcessCommandAsync(voiceConnection, voiceCommand.SpeechRecognitionResult);

                    await voiceConnection.ReportSuccessAsync(MakeResponse("all done"));
                }
                else
                {
                    // Need to report an error
                    await ReportErrorAsync(voiceConnection,
                                           "the command name passed does not match across XML/code");
                }
                deferral.Complete();
            }
        }
Example #4
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}");
            }
        }