Merge pull request #12 from justinkillen/master

Update variable delimiter handling to be per host/asterisk version
This commit is contained in:
Ben Merrills 2015-04-07 20:17:37 +01:00
commit 416acc90f8
7 changed files with 74 additions and 43 deletions

View file

@ -260,6 +260,7 @@
<Compile Include="Manager\Event\QueueCallerAbandonEvent.cs" />
<Compile Include="Manager\Event\MasqueradeEvent.cs" />
<Compile Include="Manager\Exceptions\AuthenticationFailedException.cs" />
<Compile Include="Manager\IActionVariable.cs" />
<Compile Include="Manager\Response\GetConfigResponse.cs" />
<Compile Include="Manager\Response\OriginateResponse.cs" />
<Compile Include="Manager\ManagerConnection.cs" />

View file

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
@ -25,7 +26,7 @@ namespace AsterNET
public static char[] MINUS_SEPARATOR = {'-'};
public static char INTERNAL_ACTION_ID_DELIMITER = '#';
/// <summary> Variables delimiter </summary>
[Obsolete("VAR_DELIMITER moved to ManagerConnection", true)]
public static char[] VAR_DELIMITER = {'|'};
public static IFormatProvider CultureInfoEn = new CultureInfo("en-US", false);

View file

@ -22,7 +22,7 @@ namespace AsterNET.Manager.Action
/// </summary>
/// <seealso cref="AsterNET.Manager.Event.OriginateSuccessEvent" />
/// <seealso cref="AsterNET.Manager.Event.OriginateFailureEvent" />
public class OriginateAction : ManagerActionEvent
public class OriginateAction : ManagerActionEvent, IActionVariable
{
private Dictionary<string, string> variables;
@ -158,10 +158,12 @@ namespace AsterNET.Manager.Action
/// 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>
[Obsolete("Don't use this anymore - the delimiter is not server context aware", true)]
public string Variable
{
get { return Helper.JoinVariables(variables, Common.VAR_DELIMITER, "="); }
set { variables = Helper.ParseVariables(variables, value, Common.VAR_DELIMITER); }
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

View file

@ -5,7 +5,7 @@ using System.Collections;
namespace AsterNET.Manager.Event
{
public abstract class AbstractAgentVariables : ManagerEvent
public abstract class AbstractAgentVariables : ManagerEvent, IActionVariable
{
private Dictionary<string, string> variables;
@ -18,25 +18,26 @@ namespace AsterNET.Manager.Event
/// Get/Set the variables to set on the queue call in native asterisk format.<br/>
/// Example: "VAR1=abc|VAR2=def".
/// </summary>
public string Variable
{
get { return Helper.JoinVariables(variables, Common.VAR_DELIMITER, "="); }
set { variables = Helper.ParseVariables(variables, value, Common.VAR_DELIMITER); }
}
[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()
/// <summary>
/// Get the variables dictionary to set on the originated call.
/// </summary>
public IDictionary GetVariables()
public Dictionary<string, string> GetVariables()
{
return variables;
}
#endregion
#region SetVariables(IDictionary vars)
/// <summary>
#region SetVariables(Dictionary<string, string> vars)
/// <summary>
/// Set the variables dictionary to set on the originated call.
/// </summary>
public void SetVariables(Dictionary<string, string> vars)

View file

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AsterNET.Manager
{
interface IActionVariable
{
Dictionary<string, string> GetVariables();
void SetVariables(Dictionary<string, string> vars);
}
}

View file

@ -157,6 +157,8 @@ namespace AsterNET.Manager
/// <summary> Default Slow Reconnect interval in milliseconds.</summary>
private int reconnectIntervalMax = 10000;
public char[] VAR_DELIMITER = { '|' };
#endregion
/// <summary>
@ -1506,22 +1508,43 @@ namespace AsterNET.Manager
if (m.Groups.Count >= 2)
{
version = m.Groups[1].Value;
if (version.StartsWith("1.4."))
return AsteriskVersion.ASTERISK_1_4;
else if (version.StartsWith("1.6."))
return Manager.AsteriskVersion.ASTERISK_1_6;
else if (version.StartsWith("1.8."))
return Manager.AsteriskVersion.ASTERISK_1_8;
else if (version.StartsWith("10."))
return Manager.AsteriskVersion.ASTERISK_10;
else if (version.StartsWith("11."))
return Manager.AsteriskVersion.ASTERISK_11;
else if (version.StartsWith("12."))
return Manager.AsteriskVersion.ASTERISK_12;
if (version.StartsWith("1.4."))
{
VAR_DELIMITER = new char[] { '|' };
return AsteriskVersion.ASTERISK_1_4;
}
else if (version.StartsWith("1.6."))
{
VAR_DELIMITER = new char[] { '|' };
return Manager.AsteriskVersion.ASTERISK_1_6;
}
else if (version.StartsWith("1.8."))
{
VAR_DELIMITER = new char[] { '|' };
return Manager.AsteriskVersion.ASTERISK_1_8;
}
else if (version.StartsWith("10."))
{
VAR_DELIMITER = new char[] { '|' };
return Manager.AsteriskVersion.ASTERISK_10;
}
else if (version.StartsWith("11."))
{
VAR_DELIMITER = new char[] { ',' };
return Manager.AsteriskVersion.ASTERISK_11;
}
else if (version.StartsWith("12."))
{
VAR_DELIMITER = new char[] { ',' };
return Manager.AsteriskVersion.ASTERISK_12;
}
else if (version.StartsWith("13."))
{
VAR_DELIMITER = new char[] { ',' };
return Manager.AsteriskVersion.ASTERISK_13;
else
throw new ManagerException("Unknown Asterisk version " + version);
}
else
throw new ManagerException("Unknown Asterisk version " + version);
}
}
}
@ -2138,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();
}

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>