Tapi3



Please help me to discoonect the call in tapi3

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using TAPI3Lib;
using System.Media;

namespace tapi_dev
{
/// <summary>
/// Summary description for Form1.
/// </summary>
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button clear;
private TAPIClass tobj;
private ITAddress[] ia = new TAPI3Lib.ITAddress[10];
private ITBasicCallControl bcc;
private callnotification cn;

private bool reject;
uint lines;
int line;
int[] registertoken = new int[10];
private System.Windows.Forms.Button answer;
private System.Windows.Forms.Button disconnect;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.Button register;
//int registertoken;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private object E_FAIL;
private delegate void addlistdelegate(string item);

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
initializetapi3();
reject = false;
MessageBox.Show("lines : " + lines, "Lines avaialble are");
//
// TODO: Add any constructor code after InitializeComponent call
//
}

static void Main()
{
Application.Run(new Form1());
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
{
tobj.Shutdown();
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}

void initializetapi3()
{
try
{
tobj = new TAPIClass();
tobj.Initialize();
IEnumAddress ea = tobj.EnumerateAddresses();
ITAddress ln;
uint arg3 = 0;
lines = 0;

cn = new callnotification();
cn.addtolist = new callnotification.listshow(this.status);
tobj.ITTAPIEventNotification_Event_Event += new TAPI3Lib.ITTAPIEventNotification_EventEventHandler(cn.Event);
tobj.EventFilter = (int)(TAPI_EVENT.TE_CALLNOTIFICATION |
TAPI_EVENT.TE_DIGITEVENT |
TAPI_EVENT.TE_PHONEEVENT |
TAPI_EVENT.TE_CALLSTATE |
TAPI_EVENT.TE_GENERATEEVENT |
TAPI_EVENT.TE_GATHERDIGITS |
TAPI_EVENT.TE_REQUEST);
for (int i = 0; i < 10; i++)
{
ea.Next(1, out ln, ref arg3);
ia[i] = ln;
if (ln != null)
{
comboBox1.Items.Add(ia[i].AddressName);
lines++;
}
else
break;
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
public void status(string str)
{
if (listBox1.InvokeRequired)
{
this.listBox1.Invoke(new addlistdelegate(this.status), str);
}
else
{
listBox1.Items.Add(str);
}
}



#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.clear = new System.Windows.Forms.Button();
this.listBox1 = new System.Windows.Forms.ListBox();
this.answer = new System.Windows.Forms.Button();
this.disconnect = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.register = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(80, 32);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(408, 21);
this.comboBox1.TabIndex = 0;
this.comboBox1.Text = "Select Line of communication";
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// label1
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.Location = new System.Drawing.Point(24, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(50, 23);
this.label1.TabIndex = 1;
this.label1.Text = "Line";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.clear);
this.groupBox1.Controls.Add(this.listBox1);
this.groupBox1.Location = new System.Drawing.Point(80, 72);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(408, 160);
this.groupBox1.TabIndex = 5;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Call status";
//
// clear
//
this.clear.Location = new System.Drawing.Point(296, 120);
this.clear.Name = "clear";
this.clear.Size = new System.Drawing.Size(75, 23);
this.clear.TabIndex = 1;
this.clear.Text = "Clear status";
this.clear.Click += new System.EventHandler(this.clear_Click);
//
// listBox1
//
this.listBox1.Location = new System.Drawing.Point(32, 24);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(344, 82);
this.listBox1.TabIndex = 0;
//
// answer
//
this.answer.Location = new System.Drawing.Point(532, 155);
this.answer.Name = "answer";
this.answer.Size = new System.Drawing.Size(75, 23);
this.answer.TabIndex = 9;
this.answer.Text = "Answer";
this.answer.Click += new System.EventHandler(this.answer_Click);
//
// disconnect
//
this.disconnect.Location = new System.Drawing.Point(532, 192);
this.disconnect.Name = "disconnect";
this.disconnect.Size = new System.Drawing.Size(75, 23);
this.disconnect.TabIndex = 11;
this.disconnect.Text = "Disconnect";
this.disconnect.Click += new System.EventHandler(this.disconnect_Click);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.checkBox2);
this.groupBox2.Location = new System.Drawing.Point(516, 72);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(104, 64);
this.groupBox2.TabIndex = 12;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Answer mode";
//
// checkBox2
//
this.checkBox2.Location = new System.Drawing.Point(16, 24);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(80, 24);
this.checkBox2.TabIndex = 0;
this.checkBox2.Text = "Reject";
this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
//
// register
//
this.register.Location = new System.Drawing.Point(520, 24);
this.register.Name = "register";
this.register.Size = new System.Drawing.Size(75, 23);
this.register.TabIndex = 17;
this.register.Text = "Register";
this.register.Click += new System.EventHandler(this.register_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(632, 326);
this.Controls.Add(this.register);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.disconnect);
this.Controls.Add(this.answer);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.comboBox1);
this.Name = "Form1";
this.Text = "tapi3_dev";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]

//FORM LOAD AT THE START
private void Form1_Load(object sender, System.EventArgs e)
{
MessageBox.Show("To recieve calls from any line you need to register on that line\n,you can do this by selecting the line ansd press the register button!", "Instruction");
}

private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
try
{
line = comboBox1.SelectedIndex;
registertoken[line] = tobj.RegisterCallNotifications(ia[line], true, true, TapiConstants.TAPIMEDIATYPE_DATAMODEM, 2);
MessageBox.Show("Registration Succeed on line " + line + "\nToken is " + registertoken[line], "Registration succeed");
}
catch (Exception ep)
{
MessageBox.Show("Token not registred on line " + line, "Registration Failed");
}
}

//CLEAR BUTTON
private void clear_Click(object sender, System.EventArgs e)
{
listBox1.Items.Clear();
}

//REGISTER BUTTON
private void register_Click(object sender, System.EventArgs e)
{
try
{
registertoken[line] = tobj.RegisterCallNotifications(ia[line], true, true, TapiConstants.TAPIMEDIATYPE_DATAMODEM, 2);
MessageBox.Show("Registration token : " + registertoken[line], "Registration Succeed for line " + line);
}
catch (Exception ein)
{
MessageBox.Show("Failed to register on line " + line, "Registration for calls");
}

}

//REJECT CHECKBOX(TICKMARK)
private void checkBox2_CheckedChanged(object sender, System.EventArgs e)
{
reject = checkBox2.Checked;
}


//ANSWER BUTTON
private void answer_Click(object sender, System.EventArgs e)
{
ITAddress i;
i = ia[line];
bool status = false;

IEnumCall ec = ia[line].EnumerateCalls();
uint arg = 0;
ITCallInfo ici;

try
{
ec.Next(1, out ici, ref arg);
ITBasicCallControl m_CallControl = (TAPI3Lib.ITBasicCallControl)ici;
// ITBasicCallControl2 callControl2 = ici as ITBasicCallControl2;
ITStreamControl isc = ici as ITStreamControl; //(TAPI3Lib.ITStreamControl)ici; //ici as ITStreamControl;//= (TAPI3Lib.ITStreamControl)ici;
ITStream ist = ici as ITStream;
ITTerminal localTerm = ici as ITTerminal;//(TAPI3Lib.ITTerminal)ici;
ITBasicCallControl2 itb2=ici as ITBasicCallControl2;

if (!reject)
{
try
{
m_CallControl.Answer();
}


// request the terminal using right media type and direction
//localTerm = callControl2.RequestTerminal(TapiConstants.CLSID_String_FilePlaybackTerminal, TapiConstants.TAPIMEDIATYPE_AUDIO, TERMINAL_DIRECTION.TD_CAPTURE);
/*
isc.CreateStream(TapiConstants.TAPIMEDIATYPE_DATAMODEM, TERMINAL_DIRECTION.TD_CAPTURE);

ist.SelectTerminal(localTerm);
ist.StartStream();


ITMediaSupport mediasupport = localTerm as ITMediaSupport;
// prepare to put the file name

ITMediaPlayback mediaPlayback = localTerm as ITMediaPlayback;

if (mediaPlayback != null)
{
try
{
// Set the filename to play
object[] fileList = { @"E:\tapi8.2\w.wav" };


mediaPlayback.PlayList = fileList;

// Select the terminal
//callControl2.SelectTerminalOnCall(localTerm);
// ist.SelectTerminal(localTerm);
ist.StartStream();

// Answer the call
m_CallControl.Answer();
//callControl2.Answer();

// Start playback.
ITMediaControl mediaControl = localTerm as ITMediaControl;
mediaControl.Start();

// Assign the terminal now terminal
// m_PlayFileTerminal = localTerm;
status = true;
}*/

catch (Exception ep)
{
MessageBox.Show("here is exception inplaying music\n\n" + ep);
//if (Log.IsErrorEnabled)
//{
// Log.ErrorFormat("Call.ReadyPlayTerminal: *** EXCEPTION*** {0}", e);
//}
}

}
//}

else
{
MessageBox.Show("All calls are rejected. Please remove 'Reject' tickmark");
m_CallControl.Disconnect(DISCONNECT_CODE.DC_REJECTED);
//ici.ReleaseUserUserInfo();
tobj.Shutdown();
initializetapi3();
registertoken[line] = tobj.RegisterCallNotifications(ia[line], true, true, TapiConstants.TAPIMEDIATYPE_DATAMODEM, 2);
MessageBox.Show("Registration token : " + registertoken[line], "Registration Succeed for line " + line);
}

}
catch (Exception exp)
{
MessageBox.Show("There may not be any calls to answer! \n\n" + exp, "TAPI3");
}
}

//DISCONNECT BUTTON
private void disconnect_Click(object sender, System.EventArgs e)
{
IEnumCall ec = ia[line].EnumerateCalls();
uint arg = 0;
ITCallInfo ici;
try
{
ec.Next(1, out ici, ref arg);
ITBasicCallControl bc = (TAPI3Lib.ITBasicCallControl)ici;
// bc.Transfer(bc, false);
bc.Disconnect(DISCONNECT_CODE.DC_REJECTED);

tobj.Shutdown();
initializetapi3();
registertoken[line] = tobj.RegisterCallNotifications(ia[line], true, true, TapiConstants.TAPIMEDIATYPE_DATAMODEM, 2);
MessageBox.Show("Registration token : " + registertoken[line], "Registration Succeed for line " + line);
}
catch (NullReferenceException exp)
{
//MessageBox.Show("No call to disconnect!\n"+exp,"TAPI3");
MessageBox.Show("No call to disconnect!\n" + exp, "no call");
}
catch (Exception ecd)
{
MessageBox.Show("Exception is \n\n" + ecd, "Another exception");

}
}
}

class callnotification : TAPI3Lib.ITTAPIEventNotification
{
public delegate void listshow(string str);
public listshow addtolist;

public void Event(TAPI3Lib.TAPI_EVENT te, object eobj)
{
switch (te)
{
case TAPI3Lib.TAPI_EVENT.TE_CALLNOTIFICATION:
addtolist("call notification event has occured");
break;
case TAPI3Lib.TAPI_EVENT.TE_DIGITEVENT:
TAPI3Lib.ITDigitDetectionEvent dd = (TAPI3Lib.ITDigitDetectionEvent)eobj;
addtolist("Dialed digit" + dd.ToString());
break;
case TAPI3Lib.TAPI_EVENT.TE_GENERATEEVENT:
TAPI3Lib.ITDigitGenerationEvent dg = (TAPI3Lib.ITDigitGenerationEvent)eobj;
MessageBox.Show("digit dialed!");
addtolist("Dialed digit" + dg.ToString());
break;
case TAPI3Lib.TAPI_EVENT.TE_PHONEEVENT:
addtolist("A phone event!");
break;
case TAPI3Lib.TAPI_EVENT.TE_GATHERDIGITS:
addtolist("Gather digit event!");
break;
case TAPI3Lib.TAPI_EVENT.TE_CALLSTATE:
TAPI3Lib.ITCallStateEvent a = (TAPI3Lib.ITCallStateEvent)eobj;
TAPI3Lib.ITCallInfo b = a.Call;
switch (b.CallState)
{
case TAPI3Lib.CALL_STATE.CS_INPROGRESS:
addtolist("dialing");
break;
case TAPI3Lib.CALL_STATE.CS_CONNECTED:
addtolist("Connected");
break;
case TAPI3Lib.CALL_STATE.CS_DISCONNECTED:
addtolist("Disconnected");
break;
case TAPI3Lib.CALL_STATE.CS_OFFERING:
addtolist("A party wants to communicate with you!");
break;
case TAPI3Lib.CALL_STATE.CS_IDLE:
addtolist("Call is created!");
break;
}
break;
}
}
}
}




.



Relevant Pages

  • Re: Send message like Yahoo Messenger??
    ... //Required by the Windows Form Designer ... private System.Windows.Forms.MainMenu mnuMain; ... private void mnuAbout_Click(object sender, System.EventArgs e) ...
    (microsoft.public.dotnet.languages.csharp)
  • Program terminated without any erre message or exception thrown.
    ... private Input.TextInput.FormInput frmInput; ... this.lblTime.Font = new System.Drawing.Font("Microsoft Sans Serif", ... private void InitializeCustomComponent() ... private void frmMenu_Load(object sender, System.EventArgs e) ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Populate an ImageList from another thread
    ... private void InitializeComponent() ... private void Form1_Load ... private void CreateImages(object dataFromOtherThread) ... public delegate void LoadBitmapProgressDelegate(int sender); ...
    (microsoft.public.dotnet.languages.csharp)
  • Related datagrid issue, end edit ect
    ... What do the different ways of ending edit (datagrid, ... private System.Windows.Forms.DataGrid dataGrid1; ... private void Form1_Load ... private void dataGrid1_Enter(object sender, System.EventArgs e) ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Comments please.
    ... private System.Windows.Forms.TextBox NameValue; ... private void Exit_Click(object sender, System.EventArgs e) ... IsOk = false; ...
    (microsoft.public.dotnet.languages.csharp)