Change variable delimiter to be variable per host

Change variable delimiter to be a command on asterisk >= 11
This commit is contained in:
Justin 2015-03-31 10:40:55 -07:00
parent 2010cc85e0
commit 58ab6be525
5 changed files with 63 additions and 35 deletions

View file

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
@ -26,7 +27,29 @@ namespace AsterNET
public static char INTERNAL_ACTION_ID_DELIMITER = '#';
/// <summary> Variables delimiter </summary>
public static char[] VAR_DELIMITER = {'|'};
public static Dictionary<string, char[]> VAR_DELIMITERS = new Dictionary<string, char[]>();
/// <summary> Variables delimiter getter </summary>
public static char[] GET_VAR_DELIMITER(string hostname)
{
if (!VAR_DELIMITERS.ContainsKey(hostname))
{
VAR_DELIMITERS.Add(hostname, new char[] { '|' });
}
return VAR_DELIMITERS[hostname];
}
/// <summary> Variables delimiter setter </summary>
public static char[] SET_VAR_DELIMITER(string hostname, char[] delimiter)
{
if (!VAR_DELIMITERS.ContainsKey(hostname))
{
VAR_DELIMITERS.Add(hostname, new char[] { '|' });
}
return VAR_DELIMITERS[hostname] = delimiter;
}
public static IFormatProvider CultureInfoEn = new CultureInfo("en-US", false);

View file

@ -160,8 +160,8 @@ namespace AsterNET.Manager.Action
/// </summary>
public string Variable
{
get { return Helper.JoinVariables(variables, Common.VAR_DELIMITER, "="); }
set { variables = Helper.ParseVariables(variables, value, Common.VAR_DELIMITER); }
get { return Helper.JoinVariables(variables, Common.GET_VAR_DELIMITER(this.Server), "="); }
set { variables = Helper.ParseVariables(variables, value, Common.GET_VAR_DELIMITER(this.Server)); }
}
#endregion

View file

@ -20,8 +20,8 @@ namespace AsterNET.Manager.Event
/// </summary>
public string Variable
{
get { return Helper.JoinVariables(variables, Common.VAR_DELIMITER, "="); }
set { variables = Helper.ParseVariables(variables, value, Common.VAR_DELIMITER); }
get { return Helper.JoinVariables(variables, Common.GET_VAR_DELIMITER(this.Server), "="); }
set { variables = Helper.ParseVariables(variables, value, Common.GET_VAR_DELIMITER(this.Server)); }
}
#endregion

View file

@ -1507,19 +1507,40 @@ namespace AsterNET.Manager
{
version = m.Groups[1].Value;
if (version.StartsWith("1.4."))
{
Common.SET_VAR_DELIMITER(this.hostname, new char[] { '|' });
return AsteriskVersion.ASTERISK_1_4;
}
else if (version.StartsWith("1.6."))
{
Common.SET_VAR_DELIMITER(this.hostname, new char[] { '|' });
return Manager.AsteriskVersion.ASTERISK_1_6;
}
else if (version.StartsWith("1.8."))
{
Common.SET_VAR_DELIMITER(this.hostname, new char[] { '|' });
return Manager.AsteriskVersion.ASTERISK_1_8;
}
else if (version.StartsWith("10."))
{
Common.SET_VAR_DELIMITER(this.hostname, new char[] { '|' });
return Manager.AsteriskVersion.ASTERISK_10;
}
else if (version.StartsWith("11."))
{
Common.SET_VAR_DELIMITER(this.hostname, new char[] { ',' });
return Manager.AsteriskVersion.ASTERISK_11;
}
else if (version.StartsWith("12."))
{
Common.SET_VAR_DELIMITER(this.hostname, new char[] { ',' });
return Manager.AsteriskVersion.ASTERISK_12;
}
else if (version.StartsWith("13."))
{
Common.SET_VAR_DELIMITER(this.hostname, new char[] { ',' });
return Manager.AsteriskVersion.ASTERISK_13;
}
else
throw new ManagerException("Unknown Asterisk version " + version);
}

View file

@ -141,22 +141,6 @@ namespace AsterNET.Manager
#endregion
#region Variable
/// <summary>
/// Get/Set the variables to set on the originated call.<br />
/// Variable assignments are of the form "VARNAME=VALUE". You can specify
/// multiple variable assignments separated by the '|' character.<br />
/// Example: "VAR1=abc|VAR2=def" sets the channel variables VAR1 to "abc" and VAR2 to "def".
/// </summary>
public string Variable
{
get { return Helper.JoinVariables(variables, Common.VAR_DELIMITER, "="); }
set { variables = Helper.ParseVariables(variables, value, Common.VAR_DELIMITER); }
}
#endregion
#region GetVariables()
/// <summary>