Advertisement
Guest User

AGI AsterNET

a guest
May 20th, 2014
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.47 KB | None | 0 0
  1. //Program.cs
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Windows.Forms;
  6. using AsterNET.FastAGI;
  7. using AsterNET.FastAGI.MappingStrategies;
  8. using System.Threading;
  9.  
  10. namespace test_calls
  11. {
  12.     static class Program
  13.     {
  14.         /// <summary>
  15.         /// Главная точка входа для приложения.
  16.         /// </summary>
  17.         [STAThread]
  18.         static void Main()
  19.         {
  20.  
  21.             Thread test =  new Thread(qwe);
  22.             test.Start();
  23.             Application.EnableVisualStyles();
  24.             Application.SetCompatibleTextRenderingDefault(false);
  25.             Application.Run(new Form1());
  26.         }
  27.         static void qwe()
  28.         {
  29.             AsteriskFastAGI agiServer = new AsteriskFastAGI();
  30.             agiServer.MappingStrategy = new GeneralMappingStrategy(
  31.                 new List<ScriptMapping>()
  32.                 {
  33.                     new ScriptMapping() {
  34.                         ScriptName = "redialer",
  35.                         ScriptClass = "test_calls.ReDialerAGI"
  36.                     }
  37.                 });
  38.             agiServer.Start();
  39.         }
  40.     }
  41. }
  42.  
  43. //ReDialerAGI.cs
  44. using System;
  45. using System.Collections.Generic;
  46. using System.Linq;
  47. using System.Text;
  48. using AsterNET.FastAGI;
  49.  
  50. namespace test_calls
  51. {
  52.     public class ReDialerAGI : AGIScript
  53.     {
  54.         public override void Service(AGIRequest param1, AGIChannel param2)
  55.         {
  56.             //some actions?
  57.             Answer();
  58.         }
  59.     }
  60. }
  61.  
  62. //Form1.cs
  63. using System;
  64. using System.Collections.Generic;
  65. using System.ComponentModel;
  66. using System.Data;
  67. using System.Drawing;
  68. using System.Linq;
  69. using System.Text;
  70. using System.Windows.Forms;
  71. using AsterNET.Manager.Event;
  72. using AsterNET.Manager;
  73. using AsterNET.FastAGI;
  74.  
  75. namespace test_calls
  76. {
  77.     public partial class Form1 : Form
  78.     {
  79.         public static ManagerConnection manager;
  80.         public static NewStateEvent info;
  81.         public Form1()
  82.         {
  83.             InitializeComponent();
  84.         }
  85.  
  86.         private void button1_Click(object sender, EventArgs e)
  87.         {
  88.             string user = "user1";
  89.             string password = "GhjcnjNFR456";
  90.             string adress = "194.34.182.35";
  91.             manager = new ManagerConnection(adress, 5038, user, password);
  92.            manager.NewState += new NewStateEventHandler(manager_Events);
  93.            try
  94.            {
  95.                this.Cursor = Cursors.WaitCursor;
  96.                manager.Login();
  97.            }
  98.            catch (Exception ex)
  99.            {
  100.                MessageBox.Show("Error!");
  101.            }
  102.            this.Cursor = Cursors.Default;
  103.  
  104.         }
  105.         public static void manager_Events(object sender, ManagerEvent e)
  106.         {
  107.             info = (NewStateEvent)e;
  108.             //Answered call
  109.             if (info.ChannelState == "6")
  110.             {
  111.                 // MessageBox.Show("Dispatcher" + Global.info.CallerIdName + " has received a call " + e.Attributes["connectedlinename"]);
  112.             }
  113.             if (info.ChannelState == "4")
  114.             {
  115.                 test();
  116.             }
  117.             //  else
  118.             //    MessageBox.Show(info.ChannelStateDesc);
  119.         }
  120.         public static void test()
  121.         {
  122.         button2.Visible=true;    
  123.     MessageBox.Show("Someone is ringing!");
  124.         }
  125.  
  126.         private void button2_Click(object sender, EventArgs e)
  127.         {
  128.             //Answer();      ????????
  129.         }
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement