示例#1
0
        public CallAnalysis Dial(string number, int answeringMachineLengthInMilliseconds)
        {
            if (_stopped)
            {
                ResetAndThrowStop();
            }

            TakeOffHook();
            Logger.Debug("Line is now off hook");

            var dialToneTid   = VoiceProperties.Current.DialTone.Tid;
            var noFreeLineTid = VoiceProperties.Current.NoFreeLineTone.Tid;

            var dialToneEnabled = false;

            if (VoiceProperties.Current.PreTestDialTone)
            {
                Logger.Debug("We are pre-testing the dial tone");
                dialToneEnabled = true;
                Dialogic.EnableTone(_devh, dialToneTid);
                var tid = Dialogic.ListenForCustomTones(_devh, 2);

                if (tid == 0)
                {
                    Logger.Debug("No tone was detected");
                    Dialogic.DisableTone(_devh, dialToneTid);
                    Hangup();
                    return(CallAnalysis.NoDialTone);
                }
            }
            var index = number.IndexOf(',');

            if (VoiceProperties.Current.CustomOutboundEnabled && index != -1)
            {
                Logger.Debug("Custom dial-9 logic");
                var prefix = number.Substring(0, index);

                number = number.Substring(index + 1).Replace(",", ""); // there may be more than one comma

                if (!dialToneEnabled)
                {
                    Dialogic.EnableTone(_devh, dialToneTid);
                }
                Dialogic.EnableTone(_devh, noFreeLineTid);

                // send prefix (usually a 9)
                Dialogic.Dial(_devh, prefix);

                // listen for tones
                var tid = Dialogic.ListenForCustomTones(_devh, 2);

                Dialogic.DisableTone(_devh, dialToneTid);
                Dialogic.DisableTone(_devh, noFreeLineTid);


                if (tid == 0)
                {
                    Hangup();
                    return(CallAnalysis.NoDialTone);
                }
                if (tid == noFreeLineTid)
                {
                    Hangup();
                    return(CallAnalysis.NoFreeLine);
                }
            }
            else
            {
                if (dialToneEnabled)
                {
                    Dialogic.DisableTone(_devh, dialToneTid);
                }
            }

            Logger.Debug("about to dial: {0}", number);
            var result = Dialogic.DialWithCpa(_devh, number, answeringMachineLengthInMilliseconds);

            Logger.Debug("CallAnalysis is: {0}", result.ToString());
            if (result == CallAnalysis.Stopped)
            {
                ResetAndThrowStop();
            }

            if (result == CallAnalysis.AnsweringMachine || result == CallAnalysis.Connected)
            {
                _status = LineStatusTypes.Connected;
            }
            else
            {
                Hangup();
            }
            return(result);
        }
示例#2
0
 public void EnableTone(int tid)
 {
     Dialogic.EnableTone(_devh, tid);
 }