Skip to content

Instantly share code, notes, and snippets.

@lameventanas
Created July 4, 2019 07:12
Show Gist options
  • Save lameventanas/406cd591bb727f6aabe2cb50555623c2 to your computer and use it in GitHub Desktop.
Save lameventanas/406cd591bb727f6aabe2cb50555623c2 to your computer and use it in GitHub Desktop.
AsterNET code to reproduce issue #205
using System;
using AsterNET.Manager;
using AsterNET.Manager.Action;
using AsterNET.Manager.Response;
using AsterNET.Manager.Event;
using System.Threading;
namespace AsterNET_205
{
class Program
{
static String host = "10.6.0.1";
static int port = 5038;
static String user = "astm";
static String password = "secret";
static String myExtension = "01";
static bool quit = false;
static void Main(string[] args)
{
try
{
ManagerConnection manager = new ManagerConnection(host, port, user, password);
manager.UserEvents += new EventHandler<UserEvent>(cbUserEvent);
MyWriteLine("Connecting to " + host);
manager.Login();
MyWriteLine("Waiting for events");
while (! quit)
Thread.Sleep(50);
manager.Logoff();
} catch (Exception ex)
{
MyWriteLine("Main exception: "+ex.Message);
}
MyWriteLine("Press ENTER to exit");
Console.ReadLine();
}
static void cbUserEvent(object sender, UserEvent e)
{
try
{
MyWriteLine("Event handler received event:");
MyWriteLine(e.ToString());
ExtensionStateAction action = new ExtensionStateAction();
action.Exten = Program.myExtension;
MyWriteLine("Sending action: " + action.Action + " to " + e.Source);
ManagerResponse res = e.Source.SendAction(action);
MyWriteLine("Received response: " + res);
} catch (Exception ex)
{
MyWriteLine("Handler exception: " + ex.Message);
}
quit = true;
}
static void MyWriteLine(string msg)
{
Console.WriteLine(DateTime.Now.ToString("[H:mm:ss.fff] ") + msg);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment