AsterNET
AsterNET copied to clipboard
Reload asterisk after saving extenstion into the asterisk database.
I am developing a web application using ASP.NET MVC. I wrote add functionality in my application to add extension details into asterisk database using asterisk realtime database configuration. But after saving extension details to asterisk database, it needs reload. So how can I reload remotely located asterisk server from my application? For example: we can use asterisk -rx "reload" shell command. I wrote following code to achieve same functionality from my code:
private static ManagerConnection manager;
const int ASTERISK_PORT = 5038;
const string ASTERISK_HOST = "192.168.13.36";
const string ASTERISK_LOGINNAME = "admin";
const string ASTERISK_LOGINPWD = "amp111";
public static void ApplyConfigOnAsterisk() {
manager = new ManagerConnection(ASTERISK_HOST, ASTERISK_PORT, ASTERISK_LOGINNAME, ASTERISK_LOGINPWD);
try
{
manager.Login();
}
catch (Exception ex)
{
Console.WriteLine("Error connect\n" + ex.Message);
manager.Logoff();
}
{
Console.WriteLine("\nUpdateConfig action");
UpdateConfigAction config = new UpdateConfigAction("asterisk.conf", "asterisk.conf", true);
ManagerResponse response = manager.SendAction(config);
}
}
But this code is not working as needed.
When you say not working, are you getting an error or is it simply nothing is happening.
Supplying log output from the console would be helpful, or copies of any exceptions thrown.
Cheers
Could you maybe be looking for the Reload action? It looks like it isn't implemented in AsterNET right now.
See: https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+ManagerAction_Reload
You can try:
CommandAction commandAction = new CommandAction("core reload");
CommandResponse commandResponse = (CommandResponse)_ami.SendAction(commandAction, 0);
return commandResponse.ToString();
Not sure it will work, but maybe.
If nothing else, the Reload action shouldn't be hard to implement.