예제 #1
0
        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);
            }
        }
예제 #2
0
        public static void Execute_DisplayConsoleChoice(object sender, PresenterExecuteEventArgs eventArgs)
        {
            IChoicePresenter cp = (IChoicePresenter)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));

                // Activate the KC_IDSelectionRequest stored on the selected choice unit.
                uint choiceMade = uint.Parse(keyInfo.KeyChar.ToString());
                cp.SelectChoice(eventArgs.Choices, choiceMade);
            }
        }
        // Gathers the choices for the selected content unit, stores them on fields provided on this KS, and calls any calls any registered event handlers.
        internal override void Execute(IDictionary <string, object> boundVars)
        {
            ContentUnit selectedCU = (ContentUnit)boundVars[SelectedContentUnit];

            string textToDisplay = (string)selectedCU.Content[Text];

            ContentUnit[] choices = GetChoices(selectedCU);

            string[] choicesToDisplay;

            if (choices.Any())
            {
                int choiceCounter = 0;
                choicesToDisplay = new string[choices.Count()];
                foreach (ContentUnit choice in choices)
                {
                    choicesToDisplay[choiceCounter++] = (string)choice.Content[Text];
                }
            }
            else
            {
                // No choices. Create a 0 length string array so that callers don't have to worry about null checks.
                choicesToDisplay = new string[0];
            }

            // Remove the displayed SelectedContentUnit from the blackboard. Do this to indicate that we have processed the selectedCU.
            m_blackboard.RemoveUnit(selectedCU);

            // Construct event args and call the event handler.
            var eventArgs = new PresenterExecuteEventArgs(textToDisplay, choicesToDisplay, choices);

            OnExecute(eventArgs);
        }
        // Gathers the choices for the selected unit and calls any registered event handlers.
        protected override void Execute(object[] boundVars)
        {
            IEnumerable <Unit> selectedUnits = (IEnumerable <Unit>)boundVars[FilteredUnits];

            // fixme: now that we're passing choice info as params should be able to handle multiple selected Units
            Debug.Assert(selectedUnits.Count() == 1);

            Unit selectedUnit = selectedUnits.First();

            string textToDisplay = selectedUnit.GetText();

            Unit[] choices = GetChoices(selectedUnit);

            string[] choicesToDisplay;

            if (choices.Any())
            {
                int choiceCounter = 0;
                choicesToDisplay = new string[choices.Count()];
                foreach (Unit choice in choices)
                {
                    choicesToDisplay[choiceCounter++] = choice.GetText();
                }
            }
            else
            {
                // No choices. Create a 0 length string array so that callers don't have to worry about null checks.
                choicesToDisplay = new string[0];
            }

            PresenterExecuteEventArgs eventArgs = new PresenterExecuteEventArgs(textToDisplay, choicesToDisplay, choices);

            OnExecute(eventArgs);
        }
 protected virtual void OnExecute(PresenterExecuteEventArgs eventArgs)
 {
     PresenterExecute?.Invoke(this, eventArgs);
 }