Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using JulMar.Atapi;
- namespace TAPI20
- {
- public partial class Form1 : Form
- {
- private string lineName = string.Empty;
- private string name = "";
- TapiManager myTAPI;
- public Form1()
- {
- InitializeComponent();
- initTAPI();
- }
- void initTAPI()
- {
- myTAPI = new TapiManager("GetCaller");
- if (!myTAPI.Initialize())
- {
- MessageBox.Show("FAILED!");
- }else
- {
- name = myTAPI.Lines[0].Name;
- lineName = (myTAPI != null && myTAPI.Lines.Length > 0 ? name : string.Empty);
- foreach(TapiLine line in myTAPI.Lines)
- {
- line.NewCall += this.OnNewCall;
- line.Ringing += this.OnRinging;
- line.CallStateChanged += this.OnCallState;
- line.CallInfoChanged += this.OnCallInfo;
- }
- MessageBox.Show(lineName);
- }
- }
- private void OnNewCall(object sender, NewCallEventArgs e)
- {
- if(InvokeRequired == true)
- {
- this.BeginInvoke(new EventHandler<NewCallEventArgs>(this.OnNewCall), new object[] { sender, e });
- return;
- }
- label1.Text = "Dialing...";
- }
- private void OnRinging(object sender, RingEventArgs e)
- {
- if (InvokeRequired == true)
- {
- this.BeginInvoke(new EventHandler<RingEventArgs>(this.OnRinging), new object[] { sender, e });
- return;
- }
- label1.Text = "Ringing...";
- }
- private void OnCallState(object sender, CallStateEventArgs e)
- {
- if (InvokeRequired == true)
- {
- this.BeginInvoke(new EventHandler<CallStateEventArgs>(this.OnCallState), new object[] { sender, e });
- return;
- }
- label1.Text = "Outgoing Call...";
- }
- private void OnCallInfo(object sender, CallInfoChangeEventArgs e)
- {
- if (InvokeRequired == true)
- {
- this.BeginInvoke(new EventHandler<CallInfoChangeEventArgs>(this.OnCallInfo), new object[] { sender, e });
- return;
- }
- label1.Text = "Incoming Call...";
- }
- private void MakePhoneCall(string phoneNumber)
- {
- TapiLine line = myTAPI.GetLineByName(this.lineName, true);
- if (line != null)
- {
- if (!line.IsOpen)
- line.Open(MediaModes.All);
- line.NewCall += new EventHandler<NewCallEventArgs>(line_NewCall);
- line.CallInfoChanged += new EventHandler<CallInfoChangeEventArgs>(line_CallInfoChanged);
- line.CallStateChanged += new EventHandler<CallStateEventArgs>(line_CallStateChanged);
- if (phoneNumber.Length > 0)
- {
- MakeCallParams makeCallParams = new MakeCallParams();
- makeCallParams.DialPause = 2000;
- try
- {
- TapiCall call = line.MakeCall(phoneNumber, null, makeCallParams);
- MessageBox.Show("Created call " + phoneNumber + " -> " + call, "Sendingβ¦");
- }
- catch (Exception exc)
- {
- if (exc.Message.IndexOf("[0x80000005]") > -1 && myTAPI != null)
- {
- myTAPI.Shutdown();
- myTAPI = new TapiManager("GetCaller");
- if (myTAPI.Initialize())
- this.MakePhoneCall(phoneNumber);
- }
- }
- }
- }
- }
- private void line_NewCall(object sender, NewCallEventArgs e)
- {
- MessageBox.Show("New call: " + e.Call, e.Privilege.ToString());
- }
- private void line_CallStateChanged(object sender, CallStateEventArgs e)
- {
- MessageBox.Show("CallState: " + e.Call.ToString(), e.CallState.ToString());
- }
- private void line_CallInfoChanged(object sender, CallInfoChangeEventArgs e)
- {
- MessageBox.Show("CallInfo: " + e.Call.ToString(), e.Change.ToString());
- }
- private void button1_Click(object sender, EventArgs e)
- {
- MakePhoneCall("123456789");
- }
- private void Form1_FormClosed(object sender, FormClosedEventArgs e)
- {
- myTAPI.Shutdown();
- Application.ExitThread();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement