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:
parent
2f04804a48
commit
f179276c91
|
@ -251,6 +251,7 @@
|
||||||
<Compile Include="Manager\Event\QueueCallerAbandonEvent.cs" />
|
<Compile Include="Manager\Event\QueueCallerAbandonEvent.cs" />
|
||||||
<Compile Include="Manager\Event\MasqueradeEvent.cs" />
|
<Compile Include="Manager\Event\MasqueradeEvent.cs" />
|
||||||
<Compile Include="Manager\Exceptions\AuthenticationFailedException.cs" />
|
<Compile Include="Manager\Exceptions\AuthenticationFailedException.cs" />
|
||||||
|
<Compile Include="Manager\IActionVariable.cs" />
|
||||||
<Compile Include="Manager\Response\GetConfigResponse.cs" />
|
<Compile Include="Manager\Response\GetConfigResponse.cs" />
|
||||||
<Compile Include="Manager\Response\OriginateResponse.cs" />
|
<Compile Include="Manager\Response\OriginateResponse.cs" />
|
||||||
<Compile Include="Manager\ManagerConnection.cs" />
|
<Compile Include="Manager\ManagerConnection.cs" />
|
||||||
|
|
|
@ -26,25 +26,8 @@ namespace AsterNET
|
||||||
public static char[] MINUS_SEPARATOR = {'-'};
|
public static char[] MINUS_SEPARATOR = {'-'};
|
||||||
public static char INTERNAL_ACTION_ID_DELIMITER = '#';
|
public static char INTERNAL_ACTION_ID_DELIMITER = '#';
|
||||||
|
|
||||||
/// <summary> Variables delimiter </summary>
|
[Obsolete("VAR_DELIMITER moved to ManagerConnection", true)]
|
||||||
public static Dictionary<string, char[]> VAR_DELIMITERS = new Dictionary<string, char[]>();
|
public static char[] VAR_DELIMITER = {'|'};
|
||||||
|
|
||||||
/// <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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IFormatProvider CultureInfoEn = new CultureInfo("en-US", false);
|
public static IFormatProvider CultureInfoEn = new CultureInfo("en-US", false);
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace AsterNET.Manager.Action
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <seealso cref="AsterNET.Manager.Event.OriginateSuccessEvent" />
|
/// <seealso cref="AsterNET.Manager.Event.OriginateSuccessEvent" />
|
||||||
/// <seealso cref="AsterNET.Manager.Event.OriginateFailureEvent" />
|
/// <seealso cref="AsterNET.Manager.Event.OriginateFailureEvent" />
|
||||||
public class OriginateAction : ManagerActionEvent
|
public class OriginateAction : ManagerActionEvent, IActionVariable
|
||||||
{
|
{
|
||||||
private Dictionary<string, string> variables;
|
private Dictionary<string, string> variables;
|
||||||
|
|
||||||
|
@ -158,10 +158,12 @@ namespace AsterNET.Manager.Action
|
||||||
/// multiple variable assignments separated by the '|' character.<br />
|
/// multiple variable assignments separated by the '|' character.<br />
|
||||||
/// Example: "VAR1=abc|VAR2=def" sets the channel variables VAR1 to "abc" and VAR2 to "def".
|
/// Example: "VAR1=abc|VAR2=def" sets the channel variables VAR1 to "abc" and VAR2 to "def".
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
|
[Obsolete("Don't use this anymore - the delimiter is not server context aware", true)]
|
||||||
public string Variable
|
public string Variable
|
||||||
{
|
{
|
||||||
get { return Helper.JoinVariables(variables, 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)); }
|
set { /* variables = Helper.ParseVariables(variables, value, Common.GET_VAR_DELIMITER(this.Server)); */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -5,7 +5,7 @@ using System.Collections;
|
||||||
|
|
||||||
namespace AsterNET.Manager.Event
|
namespace AsterNET.Manager.Event
|
||||||
{
|
{
|
||||||
public abstract class AbstractAgentVariables : ManagerEvent
|
public abstract class AbstractAgentVariables : ManagerEvent, IActionVariable
|
||||||
{
|
{
|
||||||
private Dictionary<string, string> variables;
|
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/>
|
/// Get/Set the variables to set on the queue call in native asterisk format.<br/>
|
||||||
/// Example: "VAR1=abc|VAR2=def".
|
/// Example: "VAR1=abc|VAR2=def".
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Variable
|
[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
|
#endregion
|
||||||
|
|
||||||
#region GetVariables()
|
#region GetVariables()
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the variables dictionary to set on the originated call.
|
/// Get the variables dictionary to set on the originated call.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IDictionary GetVariables()
|
public Dictionary<string, string> GetVariables()
|
||||||
{
|
{
|
||||||
return variables;
|
return variables;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region SetVariables(IDictionary vars)
|
#region SetVariables(Dictionary<string, string> vars)
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set the variables dictionary to set on the originated call.
|
/// Set the variables dictionary to set on the originated call.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SetVariables(Dictionary<string, string> vars)
|
public void SetVariables(Dictionary<string, string> vars)
|
||||||
|
|
13
Asterisk.2013/Asterisk.NET/Manager/IActionVariable.cs
Normal file
13
Asterisk.2013/Asterisk.NET/Manager/IActionVariable.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -157,6 +157,8 @@ namespace AsterNET.Manager
|
||||||
/// <summary> Default Slow Reconnect interval in milliseconds.</summary>
|
/// <summary> Default Slow Reconnect interval in milliseconds.</summary>
|
||||||
private int reconnectIntervalMax = 10000;
|
private int reconnectIntervalMax = 10000;
|
||||||
|
|
||||||
|
public char[] VAR_DELIMITER = { '|' };
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1508,37 +1510,37 @@ namespace AsterNET.Manager
|
||||||
version = m.Groups[1].Value;
|
version = m.Groups[1].Value;
|
||||||
if (version.StartsWith("1.4."))
|
if (version.StartsWith("1.4."))
|
||||||
{
|
{
|
||||||
Common.SET_VAR_DELIMITER(this.hostname, new char[] { '|' });
|
VAR_DELIMITER = new char[] { '|' };
|
||||||
return AsteriskVersion.ASTERISK_1_4;
|
return AsteriskVersion.ASTERISK_1_4;
|
||||||
}
|
}
|
||||||
else if (version.StartsWith("1.6."))
|
else if (version.StartsWith("1.6."))
|
||||||
{
|
{
|
||||||
Common.SET_VAR_DELIMITER(this.hostname, new char[] { '|' });
|
VAR_DELIMITER = new char[] { '|' };
|
||||||
return Manager.AsteriskVersion.ASTERISK_1_6;
|
return Manager.AsteriskVersion.ASTERISK_1_6;
|
||||||
}
|
}
|
||||||
else if (version.StartsWith("1.8."))
|
else if (version.StartsWith("1.8."))
|
||||||
{
|
{
|
||||||
Common.SET_VAR_DELIMITER(this.hostname, new char[] { '|' });
|
VAR_DELIMITER = new char[] { '|' };
|
||||||
return Manager.AsteriskVersion.ASTERISK_1_8;
|
return Manager.AsteriskVersion.ASTERISK_1_8;
|
||||||
}
|
}
|
||||||
else if (version.StartsWith("10."))
|
else if (version.StartsWith("10."))
|
||||||
{
|
{
|
||||||
Common.SET_VAR_DELIMITER(this.hostname, new char[] { '|' });
|
VAR_DELIMITER = new char[] { '|' };
|
||||||
return Manager.AsteriskVersion.ASTERISK_10;
|
return Manager.AsteriskVersion.ASTERISK_10;
|
||||||
}
|
}
|
||||||
else if (version.StartsWith("11."))
|
else if (version.StartsWith("11."))
|
||||||
{
|
{
|
||||||
Common.SET_VAR_DELIMITER(this.hostname, new char[] { ',' });
|
VAR_DELIMITER = new char[] { ',' };
|
||||||
return Manager.AsteriskVersion.ASTERISK_11;
|
return Manager.AsteriskVersion.ASTERISK_11;
|
||||||
}
|
}
|
||||||
else if (version.StartsWith("12."))
|
else if (version.StartsWith("12."))
|
||||||
{
|
{
|
||||||
Common.SET_VAR_DELIMITER(this.hostname, new char[] { ',' });
|
VAR_DELIMITER = new char[] { ',' };
|
||||||
return Manager.AsteriskVersion.ASTERISK_12;
|
return Manager.AsteriskVersion.ASTERISK_12;
|
||||||
}
|
}
|
||||||
else if (version.StartsWith("13."))
|
else if (version.StartsWith("13."))
|
||||||
{
|
{
|
||||||
Common.SET_VAR_DELIMITER(this.hostname, new char[] { ',' });
|
VAR_DELIMITER = new char[] { ',' };
|
||||||
return Manager.AsteriskVersion.ASTERISK_13;
|
return Manager.AsteriskVersion.ASTERISK_13;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2159,6 +2161,12 @@ namespace AsterNET.Manager
|
||||||
sb.Append(string.Concat(name, ": ", valueAsString, Common.LINE_SEPARATOR));
|
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);
|
sb.Append(Common.LINE_SEPARATOR);
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue