Move VAR_DELIMITER from Common to ManagerConnection

Setup Interface for ManagerConnection to do the variable joining instead of doing it in the Action classes
This commit is contained in:
Justin 2015-04-02 10:23:08 -07:00
parent 2f04804a48
commit f179276c91
6 changed files with 46 additions and 38 deletions

View file

@ -251,6 +251,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

@ -26,25 +26,8 @@ namespace AsterNET
public static char[] MINUS_SEPARATOR = {'-'};
public static char INTERNAL_ACTION_ID_DELIMITER = '#';
/// <summary> Variables delimiter </summary>
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 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);

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.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

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,10 +18,11 @@ 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>
[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
@ -29,13 +30,13 @@ namespace AsterNET.Manager.Event
/// <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)
#region SetVariables(Dictionary<string, string> vars)
/// <summary>
/// Set the variables dictionary to set on the originated call.
/// </summary>

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>
@ -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();
}