public async void Run(IBackgroundTaskInstance taskInstance)
        {
            deferral = taskInstance.GetDeferral();
            taskInstance.Canceled += TaskInstance_Canceled;
            try
            {
                var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;
                voiceServiceConn = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                var command = await voiceServiceConn?.GetVoiceCommandAsync();

                switch (command.CommandName)
                {
                case "RollCommand":
                    await ServiceCommandHandleAsync(command.SpeechRecognitionResult.SemanticInterpretation);

                    break;

                case "ShowAllCommand":
                    await FindCommandHandleAsync(command.SpeechRecognitionResult.SemanticInterpretation);

                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            finally
            {
                deferral?.Complete();
            }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral        = taskInstance.GetDeferral();
            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            cortanaResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("Resources");

            cortanaContext = ResourceContext.GetForViewIndependentUse();

            dateFormatInfo = CultureInfo.CurrentCulture.DateTimeFormat;

            if (triggerDetails != null && triggerDetails.Name == "JeedomAppVoiceCommandService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    var    userMessage = new VoiceCommandUserMessage();
                    string message     = "";


                    // Ajout d'une requet jeedom pour retrouver la commande
                    switch (voiceCommand.CommandName)
                    {
                    case "JeedomInteractList":
                        string CortanaVoiceCommande = voiceCommand.Properties["InteractList"][0];
                        await Jeedom.RequestViewModel.Instance.interactTryToReply(CortanaVoiceCommande);

                        message = Jeedom.RequestViewModel.Instance.InteractReply;
                        break;

                    default:
                        LaunchAppInForeground();
                        break;
                    }

                    userMessage.DisplayMessage = message;
                    userMessage.SpokenMessage  = message;


                    var response = VoiceCommandResponse.CreateResponse(userMessage);
                    response.AppLaunchArgument = message;


                    await voiceServiceConnection.ReportSuccessAsync(response);
                }
                catch (Exception ex)
                {
                    //System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Helper method for initalizing the voice service, bridge, and lights. Returns if successful.
        /// </summary>
        private async Task <bool> InitializeAsync(AppServiceTriggerDetails triggerDetails)
        {
            _voiceServiceConnection =
                VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
            _voiceServiceConnection.VoiceCommandCompleted += (s, e) => _deferral.Complete();

            _voiceCommand = await _voiceServiceConnection.GetVoiceCommandAsync();

            _colors = HsbColor.CreateAll().ToDictionary(x => x.Name);

            var localStorage = ApplicationData.Current.LocalSettings.Values;

            _bridge = new Bridge(
                localStorage["bridgeIp"].ToString(), localStorage["userId"].ToString());
            try
            {
                _lights = await _bridge.GetLightsAsync();
            }
            catch (Exception)
            {
                var response = CreateCortanaResponse("Sorry, I couldn't connect to your bridge.");
                await _voiceServiceConnection.ReportFailureAsync(response);

                return(false);
            }
            if (!_lights.Any())
            {
                var response = CreateCortanaResponse("Sorry, I couldn't find any lights.");
                await _voiceServiceConnection.ReportFailureAsync(response);

                return(false);
            }
            return(true);
        }
Beispiel #4
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            // add service functionality here
            // inform the system that the background task may
            // continue after the Run method has completed
            this._deferral = taskInstance.GetDeferral();

            // added event handler to handle cancel by user
            taskInstance.Canceled += TaskInstance_Canceled;

            // trigger details gives more information about the
            // task instance
            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if ((triggerDetails != null) &&
                (triggerDetails.Name == "CortanaBackgroundService"))
            {
                // try to get the voice command and respond to it.
                try
                {
                    // Retrieves a VoiceCommandServiceConnection object
                    // from the AppServiceTriggerDetails that
                    // contains info associated with the background
                    // task for the app service
                    voiceServiceConection =
                        VoiceCommandServiceConnection.
                        FromAppServiceTriggerDetails(triggerDetails);

                    // set up the command completed method to indicate completion
                    // calls deferral.complete here
                    voiceServiceConection.VoiceCommandCompleted += VoiceServiceConection_VoiceCommandCompleted;

                    // get the voice command information
                    VoiceCommand voiceCommand = await voiceServiceConection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "howsMyCoffee":
                    {
                        sendUpdateMessageByReturn();
                        break;
                    }

                    default:
                    {
                        launchAppInForeground();
                        break;
                    }
                    }
                }
                finally
                {
                    if (this._deferral != null)
                    {
                        // complete the service deferral
                        this._deferral.Complete();
                    }
                } // end try
            }
        }
Beispiel #5
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral        = taskInstance.GetDeferral();
            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            try
            {
                voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                var interpretation = voiceCommand.SpeechRecognitionResult.SemanticInterpretation;

                await ProcessGenerateFactAsync(interpretation);

                this.serviceDeferral.Complete();
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #6
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

            taskInstance.Canceled += TaskInstance_Canceled;

            var triggerDetails = taskInstance.TriggerDetails
                                 as AppServiceTriggerDetails;

            if (triggerDetails?.Name != nameof(VoiceCommandService))
            {
                return;
            }

            var connection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

            connection.VoiceCommandCompleted += ConnectionOnVoiceCommandCompleted;

            var command = await connection.GetVoiceCommandAsync();

            switch (command.CommandName)
            {
            case "ReadEventsByCortanaCommand":
                await HandleReadNamedaysCommandAsync(connection);

                break;
            }


            deferral.Complete();
        }
Beispiel #7
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

            taskInstance.Canceled += TaskInstance_Canceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails?.Name != nameof(VoiceCommandService))
            {
                return;
            }

            var connection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

            connection.VoiceCommandCompleted += ConnectionOnVoiceCommandCompleted;

            var command = await connection.GetVoiceCommandAsync();

            // even if it's not used, you can run into issues without this line.

            switch (command.CommandName)
            {
            case "ReadTodaysNamedays":
                await HandleReadNamedaysCommandAsync(connection);

                break;
            }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            // Create the deferral by requesting it from the task instance
            serviceDeferral = taskInstance.GetDeferral();

            AppServiceTriggerDetails triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null && triggerDetails.Name.Equals("VoiceCommandService"))
            {
                voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                // Perform the appropriate command depending on the operation defined in VCD
                switch (voiceCommand.CommandName)
                {
                case "CheckTemperature":
                    VoiceCommandUserMessage userMessage = new VoiceCommandUserMessage();
                    userMessage.DisplayMessage = "The current temperature is 23 degrees";
                    userMessage.SpokenMessage  = "The current temperature is 23 degrees";

                    VoiceCommandResponse response = VoiceCommandResponse.CreateResponse(userMessage, null);
                    await voiceServiceConnection.ReportSuccessAsync(response);

                    break;

                default:
                    break;
                }
            }

            // Once the asynchronous method(s) are done, close the deferral
            serviceDeferral.Complete();
        }
        /*  ResourceMap cortanaResourceMap;
         * ResourceContext cortanaContext;
         * DateTimeFormatInfo dateFormatInfo;*/

        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            ServiceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += TaskInstance_Canceled;

            var TriggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (TriggerDetails != null && TriggerDetails.Name == "TDTCortanaCommandServices")
            {
                VoiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(TriggerDetails);

                VoiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                // GetVoiceCommandAsync establishes initial connection to Cortana, and must be called prior to any
                // messages sent to Cortana. Attempting to use ReportSuccessAsync, ReportProgressAsync, etc
                // prior to calling this will produce undefined behavior.
                VoiceCommand voiceCommand = await VoiceServiceConnection.GetVoiceCommandAsync();

                switch (voiceCommand.CommandName)
                {
                case "ShowMyTasks":
                    string Style;
                    try
                    {
                        Style = voiceCommand.Properties["Style"][0];
                    }
                    catch
                    {
                        Style = "";
                    }
                    await ShowTasks(Style, voiceCommand.SpeechRecognitionResult.Text.Contains("today"));

                    break;

                case "CompleteSpecificTask":
                    var CompletedTask = voiceCommand.Properties["Tasks"][0];
                    CompleteTask(CompletedTask);
                    break;

                case "DeleteSpecificTask":
                    var DeletedTask = voiceCommand.Properties["Tasks"][0];
                    DeleteTask(DeletedTask);
                    break;

                case "ShowDetailForSpecificTask":
                    var DetailedTask = voiceCommand.Properties["Tasks"][0];
                    ShowDetailsOfTask(DetailedTask);
                    break;

                default:
                    // As with app activation VCDs, we need to handle the possibility that
                    // an app update may remove a voice command that is still registered.
                    // This can happen if the user hasn't run an app since an update.
                    //LaunchAppInForeground();
                    break;
                }
            }
        }
Beispiel #10
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            this.serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails =
                taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null &&
                triggerDetails.Name == "CortanaAppService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted +=
                        VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "drinkAGlass":
                    {
                        var subject = voiceCommand.Properties["subject"][0];
                        var amount  = voiceCommand.Properties["amount"][0];
                        await SendCompletionMessageForFixedAmount(amount, subject);

                        break;
                    }

                    case "drinkAmount":
                    {
                        var amount   = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["amount"][0];
                        var beverage = voiceCommand.Properties["beverage"][0];
                        await SendCompletionMessageForAmount(amount, beverage);

                        break;
                    }

                    // As a last resort launch the app in the foreground
                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                finally
                {
                    //if (this.serviceDeferral != null)
                    //{
                    //    //Complete the service deferral
                    //    this.serviceDeferral.Complete();
                    //}
                }
            }
        }
Beispiel #11
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            this.serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null &&
                triggerDetails.Name == "TalkToMeVoiceCommandService")
            {
                try
                {
                    voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                    voiceServiceConnection.VoiceCommandCompleted += VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "startMyPresentation":
                        ShowStartMyPresentation();
                        break;

                    case "endMyPresentation":
                        ShowEndMyPresentation();
                        break;

                    case "bankBalance":
                        SendCompletionMessageForBankAccount();
                        break;

                    case "whatDoYouThinkAbout":
                        var name = voiceCommand.Properties["name"][0];
                        SendCompletionMessageForName(name);
                        break;

                    case "birthday":
                        var birthdayName = voiceCommand.Properties["name"][0];
                        SingABirthdaySong(birthdayName);
                        break;

                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                finally
                {
                    if (this.serviceDeferral != null)
                    {
                        //Complete the service deferral
                        this.serviceDeferral.Complete();
                    }
                }
            }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //Take a service deferral so the service isn&#39;t terminated.
            this.serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails =
                taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null &&
                triggerDetails.Name == "VoiceCommandsService")
            {
                try
                {
                    voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted += VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "calculatePropablityDSA":
                    {
                        string e1             = voiceCommand.Properties["eigenschaft1"][0];
                        string e2             = voiceCommand.Properties["eigenschaft2"][0];
                        string e3             = voiceCommand.Properties["eigenschaft3"][0];
                        string tawString      = voiceCommand.Properties["taw"][0];
                        var    voiceParameter = new DSAVoiceCommand(e1, e2, e3);
                        var    calculator     = new DSAPropabilityCaluator(voiceParameter.Eigentschaft1, voiceParameter.Eigentschaft2, voiceParameter.Eigentschaft3);
                        int    taw;
                        if (!int.TryParse(tawString, out taw))
                        {
                            taw = 5;
                        }
                        var probability = calculator.CalcualteDicePropability(taw);
                        SendCompletionMessageForDestination(probability, voiceParameter);
                        break;
                    }

                    // As a last resort, launch the app in the foreground.
                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                finally
                {
                    if (this.serviceDeferral != null)
                    {
                        // Complete the service deferral.
                        this.serviceDeferral.Complete();
                    }
                }
            }
        }
Beispiel #13
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral        = taskInstance.GetDeferral();
            taskInstance.Canceled += TaskInstance_Canceled;

            httpClient = new HttpClient();

            AppServiceTriggerDetails triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null && triggerDetails.Name == "HuemongousVoiceCommandService")
            {
                voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                voiceServiceConnection.VoiceCommandCompleted += VoiceServiceConnection_VoiceCommandCompleted;

                VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                if (voiceCommand.CommandName == "LightsOnOrOff")
                {
                    string lightState = voiceCommand.Properties["lightState"][0];
                    await HandleLightsOnOrOff(lightState);
                }
                else if (voiceCommand.CommandName == "LightOnOrOff")
                {
                    string lightState     = voiceCommand.Properties["lightState"][0];
                    string lightOrRoom    = voiceCommand.Properties["lightOrRoom"][0];
                    string lightPlurality = voiceCommand.Properties["lightPlurality"][0];
                    await HandleLightOnOrOff(lightState, lightOrRoom, lightPlurality);
                }
                else if (voiceCommand.CommandName == "SpecifyLightOnOrOff")
                {
                    string lightState = voiceCommand.Properties["lightState"][0];
                }
                else if (voiceCommand.CommandName == "SetLightScene")
                {
                    string scene = voiceCommand.Properties["scene"][0];
                }
                else if (voiceCommand.CommandName == "SetLightsColor")
                {
                    string color = voiceCommand.Properties["color"][0];
                    await HandleSetLightsColor(color);
                }
                else if (voiceCommand.CommandName == "SetLightColor")
                {
                    string lightOrRoom    = voiceCommand.Properties["lightOrRoom"][0];
                    string lightPlurality = voiceCommand.Properties["lightPlurality"][0];
                    string color          = voiceCommand.Properties["color"][0];
                }
                else if (voiceCommand.CommandName == "SpecifyLightColor")
                {
                    string color = voiceCommand.Properties["color"][0];
                }
                else
                {
                    Debug.WriteLine("unknown command");
                }
            }
        }
        /// <summary>
        /// Background task entrypoint. Voice Commands using the <VoiceCommandService Target="...">
        /// tag will invoke this when they are recognized by Cortana, passing along details of the
        /// invocation.
        ///
        /// Background tasks must respond to activation by Cortana within 0.5 seconds, and must
        /// report progress to Cortana every 5 seconds (unless Cortana is waiting for user
        /// input). There is no execution time limit on the background task managed by Cortana,
        /// but developers should use plmdebug (https://msdn.microsoft.com/en-us/library/windows/hardware/jj680085%28v=vs.85%29.aspx)
        /// on the Cortana app package in order to prevent Cortana timing out the task during
        /// debugging.
        ///
        /// Cortana dismisses its UI if it loses focus. This will cause it to terminate the background
        /// task, even if the background task is being debugged. Use of Remote Debugging is recommended
        /// in order to debug background task behaviors. In order to debug background tasks, open the
        /// project properties for the app package (not the background task project), and enable
        /// Debug -> "Do not launch, but debug my code when it starts". Alternatively, add a long
        /// initial progress screen, and attach to the background task process while it executes.
        /// </summary>
        /// <param name="taskInstance">Connection to the hosting background service process.</param>
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral = taskInstance.GetDeferral();

            // Register to receive an event if Cortana dismisses the background task. This will
            // occur if the task takes too long to respond, or if Cortana's UI is dismissed.
            // Any pending operations should be cancelled or waited on to clean up where possible.
            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            // This should match the uap:AppService and VoiceCommandService references from the
            // package manifest and VCD files, respectively. Make sure we've been launched by
            // a Cortana Voice Command.
            if (triggerDetails != null && triggerDetails.Name == "AdventureWorksVoiceCommandService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    // Depending on the operation (defined in AdventureWorks:AdventureWorksCommands.xml)
                    // perform the appropriate command.
                    switch (voiceCommand.CommandName)
                    {
                    case "whenIsTripToDestination":
                        var destination = voiceCommand.Properties["destination"][0];
                        await SendCompletionMessageForDestination(destination);

                        break;

                    case "cancelTripToDestination":
                        var cancelDestination = voiceCommand.Properties["destination"][0];
                        await SendCompletionMessageForCancellation(cancelDestination);

                        break;

                    default:
                        // As with app activation VCDs, we need to handle the possibility that
                        // an app update may remove a voice command that is still registered.
                        // This can happen if the user hasn't run an app since an update.
                        LaunchAppInForeground();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
Beispiel #15
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //Take a service deferral so the service isn't terminated
            this.serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails =
                taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null &&
                triggerDetails.Name == "CortanaAppService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted +=
                        VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await
                                                voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "toggleSwitch":
                    {
                        var pref =
                            voiceCommand.Properties["pref"][0];
                        var switchname =
                            voiceCommand.Properties["switch"][0];
                        var state =
                            voiceCommand.Properties["state"][0];
                        await ToggleSwitch(pref, switchname, state);

                        break;
                    }

                    // As a last resort launch the app in the foreground
                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                finally
                {
                    if (this.serviceDeferral != null)
                    {
                        //Complete the service deferral
                        this.serviceDeferral.Complete();
                    }
                }
            }
        }
