コード例 #1
0
        protected string ExtractPropertyFromVoiceCommand(Windows.ApplicationModel.VoiceCommands.VoiceCommand voiceCommand, string propertyKey)
        {
            string result = string.Empty;

            if (voiceCommand.Properties.ContainsKey(propertyKey))
            {
                var entries = voiceCommand.Properties[propertyKey];

                if ((entries != null) && (entries.Count > 0))
                {
                    result = entries[0];
                }
            }
            return(result);
        }
コード例 #2
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");
                    }
                }
            }
        }
コード例 #3
0
        public override VoiceCommandResponse Execute(IWorkbook workbook, IPersistenceLayer persistenceLayer, Windows.ApplicationModel.VoiceCommands.VoiceCommand voiceCommand)
        {
            var dateTime = DateTime.Now.Date;
            int count    = workbook.Tasks.Count(t => (t.Due.HasValue && t.Due.Value.Date == dateTime) || t.IsLate);

            var userMessage = new VoiceCommandUserMessage
            {
                DisplayMessage = "Aujourd'hui, vous avez " + count + " tâches",
                SpokenMessage  = "Aujourd'hui, vous avez " + count + " tâches"
            };

            return(VoiceCommandResponse.CreateResponse(userMessage));
        }
コード例 #4
0
 public abstract VoiceCommandResponse Execute(IWorkbook workbook, IPersistenceLayer persistenceLayer, Windows.ApplicationModel.VoiceCommands.VoiceCommand voiceCommand);
コード例 #5
0
        public override VoiceCommandResponse Execute(IWorkbook workbook, IPersistenceLayer persistenceLayer, Windows.ApplicationModel.VoiceCommands.VoiceCommand voiceCommand)
        {
            string content = this.ExtractPropertyFromVoiceCommand(voiceCommand, "speech");

            content = content.FirstLetterToUpper();
            content = content.Trim();
            content = content.Trim('.');

            var task = new Task
            {
                Added    = DateTime.Now,
                Modified = DateTime.Now,
                Title    = content,
                Folder   = workbook.Folders[0]
            };

            task.Priority = workbook.Settings.GetValue <TaskPriority>(CoreSettings.DefaultPriority);
            task.Due      = ModelHelper.GetDefaultDueDate(workbook.Settings);
            task.Start    = ModelHelper.GetDefaultStartDate(workbook.Settings);
            task.Context  = ModelHelper.GetDefaultContext(workbook);

            persistenceLayer.Save();

            this.UpdateLiveTiles(workbook);

            var userMessage = new VoiceCommandUserMessage
            {
                DisplayMessage = string.Format(StringResources.Notification_NewTaskCreatedNoDueDateFormat, content),
                SpokenMessage  = StringResources.Notification_NewTaskCreatedNoDueDateFormat.Replace("\"{0}\"", string.Empty)
            };

            this.SignalForegroundAppWorkbookChanged();

            return(VoiceCommandResponse.CreateResponse(userMessage));
        }