using System;
using System.Collections;
using System.Collections.Generic;
namespace Asterisk.NET.Manager.Action
{
///
/// The OriginateAction generates an outgoing call to the extension in the given
/// context with the given priority or to a given application with optional
/// parameters.
/// If you want to connect to an extension use the properties context, exten and
/// priority. If you want to connect to an application use the properties
/// application and data if needed. Note that no call detail record will be
/// written when directly connecting to an application, so it may be better to
/// connect to an extension that starts the application you wish to connect to.
/// The response to this action is sent when the channel has been answered and
/// asterisk starts connecting it to the given extension. So be careful not to
/// choose a too short timeout when waiting for the response.
/// If you set async to true
Asterisk reports an OriginateSuccess-
/// and OriginateFailureEvents. The action id of these events equals the action
/// id of this OriginateAction.
///
///
///
public class OriginateAction : ManagerActionEvent
{
private string channel;
private string exten;
private string context;
private string priority;
private int timeout;
private string callerId;
private Dictionary variables;
private string account;
private string application;
private string data;
private bool async;
#region Action
///
/// Get the name of this action, i.e. "Originate".
///
override public string Action
{
get { return "Originate"; }
}
#endregion
#region Account
///
/// Get/Set the account code to use for the originated call.
/// The account code is included in the call detail record generated for this call and will be used for billing.
///
public string Account
{
get { return account; }
set { this.account = value; }
}
#endregion
#region CallerId
///
/// Get/Set the caller id to set on the outgoing channel.
///
public string CallerId
{
get { return callerId; }
set { this.callerId = value; }
}
#endregion
#region Channel
///
/// Get/Set Channel on which to originate the call (The same as you specify in the Dial application command)
/// This property is required.
///
public string Channel
{
get { return channel; }
set { this.channel = value; }
}
#endregion
#region Context
///
/// Get/Set the name of the context of the extension to connect to.
/// If you set the context you also have to set the exten and priority properties.
///
public string Context
{
get { return context; }
set { this.context = value; }
}
#endregion
#region Exten
///
/// Get/Ser the extension to connect to.
/// If you set the extension you also have to set the context and priority properties.
///
public string Exten
{
get { return exten; }
set { this.exten = value; }
}
#endregion
#region Priority
///
/// Get /Set the priority of the extension to connect to.
/// If you set the priority you also have to set the context and exten properties.
///
public string Priority
{
get { return priority; }
set { this.priority = value; }
}
#endregion
#region Application
///
/// Get/Set Application to use on connect (use Data for parameters)
///
public string Application
{
get { return application; }
set { this.application = value; }
}
#endregion
#region Data
///
/// Get/Set the parameters to pass to the application.
/// Data if Application parameter is user
///
/// Sets the parameters to pass to the application.
public string Data
{
get { return data; }
set { this.data = value; }
}
#endregion
#region Async
///
/// Get/Set true
if this is a fast origination.
/// For the origination to be asynchronous (allows multiple calls to be generated without waiting for a response).
/// Will send OriginateSuccess- and OriginateFailureEvents.
///
public bool Async
{
get { return async; }
set { this.async = value; }
}
#endregion
#region ActionCompleteEventClass
public override Type ActionCompleteEventClass()
{
return typeof(Event.OriginateResponseEvent);
}
#endregion
#region Timeout
///
/// Get/Set the timeout for the origination in seconds.
/// The channel must be answered within this time, otherwise the origination
/// is considered to have failed and an OriginateFailureEvent is generated.
/// If not set, Asterisk assumes a default value of 30000 meaning 30 seconds.
///
public int Timeout
{
get { return timeout; }
set { this.timeout = value; }
}
#endregion
#region Variable
///
/// Get/Set the variables to set on the originated call.
/// Variable assignments are of the form "VARNAME=VALUE". You can specify
/// multiple variable assignments separated by the '|' character.
/// Example: "VAR1=abc|VAR2=def" sets the channel variables VAR1 to "abc" and VAR2 to "def".
///
public string Variable
{
get { return Helper.JoinVariables(variables, Common.VAR_DELIMITER, "="); }
set { variables = Helper.ParseVariables(variables, value, Common.VAR_DELIMITER); }
}
#endregion
#region GetVariables()
///
/// Get the variables dictionary to set on the originated call.
///
public Dictionary GetVariables()
{
return variables;
}
#endregion
#region SetVariables(IDictionary vars)
///
/// Set the variables dictionary to set on the originated call.
///
public void SetVariables(Dictionary vars)
{
this.variables = vars;
}
#endregion
#region GetVariable(string name, string val)
///
/// Gets a variable on the originated call. Replaces any existing variable with the same name.
///
public string GetVariable(string key)
{
if (variables == null)
return string.Empty;
return variables[key];
}
#endregion
#region SetVariable(string name, string val)
///
/// Sets a variable dictionary on the originated call. Replaces any existing variable with the same name.
///
public void SetVariable(string key, string value)
{
if (variables == null)
variables = new Dictionary();
if (variables.ContainsKey(key))
variables[key] = value;
else
variables.Add(key, value);
}
#endregion
}
}