From ac993790be8a543ae37a166d688c3cbc5899fa3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BD=D0=B8=D1=81=20=D0=95=D0=B2=D0=B3=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9?= Date: Fri, 26 Apr 2019 19:44:36 +0700 Subject: [PATCH] - ReloadEvent fix - OriginateAction improve - UpdateCOnfigAction improve - ModuleLoadAction - ReloadAction --- .../Manager/Action/ModuleLoadAction.cs | 33 +++++++++++++++++++ .../Manager/Action/OriginateAction.cs | 9 +++++ .../Manager/Action/ReloadAction.cs | 26 +++++++++++++++ .../Manager/Action/UpdateConfigAction.cs | 21 ++++++++---- .../Asterisk.NET/Manager/ManagerConnection.cs | 11 +++++-- 5 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 Asterisk.2013/Asterisk.NET/Manager/Action/ModuleLoadAction.cs create mode 100644 Asterisk.2013/Asterisk.NET/Manager/Action/ReloadAction.cs diff --git a/Asterisk.2013/Asterisk.NET/Manager/Action/ModuleLoadAction.cs b/Asterisk.2013/Asterisk.NET/Manager/Action/ModuleLoadAction.cs new file mode 100644 index 0000000..8e63ed5 --- /dev/null +++ b/Asterisk.2013/Asterisk.NET/Manager/Action/ModuleLoadAction.cs @@ -0,0 +1,33 @@ +namespace AsterNET.Manager.Action +{ + /// + /// + /// The ModuleLoadAction loads/unloads Asterisk modules. + /// + public class ModuleLoadAction : ManagerAction + { + /// + /// Creates ModuleLoadAction for given module. + /// + //// module to load/unload. + //// loadType parameter can have the following values: load/unload + public ModuleLoadAction(string module, string loadType) + { + Module = module; + LoadType = loadType; + } + + /// + public override string Action => "ModuleLoad"; + + /// + /// Get the name of the module. + /// + public string Module { get; } + + /// + /// Get the type of action (load/unload). + /// + public string LoadType { get; } + } +} \ No newline at end of file diff --git a/Asterisk.2013/Asterisk.NET/Manager/Action/OriginateAction.cs b/Asterisk.2013/Asterisk.NET/Manager/Action/OriginateAction.cs index 0dd5469..a7ca8ee 100644 --- a/Asterisk.2013/Asterisk.NET/Manager/Action/OriginateAction.cs +++ b/Asterisk.2013/Asterisk.NET/Manager/Action/OriginateAction.cs @@ -67,6 +67,15 @@ namespace AsterNET.Manager.Action #endregion + #region ChannelId + + /// + /// Get/Set originated channel id + /// + public string ChannelId { get; set; } + + #endregion + #region Context /// diff --git a/Asterisk.2013/Asterisk.NET/Manager/Action/ReloadAction.cs b/Asterisk.2013/Asterisk.NET/Manager/Action/ReloadAction.cs new file mode 100644 index 0000000..5e27cab --- /dev/null +++ b/Asterisk.2013/Asterisk.NET/Manager/Action/ReloadAction.cs @@ -0,0 +1,26 @@ +namespace AsterNET.Manager.Action +{ + /// + /// + /// The ReloadAction reloads Asterisk modules. + /// + public class ReloadAction : ManagerAction + { + /// + /// Creates ReloadAction for given module. + /// + //// module to reload. + public ReloadAction(string module) + { + Module = module; + } + + /// + public override string Action => "Reload"; + + /// + /// Get the name of the module. + /// + public string Module { get; } + } +} \ No newline at end of file diff --git a/Asterisk.2013/Asterisk.NET/Manager/Action/UpdateConfigAction.cs b/Asterisk.2013/Asterisk.NET/Manager/Action/UpdateConfigAction.cs index e946169..f3b7526 100644 --- a/Asterisk.2013/Asterisk.NET/Manager/Action/UpdateConfigAction.cs +++ b/Asterisk.2013/Asterisk.NET/Manager/Action/UpdateConfigAction.cs @@ -114,7 +114,8 @@ namespace AsterNET.Manager.Action /// Variable to work on /// Value to work on /// Extra match required to match line - public void AddCommand(string action, string category, string variable, string value, string match) + /// Extra match required to match line + public void AddCommand(string action, string category, string variable, string value, string match, string options) { var i = actionCounter++; var index = i.ToString().PadLeft(6, '0'); @@ -133,31 +134,39 @@ namespace AsterNET.Manager.Action if (!string.IsNullOrEmpty(match)) actions.Add("Match-" + index, match); + + if (!string.IsNullOrEmpty(options)) + Actions.Add("Options-" + index, options); + } + + public void AddCommand(string action, string category, string variable, string value, string match) + { + AddCommand(action, category, variable, value, match, null); } public void AddCommand(string action, string category, string variable, string value) { - AddCommand(action, category, variable, value, null); + AddCommand(action, category, variable, value, null, null); } public void AddCommand(string action, string category, string variable) { - AddCommand(action, category, variable, null, null); + AddCommand(action, category, variable, null, null, null); } public void AddCommand(string action, string category) { - AddCommand(action, category, null, null, null); + AddCommand(action, category, null, null, null, null); } public void AddCommand(string action) { - AddCommand(action, null, null, null, null); + AddCommand(action, null, null, null, null, null); } public void AddCommand() { - AddCommand(null, null, null, null, null); + AddCommand(null, null, null, null, null, null); } #endregion diff --git a/Asterisk.2013/Asterisk.NET/Manager/ManagerConnection.cs b/Asterisk.2013/Asterisk.NET/Manager/ManagerConnection.cs index fda032d..49d2302 100644 --- a/Asterisk.2013/Asterisk.NET/Manager/ManagerConnection.cs +++ b/Asterisk.2013/Asterisk.NET/Manager/ManagerConnection.cs @@ -362,10 +362,15 @@ namespace AsterNET.Manager /// public event EventHandler ZapShowChannels; /// - /// A ConnectionState is triggered after Connect/Disconnect/Reload/Shutdown events. + /// A ConnectionState is triggered after Connect/Disconnect/Shutdown events. /// public event EventHandler ConnectionState; + /// + /// A Reload is triggered after Reload events. + /// + public event EventHandler Reload; + /// /// When a variable is set /// @@ -573,7 +578,7 @@ namespace AsterNET.Manager Helper.RegisterEventHandler(registeredEventHandlers, typeof(ConnectEvent), arg => fireEvent(ConnectionState, arg)); Helper.RegisterEventHandler(registeredEventHandlers, typeof(DisconnectEvent), arg => fireEvent(ConnectionState, arg)); - Helper.RegisterEventHandler(registeredEventHandlers, typeof(ReloadEvent), arg => fireEvent(ConnectionState, arg)); + Helper.RegisterEventHandler(registeredEventHandlers, typeof(ReloadEvent), arg => fireEvent(Reload, arg)); Helper.RegisterEventHandler(registeredEventHandlers, typeof(ShutdownEvent), arg => fireEvent(ConnectionState, arg)); Helper.RegisterEventHandler(registeredEventHandlers, typeof(BridgeEvent), arg => fireEvent(Bridge, arg)); @@ -1981,7 +1986,7 @@ namespace AsterNET.Manager fireEvent(e); reconnect(false); } - else if (!reconnected && reconnectEnable && (e is DisconnectEvent || e is ReloadEvent || e is ShutdownEvent)) + else if (!reconnected && reconnectEnable && (e is DisconnectEvent || e is ShutdownEvent)) { ((ConnectionStateEvent)e).Reconnect = true; fireEvent(e);