コード例 #1
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral = taskInstance.GetDeferral();
            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails == null)
            {
                serviceDeferral.Complete();
                return;
            }

            try
            {
                voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                var voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                //Find the command name witch should match the VCD
                if (voiceCommand.CommandName == "buildit_help")
                {
                    var props = voiceCommand.Properties;
                    await CortanaHelpList();
                }
                await Task.Delay(1000);
                await ShowProgressScreen();
            }
            catch
            {
                Debug.WriteLine("Unable to process voice command");
            }
            serviceDeferral.Complete();
        }
コード例 #2
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral = taskInstance.GetDeferral();
            taskInstance.Canceled += TaskInstance_Canceled;

            // Get trigger details , it from Cortana
            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;
            if (triggerDetails != null && triggerDetails.Name == "com.poumason.uwp.VCBusService")
            {
                // 取得 VoiceCommandServiceConnection
                vcConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                vcConnection.VoiceCommandCompleted += VcConnection_VoiceCommandCompleted;

                VoiceCommand vCommand = await vcConnection.GetVoiceCommandAsync();
                // 判断 command name
                switch (vCommand.CommandName)
                {
                    case "SearchWhereBusList":
                        foreach (var item in vCommand.Properties)
                        {
                            Debug.WriteLine(String.Format("{0}={1}", item.Key, item.Value));
                        }
                        await HandleSearchWhereBusList();
                        break;
                    case "CheckStartBusStation":
                        ShowHaveOtherBusConfirm();
                        break;
                    default:
                        // 需要注册这个处理,以相容那些不再使用的 VCDs.
                        LaunchAppInForeground();
                        break;
                }
            }
        }
コード例 #3
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;
            if (triggerDetails != null && triggerDetails.Name == "BotWorldVoiceCommandService")
            {
                voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                voiceServiceConnection.VoiceCommandCompleted += VoiceServiceConnection_VoiceCommandCompleted;

                VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();
                switch(voiceCommand.CommandName)
                {
                    case "checkScore":
                        {
                            await SendAnswer();
                            break;
                        }
                    default:
                        {
                            break;
                        }
                }
            }

            deferral.Complete();

        }
コード例 #4
0
        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("IMCommandVoice"))
            {
                voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                // Perform the appropriate command depending on the operation defined in VCD
                switch (voiceCommand.CommandName)
                {
                    case "oldback":
                        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();
        }
コード例 #5
0
        private async void ShowProtection(VoiceCommandServiceConnection voiceCommandServiceConnection)
        {
            // Show we've recognized the command.
            await this.ReportProgress("Checking your protection status...", voiceCommandServiceConnection);

            // Read data.
            var serializer = new FantasyKingdomSerializer();
            var protection = await serializer.Load<Protection>();

            // Return answer.
            string message;

            if (protection != null)
            {
                if (protection.ExpirationTime < DateTime.Now)
                {
                    message = string.Format(
                        "Unfortunately, your protection has expired at {0}.",
                        protection.ExpirationTime);
                }
                else
                {
                    message = string.Format("Yes, you are still protected until {0}.", protection.ExpirationTime);
                }
            }
            else
            {
                message = "Sorry, I couldn't find any protection status data.";
            }

            await this.ReportSuccess(message, voiceCommandServiceConnection);
        }
コード例 #6
0
 private void OnVoiceCommandCompleted(VoiceCommandServiceConnection sender, VoiceCommandCompletedEventArgs args)
 {
     if (this.serviceDeferral != null)
     {
         this.serviceDeferral.Complete();
     }
 }
コード例 #7
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;

            // 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();

            // Get the currently used system date format
            dateFormatInfo = CultureInfo.CurrentCulture.DateTimeFormat;

            // 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 == "AwfulVoiceCommandService")
            {
                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 "didMyThreadsUpdate":
                            await CheckForBookmarksForUpdates();
                            break;
                        case "didMyPmUpdate":
                            await CheckPmsForUpdates();
                            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());
                }
            }
        }
コード例 #8
0
 private void Vsvc_VoiceCommandCompleted(VoiceCommandServiceConnection sender, VoiceCommandCompletedEventArgs args)
 {
     Debug.Write("Command Completed.");
     if(this.serviceDeferral != null)
     {
         this.serviceDeferral.Complete();
     }
 }
        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();
                    }
                }
            }

        }
コード例 #10
0
        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 == "DomojeeVoiceCommandService")
            {
                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());
                }
            }
        }
コード例 #11
0
ファイル: AlternaService.cs プロジェクト: nicol3ta/alterna
 private void VoiceCommandCompleted(VoiceCommandServiceConnection sender, VoiceCommandCompletedEventArgs args)
 {
     if (this.serviceDeferral != null)
     {
         // Insert your code here
         //Complete the service deferral
         this.serviceDeferral.Complete();
     }
 }
コード例 #12
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            this._deferral = taskInstance.GetDeferral();

            try
            {
                taskInstance.Canceled += (s, e) => this.Close();

                var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

                if (triggerDetails != null &&
                    triggerDetails.Name == "CTime2VoiceCommandService")
                {
                    this._connection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                    this._connection.VoiceCommandCompleted += (s, e) => this.Close();

                    var voiceCommand = await this._connection.GetVoiceCommandAsync();

                    Logger.Info($"Executing voice command '{voiceCommand.CommandName}'.");

                    var applicationStateService = new ApplicationStateService();
                    await applicationStateService.RestoreStateAsync();
                    var cTimeService = new CTimeService(new EventAggregator(), applicationStateService, new GeoLocationService());

                    var stampHelper = new CTimeStampHelper(applicationStateService, cTimeService);
                    var stampHelperCallback = new CTimeStampHelperCallback(
                        this.OnNotLoggedIn, 
                        this.SupportsQuestions, 
                        this.OnDidNothing,
                        this.OnAlreadyCheckedInWannaCheckOut,
                        this.OnAlreadyCheckedIn,
                        this.OnAlreadyCheckedOutWannaCheckIn,
                        this.OnAlreadyCheckedOut,
                        this.OnSuccess);
                    
                    switch (voiceCommand.CommandName)
                    {
                        case "checkIn":
                            await stampHelper.Stamp(stampHelperCallback, TimeState.Entered);
                            break;
                        case "checkOut":
                            await stampHelper.Stamp(stampHelperCallback, TimeState.Left);
                            break;
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.Warn("Exception occured in the voice command service.");
                Logger.Error(exception);
            }
            finally
            {
                this.Close();
            }
        }
        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());
                }
            }


        }
コード例 #14
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            try
            {
                _resourceLoader = ResourceLoader.GetForViewIndependentUse();
            }
            catch (Exception ex)
            {
                // todo: do something
            }
            _serviceDeferral = taskInstance.GetDeferral();

            // If cancelled, set deferal
            // Mets le déféral si annulation
            taskInstance.Canceled += (sender, reason) => _serviceDeferral?.Complete();

            // Get the details of the event that trigered the service
            // Obtient les détails de l'évenement qui à démarré le service
            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            // Check if it is service name set in VCD
            // Regarde si c'est le nom du service qui est mis dans le VCD
            if (triggerDetails?.Name == "PresidentsService")
            {
                _voiceCommandServiceConnection =
                    VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                // Set deferal when voice command is completed
                // Mets le deferal quand la commande vocale est terminée
                _voiceCommandServiceConnection.VoiceCommandCompleted += (sender, args) => _serviceDeferral?.Complete();
                // Get voice command
                // Obtient la commande vocale
                var voicecommand = await _voiceCommandServiceConnection.GetVoiceCommandAsync();

                switch (voicecommand.CommandName)
                {
                    case "whichPresidentYear":
                        var year = voicecommand.Properties["year"][0];
                        await SendProgressMessageAsync(string.Format(GetString(Strings.LookingYear), year));
                        await SearchPresidentForYearAsync(year);
                        break;
                    case "showTerm":
                        var president = voicecommand.Properties["president"][0];
                        await SendProgressMessageAsync(string.Format(GetString(Strings.LookingTerms), president));
                        await SearchTermOfPresidentAsync(president);
                        break;
                }
            }
        }
コード例 #15
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;
            if (triggerDetails != null && triggerDetails.Name == "FeedReaderVoiceCommandService")
            {
                _voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                _voiceServiceConnection.VoiceCommandCompleted += VoiceServiceConnection_VoiceCommandCompleted;
                var voiceCommand = await _voiceServiceConnection.GetVoiceCommandAsync();
                if (voiceCommand?.CommandName == "ShowLatestNews")
                {
                    await ShowLatestNews();
                }
            }
        }
コード例 #16
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral = taskInstance.GetDeferral();

            // Does a ton of like, super important stuff
            
            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

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

                    voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                        case "makeMeCoffeeBitch":
                            {
                                //await ShowProgressScreen("Working");
                                //WhatKindOfCoffee();

                                GetSassy();
                                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();
                    }
                }
            }
        }
コード例 #17
0
ファイル: Service.cs プロジェクト: BrianLima/QuickForCortana
        protected override async void OnRun(IBackgroundTaskInstance taskInstance)
        {
            this.serviceDeferral = taskInstance.GetDeferral();

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            // get the voiceCommandServiceConnection from the tigger details
            voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

            VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

            VoiceCommandResponse response;

            // switch statement to handle different commands
            switch (voiceCommand.CommandName)
            {
                case "sendMessage":
                    // get the message the user has spoken
                    var message = voiceCommand.Properties["message"][0];
                    //var bot = new Bot();

                    // get response from bot
                    string firstResponse = "";
                        //await bot.SendMessageAndGetResponseFromBot(message);

                    // create response messages for Cortana to respond
                    var responseMessage = new VoiceCommandUserMessage();
                    var responseMessage2 = new VoiceCommandUserMessage();
                    responseMessage.DisplayMessage =
                        responseMessage.SpokenMessage = firstResponse;
                    responseMessage2.DisplayMessage =
                        responseMessage2.SpokenMessage = "did you not hear me?";

                    // create a response and ask Cortana to respond with success
                    response = VoiceCommandResponse.CreateResponse(responseMessage);
                    await voiceServiceConnection.ReportSuccessAsync(response);

                    break;
            }

            if (this.serviceDeferral != null)
            {
                //Complete the service deferral
                this.serviceDeferral.Complete();
            }

        }
コード例 #18
0
        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());
                }
            }

        }
コード例 #19
0
        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());
                }
            }
        }
コード例 #20
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            // inform the system that the background task may continue after the 
            // Run method has completed
            this._deferral = taskInstance.GetDeferral();

            taskInstance.Canceled += TaskInstance_Canceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

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

                    voiceServiceConection.VoiceCommandCompleted += VoiceServiceConection_VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                        case "highScorer":
                            {
                       
                                sendCompletionMessageForHighScorer();
                                break;
                            }
                        default:
                            {
                                launchAppInForeground();
                                break;
                            }
                    }
                }
                finally 
                {
                    if( this._deferral != null)
                    {
                        // complete the service deferral
                        this._deferral.Complete();
                    }
                }

            } // end if (triggerDetails
        }
コード例 #21
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //Take a service deferral so the service isn't terminated
            this.serviceDeferral = taskInstance.GetDeferral();
            data = await GetRecommendation();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

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

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                        case "ShowSomeMovies":
                            string content = string.Empty;
                            if (voiceCommand.Properties.ContainsKey("content"))
                            {
                                content = voiceCommand.Properties["content"][0];
                            }
                            SendCompletionMessageForSearchContent(content);
                            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();
                    }
                }
            }
        }
コード例 #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());
                }
            }
        }
コード例 #23
0
    async Task ProcessVoiceCommandAsync(List<ServiceInfoWithLocation> serviceInfoList,
      VoiceCommandServiceConnection voiceConnection)
    {
      var command = await voiceConnection.GetVoiceCommandAsync();

      switch (command.CommandName)
      {
        case VOICE_COMMAND_SHOW_LIGHTS:
          await ProcessShowLightsCommandAsync(serviceInfoList, voiceConnection);
          break;
        case VOICE_COMMAND_SWITCH_LIGHT:
          await ProcessSwitchLightCommandAsync(serviceInfoList, voiceConnection);
          break;
        default:
          break;
      }
    }
コード例 #24
0
ファイル: bgTask.cs プロジェクト: AgentPierce/Surgical-Band
        protected override async void OnRun(IBackgroundTaskInstance taskInstance)
        {
            this.serviceDeferral = taskInstance.GetDeferral();
            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            VoiceCommandUserMessage userMessage;
            VoiceCommandResponse response;
            try
            {
                voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                voiceServiceConnection.VoiceCommandCompleted += VoiceCommandCompleted;
                VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                switch (voiceCommand.CommandName)
                {

                    case "getPatientData":
                        userMessage = new VoiceCommandUserMessage();
                        userMessage.SpokenMessage = "Here is the Patient Data";

                        var responseMessage = new VoiceCommandUserMessage();
                        responseMessage.DisplayMessage = responseMessage.SpokenMessage = "Patient Name: John Spartan\nAge: 47\nBlood Type: O+\nPatient ID: 000S00117";

                        response = VoiceCommandResponse.CreateResponse(responseMessage);
                        await voiceServiceConnection.ReportSuccessAsync(response);

                        break;

                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                if (this.serviceDeferral != null)
                {
                    //Complete the service deferral
                    this.serviceDeferral.Complete();
                }
            }
        }
コード例 #25
0
ファイル: AlternaService.cs プロジェクト: nicol3ta/alterna
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            
            addressTable = MobileService.GetTable<Address>();
            serviceDeferral = taskInstance.GetDeferral();
            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

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

                    voiceServiceConnection.VoiceCommandCompleted +=
                      VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await
                    voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                        case "showLocations":
                            {
                                SendCompletionMessageForLocations();
                                break;
                            }

                        // As a last resort launch the app in the foreground
                        default:
                            LaunchAppInForeground();
                            break;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
コード例 #26
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            m_VoiceServiceDeferral = taskInstance.GetDeferral();

            AppServiceTriggerDetails triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null && triggerDetails.Name == "VoiceCommandService")
            {
                taskInstance.Canceled += VoiceTaskInstance_Canceled;

                if (triggerDetails.CallerPackageFamilyName == cortanaFamilyId)
                {
                    // Being called from Cortana
                    m_VoiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                    m_VoiceServiceConnection.VoiceCommandCompleted += VoiceServiceConnection_VoiceCommandCompleted;

                    // 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 m_VoiceServiceConnection.GetVoiceCommandAsync();


                    switch (voiceCommand.CommandName)
                    {
                    case "queryTemperature":
                        await g_CommandHandler.HandleQueryTemperatureCommand(m_VoiceServiceConnection, voiceCommand);

                        break;

                    case "queryTrend":
                        await g_CommandHandler.HandleQueryTrendCommand(m_VoiceServiceConnection, voiceCommand);

                        break;
                    }
                }
            }
        }
コード例 #27
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //Take a service deferral so the service isnt terminated.
            this.serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

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

                    voiceServiceConnection.VoiceCommandCompleted += VoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "test":
                    {
                        LaunchAppInForeground();
                        break;
                    }
                    }
                }
                finally
                {
                    if (this.serviceDeferral != null)
                    {
                        // Complete the service deferral.
                        this.serviceDeferral.Complete();
                    }
                }
            }
        }
コード例 #28
0
        private static async Task HandleReadNamedaysCommandAsync(VoiceCommandServiceConnection connection)
        {
            var userMessage = new VoiceCommandUserMessage();

            userMessage.DisplayMessage = "Fetching today's namedays for you";
            userMessage.SpokenMessage  = "Fetching today's namedays for you";
            var response = VoiceCommandResponse.CreateResponse(userMessage);
            await connection.ReportProgressAsync(response);

            var today    = DateTime.Now.Date;
            var namedays = await NamedayRepository.GetAllNamedaysAsync();

            var todaysNameday    = namedays.Find(e => e.Day == today.Day && e.Month == today.Month);
            var namedaysAsString = todaysNameday.NamesAsString;

            if (todaysNameday.Names.Count() == 1)
            {
                userMessage.SpokenMessage = userMessage.DisplayMessage = $"It is { namedaysAsString}'s nameday today";

                response = VoiceCommandResponse.CreateResponse(userMessage);
            }
            else
            {
                userMessage.SpokenMessage  = $"Today's namedays are: {namedaysAsString}";
                userMessage.DisplayMessage = "Here are today's namedays:";

                var tile = new VoiceCommandContentTile();

                tile.ContentTileType = VoiceCommandContentTileType.TitleOnly;
                tile.Title           = namedaysAsString;

                response = VoiceCommandResponse.CreateResponse(userMessage, new List <VoiceCommandContentTile> {
                    tile
                });
            }

            await connection.ReportSuccessAsync(response);
        }
コード例 #29
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral        = taskInstance.GetDeferral();
            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 == "Cortana")
            {
                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.
                    var voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    var text = voiceCommand.SpeechRecognitionResult.Text;
                    var loc  = await Geolocator.RequestAccessAsync();

                    if (loc == GeolocationAccessStatus.Allowed)
                    {
                        Geolocator geolocator = new Geolocator();
                        var        myloc      = await geolocator.GetGeopositionAsync();

                        RespondTouser("Here is your location", myloc.Coordinate.Point);
                    }
                    else
                    {
                        RespondTouser("I can't access to your location! Where are you?");
                    }
                }
                catch { }
            }
        }
コード例 #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 == "CodecampSessionsVoiceCommandService")
            {
                voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                await _agendaService.GetSessionsAsync();
                switch (voiceCommand.CommandName)
                {
                    case "sayPresentationDescription":
                        var userMessage = new VoiceCommandUserMessage();
                        userMessage.DisplayMessage = "You already forgot? You are going to talk about how I can help developers to create voice activated apps";
                        userMessage.SpokenMessage = "You already forgot? You are going to talk about how I can help developers to create voice activated apps. By the way...asshole, stop forcing me to help you with this stupid presentation. You're lucky I can't use curse words";
                        var response = VoiceCommandResponse.CreateResponse(userMessage);
                        await voiceServiceConnection.ReportSuccessAsync(response);
                        break;
                    case "findSessionsWithCortana":
                        var tags = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["search"][0];
                        await FindSessionsByTag(tags);
                        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;
                }
            }
        }
コード例 #31
0
        private static async Task HandleReadNamedaysCommandAsync(VoiceCommandServiceConnection connection)
        {
            var userMessage = new VoiceCommandUserMessage();

            userMessage.DisplayMessage = "Je récupères les noms du jour pour vous";
            userMessage.SpokenMessage  = "Je récupères les noms du jour pour vous";
            var response = VoiceCommandResponse.CreateResponse(userMessage);
            await connection.ReportProgressAsync(response);

            var today    = DateTime.Now.Date;
            var namedays = await NamedayRepository.GetAllNamedaysAsync();

            var todaysNamedays   = namedays.Find(e => e.Day == today.Day && e.Month == today.Month);
            var namedaysAsString = todaysNamedays.NamesAsString;

            if (todaysNamedays.Names.Count() == 1)
            {
                userMessage.SpokenMessage      =
                    userMessage.DisplayMessage = $"Le nom du jour est {namedaysAsString}";
                response = VoiceCommandResponse.CreateResponse(userMessage);
            }
            else
            {
                userMessage.SpokenMessage  = $"Les noms du jour sont {namedaysAsString}";
                userMessage.DisplayMessage = "Voici les noms du jour : ";

                var tile = new VoiceCommandContentTile();
                tile.ContentTileType = VoiceCommandContentTileType.TitleOnly;
                tile.Title           = namedaysAsString;
                response             = VoiceCommandResponse.CreateResponse(userMessage,
                                                                           new List <VoiceCommandContentTile> {
                    tile
                });
            }

            await connection.ReportSuccessAsync(response);
        }
コード例 #32
0
ファイル: CortanaPlus.cs プロジェクト: pombredanne/ArcherSys
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral _defferal = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetals = taskInstance.TriggerDetails as AppServiceTriggerDetails;
            if (triggerDetals != null && triggerDetals.Name == "ArcherVM.CortanaPlusEndpoint")
            {
                try
                {
                    voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetals);
                    voiceServiceConnection.VoiceCommandCompleted += VoiceServiceConnection_VoiceCommandCompleted;
                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();
                    switch (voiceCommand.CommandName)
                    {
                        case "openArcherVM":
                            var app = voiceCommand.Properties["App"][0];


                            var userMessage = new VoiceCommandUserMessage();
                            userMessage.DisplayMessage = "Here's your web app.";
                            userMessage.SpokenMessage = "Let me get Malaika to open up " + app + " for you.";
                            VoiceCommandResponse vcr = VoiceCommandResponse.CreateResponse(userMessage);
                            break;





                    }

                    }catch (Exception e)
                { }
            }

        }
コード例 #33
0
        private static async Task HandleWhosThere(VoiceCommandServiceConnection connection, VoiceCommandUserMessage user_message)
        {
            var local_folder = ApplicationData.Current.LocalFolder;
            var file         = await local_folder.CreateFileAsync("joke_state.txt", CreationCollisionOption.OpenIfExists);

            var text = await file.ReadTextAsync();

            if (text == "knock knock")
            {
                await file.WriteTextAsync("joke");

                Random random = new Random();
                var    next   = random.Next(100);
                var    index  = next % 5;

                var jokes = new string[] {
                    "amos",
                    "who",
                    "honey bee",
                    "lettuce",
                    "double"
                };

                var joke = jokes[index];

                user_message.SpokenMessage  = joke;
                user_message.DisplayMessage = user_message.SpokenMessage;
                var response = VoiceCommandResponse.CreateResponse(user_message);
                await connection.ReportSuccessAsync(response);
            }
            else
            {
                user_message.SpokenMessage = "first ask me to tell you a joke";
                var response = VoiceCommandResponse.CreateResponse(user_message);
                await connection.ReportSuccessAsync(response);
            }
        }
コード例 #34
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var contribution = ServiceLocator.Current.GetInstance <IContributionTypeContainer>();

            this.serviceDeferral   = taskInstance.GetDeferral();
            taskInstance.Canceled += this.OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

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

                    this.voiceServiceConnection.VoiceCommandCompleted += this.OnVoiceCommandCompleted;

                    var voiceCommand = await this.voiceServiceConnection.GetVoiceCommandAsync();

                    if (voiceCommand.CommandName.ToLower().Contains("contribution"))
                    {
                        await this.HandleContributionCommand(voiceCommand);
                    }
                    else
                    {
                        await this.LaunchAppForVoiceAsync();
                    }
                }
                catch (Exception ex)
                {
#if DEBUG
                    System.Diagnostics.Debug.WriteLine(ex.Message);
#endif
                }
            }
        }
コード例 #35
0
        private static async Task HandleReadNamedaysCommandAsync(VoiceCommandServiceConnection connection)
        {
            var userMessage = new VoiceCommandUserMessage();
            userMessage.DisplayMessage = "Fetching today's namedays for you";
            userMessage.SpokenMessage = "Fetching today's namedays for you";
            var response = VoiceCommandResponse.CreateResponse(userMessage);
            await connection.ReportProgressAsync(response);

            var today = DateTime.Now.Date;
            var namedays = await NamedayRepository.GetAllNamedaysAsync();
            var todaysNameday = namedays.Find(e => e.Day == today.Day && e.Month == today.Month);
            var namedaysAsString = todaysNameday.NamesAsString;

            if (todaysNameday.Names.Count() == 1)
            {
                userMessage.SpokenMessage =
                    userMessage.DisplayMessage =
                    $"It is {namedaysAsString}'s nameday today";

                response = VoiceCommandResponse.CreateResponse(userMessage);
            }
            else
            {
                userMessage.SpokenMessage = $"Today's namedays are: {namedaysAsString}";
                userMessage.DisplayMessage = "Here are today's namedays:";

                var tile = new VoiceCommandContentTile();
                tile.ContentTileType = VoiceCommandContentTileType.TitleOnly;
                tile.Title = namedaysAsString;

                response = VoiceCommandResponse.CreateResponse(userMessage,
                    new List<VoiceCommandContentTile> { tile });
            }

            await connection.ReportSuccessAsync(response);
        }
コード例 #36
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

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

                    voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;
                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "showBaikeForKeyword":
                        string keyword = voiceCommand.Properties["keyword"][0];
                        await QueryBaikeByKeyword(keyword);

                        break;

                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
コード例 #37
0
        public async void RunOther(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;

                Debug.WriteLine("trying to get voice command");
                VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                if (voiceCommand.CommandName == "LightsOnOrOff")
                {
                    string lightState = voiceCommand.Properties["lightState"][0];
                    await HandleLightsOnOrOff(lightState);
                }
            }
        }
コード例 #38
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails?.Name == "VoiceCommandService")
            {
                var deferral             = taskInstance.GetDeferral();
                var cancelledTokenSource = new CancellationTokenSource();

                // Whatever the command is, we need a list of lightbulbs and their
                // location names. Attemping to build that here but trying to make
                // sure that we factor in cancellation.
                taskInstance.Canceled += (s, e) =>
                {
                    cancelledTokenSource.Cancel();
                };

                VoiceCommandServiceConnection voiceConnection =
                    VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                voiceConnection.VoiceCommandCompleted += (s, e) =>
                {
                    cancelledTokenSource.Cancel();
                };

                var serviceInfoList = await this.GetLightListingAsync(DELAY_TIMEOUT, cancelledTokenSource.Token);

                await this.ProcessVoiceCommandAsync(serviceInfoList, voiceConnection);

                cancelledTokenSource.Dispose();

                this.StopWatcherAndBusAttachment(serviceInfoList);

                deferral.Complete();
            }
        }
コード例 #39
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;

            // 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();

            // Get the currently used system date format
            dateFormatInfo = CultureInfo.CurrentCulture.DateTimeFormat;

            // 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 == "GeneralQueryVoiceCommandService")
            {
                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();

                    var interpretation = voiceCommand.SpeechRecognitionResult.SemanticInterpretation;

                    string clientId    = cortanaResourceMap.GetValue("ClientId", cortanaContext).ValueAsString;
                    string userName    = cortanaResourceMap.GetValue("Domain", cortanaContext).ValueAsString;
                    string rootSiteUrl = cortanaResourceMap.GetValue("rootSite", cortanaContext).ValueAsString;

                    StringBuilder searchAPIUrl = new StringBuilder();

                    switch (voiceCommand.CommandName)
                    {
                    case "SharePointWhatsCheckedOutQueryCommand":
                        searchAPIUrl = searchAPIUrl.Append("/_api/search/query?querytext='CheckoutUserOWSUSER:"******"'");
                        await SearchCheckedOutDocumentsAsync(rootSiteUrl, searchAPIUrl.ToString());

                        break;

                    case "SPSearchContentCommand":

                        var searchSiteName = voiceCommand.Properties["searchsite"][0];
                        var searchText     = voiceCommand.Properties["dictatedSearchText"][0];
                        searchAPIUrl = searchAPIUrl.Append("/_api/search/query?querytext='" + searchText + "'");
                        await SearchSharePointDocumentsAsync(rootSiteUrl, searchAPIUrl.ToString());

                        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());
                }
            }
        }
コード例 #40
0
        async Task ProcessSwitchLightCommandAsync(
            List <ServiceInfoWithLocation> serviceInfoList,
            VoiceCommandServiceConnection voiceConnection)
        {
            var  message = new VoiceCommandUserMessage();
            var  tiles   = new List <VoiceCommandContentTile>();
            bool worked  = false;

            if ((serviceInfoList == null) || (serviceInfoList.Count == 0))
            {
                message.SpokenMessage  = "I couldn't find any lights at all, sorry";
                message.DisplayMessage = "No lights could be found at any location";
            }
            else
            {
                var voiceCommand = await voiceConnection.GetVoiceCommandAsync();

                var location = ExtractPropertyFromVoiceCommand(voiceCommand, VOICE_COMMAND_LOCATION_KEY);
                var onOff    = ExtractPropertyFromVoiceCommand(voiceCommand, VOICE_COMMAND_ON_OFF_KEY);

                if (string.IsNullOrEmpty(location))
                {
                    message.SpokenMessage  = "I couldn't find a location in what you said, sorry";
                    message.DisplayMessage = "Interpreted text did not contain an audible location";
                }
                else if (string.IsNullOrEmpty(onOff))
                {
                    message.SpokenMessage  = "I couldn't figure out whether you said on or off, sorry";
                    message.DisplayMessage = "Not clear around on/off status";
                }
                else
                {
                    var serviceInfo = serviceInfoList.SingleOrDefault(
                        sinfo => string.Compare(sinfo.Location.Trim(), location.Trim(), true) == 0);

                    if (serviceInfo == null)
                    {
                        message.SpokenMessage  = $"I couldn't find any lights in the location {location}, sorry";
                        message.DisplayMessage = $"No lights in the {location}";
                    }
                    else
                    {
                        // It may just work...
                        await serviceInfo.Consumer.SwitchAsync(string.Compare(onOff, "on", true) == 0);

                        message.SpokenMessage  = $"I think I did it! The light should now be {onOff}";
                        message.DisplayMessage = $"the light is now {onOff}";
                    }
                }
            }
            var response = VoiceCommandResponse.CreateResponse(message);

            if (worked)
            {
                await voiceConnection.ReportSuccessAsync(response);
            }
            else
            {
                await voiceConnection.ReportFailureAsync(response);
            }
        }
コード例 #41
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null)
            {
                var config = new AIConfiguration("cb9693af-85ce-4fbf-844a-5563722fc27f",
                                                 "40048a5740a1455c9737342154e86946",
                                                 SupportedLanguage.English);

                apiAi = new ApiAi(config);
                apiAi.DataService.PersistSessionId();

                try
                {
                    voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                    voiceServiceConnection.VoiceCommandCompleted += VoiceCommandCompleted;
                    var voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    var recognizedText = voiceCommand.SpeechRecognitionResult?.Text;

                    switch (voiceCommand.CommandName)
                    {
                    case "type":
                    {
                        var aiResponse = await apiAi.TextRequestAsync(recognizedText);

                        await apiAi.LaunchAppInForegroundAsync(voiceServiceConnection, aiResponse);
                    }
                    break;

                    case "unknown":
                    {
                        if (!string.IsNullOrEmpty(recognizedText))
                        {
                            var aiResponse = await apiAi.TextRequestAsync(recognizedText);

                            if (aiResponse != null)
                            {
                                await apiAi.SendResponseToCortanaAsync(voiceServiceConnection, aiResponse);
                            }
                        }
                    }
                    break;

                    case "greetings":
                    {
                        var aiResponse = await apiAi.TextRequestAsync(recognizedText);

                        var repeatMessage = new VoiceCommandUserMessage
                        {
                            DisplayMessage = "Repeat please",
                            SpokenMessage  = "Repeat please"
                        };

                        var processingMessage = new VoiceCommandUserMessage
                        {
                            DisplayMessage = aiResponse?.Result?.Fulfillment?.Speech ?? "Pizza",
                            SpokenMessage  = ""
                        };

                        var resp = VoiceCommandResponse.CreateResponseForPrompt(processingMessage, repeatMessage);
                        await voiceServiceConnection.ReportSuccessAsync(resp);

                        break;
                    }

                    default:
                        if (!string.IsNullOrEmpty(recognizedText))
                        {
                            var aiResponse = await apiAi.TextRequestAsync(recognizedText);

                            if (aiResponse != null)
                            {
                                await apiAi.SendResponseToCortanaAsync(voiceServiceConnection, aiResponse);
                            }
                        }
                        else
                        {
                            await SendResponse("Can't recognize");
                        }

                        break;
                    }
                }
                catch (Exception e)
                {
                    var message = e.ToString();
                    Debug.WriteLine(message);
                }
                finally
                {
                    serviceDeferral?.Complete();
                }
            }
        }
コード例 #42
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.
        ///
        /// 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)
        {
            Debug.WriteLine("Start Task");
            skipCounter = 0;
            Result      = "";
            path        = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "FileCustomCommands.xml");

            Debug.WriteLine("deferral");
            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;

            Debug.WriteLine("details");
            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            Debug.WriteLine(triggerDetails.Name);

            // 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 == "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();

                    // TODO Clean up debug - this only slows down the progressing and dumps unused variables
                    Debug.WriteLine("CommandName");
                    Debug.WriteLine(voiceCommand.CommandName);
                    Debug.WriteLine("Properties");
                    Debug.WriteLine(voiceCommand.Properties.Values);
                    if (voiceCommand.Properties.Count != 0)
                    {
                        Debug.WriteLine("got Properties");
                        foreach (var property in voiceCommand.Properties)
                        {
                            Debug.WriteLine("Property: Key: " + property.Key + " Value: " + property.Value);
                        }
                        if (voiceCommand.Properties.ContainsKey("searchTerm"))
                        {
                            Debug.WriteLine("got searchTerm");
                            this.searchTerm = voiceCommand.Properties["searchTerm"][0];//TODO multiple terms support
                        }
                    }
                    Debug.WriteLine("searchTerm");
                    Debug.WriteLine(searchTerm);
                    foreach (KeyValuePair <string, IReadOnlyList <string> > property in voiceCommand.Properties)
                    {
                        Debug.WriteLine(property.Key);
                        Debug.WriteLine(property.Value);
                        foreach (string content in property.Value)
                        {
                            Debug.WriteLine(content);
                        }
                    }

                    await ShowProgressScreen("Loading commands");

                    LoadCommands();// TODO - only load the 1 specific command to reduce load time

                    this.ViewModel = new CommandViewModel()
                    {
                        GetCommands = this.commands
                    };

                    Debug.WriteLine("Loaded " + this.commands.Count.ToString() + " commands from file");

                    try
                    {
                        if (!this.ViewModel.GetCommands.Any(i => i.Name == voiceCommand.CommandName))
                        {
                            LaunchAppInForeground();
                        }
                        else
                        {
                            CustomCommand foundCMD = this.ViewModel.GetCommands.Single(i => i.Name == voiceCommand.CommandName);
                            await SendCompletionMessage(foundCMD);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                        Debug.WriteLine(ex.StackTrace);
                        Debug.WriteLine("Command not found, launching in foreground");
                        LaunchAppInForeground();
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Handling Voice Command failed. Exception:");
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                }

                if (this.serviceDeferral != null)
                {
                    this.serviceDeferral.Complete();
                }
            }
        }
コード例 #43
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            Debug.WriteLine("Fug me");
            // Take a service deferral so the service isn&#39;t terminated.
            serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled       += TaskInstance_Canceled;
            taskInstance.Task.Completed += Task_Completed;

            var triggerDetails =
                taskInstance.TriggerDetails as AppServiceTriggerDetails;

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

                    voiceServiceConnection.VoiceCommandCompleted +=
                        VoiceCommandCompleted;

                    var voiceCommand = await
                                       voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "ToDoFetcher":
                    {
                        SendCompletionMessageFortodolist();
                        break;
                    }

                    case "TodoCounter":
                    {
                        taskcounter();
                        break;
                    }

                    case "addtask":
                    {
                        LaunchAppInForeground();
                        break;
                    }

                    //   As a last resort, launch the app in the foreground.
                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                finally
                {
                    if (serviceDeferral != null)
                    {
                        // Complete the service deferral.
                        serviceDeferral.Complete();
                    }
                }
            }
        }
コード例 #44
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral        = taskInstance.GetDeferral();
            taskInstance.Canceled += OnTaskCanceled;
            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null && triggerDetails.Name == "MirrorVoiceCommandService")
            {
                try
                {
                    voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                    voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;
                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    CompletionMessage message;

                    switch (voiceCommand.CommandName)
                    {
                    case "changeName":
                        string name = voiceCommand.Properties["name"][0];

                        message = new CompletionMessage
                        {
                            Message          = $"Change your name to {name}?",
                            RepeatMessage    = $"Do you want to change your name to {name}?",
                            ConfirmMessage   = $"Changing name to {name}",
                            CompletedMessage = $"Your Magic Mirror name has been changed to {name}",
                            CanceledMessage  = "Keeping name to original value",
                        };
                        await SendCompletionMessage(ParameterAction.ChangeName, name, message);

                        break;

                    case "changeAddress":
                        string address = voiceCommand.Properties["address"][0];

                        message = new CompletionMessage
                        {
                            Message          = $"Change your address to {address}?",
                            RepeatMessage    = $"Do you want to change your address to {address}?",
                            ConfirmMessage   = $"Changing address to {address}",
                            CompletedMessage = $"Your address has been changed to {address}",
                            CanceledMessage  = "Keeping address to original value",
                        };
                        await SendCompletionMessage(ParameterAction.ChangeAddress, address, message);

                        break;

                    case "changeTown":
                        string town = voiceCommand.Properties["town"][0];

                        message = new CompletionMessage
                        {
                            Message          = $"Change your home town to {town}?",
                            RepeatMessage    = $"Do you want to change your home town to {town}?",
                            ConfirmMessage   = $"Changing home town to {town}",
                            CompletedMessage = $"Your home town has been changed to {town}",
                            CanceledMessage  = "Keeping town to original value",
                        };
                        await SendCompletionMessage(ParameterAction.ChangeTown, town, message);

                        break;

                    case "changeWorkAddress":
                        string workAddress = voiceCommand.Properties["workAddress"][0];

                        message = new CompletionMessage
                        {
                            Message          = $"Change your work Address to {workAddress}?",
                            RepeatMessage    = $"Do you want to change your work Address to {workAddress}?",
                            ConfirmMessage   = $"Changing work Address to {workAddress}",
                            CompletedMessage = $"Your workAddress changed to {workAddress}",
                            CanceledMessage  = "Keeping workAddress to original value",
                        };
                        await SendCompletionMessage(ParameterAction.ChangeWorkAddress, workAddress, message);

                        break;

                    case "changeTemperature":
                        string temperature = voiceCommand.Properties["temperature"][0];

                        message = new CompletionMessage
                        {
                            Message          = $"Change your temperature notation to {temperature}?",
                            RepeatMessage    = $"Do you want to hange your temperature notation to {temperature}?",
                            ConfirmMessage   = $"Changing temperature notation to {temperature}",
                            CompletedMessage = $"Your temperature notation changed to {temperature}",
                            CanceledMessage  = "Keeping temperature to original value",
                        };
                        await SendCompletionMessage(ParameterAction.ChangeTemperature, temperature, message);

                        break;

                    case "changeDistance":
                        string distance = voiceCommand.Properties["distance"][0];

                        message = new CompletionMessage
                        {
                            Message          = $"Change your distance notation to {distance} system?",
                            RepeatMessage    = $"Do you want to hange your distance notation to {distance} system?",
                            ConfirmMessage   = $"Changing distance notation to {distance} system",
                            CompletedMessage = $"Your temperature notation changed to {distance}",
                            CanceledMessage  = "Keeping distance to original system",
                        };
                        await SendCompletionMessage(ParameterAction.ChangeDistance, distance, message);

                        break;

                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
コード例 #45
0
        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();

            // Get the currently used system date format
            dateFormatInfo = CultureInfo.CurrentCulture.DateTimeFormat;

            if (triggerDetails != null && triggerDetails.Name == "VoiceCommandService")
            {
                Debug.WriteLine(triggerDetails.Name);
                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 AdventureWorks:AdventureWorksCommands.xml)
                    // perform the appropriate command.
                    Debug.WriteLine(voiceCommand.CommandName);


                    switch (voiceCommand.CommandName)
                    {
                    case "PowerOnOff":
                        //await ReportStatus(voiceCommand.Properties["device"][0]);
                        var PowerTarget = voiceCommand.Properties["target"][0];
                        var onoff       = voiceCommand.Properties["onoff"][0];
                        await SendCompletionMessageForPowerOnOff(PowerTarget, onoff);

                        break;

                    case "reportStatus":
                        var ReportTarget = voiceCommand.Properties["target"][0];
                        await SendCompletionMessageForReport(ReportTarget);

                        break;

                    case "reportAppointment":
                        var AppointmentTarget = voiceCommand.Properties["Days"][0];
                        await SendCompletionMessageForAppointmentReport(AppointmentTarget);

                        break;

                    case "SetTemperature":
                        var Temperature = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["TemperatureNumber"].FirstOrDefault().ToString();
                        await SendCompletionMessageForSetTemperature(Temperature);

                        break;

                    case "StartFan":
                        //var startmin = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["TemperatureNumber"].FirstOrDefault().ToString();
                        var startmin = voiceCommand.Properties["fanstartminutes"][0];
                        await SendCompletionMessageForFan(false, startmin);

                        break;

                    case "StopFan":
                        await SendCompletionMessageForFan(true, string.Empty);

                        break;

                    case "AskNest":
                        var NestTarget = voiceCommand.Properties["NestDevice"][0];
                        await SendCompletionMessageForAskNest(NestTarget);

                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
                finally
                {
                    if (this.serviceDeferral != null)
                    {
                        // Complete the service deferral.
                        this.serviceDeferral.Complete();
                    }
                }
            }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //Service deferral to prevent service termination
            this.serviceDeferral = taskInstance.GetDeferral();
            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

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

                    /* Note: these background commands don't do anything interesting and are simply here to demonstrate
                     * that commands can be run in the background using Cortana as part of this project. It is possible
                     * to add commands relevant to this application such as playing a song in the background however
                     * it's not practical since Cortana must provide progress every 5 seconds and besides the user can
                     * give a command to play a song and simply minimize the app and the song continues to play while
                     * the app is in the suspended state.
                     */
                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "backgroundTask":
                    {
                        var userMessage = new VoiceCommandUserMessage();
                        userMessage.DisplayMessage = "Processing your request";
                        userMessage.SpokenMessage  = "Processing your request";
                        var progressReport = VoiceCommandResponse.CreateResponse(userMessage);
                        await voiceServiceConnection.ReportProgressAsync(progressReport);

                        try
                        {
                            userMessage = new VoiceCommandUserMessage();
                            userMessage.DisplayMessage = "Executing your request";
                            userMessage.SpokenMessage  = "Executing your request";

                            await voiceServiceConnection.ReportSuccessAsync(VoiceCommandResponse.CreateResponse(userMessage));
                        }
                        catch (Exception)
                        {
                            userMessage.DisplayMessage = "Something went wrong, terminating process";
                            userMessage.SpokenMessage  = "Something went wrong, terminating process";
                            await voiceServiceConnection.ReportFailureAsync(VoiceCommandResponse.CreateResponse(userMessage));
                        }
                        break;
                    }

                    case "backgroundTask2":
                    {
                        var userMessage = new VoiceCommandUserMessage();
                        userMessage.DisplayMessage = "Processing your request";
                        userMessage.SpokenMessage  = "Processing your request";
                        var progressReport = VoiceCommandResponse.CreateResponse(userMessage);
                        await voiceServiceConnection.ReportProgressAsync(progressReport);

                        try
                        {
                            userMessage = new VoiceCommandUserMessage();
                            userMessage.DisplayMessage = "Executing your request";
                            userMessage.SpokenMessage  = "Executing your request";

                            await voiceServiceConnection.ReportSuccessAsync(VoiceCommandResponse.CreateResponse(userMessage));
                        }
                        catch (Exception)
                        {
                            userMessage.DisplayMessage = "Something went wrong, terminating process";
                            userMessage.SpokenMessage  = "Something went wrong, terminating process";
                            await voiceServiceConnection.ReportFailureAsync(VoiceCommandResponse.CreateResponse(userMessage));
                        }
                        break;
                    }
                    }
                }
                finally
                {
                    if (this.serviceDeferral != null)
                    {
                        //Complete the service deferral
                        this.serviceDeferral.Complete();
                    }
                }
            }
        }
コード例 #47
0
        public async Task HandleCommandAsync()
        {
            // 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 (this.triggerDetails != null && this.triggerDetails.Name == CortanaConstants.BackgroundServiceName)
            {
                try
                {
                    DeviceFamily deviceFamily = DeviceFamily.Unkown;
                    if (AnalyticsInfo.VersionInfo.DeviceFamily.Equals("Windows.Desktop", StringComparison.OrdinalIgnoreCase))
                    {
                        deviceFamily = DeviceFamily.WindowsDesktop;
                    }
                    else if (AnalyticsInfo.VersionInfo.DeviceFamily.Equals("Windows.Mobile", StringComparison.OrdinalIgnoreCase))
                    {
                        deviceFamily = DeviceFamily.WindowsMobile;
                    }

                    this.trackingManager = new TrackingManager(false, deviceFamily);

                    this.voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(this.triggerDetails);
                    this.voiceServiceConnection.VoiceCommandCompleted += this.OnVoiceCommandCompleted;

                    Windows.ApplicationModel.VoiceCommands.VoiceCommand voiceCommand = await this.voiceServiceConnection.GetVoiceCommandAsync();

                    CortanaBackgroundCommandBase backgroundCommand = null;
                    foreach (var command in this.commands)
                    {
                        if (command.CommandName.Equals(voiceCommand.CommandName, StringComparison.OrdinalIgnoreCase))
                        {
                            backgroundCommand = command;
                            break;
                        }
                    }

                    if (backgroundCommand != null)
                    {
                        await CortanaDialogHelper.ShowProgressScreen(this.voiceServiceConnection, StringResources.Message_LoadingTasks);

                        this.persistenceLayer = new WinPersistenceLayer(automaticSave: false);
                        var workbook = this.persistenceLayer.Open(tryUpgrade: true);
                        workbook.Initialize();

                        VoiceCommandResponse response = backgroundCommand.Execute(workbook, this.persistenceLayer, voiceCommand);

                        bool success = false;
                        if (response != null)
                        {
                            await this.voiceServiceConnection.ReportSuccessAsync(response);

                            success = true;
                        }

                        this.trackingManager.TagEvent("Cortana", new Dictionary <string, string>
                        {
                            { "Command", backgroundCommand.CommandName },
                            { "Success", success.ToString() },
                            { "Language", CultureInfo.CurrentUICulture?.ToString() ?? "unkown" }
                        });
                    }
                    else
                    {
                        // 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.
                        this.LaunchAppInForeground();
                    }
                }
                catch (Exception ex)
                {
                    if (this.trackingManager != null)
                    {
                        this.trackingManager.Exception(ex, "Cortana background service");
                    }
                }
            }
        }
コード例 #48
0
 private void VoiceCommandCompleted(VoiceCommandServiceConnection sender, VoiceCommandCompletedEventArgs args)
 {
     serviceDeferral?.Complete();
 }
コード例 #49
0
ファイル: Service.cs プロジェクト: nmetulev/lamna
        protected async override void OnRun(IBackgroundTaskInstance taskInstance)
        {
            this.serviceDeferral   = taskInstance.GetDeferral();
            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            VoiceCommandUserMessage userMessage;
            VoiceCommandResponse    response;

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

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

                    var appointment = (await DataSource.GetInstance().GetAppointmentsAsync()).FirstOrDefault();
                    if (appointment != null)
                    {
                        var tiles = new List <VoiceCommandContentTile>();
                        var tile  = new VoiceCommandContentTile();

                        tile.ContentTileType = VoiceCommandContentTileType.TitleWith280x140IconAndText;

                        tiles.Add(tile);
                        tile.Image = await MapService.GetStaticRoute(280, 140, DataSource.GetCurrentLocation(), appointment.Location);

                        userMessage = new VoiceCommandUserMessage()
                        {
                            SpokenMessage  = "Your next appointment is the " + appointment.FamilyName + " family. It looks like you are 20 minutes away, should I let them know?",
                            DisplayMessage = "Your next appointment is the " + appointment.FamilyName + " family."
                        };

                        var repromptMessage = new VoiceCommandUserMessage()
                        {
                            DisplayMessage = "Should I let the " + appointment.FamilyName + " family know of your arrival?",
                            SpokenMessage  = "Should I let the " + appointment.FamilyName + " family know of your arrival?"
                        };

                        response = VoiceCommandResponse.CreateResponseForPrompt(userMessage, repromptMessage, tiles);
                        var userResponse = await voiceServiceConnection.RequestConfirmationAsync(response);

                        string secondResponse;
                        if (userResponse.Confirmed)
                        {
                            secondResponse = "Great, I'll take care of it!";
                        }
                        else
                        {
                            secondResponse = "OK, no problem!";
                        }

                        //userMessage = new VoiceCommandUserMessage()
                        //{
                        //    DisplayMessage = secondResponse + "Should I start navigation?",
                        //    SpokenMessage = secondResponse + "Should I start navigation?",
                        //};

                        //repromptMessage = new VoiceCommandUserMessage()
                        //{
                        //    DisplayMessage = "Should I start navigation?",
                        //    SpokenMessage = "Should I start navigation?",
                        //};

                        //response = VoiceCommandResponse.CreateResponseForPrompt(userMessage, repromptMessage, tiles);
                        //var userResponse = await voiceServiceConnection.RequestConfirmationAsync(response);

                        ////await Task.Delay(1000);


                        userMessage = new VoiceCommandUserMessage()
                        {
                            DisplayMessage = secondResponse + " Safe driving!",
                            SpokenMessage  = secondResponse + " Safe driving!",
                        };

                        response = VoiceCommandResponse.CreateResponse(userMessage, tiles);
                        await voiceServiceConnection.ReportSuccessAsync(response);
                    }
                    else
                    {
                        userMessage = new VoiceCommandUserMessage()
                        {
                            DisplayMessage = "All done for today!",
                            SpokenMessage  = "You don't have any appointments for the rest of the day!"
                        };

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



                    break;

                case "what":

                    var appointments = (await DataSource.GetInstance().GetAppointmentsAsync()).Take(3);
                    if (appointments != null & appointments.Count() > 0)
                    {
                        var tiles = new List <VoiceCommandContentTile>();

                        foreach (var app in appointments)
                        {
                            var tile = new VoiceCommandContentTile();

                            tile.ContentTileType = VoiceCommandContentTileType.TitleWith68x68IconAndText;

                            tile.TextLine1 = app.FamilyName;
                            tile.TextLine2 = app.Address;
                            tile.Title     = app.Time.ToString("hh:mm");
                            tile.Image     = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/house.png"));

                            tiles.Add(tile);
                        }

                        userMessage = new VoiceCommandUserMessage()
                        {
                            SpokenMessage  = "Here are your next " + appointments.Count() + " appointments",
                            DisplayMessage = "Here are your next " + appointments.Count() + " appointments",
                        };

                        response = VoiceCommandResponse.CreateResponse(userMessage, tiles);
                        await voiceServiceConnection.ReportSuccessAsync(response);
                    }
                    else
                    {
                        userMessage = new VoiceCommandUserMessage()
                        {
                            DisplayMessage = "All done for today!",
                            SpokenMessage  = "You don't have any appointments for the rest of the day!"
                        };

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



                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                if (this.serviceDeferral != null)
                {
                    //Complete the service deferral
                    this.serviceDeferral.Complete();
                }
            }
        }
コード例 #50
0
        protected override async void OnRun(IBackgroundTaskInstance taskInstance)
        {
            this.serviceDeferral   = taskInstance.GetDeferral();
            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;


            VoiceCommandResponse response;

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

                VoiceCommandUserMessage userMessage = new VoiceCommandUserMessage();

                List <VoiceCommandContentTile> contentTiles;

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

                    _todoItemRepository = TODOAdaptiveUISample.Repositories.TodoItemFileRepository.GetInstance();
                    var data = await _todoItemRepository.RefreshTodoItemsAsync();

                    contentTiles = new List <VoiceCommandContentTile>();

                    userMessage.SpokenMessage = "Your Top To Do's are: ";

                    foreach (var item in data.Where(x => x.IsComplete == false).OrderBy(x => x.DueDate).Take((int)VoiceCommandResponse.MaxSupportedVoiceCommandContentTiles))
                    {
                        var tile = new VoiceCommandContentTile();
                        tile.ContentTileType = VoiceCommandContentTileType.TitleWithText;
                        tile.Title           = item.Title;
                        //tile.TextLine1 = item.Details;
                        contentTiles.Add(tile);

                        userMessage.SpokenMessage += item.Title + ", ";
                    }

                    userMessage.DisplayMessage = "Here are the top " + contentTiles.Count + " To Do's";



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

                    break;


                case "new":
                    var todo = voiceCommand.Properties["todo"][0];

                    var responseMessage = new VoiceCommandUserMessage()
                    {
                        DisplayMessage = String.Format("Add \"{0}\" to your To Do's?", todo),
                        SpokenMessage  = String.Format("Do you want me to add \"{0}\" to your To Do's?", todo)
                    };

                    var repeatMessage = new VoiceCommandUserMessage()
                    {
                        DisplayMessage = String.Format("Are you sure you want me to add \"{0}\" to your To Do's?", todo),
                        SpokenMessage  = String.Format("Are you sure you want me to add \"{0}\" to your To Do's?", todo)
                    };

                    bool confirmed = false;
                    response = VoiceCommandResponse.CreateResponseForPrompt(responseMessage, repeatMessage);
                    try
                    {
                        var confirmation = await voiceServiceConnection.RequestConfirmationAsync(response);

                        confirmed = confirmation.Confirmed;
                    }
                    catch
                    {
                    }
                    if (confirmed)
                    {
                        _todoItemRepository = TODOAdaptiveUISample.Repositories.TodoItemFileRepository.GetInstance();
                        var i = _todoItemRepository.Factory(title: todo);
                        await _todoItemRepository.InsertTodoItem(i);

                        var todos = await _todoItemRepository.RefreshTodoItemsAsync();

                        contentTiles = new List <VoiceCommandContentTile>();

                        foreach (var itm in todos.Where(x => x.IsComplete == false).OrderBy(x => x.DueDate).Take((int)VoiceCommandResponse.MaxSupportedVoiceCommandContentTiles))
                        {
                            var tile = new VoiceCommandContentTile();
                            tile.ContentTileType = VoiceCommandContentTileType.TitleWithText;
                            tile.Title           = itm.Title;
                            contentTiles.Add(tile);
                        }

                        userMessage.SpokenMessage  = "Done and Done! Here are your top To Do's";
                        userMessage.DisplayMessage = "Here are your top " + contentTiles.Count + " To Do's";

                        response = VoiceCommandResponse.CreateResponse(userMessage, contentTiles);
                        await voiceServiceConnection.ReportSuccessAsync(response);
                    }
                    else
                    {
                        userMessage.DisplayMessage = userMessage.SpokenMessage = "OK then";
                        response = VoiceCommandResponse.CreateResponse(userMessage);
                        await voiceServiceConnection.ReportSuccessAsync(response);
                    }



                    break;
                }
            }
            catch (Exception ex)
            {
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
            }
            finally
            {
                if (this.serviceDeferral != null)
                {
                    //Complete the service deferral
                    this.serviceDeferral.Complete();
                }
            }
        }
コード例 #51
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. 
        /// 
        /// 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;

            // 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();

            // Get the currently used system date format
            dateFormatInfo = CultureInfo.CurrentCulture.DateTimeFormat;

            VoiceCommandResponse response = null;

            // This should match the uap:AppService and RuleVoiceCommandService 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 == this.GetType().Name)
            {
                try
                {
                    voiceServiceConnection =
                        VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
                            triggerDetails);

                    voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    HttpClient client = new HttpClient();

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

                            string postBody = JsonConvert.SerializeObject(new Settings
                            {
                                IsOn = false
                            });
                            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                            var webResponse = await client.PostAsync("http://hiremotemeetcortana.azurewebsites.net/api/settings", new StringContent(postBody, Encoding.UTF8, "application/json"));

                            if (webResponse.IsSuccessStatusCode)
                            {
                                var turnOnLightMessage = new VoiceCommandUserMessage
                                {
                                    DisplayMessage = "Wakeup Light has been turned on ",
                                    SpokenMessage = "Wakeup Light has been turned on "
                                };

                                response = VoiceCommandResponse.CreateResponse(turnOnLightMessage);
                                await voiceServiceConnection.ReportSuccessAsync(response);
                            } else
                            {
                                var turnOnLightMessage = new VoiceCommandUserMessage
                                {
                                    DisplayMessage = "Something went wrong",
                                    SpokenMessage = "Something went wrong"
                                };

                                response = VoiceCommandResponse.CreateResponse(turnOnLightMessage);
                                await voiceServiceConnection.ReportFailureAsync(response);
                            }
                            break;
                        case "turnOffLight":

                            string turnOffLightBody = JsonConvert.SerializeObject(new Settings
                            {
                                IsOn = false
                            });
                            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                            var saveRurnOffLight = await client.PostAsync("http://hiremotemeetcortana.azurewebsites.net/api/settings", new StringContent(turnOffLightBody, Encoding.UTF8, "application/json"));


                            if (saveRurnOffLight.IsSuccessStatusCode)
                            {
                                var turnOnLightMessage = new VoiceCommandUserMessage
                                {
                                    DisplayMessage = "Wakeup Light has been turned off ",
                                    SpokenMessage = "Wakeup Light has been turned off "
                                };

                                response = VoiceCommandResponse.CreateResponse(turnOnLightMessage);
                                await voiceServiceConnection.ReportSuccessAsync(response);
                            }
                            else
                            {
                                var turnOnLightMessage = new VoiceCommandUserMessage
                                {
                                    DisplayMessage = "Something went wrong",
                                    SpokenMessage = "Something went wrong"
                                };

                                response = VoiceCommandResponse.CreateResponse(turnOnLightMessage);
                                await voiceServiceConnection.ReportFailureAsync(response);
                            }
                            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());
                }
            }
        }
コード例 #52
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="connection"></param>
        /// <returns></returns>
        private static async Task HandleReadImageLabelsCommandAsync(VoiceCommandServiceConnection connection)
        {
            //Initialize some stuff
            var CaptureClient = new CameraCaptureService.CameraCaptureService();
            await CaptureClient.Init();


            ///var GoogleVisionClient = new GoogleVisionAPI.VisionClient();
            var MicrosoftVisionClient = new MicrosoftCognitiveVisionRepository.MicrosoftCognitiveVisionClient();

            //Tell the user that we are doing something
            var userMessage = new VoiceCommandUserMessage();

            userMessage.DisplayMessage = "Analyzing your surroundings";
            userMessage.SpokenMessage  = "Analyzing";
            var response = VoiceCommandResponse.CreateResponse(userMessage);
            await connection.ReportProgressAsync(response);

            //TODO: Get the image
            string imageString;

            try
            {
                imageString = await CaptureClient.Capture();
            }
            catch (Exception)
            {
                userMessage.DisplayMessage = "I can't access the camera, try opening up  the Identify app first";
                userMessage.SpokenMessage  = "No Camera. Try opening Identify first, then ask me again.";
                response = VoiceCommandResponse.CreateResponse(userMessage);
                await connection.ReportFailureAsync(response);

                return;
            }



            //TODO: Send the Image through the Vision Client
            ///List<string> googleAnnotationResponse;
            string microsoftAnnotationResponse;

            try
            {
                //Use Google
                ///googleAnnotationResponse = await GoogleVisionClient.Run(imageString);
                //Use Microsoft
                microsoftAnnotationResponse = await MicrosoftVisionClient.Run(imageString);
            }
            catch (Exception)
            {
                userMessage.DisplayMessage = "Try checking your connection";
                userMessage.SpokenMessage  = "Hmm... I can't get a response from the cloud.";
                response = VoiceCommandResponse.CreateResponse(userMessage);
                await connection.ReportFailureAsync(response);

                return;
            }

            //var finalResponse = string.Join(", ", googleAnnotationResponse);
            var finalResponse = microsoftAnnotationResponse;

            //TODO: Set the User Message, Display & Spoken
            userMessage.DisplayMessage = finalResponse;
            userMessage.SpokenMessage  = finalResponse;
            response = VoiceCommandResponse.CreateResponse(userMessage);

            await connection.ReportSuccessAsync(response);
        }
コード例 #53
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 == "InClassBackgroundService"))
            {
                // 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 "howManyGames":
                    {
                        sendUpdateMessageByReturn();
                        break;
                    }

                    default:
                    {
                        launchAppInForeground();
                        break;
                    }
                    }
                }
                finally
                {
                    if (this._deferral != null)
                    {
                        // complete the service deferral
                        this._deferral.Complete();
                    }
                } // end try
            }
        }
コード例 #54
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            defferal = taskInstance.GetDeferral();
            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            taskInstance.Canceled += OnCanceled;
            if (triggerDetails?.Name == "VoiceService")

            {
                voiceService = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                voiceService.VoiceCommandCompleted += OnCompleted;
                VoiceCommand voiceCommand = await voiceService.GetVoiceCommandAsync();


                switch (voiceCommand.CommandName)

                {
                case "openMyTech":
                {
                    Uri website = new Uri(@"https://ge.service-now.com/mytech/");
                    await Launcher.LaunchUriAsync(website);
                };
                    break;

                case "openAccessories":
                {
                    Uri website = new Uri(@"https://ge.service-now.com/mytech/accessoriesSpecialOrder.do");
                    await Launcher.LaunchUriAsync(website);
                };
                    break;

                case "isBrokenPhone":
                {
                    Uri website = new Uri(@"https://ge.service-now.com/mytech/lifeEvents.do?sysparm=replaceBroken#/commsDevices");
                    await Launcher.LaunchUriAsync(website);
                };
                    break;

                case "isBrokenComputer":
                {
                    Uri website = new Uri(@"https://ge.service-now.com/mytech/lifeEvents.do?sysparm=replaceBroken#/compDevices//");
                    await Launcher.LaunchUriAsync(website);
                };
                    break;

                case "missingComputer":
                {
                    Uri website = new Uri(@"https://ge.service-now.com/mytech/lifeEvents.do?sysparm=lostStolen");
                    await Launcher.LaunchUriAsync(website);
                };
                    break;

                case "missingMobile":
                {
                    Uri website = new Uri(@"https://ge.service-now.com/mytech/lifeEvents.do?sysparm=lostStolen#/commsDevices");
                    await Launcher.LaunchUriAsync(website);
                };
                    break;

                case "reassign":
                {
                    Uri website = new Uri(@"https://ge.service-now.com/mytech/manage_request.do?sysparm=Reassign");
                    await Launcher.LaunchUriAsync(website);
                };
                    break;

                case "rAccessories":
                {
                    Uri website = new Uri(@"https://ge.service-now.com/mytech/accessoriesSpecialOrder.do");
                    await Launcher.LaunchUriAsync(website);
                };
                    break;

                case "openMyTechnology":
                {
                    Uri website = new Uri(@"https://ge.service-now.com/mytech/mytechnology.do");
                    await Launcher.LaunchUriAsync(website);
                };
                    break;

                case "openMyTechGuide":
                {
                    Uri website = new Uri(@"http://sc.ge.com/*mytechguide");
                    await Launcher.LaunchUriAsync(website);
                };
                    break;

                case "openRequests":
                {
                    Uri website = new Uri(@"https://ge.service-now.com/mytech/my_requests.do");
                    await Launcher.LaunchUriAsync(website);
                };
                    break;

                case "openRefresh":
                {
                    Uri website = new Uri(@"https://ge.service-now.com/mytech/lifeEvents.do?sysparm=refreshUpgrade");
                    await Launcher.LaunchUriAsync(website);
                };
                    break;

                case "openRPhone":
                {
                    Uri website = new Uri(@"https://ge.service-now.com/mytech/requestCommunication.do?sysparam=Phones");
                    await Launcher.LaunchUriAsync(website);
                };
                    break;

                case "requestSoftware":
                {
                    Uri website = new Uri(@"https://ge.service-now.com/mytech/software.do?sysparam=PC");
                    await Launcher.LaunchUriAsync(website);
                };
                    break;

                case "manageSoftware":
                {
                    Uri website = new Uri(@"https://ge.service-now.com/mytech/softwareLibrary.do");
                    await Launcher.LaunchUriAsync(website);
                };
                    break;

                case "discoverMytech":
                {
                    Uri website = new Uri(@"https://ge.service-now.com/mytech/discoverhome.do");
                    await Launcher.LaunchUriAsync(website);
                };
                    break;

                case "leaderCode":
                {
                    Uri website = new Uri(@"https://ge.service-now.com/mytech/audioconferencing.do");
                    await Launcher.LaunchUriAsync(website);
                };
                    break;
                }
            }
        }
コード例 #55
0
 private void OnVoiceCommandCompleted(VoiceCommandServiceConnection sender, VoiceCommandCompletedEventArgs args)
 {
     serviceDeferral?.Complete();
 }
コード例 #56
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral = taskInstance.GetDeferral();
            var    userMessage1 = new VoiceCommandUserMessage();
            string book;

            taskInstance.Canceled += OnTaskCanceled;
            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

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

                    switch (voiceCommand.CommandName)
                    {
                    case "bookFromXToY":
                        try
                        {
                            string source      = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["bookFromX"].FirstOrDefault();
                            string destination = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["bookFromY"].FirstOrDefault();
                            await SendCompletionMessageForBookFromXtoY(source, destination);
                        }
                        catch
                        {
                            userMessage1 = new VoiceCommandUserMessage();
                            book         = "Please give proper saved places";
                            userMessage1.DisplayMessage = userMessage1.SpokenMessage = book;
                            var response = VoiceCommandResponse.CreateResponse(userMessage1);
                            await voiceServiceConnection.ReportSuccessAsync(response);
                        }
                        break;

                    case "costEstimate":
                        try
                        {
                            string sourceCost      = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["source"].First();
                            string destinationCost = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["destination"].First();
                            await SendCompletionMessageForCostEstimate(sourceCost, destinationCost);
                        }
                        catch
                        {
                            userMessage1 = new VoiceCommandUserMessage();
                            book         = "Please give proper source and destination";
                            userMessage1.DisplayMessage = userMessage1.SpokenMessage = book;
                            var response = VoiceCommandResponse.CreateResponse(userMessage1);
                            await voiceServiceConnection.ReportSuccessAsync(response);
                        }
                        break;

                    case "costEstimateCustom":
                        //try
                        //{
                        string     destinationCost1 = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["destination"].First();
                        string     slat, slng, token;
                        Geolocator locator = new Geolocator();
                        locator.DesiredAccuracyInMeters = 50;
                        var mPosition = await locator.GetGeopositionAsync();

                        slat  = mPosition.Coordinate.Point.Position.Latitude.ToString();
                        slng  = mPosition.Coordinate.Point.Position.Longitude.ToString();
                        token = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString();
                        CabsAPI            api     = new CabsAPI();
                        ReverseGeoResposne current = await api.GetReverseCodingResultlatlng(token, slat + "," + slng);

                        string source1;
                        try
                        {
                            source1 = current.FormattedAddress.Substring(0, current.FormattedAddress.IndexOf(", Hyderabad"));
                        }
                        catch
                        {
                            source1 = current.FormattedAddress;
                        }
                        await SendCompletionMessageForCostEstimate(source1, destinationCost1);


                        //catch (Exception e)
                        //{
                        //    userMessage1 = new VoiceCommandUserMessage();
                        //    book = "please give proper Destination";
                        //    userMessage1.DisplayMessage = userMessage1.SpokenMessage = book;
                        //    var response = VoiceCommandResponse.CreateResponse(userMessage1);
                        //    await voiceServiceConnection.ReportSuccessAsync(response);
                        //}
                        break;

                    case "toCustomLocation":
                        try
                        {
                            string location = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["location"].FirstOrDefault();
                            await SendCompletionMessageForBookToCustomLocation(location);
                        }
                        catch (Exception e)
                        {
                            userMessage1 = new VoiceCommandUserMessage();
                            book         = "Please give proper Destination";
                            userMessage1.DisplayMessage = userMessage1.SpokenMessage = book;
                            var response = VoiceCommandResponse.CreateResponse(userMessage1);
                            await voiceServiceConnection.ReportSuccessAsync(response);
                        }
                        break;

                    case "bookcheapest":
                        string mSource;
                        IReadOnlyList <string> voicecommandphrase;
                        if (voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties.TryGetValue("source", out voicecommandphrase))
                        {
                            mSource = voicecommandphrase.First();
                        }
                        else
                        {
                            mSource = "";
                        }
                        string mDest = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["destination"].FirstOrDefault();
                        await SendCompletionMessageForBookCheapestFromXtoY(mSource, mDest);

                        break;

                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
コード例 #57
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.
        ///
        /// 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;

            // 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();

            // Get the currently used system date format
            dateFormatInfo = CultureInfo.CurrentCulture.DateTimeFormat;

            // 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 == "ListenAppVoiceCommandService")
            {
                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 ListenApp:ListenAppCommands.xml)
                    // perform the appropriate command.
                    switch (voiceCommand.CommandName)
                    {
                    case "changingStateOfLights":
                        var room  = voiceCommand.Properties["room"][0];
                        var state = voiceCommand.Properties["state"][0].Equals("on");
                        await SendCompletionMessageChangingState(room, state);

                        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());
                }
            }
        }
コード例 #58
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.
        ///
        /// 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 == "CortanaTodoVoiceService")
            {
                try
                {
                    // Get the connection
                    voiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

                    // Subscribe to commands completed
                    voiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;

                    // Get the command
                    VoiceCommand voiceCommand = await voiceConnection.GetVoiceCommandAsync();

                    Debug.WriteLine(string.Format("Command Name: {0}", voiceCommand.CommandName));
                    Debug.WriteLine(string.Format("Result.Text: {0}", voiceCommand.SpeechRecognitionResult.Text));
                    foreach (var rule in voiceCommand.SpeechRecognitionResult.RulePath)
                    {
                        Debug.WriteLine(string.Format("Rule: {0}", rule));
                    }
                    foreach (var prop in voiceCommand.Properties)
                    {
                        foreach (var value in prop.Value)
                        {
                            Debug.WriteLine(string.Format("Prop: {0} Val: {1}", prop.Key, value));
                        }
                    }
                    foreach (var prop in voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties)
                    {
                        foreach (var value in prop.Value)
                        {
                            Debug.WriteLine(string.Format("S-Prop: {0} Val: {1}", prop.Key, value));
                        }
                    }

                    // Depending on the operation (defined in VoiceCommands.xml)
                    // perform the appropriate command.
                    string listName = null;
                    string itemName = null;
                    switch (voiceCommand.CommandName)
                    {
                    case "addToList":
                        listName = voiceCommand.Properties["listName"].FirstOrDefault();
                        itemName = voiceCommand.Properties["itemName"].FirstOrDefault();
                        await HandleAddToListAsync(listName, itemName);

                        break;

                    case "addNewList":
                        listName = voiceCommand.Properties["listNameNL"].FirstOrDefault();
                        await HandleNewListAsync(listName);

                        break;

                    case "markItemComplete":
                        listName = voiceCommand.Properties["listName"].FirstOrDefault();
                        itemName = voiceCommand.Properties["itemName"].FirstOrDefault();
                        await HandleMarkItemCompleteAsync(listName, itemName);

                        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.
                        await RequestAppLaunchAsync();

                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
コード例 #59
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral = taskInstance.GetDeferral();

            taskInstance.Canceled += OnTaskCanceled;

            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null)
            {
                var config = new AIConfiguration("6bcfd8fcf822482e935475852b97c02d",
                                                 SupportedLanguage.English);

                apiAi = new ApiAi(config);
                apiAi.DataService.PersistSessionId();

                try
                {
                    voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                    voiceServiceConnection.VoiceCommandCompleted += VoiceCommandCompleted;
                    var voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    var recognizedText = voiceCommand.SpeechRecognitionResult?.Text;

                    switch (voiceCommand.CommandName)
                    {
                    case "Open":      //개점
                    {
                        var aiResponse = await apiAi.TextRequestAsync(recognizedText);

                        //await apiAi.LaunchAppInForegroundAsync(voiceServiceConnection, aiResponse);

                        var processingMessage = new VoiceCommandUserMessage
                        {
                            DisplayMessage = "Starting POS...",
                            SpokenMessage  = "Starting POS..."
                        };

                        var resp = VoiceCommandResponse.CreateResponse(processingMessage);
                        await voiceServiceConnection.ReportSuccessAsync(resp);

                        POS_main.start = true;
                    }
                    break;

                    case "Close":      //마감
                    {
                        var aiResponse = await apiAi.TextRequestAsync(recognizedText);

                        var processingMessage = new VoiceCommandUserMessage
                        {
                            DisplayMessage = "Program The End...",
                            SpokenMessage  = "Program The End..."
                        };

                        var resp = VoiceCommandResponse.CreateResponse(processingMessage);
                        await voiceServiceConnection.ReportSuccessAsync(resp);

                        /*시스템 종료 함수*/
                        SetFinishing();

                        break;
                    }

                    case "SaleStatus":      //매출현황
                    {
                    }
                    break;

                    case "SaleSearch":      //판매조회
                    {
                    }
                    break;

                    case "PayCheck":     //아르바이트 시간 및 급여 확인
                    {
                    }
                    break;

                    default:
                        if (!string.IsNullOrEmpty(recognizedText))
                        {
                            var aiResponse = await apiAi.TextRequestAsync(recognizedText);

                            if (aiResponse != null)
                            {
                                await apiAi.SendResponseToCortanaAsync(voiceServiceConnection, aiResponse);
                            }
                        }
                        else
                        {
                            await SendResponse("Can't recognize");
                        }

                        break;
                    }
                }
                catch (Exception e)
                {
                    var message = e.ToString();
                    Debug.WriteLine(message);
                }
                finally
                {
                    serviceDeferral?.Complete();
                }
            }
        }
コード例 #60
0
 private void ConnectionOnVoiceCommandCompleted(VoiceCommandServiceConnection sender, VoiceCommandCompletedEventArgs args)
 {
 }