using System; namespace AsterNET.FastAGI.Command { /// /// Stream the given file, and recieve DTMF data. The user may interrupt the streaming by starting to enter digits.
/// Returns the digits recieved from the channel at the other end.
/// Input ends when the timeout is reached, the maximum number of digits is read or the user presses #. ///
public class GetDataCommand : AGICommand { /// The name of the file to stream. private string file; /// The timeout in milliseconds to wait for data.
/// 0 means standard timeout value, -1 means "ludicrous time" (essentially never times out). ///
private long timeout; /// The maximum number of digits to read.
/// Must be in [1..1024]. ///
private int maxDigits; /// /// Get/Set the name of the file to stream. Must not include extension. /// public string File { get { return file; } set { this.file = value; } } /// /// Get/Set the timeout in milliseconds to wait for data. 0 means standard timeout value, -1 means "ludicrous time" (essentially never times out). /// public long Timeout { get { return timeout; } set { this.timeout = value; } } /// /// Get/Set the maximum number of digits to read. The maximum number of digits to read. Must be in [1..1024]. /// /// IllegalArgumentException if maxDigits is not in [1..1024] public int MaxDigits { get { return maxDigits; } set { if (value < 1 || value > 1024) throw new ArgumentException("maxDigits must be in [1..1024]"); this.maxDigits = value; } } /// /// Creates a new GetDataCommand with default timeout and maxDigits set to 1024. /// /// the name of the file to stream, must not include extension. public GetDataCommand(string file) { this.file = file; this.timeout = Common.AGI_DEFAULT_TIMEOUT; this.maxDigits = Common.AGI_DEFAULT_MAX_DIGITS; } /// /// Creates a new GetDataCommand with the given timeout and maxDigits set to 1024. /// /// the name of the file to stream, must not include extension. /// the timeout in milliseconds to wait for data.
/// 0 means standard timeout value, -1 means "ludicrous time" (essentially never times out). /// public GetDataCommand(string file, long timeout) { this.file = file; this.timeout = timeout; this.maxDigits = Common.AGI_DEFAULT_MAX_DIGITS; } /// /// Creates a new GetDataCommand with the given timeout and maxDigits. /// /// the name of the file to stream, must not include extension. /// the timeout in milliseconds to wait for data.
/// 0 means standard timeout value, -1 means "ludicrous time" (essentially never times out). /// /// the maximum number of digits to read.
/// Must be in [1..1024]. /// /// IllegalArgumentException if maxDigits is not in [1..1024] public GetDataCommand(string file, long timeout, int maxDigits) { this.file = file; this.timeout = timeout; this.MaxDigits = maxDigits; } public override string BuildCommand() { if (maxDigits == Common.AGI_DEFAULT_MAX_DIGITS) { if (timeout == Common.AGI_DEFAULT_TIMEOUT) return "GET DATA " + EscapeAndQuote(file); else return "GET DATA " + EscapeAndQuote(file) + " " + timeout; } return "GET DATA " + EscapeAndQuote(file) + " " + timeout + " " + maxDigits; } } }