private NextActivityKey SayAndWaitEvents( WorkflowExecutionContext context, ActivityParameterDictionary parameters, ICollection <WaitHandle> waitedEvents, NextActivityKeyResolver nextActivityKeyResolver) { var silent = NeedSilent(parameters); var composer = CreatePhraseComposer(parameters, silent); var text = composer.ComposeText(); var sounds = silent ? new string[] { } : composer.ComposePhrase(); var helpComposer = CreateHelpPhraseComposer(parameters); var helpText = helpComposer.ComposeText(); var helpSounds = helpComposer.ComposePhrase(); var ignoreButtons = NeedIgnoreButtons(parameters); var startTimeout = GetStartTimeout(parameters); var repeatTimeout = GetRepeatTimeout(parameters); int occurredEventIndex; return(SayAndWaitEvents( context, text, sounds, helpText, helpSounds, silent, ignoreButtons, waitedEvents, startTimeout, repeatTimeout, nextActivityKeyResolver, out occurredEventIndex)); }
private NextActivityKey SayAndWaitEvents( WorkflowExecutionContext context, string text, string[] sounds, string helpText, string[] helpSounds, bool silent, bool ignoreButtons, ICollection <WaitHandle> waitedEvents, int startTimeout, int repeatTimeout, NextActivityKeyResolver nextActivityKeyResolver, out int occurredEventIndex) { var filteredWaitedEvents = new List <WaitHandle>(waitedEvents.Count + 1); var needWaitKeyPressed = false; var needWaitHelpPressed = false; foreach (var currentEvent in waitedEvents) { var keyWh = currentEvent as KeyPressedWaitHandle; if (keyWh != null) { needWaitKeyPressed = true; if (keyWh.Equals(KeyPressedWaitHandle.HelpPressed)) { needWaitHelpPressed = true; } else if (ignoreButtons) { continue; } } filteredWaitedEvents.Add(currentEvent); } RaiseOutputStarting(needWaitKeyPressed ? InfoType.Question : InfoType.Information); var lastWaitedEventsIndex = filteredWaitedEvents.Count - 1; var playSoundFinishedEvent = new ManualResetEvent(false); filteredWaitedEvents.Add(playSoundFinishedEvent); var waitedEventsDuringPlaying = filteredWaitedEvents.ToArray(); if (!needWaitHelpPressed) { filteredWaitedEvents[filteredWaitedEvents.Count - 1] = KeyPressedWaitHandle.HelpPressed; } else { filteredWaitedEvents.RemoveAt(filteredWaitedEvents.Count - 1); } var waitedEventsAfterPlaying = filteredWaitedEvents.ToArray(); var helpButtonPressed = false; if (startTimeout > 0 || startTimeout == Timeout.Infinite) { ResetEvents(waitedEventsAfterPlaying); occurredEventIndex = context.WaitAny(waitedEventsAfterPlaying, startTimeout); if (0 <= occurredEventIndex && occurredEventIndex <= lastWaitedEventsIndex) { return(nextActivityKeyResolver(waitedEventsAfterPlaying[occurredEventIndex], context)); } helpButtonPressed = (occurredEventIndex == waitedEventsAfterPlaying.Length - 1); } while (true) { if (helpButtonPressed && helpSounds != null && helpSounds.Length > 0) { occurredEventIndex = SetIndicatorAndPlayPhrase( context, waitedEventsDuringPlaying, playSoundFinishedEvent, helpText ?? text, helpSounds, false); } else { occurredEventIndex = SetIndicatorAndPlayPhrase( context, waitedEventsDuringPlaying, playSoundFinishedEvent, text, sounds, silent); } if (occurredEventIndex >= 0) { return(nextActivityKeyResolver(waitedEventsDuringPlaying[occurredEventIndex], context)); } ResetEvents(waitedEventsAfterPlaying); occurredEventIndex = context.WaitAny(waitedEventsAfterPlaying, repeatTimeout); if (0 <= occurredEventIndex && occurredEventIndex <= lastWaitedEventsIndex) { return(nextActivityKeyResolver(waitedEventsAfterPlaying[occurredEventIndex], context)); } helpButtonPressed = (occurredEventIndex == waitedEventsAfterPlaying.Length - 1); } }
private NextActivityKey SayAndWaitEvents( WorkflowExecutionContext context, string text, string[] sounds, string helpText, string[] helpSounds, bool silent, bool ignoreButtons, ICollection<WaitHandle> waitedEvents, int startTimeout, int repeatTimeout, NextActivityKeyResolver nextActivityKeyResolver, out int occurredEventIndex) { var filteredWaitedEvents = new List<WaitHandle>(waitedEvents.Count + 1); var needWaitKeyPressed = false; var needWaitHelpPressed = false; foreach (var currentEvent in waitedEvents) { var keyWh = currentEvent as KeyPressedWaitHandle; if (keyWh != null) { needWaitKeyPressed = true; if (keyWh.Equals(KeyPressedWaitHandle.HelpPressed)) { needWaitHelpPressed = true; } else if (ignoreButtons) { continue; } } filteredWaitedEvents.Add(currentEvent); } RaiseOutputStarting(needWaitKeyPressed ? InfoType.Question : InfoType.Information); var lastWaitedEventsIndex = filteredWaitedEvents.Count - 1; var playSoundFinishedEvent = new ManualResetEvent(false); filteredWaitedEvents.Add(playSoundFinishedEvent); var waitedEventsDuringPlaying = filteredWaitedEvents.ToArray(); if (!needWaitHelpPressed) { filteredWaitedEvents[filteredWaitedEvents.Count - 1] = KeyPressedWaitHandle.HelpPressed; } else { filteredWaitedEvents.RemoveAt(filteredWaitedEvents.Count - 1); } var waitedEventsAfterPlaying = filteredWaitedEvents.ToArray(); var helpButtonPressed = false; if (startTimeout > 0 || startTimeout == Timeout.Infinite) { ResetEvents(waitedEventsAfterPlaying); occurredEventIndex = context.WaitAny(waitedEventsAfterPlaying, startTimeout); if (0 <= occurredEventIndex && occurredEventIndex <= lastWaitedEventsIndex) return nextActivityKeyResolver(waitedEventsAfterPlaying[occurredEventIndex], context); helpButtonPressed = (occurredEventIndex == waitedEventsAfterPlaying.Length - 1); } while (true) { if (helpButtonPressed && helpSounds != null && helpSounds.Length > 0) occurredEventIndex = SetIndicatorAndPlayPhrase( context, waitedEventsDuringPlaying, playSoundFinishedEvent, helpText ?? text, helpSounds, false); else occurredEventIndex = SetIndicatorAndPlayPhrase( context, waitedEventsDuringPlaying, playSoundFinishedEvent, text, sounds, silent); if (occurredEventIndex >= 0) return nextActivityKeyResolver(waitedEventsDuringPlaying[occurredEventIndex], context); ResetEvents(waitedEventsAfterPlaying); occurredEventIndex = context.WaitAny(waitedEventsAfterPlaying, repeatTimeout); if (0 <= occurredEventIndex && occurredEventIndex <= lastWaitedEventsIndex) return nextActivityKeyResolver(waitedEventsAfterPlaying[occurredEventIndex], context); helpButtonPressed = (occurredEventIndex == waitedEventsAfterPlaying.Length - 1); } }
private NextActivityKey SayAndWaitEvents( WorkflowExecutionContext context, ActivityParameterDictionary parameters, ICollection<WaitHandle> waitedEvents, NextActivityKeyResolver nextActivityKeyResolver) { var silent = NeedSilent(parameters); var composer = CreatePhraseComposer(parameters, silent); var text = composer.ComposeText(); var sounds = silent ? new string[] { } : composer.ComposePhrase(); var helpComposer = CreateHelpPhraseComposer(parameters); var helpText = helpComposer.ComposeText(); var helpSounds = helpComposer.ComposePhrase(); var ignoreButtons = NeedIgnoreButtons(parameters); var startTimeout = GetStartTimeout(parameters); var repeatTimeout = GetRepeatTimeout(parameters); int occurredEventIndex; return SayAndWaitEvents( context, text, sounds, helpText, helpSounds, silent, ignoreButtons, waitedEvents, startTimeout, repeatTimeout, nextActivityKeyResolver, out occurredEventIndex); }