Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. using System;
  2. using AsterNET.Manager;
  3. using AsterNET.Manager.Action;
  4. using AsterNET.Manager.Response;
  5. using AsterNET.Manager.Event;
  6. using System.Threading;
  7.  
  8. namespace AsterNET_205
  9. {
  10. class Program
  11. {
  12. static String host = "10.6.0.1";
  13. static int port = 5038;
  14. static String user = "astm";
  15. static String password = "secret";
  16. static String myExtension = "01";
  17. static bool quit = false;
  18.  
  19. static void Main(string[] args)
  20. {
  21. try
  22. {
  23. ManagerConnection manager = new ManagerConnection(host, port, user, password);
  24. manager.UserEvents += new EventHandler<UserEvent>(cbUserEvent);
  25. MyWriteLine("Connecting to " + host);
  26. manager.Login();
  27. MyWriteLine("Waiting for events");
  28. while (! quit)
  29. Thread.Sleep(50);
  30. manager.Logoff();
  31. } catch (Exception ex)
  32. {
  33. MyWriteLine("Main exception: "+ex.Message);
  34. }
  35. MyWriteLine("Press ENTER to exit");
  36. Console.ReadLine();
  37. }
  38.  
  39. static void cbUserEvent(object sender, UserEvent e)
  40. {
  41. try
  42. {
  43. MyWriteLine("Event handler received event:");
  44. MyWriteLine(e.ToString());
  45. ExtensionStateAction action = new ExtensionStateAction();
  46. action.Exten = Program.myExtension;
  47. MyWriteLine("Sending action: " + action.Action + " to " + e.Source);
  48. ManagerResponse res = e.Source.SendAction(action);
  49. MyWriteLine("Received response: " + res);
  50. } catch (Exception ex)
  51. {
  52. MyWriteLine("Handler exception: " + ex.Message);
  53. }
  54. quit = true;
  55. }
  56.  
  57. static void MyWriteLine(string msg)
  58. {
  59. Console.WriteLine(DateTime.Now.ToString("[H:mm:ss.fff] ") + msg);
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement