Esempio n. 1
0
        /// <summary>
        /// Plays the given file, allowing playback to be interrupted by the given
        /// digits, if any, and allows the listner to control the stream.<br/>
        /// If offset is provided then the audio will seek to sample offset before play
        /// starts.<br/>
        /// Returns 0 if playback completes without a digit being pressed, or the ASCII
        /// numerical value of the digit if one was pressed, or -1 on error or if the
        /// channel was disconnected. <br/>
        /// Remember, the file extension must not be included in the filename.<br/>
        /// Available since Asterisk 1.2
        /// </summary>
        /// <seealso cref="Command.ControlStreamFileCommand"/>
        /// <param name="file">the name of the file to stream, must not include extension.</param>
        /// <param name="escapeDigits">contains the digits that allow the user to interrupt this command.</param>
        /// <returns>result code</returns>
        protected internal int ControlStreamFile(string file, string escapeDigits)
        {
            AGIChannel channel   = this.Channel;
            AGIReply   lastReply = channel.SendCommand(new Command.ControlStreamFileCommand(file, escapeDigits));

            return(lastReply.ResultCode);
        }
Esempio n. 2
0
        /// <summary>
        /// Plays the given file, allowing playback to be interrupted by the given
        /// digits, if any, and allows the listner to control the stream.<br/>
        /// If offset is provided then the audio will seek to sample offset before play
        /// starts.<br/>
        /// Returns 0 if playback completes without a digit being pressed, or the ASCII
        /// numerical value of the digit if one was pressed, or -1 on error or if the
        /// channel was disconnected. <br/>
        /// Remember, the file extension must not be included in the filename.<br/>
        /// Available since Asterisk 1.2
        /// </summary>
        /// <seealso cref="Command.ControlStreamFileCommand"/>
        /// <param name="file">the name of the file to stream, must not include extension.</param>
        /// <param name="escapeDigits">contains the digits that allow the user to interrupt this command.</param>
        /// <param name="offset">the offset samples to skip before streaming.</param>
        /// <param name="forwardDigit">the digit for fast forward.</param>
        /// <param name="rewindDigit">the digit for rewind.</param>
        /// <param name="pauseDigit">the digit for pause and unpause.</param>
        /// <returns>result code</returns>
        protected internal int ControlStreamFile(string file, string escapeDigits, int offset, string forwardDigit, string rewindDigit, string pauseDigit)
        {
            AGIChannel channel   = this.Channel;
            AGIReply   lastReply = channel.SendCommand(new Command.ControlStreamFileCommand(file, escapeDigits, offset, forwardDigit, rewindDigit, pauseDigit));

            return(lastReply.ResultCode);
        }
Esempio n. 3
0
        /// <summary>
        /// Says the given character string, returning early if any of the given DTMF
        /// number are received on the channel.
        /// </summary>
        /// <param name="text">the text to say.</param>
        /// <param name="escapeDigits">a String containing the DTMF digits that allow the user to escape.</param>
        /// <returns> the DTMF digit pressed or 0x0 if none was pressed.</returns>
        protected internal char SayAlpha(string text, string escapeDigits)
        {
            AGIChannel channel   = this.Channel;
            AGIReply   lastReply = channel.SendCommand(new Command.SayAlphaCommand(text, escapeDigits));

            return(lastReply.ResultCodeAsChar);
        }
Esempio n. 4
0
        /// <summary>
        /// Record to a file until a given dtmf digit in the sequence is received.<br/>
        /// Returns -1 on hangup or error.<br/>
        /// The format will specify what kind of file will be recorded. The timeout is
        /// the maximum record time in milliseconds, or -1 for no timeout. Offset samples
        /// is optional, and if provided will seek to the offset without exceeding the
        /// end of the file. "maxSilence" is the number of seconds of maxSilence allowed
        /// before the function returns despite the lack of dtmf digits or reaching
        /// timeout.
        /// </summary>
        /// <param name="file">the name of the file to stream, must not include extension.</param>
        /// <param name="format">the format of the file to be recorded, for example "wav".</param>
        /// <param name="escapeDigits">contains the digits that allow the user to end recording.</param>
        /// <param name="timeout">the maximum record time in milliseconds, or -1 for no timeout.</param>
        /// <param name="offset">the offset samples to skip.</param>
        /// <param name="beep">true if a beep should be played before recording.</param>
        /// <param name="maxSilence">The amount of silence (in seconds) to allow before returning despite the lack of dtmf digits or reaching timeout.</param>
        /// <returns>result code</returns>
        protected internal int RecordFile(string file, string format, string escapeDigits, int timeout, int offset, bool beep, int maxSilence)
        {
            AGIChannel channel   = this.Channel;
            AGIReply   lastReply = channel.SendCommand(new Command.RecordFileCommand(file, format, escapeDigits, timeout, offset, beep, maxSilence));

            return(lastReply.ResultCode);
        }
Esempio n. 5
0
        /// <summary>
        /// Says the given time in the given format and timezone and allows interruption by one of the given escape digits.<br/>
        /// Available since Asterisk 1.2.
        /// </summary>
        /// <param name="time">the time to say in seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC)</param>
        /// <param name="escapeDigits">the digits that allow the user to interrupt this command or null for none.</param>
        /// <param name="format">the format the time should be said in</param>
        /// <param name="timezone">the timezone to use when saying the time, for example "UTC" or "Europe/Berlin".</param>
        /// <returns>the DTMF digit pressed or 0x0 if none was pressed.</returns>
        protected internal char SayDateTime(long time, string escapeDigits, string format, string timezone)
        {
            AGIChannel channel   = this.Channel;
            AGIReply   lastReply = channel.SendCommand(new Command.SayDateTimeCommand(time, escapeDigits, format, timezone));

            return(lastReply.ResultCodeAsChar);
        }
Esempio n. 6
0
        /// <summary>
        /// Waits up to 'timeout' milliseconds to receive a DTMF digit.
        /// </summary>
        /// <param name="timeout">timeout the milliseconds to wait for the channel to receive a DTMF digit, -1 will wait forever.</param>
        /// <returns> the DTMF digit pressed or 0x0 if none was pressed.</returns>
        protected internal char WaitForDigit(int timeout)
        {
            AGIChannel channel   = this.Channel;
            AGIReply   lastReply = channel.SendCommand(new Command.WaitForDigitCommand(timeout));

            return(lastReply.ResultCodeAsChar);
        }
Esempio n. 7
0
        /// <summary>
        /// Executes the given command.
        /// </summary>
        /// <param name="application">the name of the application to execute, for example "Dial".</param>
        /// <param name="options">the parameters to pass to the application, for example "SIP/123".</param>
        /// <returns> the return code of the application of -2 if the application was not found.</returns>
        protected internal int Exec(string application, string options)
        {
            AGIChannel channel   = this.Channel;
            AGIReply   lastReply = channel.SendCommand(new Command.ExecCommand(application, options));

            return(lastReply.ResultCode);
        }
Esempio n. 8
0
        /// <summary>
        /// Says the given number, returning early if any of the given DTMF number
        /// are received on the channel.
        /// </summary>
        /// <param name="number">the number to say.</param>
        /// <param name="escapeDigits">a String containing the DTMF digits that allow the user to escape.</param>
        /// <returns> the DTMF digit pressed or 0x0 if none was pressed.</returns>
        protected internal char SayNumber(string number, string escapeDigits)
        {
            AGIChannel channel   = this.Channel;
            AGIReply   lastReply = channel.SendCommand(new Command.SayNumberCommand(number, escapeDigits));

            return(lastReply.ResultCodeAsChar);
        }
Esempio n. 9
0
        /// <summary>
        /// Plays the given file, and waits for the user to press one of the given
        /// digits. If none of the esacpe digits is pressed while streaming the file
        /// it waits for the specified timeout still waiting for the user to press a
        /// digit.
        /// </summary>
        /// <param name="file">the name of the file to stream, must not include extension.</param>
        /// <param name="escapeDigits">contains the digits that the user is expected to press.</param>
        /// <param name="timeout">the timeout in seconds to wait if none of the defined esacpe digits was presses while streaming.</param>
        /// <returns> the DTMF digit pressed or 0x0 if none was pressed.</returns>
        protected internal char GetOption(string file, string escapeDigits, int timeout)
        {
            AGIChannel channel   = this.Channel;
            AGIReply   lastReply = channel.SendCommand(new Command.GetOptionCommand(file, escapeDigits, timeout));

            return(lastReply.ResultCodeAsChar);
        }
Esempio n. 10
0
        /// <summary>
        /// Plays the given file and waits for the user to enter DTMF digits until he
        /// presses '#' or the timeout occurs or the maximum number of digits has
        /// been entered. The user may interrupt the streaming by starting to enter
        /// digits.
        /// </summary>
        /// <param name="file">the name of the file to play</param>
        /// <param name="timeout">the timeout in milliseconds to wait for user input.<br/>
        /// 0 means standard timeout value, -1 means "ludicrous time"
        /// (essentially never times out).</param>
        /// <param name="maxDigits">the maximum number of digits the user is allowed to enter</param>
        /// <returns> a String containing the DTMF the user entered</returns>
        protected internal string GetData(string file, long timeout, int maxDigits)
        {
            AGIChannel channel   = this.Channel;
            AGIReply   lastReply = channel.SendCommand(new Command.GetDataCommand(file, timeout, maxDigits));

            return(lastReply.GetResult());
        }
Esempio n. 11
0
        /// <summary>
        /// Plays the given file and waits for the user to enter DTMF digits until he
        /// presses '#'. The user may interrupt the streaming by starting to enter
        /// digits.
        /// </summary>
        /// <param name="file">the name of the file to play</param>
        /// <returns> a String containing the DTMF the user entered</returns>
        protected internal string GetData(string file)
        {
            AGIChannel channel   = this.Channel;
            AGIReply   lastReply = channel.SendCommand(new Command.GetDataCommand(file));

            return(lastReply.GetResult());
        }
Esempio n. 12
0
        /// <summary>
        /// Returns the status of the channel.<br/>
        /// Return values:
        /// <ul>
        /// <li>0 Channel is down and available</li>
        /// <li>1 Channel is down, but reserved</li>
        /// <li>2 Channel is off hook</li>
        /// <li>3 Digits (or equivalent) have been dialed</li>
        /// <li>4 Line is ringing</li>
        /// <li>5 Remote end is ringing</li>
        /// <li>6 Line is up</li>
        /// <li>7 Line is busy</li>
        /// </ul>
        /// </summary>
        /// <returns> the status of the channel.
        /// </returns>
        protected internal int GetChannelStatus()
        {
            AGIChannel channel   = this.Channel;
            AGIReply   lastReply = channel.SendCommand(new Command.ChannelStatusCommand());

            return(lastReply.ResultCode);
        }
Esempio n. 13
0
        /// <summary>
        /// Retrieves an entry in the Asterisk database for a given family and key.
        /// </summary>
        /// <param name="family">the family of the entry to retrieve.</param>
        /// <param name="key">key the key of the entry to retrieve.</param>
        /// <return>the value of the given family and key or null if there is no such value.</return>
        protected internal string DatabaseGet(string family, string key)
        {
            AGIChannel channel   = this.Channel;
            AGIReply   lastReply = channel.SendCommand(new Command.DatabaseGetCommand(family, key));

            if (lastReply.ResultCode != 1)
            {
                return(null);
            }
            return(lastReply.Extra);
        }
Esempio n. 14
0
        /// <summary>
        /// Returns the value of the given channel variable.<br/>
        /// Available since Asterisk 1.2.
        /// </summary>
        /// <param name="name">the name of the variable to retrieve.</param>
        /// <param name="channel">the name of the channel.</param>
        /// <returns>the value of the given variable or null if not set.</returns>
        protected internal string GetFullVariable(string name, string channelName)
        {
            AGIChannel channel   = this.Channel;
            AGIReply   lastReply = channel.SendCommand(new Command.GetFullVariableCommand(name, channelName));

            if (lastReply.ResultCode != 1)
            {
                return(null);
            }
            return(lastReply.Extra);
        }
Esempio n. 15
0
 public AGIReply SendCommand(AGICommand command)
 {
     agiWriter.SendCommand(command);
     agiReply = agiReader.ReadReply();
     int status = agiReply.GetStatus();
     if (status == (int) AGIReplyStatuses.SC_INVALID_OR_UNKNOWN_COMMAND)
         throw new InvalidOrUnknownCommandException(command.BuildCommand());
     if (status == (int) AGIReplyStatuses.SC_INVALID_COMMAND_SYNTAX)
         throw new InvalidCommandSyntaxException(agiReply.GetSynopsis(), agiReply.GetUsage());
     if (status == (int) AGIReplyStatuses.SC_DEAD_CHANNEL && _SC511_CAUSES_EXCEPTION)
         throw new AGIHangupException();
     if ((status == 0) && agiReply.FirstLine == "HANGUP" && _SCHANGUP_CAUSES_EXCEPTION)
         throw new AGIHangupException();
     return agiReply;
 }
Esempio n. 16
0
        public AGIReply SendCommand(AGICommand command)
        {
            agiWriter.SendCommand(command);
            agiReply = agiReader.ReadReply();
            int status = agiReply.GetStatus();

            if (status == (int)AGIReplyStatuses.SC_INVALID_OR_UNKNOWN_COMMAND)
            {
                throw new InvalidOrUnknownCommandException(command.BuildCommand());
            }
            if (status == (int)AGIReplyStatuses.SC_INVALID_COMMAND_SYNTAX)
            {
                throw new InvalidCommandSyntaxException(agiReply.GetSynopsis(), agiReply.GetUsage());
            }
            if (status == (int)AGIReplyStatuses.SC_DEAD_CHANNEL && _SC511_CAUSES_EXCEPTION)
            {
                throw new AGIHangupException();
            }
            if ((status == 0) && agiReply.FirstLine == "HANGUP" && _SCHANGUP_CAUSES_EXCEPTION)
            {
                throw new AGIHangupException();
            }
            return(agiReply);
        }