示例#1
0
文件: Common.cs 项目: xoposhiy/KOIB
        private NextActivityKey SayAndReadValue(
            WorkflowExecutionContext context, ActivityParameterDictionary parameters,
            WaitHandle okEvent, WaitHandle cancelEvent)
        {
            RaiseOutputStarting(InfoType.Question);
            var silent   = NeedSilent(parameters);
            var composer = CreatePhraseComposer(parameters, silent);
            var text     = composer.ComposeText();

            LastReadedValue = parameters.GetParamValue <object>("Value") == null
                                  ? null
                                  : parameters.GetParamValue <long>("Value").ToString();
            var passwordChar     = parameters.GetParamValue("PasswordChar", ReadValueContext.NULL_PASSWORD_CHAR);
            var readValueMode    = parameters.GetParamValue("ReadValueMode", ReadValueMode.CutLeadingZero);
            var helpComposer     = CreateHelpPhraseComposer(parameters);
            var helpSounds       = helpComposer.ComposePhrase();
            var readValueContext = new ReadValueContext(
                context, _scannerManager.IndicatorLength, text, LastReadedValue, passwordChar, readValueMode);
            var readValueThread = new Thread(ReadValueMethod);
            var required        = parameters.GetParamValue("Required", false);

            try
            {
                readValueThread.Start(readValueContext);
                var sounds        = silent ? new string[] { } : composer.ComposePhrase();
                var repeatTimeout = GetRepeatTimeout(parameters);
                var startTimeout  = GetStartTimeout(parameters);


                var nextActivityKeyResolver = GetNextActivityKeyResolver(parameters);
                while (true)
                {
                    int occurredEventIndex;
                    var result = SayAndWaitEvents(
                        context, "", sounds, null, helpSounds,
                        silent, false, new[] { okEvent, cancelEvent },
                        startTimeout, repeatTimeout, nextActivityKeyResolver, out occurredEventIndex);
                    if (occurredEventIndex == 0)
                    {
                        if (required && string.IsNullOrEmpty(readValueContext.Value))
                        {
                            continue;
                        }
                        LastReadedValue = readValueContext.Value;
                    }
                    return(result);
                }
            }
            finally
            {
                readValueContext.StopReadingEvent.Set();
                readValueThread.Join(TimeSpan.FromSeconds(1));
            }
        }
示例#2
0
文件: Common.cs 项目: nico-izo/KOIB
        private NextActivityKey SayAndReadValue( 
            WorkflowExecutionContext context, ActivityParameterDictionary parameters, 
            WaitHandle okEvent, WaitHandle cancelEvent)
        {
            RaiseOutputStarting(InfoType.Question);
            var silent = NeedSilent(parameters);
            var composer = CreatePhraseComposer(parameters, silent);
            var text = composer.ComposeText();
            LastReadedValue = parameters.GetParamValue<object>("Value") == null
                                  ? null
                                  : parameters.GetParamValue<long>("Value").ToString();
            var passwordChar = parameters.GetParamValue("PasswordChar", ReadValueContext.NULL_PASSWORD_CHAR);
            var readValueMode = parameters.GetParamValue("ReadValueMode", ReadValueMode.CutLeadingZero);
            var helpComposer = CreateHelpPhraseComposer(parameters);
            var helpSounds = helpComposer.ComposePhrase();
            var readValueContext = new ReadValueContext(
                context, _scannerManager.IndicatorLength, text, LastReadedValue, passwordChar, readValueMode);
            var readValueThread = new Thread(ReadValueMethod);
            var required = parameters.GetParamValue("Required", false);
            try
            {
                readValueThread.Start(readValueContext);
                var sounds = silent ? new string[] { } : composer.ComposePhrase();
                var repeatTimeout = GetRepeatTimeout(parameters);
                var startTimeout = GetStartTimeout(parameters);

                var nextActivityKeyResolver = GetNextActivityKeyResolver(parameters);
                while (true)
                {
                    int occurredEventIndex;
                    var result = SayAndWaitEvents(
                        context, "", sounds, null, helpSounds,
                        silent, false, new[] { okEvent, cancelEvent },
                        startTimeout, repeatTimeout, nextActivityKeyResolver, out occurredEventIndex);
                    if (occurredEventIndex == 0)
                    {
                        if (required && string.IsNullOrEmpty(readValueContext.Value))
                            continue;
                        LastReadedValue = readValueContext.Value;
                    }
                    return result;
                }
            }
            finally
            {
                readValueContext.StopReadingEvent.Set();
                readValueThread.Join(TimeSpan.FromSeconds(1));
            }
        }