public static void Execute_DisplayConsoleChoice(object sender, PresenterExecuteEventArgs eventArgs) { IChoicePresenter_Old cp = (IChoicePresenter_Old)sender; Console.WriteLine(eventArgs.TextToDisplay); if (eventArgs.ChoicesToDisplay.Length > 0) { Debug.Assert(eventArgs.ChoicesToDisplay.Length < 10); for (int i = 0; i < eventArgs.ChoicesToDisplay.Length; i++) { Console.Write($"{i}. "); Console.WriteLine(eventArgs.ChoicesToDisplay[i]); } ConsoleKeyInfo keyInfo; do { keyInfo = Console.ReadKey(true); }while (!char.IsDigit(keyInfo.KeyChar)); // Add a U_IDQuery to blackboard for the target content unit associated with the choice. uint choiceMade = uint.Parse(keyInfo.KeyChar.ToString()); cp.SelectChoice((ContentUnit[])eventArgs.Choices, choiceMade); } }
private EventHandler <PresenterExecuteEventArgs> GenerateEventHandler(ContentUnit selectedCU, ContentUnit[] choices, IBlackboard blackboard) { return((object sender, PresenterExecuteEventArgs eventArgs) => { var presenterEventArgs = eventArgs as PresenterExecuteEventArgs; if (selectedCU != null) { Assert.Equal(selectedCU.Content[Text], presenterEventArgs.TextToDisplay); int numOfChoices = choices.Length; Assert.Equal(numOfChoices, presenterEventArgs.Choices.Length); foreach (ContentUnit choice in choices) { Assert.True(Array.Exists(presenterEventArgs.ChoicesToDisplay, element => element.Equals(choice.Content[Text]))); } } else { Assert.Equal("", presenterEventArgs.TextToDisplay); } // Iterate through each of the choices selecting it and confirming that the correct U_IDSelectRequest is added. IChoicePresenter_Old cp = (IChoicePresenter_Old)sender; for (uint i = 0; i < presenterEventArgs.ChoicesToDisplay.Length; i++) { cp.SelectChoice((ContentUnit[])presenterEventArgs.Choices, i); U_IDSelectRequest idSelectRequest = blackboard.LookupSingleton <U_IDSelectRequest>(); Assert.True(idSelectRequest.TargetContentUnitID.Equals(choices[i].Metadata[TargetContentUnitID])); blackboard.RemoveUnit(idSelectRequest); // Remove the U_IDSelect request before the next iteration. } }); }