diff --git a/Asterisk.2013/Asterisk.NET/AsterNET.csproj b/Asterisk.2013/Asterisk.NET/AsterNET.csproj index 74e638c..96a5ad3 100644 --- a/Asterisk.2013/Asterisk.NET/AsterNET.csproj +++ b/Asterisk.2013/Asterisk.NET/AsterNET.csproj @@ -251,6 +251,7 @@ + diff --git a/Asterisk.2013/Asterisk.NET/Common.cs b/Asterisk.2013/Asterisk.NET/Common.cs index 723f02d..9111467 100644 --- a/Asterisk.2013/Asterisk.NET/Common.cs +++ b/Asterisk.2013/Asterisk.NET/Common.cs @@ -26,25 +26,8 @@ namespace AsterNET public static char[] MINUS_SEPARATOR = {'-'}; public static char INTERNAL_ACTION_ID_DELIMITER = '#'; - /// Variables delimiter - public static Dictionary VAR_DELIMITERS = new Dictionary(); - - /// Variables delimiter getter - public static char[] GET_VAR_DELIMITER(string hostname) - { - if (!VAR_DELIMITERS.ContainsKey(hostname)) - { - VAR_DELIMITERS.Add(hostname, new char[] { '|' }); - } - - return VAR_DELIMITERS[hostname]; - } - - /// Variables delimiter setter - public static void SET_VAR_DELIMITER(string hostname, char[] delimiter) - { - VAR_DELIMITERS[hostname] = delimiter; - } + [Obsolete("VAR_DELIMITER moved to ManagerConnection", true)] + public static char[] VAR_DELIMITER = {'|'}; public static IFormatProvider CultureInfoEn = new CultureInfo("en-US", false); diff --git a/Asterisk.2013/Asterisk.NET/Manager/Action/OriginateAction.cs b/Asterisk.2013/Asterisk.NET/Manager/Action/OriginateAction.cs index afb456f..0d2190d 100644 --- a/Asterisk.2013/Asterisk.NET/Manager/Action/OriginateAction.cs +++ b/Asterisk.2013/Asterisk.NET/Manager/Action/OriginateAction.cs @@ -22,7 +22,7 @@ namespace AsterNET.Manager.Action /// /// /// - public class OriginateAction : ManagerActionEvent + public class OriginateAction : ManagerActionEvent, IActionVariable { private Dictionary variables; @@ -158,10 +158,12 @@ namespace AsterNET.Manager.Action /// multiple variable assignments separated by the '|' character.
/// Example: "VAR1=abc|VAR2=def" sets the channel variables VAR1 to "abc" and VAR2 to "def". /// + + [Obsolete("Don't use this anymore - the delimiter is not server context aware", true)] public string Variable { - get { return Helper.JoinVariables(variables, Common.GET_VAR_DELIMITER(this.Server), "="); } - set { variables = Helper.ParseVariables(variables, value, Common.GET_VAR_DELIMITER(this.Server)); } + get { return null; /* return Helper.JoinVariables(variables, Common.GET_VAR_DELIMITER(this.Server), "="); */ } + set { /* variables = Helper.ParseVariables(variables, value, Common.GET_VAR_DELIMITER(this.Server)); */ } } #endregion diff --git a/Asterisk.2013/Asterisk.NET/Manager/Event/AbstractAgentVariables.cs b/Asterisk.2013/Asterisk.NET/Manager/Event/AbstractAgentVariables.cs index 114ea5d..365dc2a 100644 --- a/Asterisk.2013/Asterisk.NET/Manager/Event/AbstractAgentVariables.cs +++ b/Asterisk.2013/Asterisk.NET/Manager/Event/AbstractAgentVariables.cs @@ -5,7 +5,7 @@ using System.Collections; namespace AsterNET.Manager.Event { - public abstract class AbstractAgentVariables : ManagerEvent + public abstract class AbstractAgentVariables : ManagerEvent, IActionVariable { private Dictionary variables; @@ -18,25 +18,26 @@ namespace AsterNET.Manager.Event /// Get/Set the variables to set on the queue call in native asterisk format.
/// Example: "VAR1=abc|VAR2=def". /// - public string Variable - { - get { return Helper.JoinVariables(variables, Common.GET_VAR_DELIMITER(this.Server), "="); } - set { variables = Helper.ParseVariables(variables, value, Common.GET_VAR_DELIMITER(this.Server)); } - } + [Obsolete("Don't use this anymore - the delimiter is not server context aware", true)] + public string Variable + { + get { return null; /* return Helper.JoinVariables(variables, Common.GET_VAR_DELIMITER(this.Server), "="); */ } + set { /* variables = Helper.ParseVariables(variables, value, Common.GET_VAR_DELIMITER(this.Server)); */ } + } #endregion #region GetVariables() /// /// Get the variables dictionary to set on the originated call. /// - public IDictionary GetVariables() + public Dictionary GetVariables() { return variables; } #endregion - #region SetVariables(IDictionary vars) - /// + #region SetVariables(Dictionary vars) + /// /// Set the variables dictionary to set on the originated call. /// public void SetVariables(Dictionary vars) diff --git a/Asterisk.2013/Asterisk.NET/Manager/IActionVariable.cs b/Asterisk.2013/Asterisk.NET/Manager/IActionVariable.cs new file mode 100644 index 0000000..09b0e66 --- /dev/null +++ b/Asterisk.2013/Asterisk.NET/Manager/IActionVariable.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AsterNET.Manager +{ + interface IActionVariable + { + Dictionary GetVariables(); + void SetVariables(Dictionary vars); + } +} diff --git a/Asterisk.2013/Asterisk.NET/Manager/ManagerConnection.cs b/Asterisk.2013/Asterisk.NET/Manager/ManagerConnection.cs index f7fd747..0c1eb81 100644 --- a/Asterisk.2013/Asterisk.NET/Manager/ManagerConnection.cs +++ b/Asterisk.2013/Asterisk.NET/Manager/ManagerConnection.cs @@ -157,6 +157,8 @@ namespace AsterNET.Manager /// Default Slow Reconnect interval in milliseconds. private int reconnectIntervalMax = 10000; + public char[] VAR_DELIMITER = { '|' }; + #endregion /// @@ -1508,37 +1510,37 @@ namespace AsterNET.Manager version = m.Groups[1].Value; if (version.StartsWith("1.4.")) { - Common.SET_VAR_DELIMITER(this.hostname, new char[] { '|' }); + VAR_DELIMITER = new char[] { '|' }; return AsteriskVersion.ASTERISK_1_4; } else if (version.StartsWith("1.6.")) { - Common.SET_VAR_DELIMITER(this.hostname, new char[] { '|' }); + VAR_DELIMITER = new char[] { '|' }; return Manager.AsteriskVersion.ASTERISK_1_6; } else if (version.StartsWith("1.8.")) { - Common.SET_VAR_DELIMITER(this.hostname, new char[] { '|' }); + VAR_DELIMITER = new char[] { '|' }; return Manager.AsteriskVersion.ASTERISK_1_8; } else if (version.StartsWith("10.")) { - Common.SET_VAR_DELIMITER(this.hostname, new char[] { '|' }); + VAR_DELIMITER = new char[] { '|' }; return Manager.AsteriskVersion.ASTERISK_10; } else if (version.StartsWith("11.")) { - Common.SET_VAR_DELIMITER(this.hostname, new char[] { ',' }); + VAR_DELIMITER = new char[] { ',' }; return Manager.AsteriskVersion.ASTERISK_11; } else if (version.StartsWith("12.")) { - Common.SET_VAR_DELIMITER(this.hostname, new char[] { ',' }); + VAR_DELIMITER = new char[] { ',' }; return Manager.AsteriskVersion.ASTERISK_12; } else if (version.StartsWith("13.")) { - Common.SET_VAR_DELIMITER(this.hostname, new char[] { ',' }); + VAR_DELIMITER = new char[] { ',' }; return Manager.AsteriskVersion.ASTERISK_13; } else @@ -2159,6 +2161,12 @@ namespace AsterNET.Manager sb.Append(string.Concat(name, ": ", valueAsString, Common.LINE_SEPARATOR)); } + IActionVariable actionVar = action as IActionVariable; + if(actionVar != null && actionVar.GetVariables().Count > 0) + { + sb.Append(string.Concat("Variable: ", Helper.JoinVariables(actionVar.GetVariables(), VAR_DELIMITER, "="), Common.LINE_SEPARATOR)); + } + sb.Append(Common.LINE_SEPARATOR); return sb.ToString(); }