Beispiel #16
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _serviceDeferral = taskInstance.GetDeferral();

            // Register to receive an event if Cortana dismisses the background task. This will
            // occur if the task takes too long to respond, or if Cortana's UI is dismissed.
            // Any pending operations should be cancelled or waited on to clean up where possible.
            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;


            // Select the system language, which is what Cortana should be running as.
            _cortanaContext = ResourceContext.GetForViewIndependentUse();

            // This should match the uap:AppService and VoiceCommandService references from the
            // package manifest and VCD files, respectively. Make sure we've been launched by
            // a Cortana Voice Command.
            if (triggerDetails != null && triggerDetails.Name == "CortanaDialogFlow")
            {
                try
                {
                    _voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    _voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                    // GetVoiceCommandAsync establishes initial connection to Cortana, and must be called prior to any
                    // messages sent to Cortana. Attempting to use ReportSuccessAsync, ReportProgressAsync, etc
                    // prior to calling this will produce undefined behavior.
                    VoiceCommand voiceCommand = await _voiceServiceConnection.GetVoiceCommandAsync();

                    // Depending on the operation (defined in TestCortana:TestCortanaCommands.xml)
                    // perform the appropriate command.
                    switch (voiceCommand.CommandName)
                    {
                    case "changeAmbiance":
                        await SendCompletionMessageForAmbiance();

                        break;

                    default:
                        // As with app activation VCDs, we need to handle the possibility that
                        // an app update may remove a voice command that is still registered.
                        // This can happen if the user hasn't run an app since an update.
                        LaunchAppInForeground();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
Beispiel #17
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _serviceDeferral = taskInstance.GetDeferral();


            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null && triggerDetails.Name == "CortanaBGService")
            {
                try
                {
                    voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted += VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "blinds":
                    {
                        foreach (var prop in voiceCommand.Properties)
                        {
                            Debug.WriteLine(String.Format("prop {0} = {1}", prop.Key, prop.Value.ToString()));
                        }

                        var state = voiceCommand.Properties["blindState"][0];
                        var blind = voiceCommand.Properties["blindId"][0];

                        await ChangeBlindState(blind, state);

                        break;
                    }

                    // As a last resort launch the app in the foreground
                    default:
                        _serviceDeferral.Complete();
                        break;
                    }
                }
                catch (Exception)
                {
                    Debugger.Break();
                }
                finally
                {
                    if (_serviceDeferral != null)
                    {
                        //Complete the service deferral
                        _serviceDeferral.Complete();
                        _serviceDeferral = null;
                    }
                }
            }
        }
        async public void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();

            var local = ApplicationData.Current.LocalFolder;

            State = await AppState.FromStorageFileAsync(local, "state.xml");

            var app_service = taskInstance.TriggerDetails as AppServiceTriggerDetails;
            var connection  = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(app_service);

            //get the voice command
            var command = await connection.GetVoiceCommandAsync();

            var rule_path = command.SpeechRecognitionResult.RulePath[0];

            VoiceCommandUserMessage user_message = new VoiceCommandUserMessage();

            if (rule_path == "change-desktop-wallpaper")
            {
                await HandleChangeWallpaper(connection, user_message);
            }
            else if (rule_path == "make-suggestions")
            {
                await HandleMakeSuggestions(connection, command, user_message);
            }
            else if (rule_path == "buy-tickets")
            {
                await HandleBuyTickets(connection, command, user_message);
            }
            else if (rule_path == "count")
            {
                count++;
                user_message.SpokenMessage  = $"the current count is {count}";
                user_message.DisplayMessage = user_message.SpokenMessage;
                var response = VoiceCommandResponse.CreateResponse(user_message);
                await connection.ReportSuccessAsync(response);
            }
            else if (rule_path == "joke-knock-knock")
            {
                await HandleTellJoke(connection, user_message);
            }
            else if (rule_path == "joke-whos-there")
            {
                await HandleWhosThere(connection, user_message);
            }
            else if (rule_path == "joke-punchline")
            {
                await HandlePunchline(connection, command, user_message);
            }

            _deferral.Complete();
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral        = taskInstance.GetDeferral();
            taskInstance.Canceled += OnTaskCancelled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            cortanaResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("Resources");
            cortanaContext     = ResourceContext.GetForViewIndependentUse();

            if (triggerDetails != null && triggerDetails.Name == "VoiceCommandService")
            {
                try
                {
                    voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    var client = await this.GetClient();

                    // Depending on the operation (defined in the VoiceCommands.xml file)
                    // perform the appropriate command.
                    switch (voiceCommand.CommandName)
                    {
                    case "turnOnItem":
                        var onTarget = voiceCommand.Properties["target"][0];
                        await SendCompletionMessageForOnOff(client, onTarget, true);

                        break;

                    case "turnOffItem":
                        var offTarget = voiceCommand.Properties["target"][0];
                        await SendCompletionMessageForOnOff(client, offTarget, false);

                        break;

                    default:
                        // As with app activation VCDs, we need to handle the possibility that
                        // an app update may remove a voice command that is still registered.
                        // This can happen if the user hasn't run an app since an update.
                        //LaunchAppInForeground();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
Beispiel #20
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //Take a service deferral so the service isn&#39;t terminated.
            this.serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += VoiceCommandCanceled;

            var triggerDetails =
                taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null &&
                triggerDetails.Name == "ContactsVoiceCommandService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted +=
                        VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await
                                                voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "zeige":
                    {
                        var contactName =
                            voiceCommand.Properties["nutzer"][0];
                        SendCompletionMessageForContact(contactName);
                        break;
                    }

                    // As a last resort, launch the app in the foreground.
                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                finally
                {
                    if (this.serviceDeferral != null)
                    {
                        // Complete the service deferral.
                        this.serviceDeferral.Complete();
                    }
                }
            }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            taskDeferall = taskInstance.GetDeferral();

            //we add OnTaskCanceled event
            taskInstance.Canceled += OnTaskCanceled;

            //grab triggerDetails and cast on ApppService type 
            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;
            try
            {
                //here we creating connection which has all our information
                voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                //Add CompletedEvent without it Cortand will hang up very often that's why Cortans won't know when task is completed
                //I divided  Completed into two ways  one: TaskCompleted and second VoiceCommand Completed to let Cortana know when task and command is completed 
                voiceServiceConnection.OnVoiceCommandCompleted += OnVoiceCommandCompleted;

                //voiceCommand is part of voiceSerivceConnection  I'm gonna to use it for....
                VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                //grab interpretation
                //Interpreatin is very important to inform Cortan what we want, it's all we care about 
                var interpretation = voiceCommand.SpeechRecognitionResult.SemanticInterpretation;
                VoiceCommandType commandType = (VoiceCommandType)Enum.Parse(typeof(VoiceCommandType), voiceCommand.CommandName, true);
                switch(commandType)
                {
                    case VoiceCommandType.InterestingFactQueryCommand:
                        await ProcessInterestingFactAsync(interpretation);
                        break;
                    case VoiceCommandType.WeekOfYearQueryCommand:
                        await ProcessWeekOfYearAsync(interpretation);
                        break;

                    case VoiceCommandType.FindBusinessQueryCommand:
                        ProcessFindBusinessAsync(interpretation);
                        break;

                    default:
                        break;
                }

            }
            catch(Exception ex)
            {

            }



        }
Beispiel #22
0
        /* Unused, because this project does not yet need localised resources
         * /// <summary>
         * /// ResourceMap containing localized strings for display in Cortana.
         * /// </summary>
         * ResourceMap cortanaResourceMap;
         *
         * /// <summary>
         * /// The context for localized strings.
         * /// </summary>
         * ResourceContext cortanaContext;
         */

        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //Use to let Cortana know what's up
            serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            AppServiceTriggerDetails triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null && triggerDetails.Name == "AdventureWorksVoiceCommandService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    // Perform the appropriate command (defined in Manto:MantoCortanaCommands.xml)
                    switch (voiceCommand.CommandName)
                    {
                    case "whenIsTripToDestination":
                        var destination = voiceCommand.Properties["destination"][0];
                        await SendCompletionMessageForDestination(destination);

                        break;

                    case "cancelTripToDestination":
                        var cancelDestination = voiceCommand.Properties["destination"][0];
                        await SendCompletionMessageForCancellation(cancelDestination);

                        break;

                    default:
                        // As with app activation VCDs, we need to handle the possibility that
                        // an app update may remove a voice command that is still registered.
                        // This can happen if the user hasn't run an app since an update.
                        LaunchAppInForeground();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //service deferral so that the  app service is not terminated while handling the voice command.
            this.serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails =
                taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null && triggerDetails.Name == "HelloCortanaVoiceCommandService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted +=
                        VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await
                                                voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "showInCanvas":
                    {
                        var destination =
                            voiceCommand.Properties["destination"][0];
                        SendCompletionMessageForDestination(destination);
                        break;
                    }


                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                finally
                {
                    if (this.serviceDeferral != null)
                    {
                        // Complete the service deferral.
                        this.serviceDeferral.Complete();
                    }
                }
            }
        }
Beispiel #24
0
        /// <summary>
        /// Background task entrypoint. Voice Commands using the <VoiceCommandService Target="...">
        /// tag will invoke this when they are recognized by Cortana, passing along details of the
        /// invocation.
        /// </summary>
        /// <param name="taskInstance">Connection to the hosting background service process.</param>
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            cortanaResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("Strings");
            cortanaContext     = ResourceContext.GetForViewIndependentUse();
            dateFormatInfo     = CultureInfo.CurrentCulture.DateTimeFormat;

            if (triggerDetails != null && triggerDetails.Name == "VoiceCommandService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                    // GetVoiceCommandAsync establishes initial connection to Cortana, and must be called prior to any
                    // messages sent to Cortana. Attempting to use ReportSuccessAsync, ReportProgressAsync, etc
                    // prior to calling this will produce undefined behavior.
                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "enterLivingRoom":
                    case "leaveLivingRoom":
                        await HandleRoomEvent(voiceCommand.CommandName);

                        break;

                    default:
                        // As with app activation VCDs, we need to handle the possibility that
                        // an app update may remove a voice command that is still registered.
                        // This can happen if the user hasn't run an app since an update.
                        LaunchAppInForeground();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            // Load localized resources for strings sent to Cortana to be displayed to the user.
            cortanaResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("Resources");

            // Select the system language, which is what Cortana should be running as.
            cortanaContext = ResourceContext.GetForViewIndependentUse();


            if (triggerDetails != null && triggerDetails.Name == "HolVoiceCommandService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "SayHello":
                        var userMessage = new VoiceCommandUserMessage();
                        userMessage.DisplayMessage = "Hello!";
                        userMessage.SpokenMessage  = "Your app says hi. It is having a great time.";
                        var response = VoiceCommandResponse.CreateResponse(userMessage);
                        await voiceServiceConnection.ReportSuccessAsync(response);

                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
Beispiel #26
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //Take a service deferral so the service isn&#39;t terminated.
            this.serviceDeferral = taskInstance.GetDeferral();


            var triggerDetails =
                taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null && triggerDetails.Name == "VoiceService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted +=
                        VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await
                                                voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "howIsMood":
                    {
                        Task.Delay(1000);
                        SendCompletionMessageForDestination("lahm");
                        break;
                    }

                    // As a last resort, launch the app in the foreground.
                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                finally
                {
                    if (this.serviceDeferral != null)
                    {
                        // Complete the service deferral.
                        this.serviceDeferral.Complete();
                    }
                }
            }
        }
Beispiel #27
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            try {
                if (triggerDetails != null)
                {
                    voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                    voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandComplete;
                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    var person = voiceCommand.Properties["person"][0];

                    var userMessage = new VoiceCommandUserMessage();
                    userMessage.DisplayMessage = "Which workflow would you like to trigger?";
                    userMessage.SpokenMessage  = "Which workflow would you like to trigger?";
                    var workflowTiles = new List <VoiceCommandContentTile>()
                    {
                        new VoiceCommandContentTile()
                        {
                            ContentTileType   = VoiceCommandContentTileType.TitleWith68x68IconAndText,
                            Image             = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///GhostRider.VoiceCommands/Images/GreyTile.scale-100.png")),
                            Title             = "Create New Page",
                            AppLaunchArgument = $"person={person}",
                            TextLine1         = "Creates a new basic page"
                        },
                        new VoiceCommandContentTile()
                        {
                            ContentTileType   = VoiceCommandContentTileType.TitleWith68x68IconAndText,
                            Image             = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Images/GreyTile.scale-100.png")),
                            Title             = "Conquer the World",
                            AppLaunchArgument = $"person={person}",
                            TextLine1         = "Destroys all of your enemies"
                        },
                    };

                    var response = VoiceCommandResponse.CreateResponse(userMessage, workflowTiles);
                    await this.voiceServiceConnection.ReportSuccessAsync(response);

                    //await DetermineAction(voiceCommand);
                }
            }
            finally {
                deferral.Complete();
            }
        }
Beispiel #28
0
        /// <summary>
        /// Runs the specified task instance.
        /// </summary>
        /// <param name="taskInstance">The task instance.</param>
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            try
            {
                this.searchClient = new SearchDocument(SearchServiceName, SearchServiceKey);
            }
            catch (Exception ex)
            {
                await this.SendErrorMessageAsync(ex.Message);

                return;
            }

            this.deferral = taskInstance.GetDeferral();

            taskInstance.Canceled += (sender, reason) => this.deferral?.Complete();

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails?.Name != "CabSearch")
            {
                return;
            }

            this.voiceCommandServiceConnection =
                VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
            this.voiceCommandServiceConnection.VoiceCommandCompleted += (sender, args) => this.deferral?.Complete();
            var voicecommand = await this.voiceCommandServiceConnection.GetVoiceCommandAsync();

            switch (voicecommand.CommandName)
            {
            case "findCabInArea":
                var area = voicecommand.Properties["area"][0];
                await this.SendProgressMessageAsync($"Searching for cars in {area}");

                await this.SearchCabsInArea(area);

                break;

            case "findCabNearby":
                await this.SendProgressMessageAsync($"Searching for cabs in 100 km radius.");

                await this.SearchCabsNearby();

                break;
            }
        }
Beispiel #29
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _taskDerral = taskInstance.GetDeferral();
            var details = taskInstance.TriggerDetails as AppServiceTriggerDetails;

                        // 验证是否调用了正确的app service
                        if(details == null || details.Name != "CortanaService")
            {
                _taskDerral.Complete();
                return;
            }

            _serviceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(details);
                        var cmd = await _serviceConnection.GetVoiceCommandAsync();

            _taskDerral.Complete();
        }
Beispiel #30
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null && triggerDetails.Name == "HolVoiceCommandService")
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;


                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "SayHello":

                        var userMessage = new VoiceCommandUserMessage();
                        userMessage.DisplayMessage = "お店で合言葉話してね。";
                        userMessage.SpokenMessage  = "ごきげんよう。";

                        var response = VoiceCommandResponse.CreateResponse(userMessage);

                        await voiceServiceConnection.ReportSuccessAsync(response);

                        break;


                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }