Exemplo n.º 1
0
        public async Task ProcessDigitsReceived()
        {
            if (DigitsReceived.Length < NumberOfDigitsToWaitForNextStep)
            {
                DigitTimeoutTimer.Start();
                return;
            }

            if (NumberOfDigitsToWaitForNextStep == 0 &&
                !DigitsReceived.EndsWith(TerminationDigit))
            {
                DigitTimeoutTimer.Start();
                return;
            }

            if (TerminationDigit != "")
            {
                if (DigitsReceived.EndsWith(TerminationDigit))
                {
                    if (_settings.SetValueAsDestination)
                    {
                        _call.CallState.Destination = DigitsReceived.Substring(0, DigitsReceived.Length - 1);
                    }
                    else if (!string.IsNullOrEmpty(_settings.SetValueAs))
                    {
                        DynamicState.SetProperty(_call.CallState, _settings.SetValueAs, DigitsReceived);
                    }

                    AddStepToProperQueue(_settings.NextStep);
                    _call.CallState.InputData = DigitsReceived.Substring(0, DigitsReceived.Length - 1);
                    ResetInputRetryCount();
                    await _call.FireStateChange(Trigger.InputReceived);

                    return;
                }
            }
            else if (_settings.SetValueAsDestination)
            {
                _call.CallState.Destination = DigitsReceived.Substring(0, DigitsReceived.Length);
                AddStepToProperQueue(_settings.NextStep);
                _call.CallState.InputData = DigitsReceived.Substring(0, DigitsReceived.Length);
                ResetInputRetryCount();
                await _call.FireStateChange(Trigger.InputReceived);

                return;
            }
            else if (!string.IsNullOrEmpty(_settings.SetValueAs))
            {
                DynamicState.SetProperty(_call.CallState, _settings.SetValueAs, DigitsReceived);
                _call.CallState.InputData = DigitsReceived;
                ResetInputRetryCount();
                AddStepToProperQueue(_settings.NextStep);
                await _call.FireStateChange(Trigger.InputReceived);

                return;
            }

            if (NumberOfDigitsToWaitForNextStep == 0)
            {
                DigitTimeoutTimer.Start();
                return;
            }

            var validStep = false;

            foreach (var option in _settings.Options.Where(option => option.Key == DigitsReceived.Substring(0, NumberOfDigitsToWaitForNextStep)))
            {
                ResetInputRetryCount();

                AddStepToProperQueue(option.Value);

                validStep = true;
            }

            if (!validStep)
            {
                if (_call.CallState.InputRetryCount > _settings.MaxRetryCount && _settings.MaxRetryCount > 0)
                {
                    ResetInputRetryCount();

                    AddStepToProperQueue(_settings.MaxAttemptsReachedStep);
                }
                else
                {
                    AddStepToProperQueue(_settings.Invalid);
                }
            }
            await _call.FireStateChange(Trigger.InputReceived);
        }