Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement