asternet/Asterisk.2013/Asterisk.NET.WinForm/FormMain.cs
zsender d1bb4249b8 fix subscribe event (for better code readability)
addcomment to method fireEvent
2017-04-06 09:25:48 +03:00

65 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AsterNET.Manager;
using AsterNET.Manager.Event;
using System.Diagnostics;
namespace AsterNET.WinForm
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
private ManagerConnection manager = null;
private void btnConnect_Click(object sender, EventArgs e)
{
string address = this.tbAddress.Text;
int port = int.Parse(this.tbPort.Text);
string user = this.tbUser.Text;
string password = this.tbPassword.Text;
btnConnect.Enabled = false;
manager = new ManagerConnection(address, port, user, password);
manager.UnhandledEvent += new EventHandler<ManagerEvent>(manager_Events);
try
{
// Uncomment next 2 line comments to Disable timeout (debug mode)
// manager.DefaultResponseTimeout = 0;
// manager.DefaultEventTimeout = 0;
manager.Login();
}
catch(Exception ex)
{
MessageBox.Show("Error connect\n" + ex.Message);
manager.Logoff();
this.Close();
}
btnDisconnect.Enabled = true;
}
void manager_Events(object sender, ManagerEvent e)
{
Debug.WriteLine("Event : " + e.GetType().Name);
}
private void btnDisconnect_Click(object sender, EventArgs e)
{
btnConnect.Enabled = true;
if (this.manager != null)
{
manager.Logoff();
this.manager = null;
}
btnDisconnect.Enabled = false;
}
}
}