using System.Text; namespace AsterNET.FastAGI.Command { /// /// Say a given time, returning early if any of the given DTMF digits are pressed.
/// 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/hangup.
/// Available since Asterisk 1.2. ///
public class SayDateTimeCommand : AGICommand { private static string DEFAULT_FORMAT = "ABdY 'digits/at' IMp"; private long time; private string escapeDigits; private string format; private string timezone; /// /// Creates a new SayDateTimeCommand that says the given time. /// the time to say in seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC) /// public SayDateTimeCommand(long time) { this.time = time; } /// /// Creates a new SayDateTimeCommand that says the given time and allows interruption by one of the given escape digits. /// /// the time to say in seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC) /// the digits that allow the user to interrupt this command or null for none. public SayDateTimeCommand(long time, string escapeDigits) { this.time = time; this.escapeDigits = escapeDigits; } /// /// Creates a new SayDateTimeCommand that says the given time in the given /// format and allows interruption by one of the given escape digits. /// /// the time to say in seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC) /// the digits that allow the user to interrupt this command or null for none. /// the format the time should be said in public SayDateTimeCommand(long time, string escapeDigits, string format) { this.time = time; this.escapeDigits = escapeDigits; this.format = format; } /// /// Creates a new SayDateTimeCommand that says the given time in the given /// format and timezone and allows interruption by one of the given escape /// digits. /// /// the time to say in seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC) /// the digits that allow the user to interrupt this command or null for none. /// the format the time should be said in /// the timezone to use when saying the time, for example "UTC" or "Europe/Berlin". public SayDateTimeCommand(long time, string escapeDigits, string format, string timezone) { this.time = time; this.escapeDigits = escapeDigits; this.format = format; this.timezone = timezone; } /// /// Get/Set the time to say in seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC). /// public long Time { get { return this.time; } set { this.time = value; } } /// /// Get/Set the digits that allow the user to interrupt this command. /// public string getEscapeDigits { get { return this.escapeDigits; } set { this.escapeDigits = value; } } /// /// Get/Set the format the time should be said in. /// public string Format { get { return this.format; } set { this.format = value; } } /// /// Get/Set the timezone to use when saying the time. /// public string Timezone { get { return this.timezone; } set { this.timezone = value; } } public override string BuildCommand() { StringBuilder sb = new StringBuilder("SAY DATETIME "); sb.Append(time); sb.Append(" "); sb.Append(EscapeAndQuote(escapeDigits)); if (format == null && timezone != null) { sb.Append(" "); sb.Append(EscapeAndQuote(DEFAULT_FORMAT)); } if (format != null) { sb.Append(" "); sb.Append(EscapeAndQuote(format)); } if (timezone != null) { sb.Append(" "); sb.Append(EscapeAndQuote(timezone)); } return sb.ToString(); } } }