コード例 #1
0
        private void submitBtn_Click(object sender, EventArgs e)
        {
            try
            {
                manager = new ManagerConnection(this.AsteriskHost.Text,
                                                    int.Parse(this.AsteriskPort.Text),
                                                    this.AsteriskUsername.Text,
                                                    this.AsteriskPassword.Text);
                manager.Login();
                if (manager.IsConnected())
                {
                    controlGroup.Enabled = true;
                    credentialGroup.Enabled = false;
                    MessageBox.Show(this, String.Format("{0} was Successfuly Initiated", AsteriskHost.Text), "Asterisk Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    AsteriskLogs.Text = "***WELCOME***";

                    // Set up AMI Eventhandlers
                    manager.OriginateResponse += new OriginateResponseEventHandler(manager_OriginateResponse);
                    manager.NewChannel += new NewChannelEventHandler(manager_NewChannel);
                    manager.Hangup += new HangupEventHandler(manager_Hangup);
                    manager.ExtensionStatus += new ExtensionStatusEventHandler(manager_ExtensionStatus);

                    // Set up AMI properties
                    manager.DefaultEventTimeout = 300000;
                    manager.DefaultResponseTimeout = 300000;
                    manager.KeepAlive = true;
                    manager.KeepAliveAfterAuthenticationFailure = true;
                    manager.FireAllEvents = true;

                    data = new AsteriskData();

                    // set up user eventhandlers
                    onStartCall += new onOriginate(AsteriskForm_onOriginateAction);
                    onEndCall += new onHangup(AsteriskForm_onEndCall);
                }
                else
                    throw new Exception("Error on Asterisk login");
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, String.Format("{0} was unSuccessfuly Initiated{1}Error Message: {2}", AsteriskHost.Text, Environment.NewLine, ex.Message), "Asterisk Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #2
0
        void AsteriskForm_onOriginateAction(string channel, string exten, string callerid)
        {
            data = new AsteriskData();
            data.originate_channel = channel;
            data.originate_exten = exten;
            data.originate_callerid = callerid;

            OriginateAction oaction = originate(data);
            ManagerResponse oresponse = sendaction(oaction);
        }
コード例 #3
0
 void manager_Hangup(object sender, Asterisk.NET.Manager.Event.HangupEvent e)
 {
     switch (e.Cause)
     {
         case 16: case 17:
             // normal clearing
             data = null;
             PopulateLogs("call is ended.");
             break;
         case 19:
             // no answer
             PopulateLogs("No answer.. hanging up.");
             break;
         default:
             break;
     }
 }
コード例 #4
0
 public OriginateAction originate(AsteriskData data)
 {
     OriginateAction oaction = new OriginateAction()
     {
         ActionId = data.originate_actionid,
         // Exten: is the number you're calling
         Exten = data.originate_exten,
         // Channel
         Channel = data.originate_channel,
         // Context
         Context = ConfigurationManager.AppSettings.Get("default_context"),
         CallerId = data.originate_callerid,
         Async = true,
         Priority = 1,
         // phone ring Timeout (default timeout is 30000 = 30 secs);
         Timeout = int.Parse(ConfigurationManager.AppSettings.Get("default_timeout"))
     };
     return oaction;
 }