BuildIt.Media.BaseCortanaBackgroundTask.CortanaList C# (CSharp) Метод

CortanaList() приватный Метод

private CortanaList ( List destContentTiles, List commandList, List commentList, int cmdsTook, int cmdCountingNo ) : Task
destContentTiles List
commandList List
commentList List
cmdsTook int
cmdCountingNo int
Результат Task
        private async Task<VoiceCommandResponse> CortanaList(List<VoiceCommandContentTile> destContentTiles, List<XElement> commandList, List<XComment> commentList, int cmdsTook, int cmdCountingNo)
        {
            var destinationContentTiles = destContentTiles;
            var cmdList = commandList;
            var cmtList = commentList;
            var commandsTook = cmdsTook;
            var commandsCountingNo = cmdCountingNo;
            //back for cortana to show the content
            var msgback = new VoiceCommandUserMessage();
            msgback.DisplayMessage = msgback.SpokenMessage = CortanaReply;
            //Cortana 
            var msgRepeat = new VoiceCommandUserMessage();
            msgRepeat.DisplayMessage = msgRepeat.SpokenMessage = CortanaSecondReply;

            var moreCommands = "Select next page commands";

            var iconsFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("builditmedia");
            destinationContentTiles.Clear();
            if (cmdList.Count - commandsTook <= 5)
            {
                for (int i = commandsCountingNo; i <= cmdList.Count - 1; i++)
                {
                    //var command = cmdList[commandsTook];
                    var attributeName = cmdList[commandsTook].Attribute("Name").Value;

                    var descriptionComment = (from comment in cmdList[commandsTook].DescendantNodes().OfType<XComment>()
                                              where comment.Value.StartsWith("Description:")
                                              select comment.Value)
                        .FirstOrDefault() // Get the first comment that starts with "Description:"
                        ?.Replace("Description:", "") ?? ""; // If one exists, trim "Description:" by replacing it with ""
                    if (attributeName.Contains("buildit") != true)
                    {
                        attributeName = "buildit_customTile";
                    }

                    //var iconFile = await iconsFolder.GetFileAsync($"{attributeName}.png");

                    destinationContentTiles.Add(new VoiceCommandContentTile
                    {
                        AppLaunchArgument = cmdList[commandsTook].Attribute("Name").Value,
                        ContentTileType = VoiceCommandContentTileType.TitleWith68x68IconAndText,
                        Title = cmdList[commandsTook].Element(VoiceCommandSchema.Example).Value,
                        TextLine1 = descriptionComment,
                        Image = await iconsFolder.GetFileAsync($"{attributeName}.png")
                    });
                    commandsTook++;
                }
            }
            else
            {
                destinationContentTiles.Clear();
                for (int i = 0; i < 4; i++)
                {
                    var command = cmdList[commandsTook];
                    var attributeName = cmdList[commandsTook].Attribute("Name").Value;
                    var descriptionComment = (from comment in command.DescendantNodes().OfType<XComment>()
                                              where comment.Value.StartsWith(" Description:")
                                              select comment.Value)
                        .FirstOrDefault() // Get the first comment that starts with "Description:"
                        ?.Replace("Description:", "") ?? ""; // If one exists, trim "Description:" by replacing it with ""
                    if (attributeName.Contains("buildit") != true)
                    {
                        attributeName = "buildit_customTile";
                    }

                    //var iconFile = await iconsFolder.GetFileAsync($"{attributeName}.png");


                    destinationContentTiles.Add(new VoiceCommandContentTile
                    {
                        AppLaunchArgument = cmdList[commandsTook].Attribute("Name").Value,
                        ContentTileType = VoiceCommandContentTileType.TitleWith68x68IconAndText,
                        Title = cmdList[commandsTook].Element(VoiceCommandSchema.Example).Value,
                        TextLine1 = descriptionComment,
                        Image = await iconsFolder.GetFileAsync($"{attributeName}.png")
                    });
                    commandsTook++;
                }
                var nextPage = new VoiceCommandContentTile
                {
                    ContentTileType = VoiceCommandContentTileType.TitleWith68x68IconAndText,
                    Title = MoreVoiceCommands,
                    AppLaunchArgument = MoreAppLaunchArgument,
                    TextLine1 = moreCommands,
                    Image = await iconsFolder.GetFileAsync("buildit_help.png")
                };
                destinationContentTiles.Add(nextPage);

                commandsCountingNo += 4;
            }


            // Cortana will handle re-prompting if the user does not provide a valid response.
            var response = VoiceCommandResponse.CreateResponseForPrompt(msgback, msgRepeat, destinationContentTiles);
            // If cortana is dismissed in this operation, null will be returned.

            var selectedRes = await VoiceServiceConnection.RequestDisambiguationAsync(response);

            //Create dialogue confirm that user selected
            msgback.DisplayMessage = msgback.SpokenMessage = "Are you sure you want select " + selectedRes.SelectedItem.Title + " ?";
            msgRepeat.DisplayMessage = msgRepeat.SpokenMessage = "Please select Yes or No";
            response = VoiceCommandResponse.CreateResponseForPrompt(msgback, msgRepeat);

            //return YES OR NO
            var result = await VoiceServiceConnection.RequestConfirmationAsync(response);
            if (result.Confirmed)
            {
                if (selectedRes.SelectedItem.AppLaunchArgument == MoreAppLaunchArgument)
                {

                    await CortanaList(destinationContentTiles, cmdList, cmtList, commandsTook, commandsCountingNo);

                    msgback.DisplayMessage = msgback.SpokenMessage = $"Please speak to Cortana to select voice command.";
                    msgRepeat.DisplayMessage = msgRepeat.SpokenMessage = $"Please speak to Cortana to select voice command.";
                    response = VoiceCommandResponse.CreateResponseForPrompt(msgback, msgRepeat);
                    return response;
                }
                else
                {
                    msgback.DisplayMessage = msgback.SpokenMessage = $"Please speak to Cortana to select voice command.";
                    msgRepeat.DisplayMessage = msgRepeat.SpokenMessage = $"Please speak to Cortana to select voice command.";
                    response = VoiceCommandResponse.CreateResponseForPrompt(msgback, msgRepeat);
                    return response;
                }
            }
            else
            {
                await Task.Delay(3000);
                await CortanaHelpList();
            }

            return response;
        }