private void OnCallStateChanged(object sender, CallStateEventArgs e) { if (this.InvokeRequired) { EventHandler <CallStateEventArgs> eh = OnCallStateChanged; this.BeginInvoke(eh, new object[] { sender, e }); return; } TapiLine line = (TapiLine)sender; TapiCall call = e.Call; foreach (ListViewItem lvi in lvCalls.Items) { if (lvi.Tag == call) { lvi.SubItems[COLUMNS_STATE].Text = call.CallState.ToString(); if (GetActiveCall() == call) { AdjustButtonState(call); } if (call.CallState == CallState.Idle) { call.Dispose(); lvCalls.Items.Remove(lvi); } break; } } }
private void OnNewCall(object sender, NewCallEventArgs e) { if (this.InvokeRequired) { EventHandler <NewCallEventArgs> eh = OnNewCall; this.BeginInvoke(eh, new object[] { sender, e }); return; } TapiLine line = (TapiLine)sender; TapiCall call = e.Call; ListViewItem lvi = new ListViewItem(line.Name); lvi.Tag = call; lvi.SubItems.AddRange( new string[] { string.Format("0x{0:X}", call.Id), call.CallState.ToString(), string.Format("{0} {1}", call.CallerId, call.CallerName), string.Format("{0} {1}", call.CalledId, call.CalledName), }); lvCalls.Items.Add(lvi); }
internal DeviceSpecificEventArgs(TapiLine line, IntPtr p1, IntPtr p2, IntPtr p3) { Line = line; Param1 = p1; Param2 = p2; Param3 = p3; }
private void OnNewCall(object sender, NewCallEventArgs e) { if (this.InvokeRequired) { EventHandler <NewCallEventArgs> eh = OnNewCall; this.BeginInvoke(eh, new object[] { sender, e }); return; } TapiLine line = (TapiLine)sender; TapiCall call = e.Call; ListViewItem lvi = new ListViewItem(line.Name); lvi.Tag = call; lvi.SubItems.AddRange( new string[] { string.Format("0x{0:X}", call.Id), call.CallState.ToString(), string.Format("{0} {1}", call.CallerId, call.CallerName), string.Format("{0} {1}", call.CalledId, call.CalledName), }); lvCalls.Items.Add(lvi); if (call.CallerId != e.Call.Address.Address) { System.Diagnostics.Process.Start("chrome.exe", "http://obelix/deia/" + call.CallerId.ToString()); } }
public void InitTapi(bool justMe, string myLine) { try { this.Initialized = this.myTapiManager.Initialize(); if (this.Initialized) { this.Connected = true; if (justMe) { this.myLine = this.myTapiManager.GetLineByName(myLine, true); if (this.myLine != null && this.myLine.Addresses.Count() > 0) { this.myAddress = this.myLine.Addresses[0]; } this.myLine.Open(MediaModes.All); this.myLine.NewCall += line_NewCall; if (this.myLine.IsOpen) { OnLineOpened?.Invoke(this, new EventArgs()); Connected = true; } } } else { Connected = false; } } catch { } }
private void OnCallInfoChanged(object sender, CallInfoChangeEventArgs e) { if (this.InvokeRequired) { EventHandler <CallInfoChangeEventArgs> eh = OnCallInfoChanged; this.BeginInvoke(eh, new object[] { sender, e }); return; } TapiLine line = (TapiLine)sender; TapiCall call = e.Call; if ((e.Change & (CallInfoChangeTypes.CalledId | CallInfoChangeTypes.CallerId)) > 0) { foreach (ListViewItem lvi in lvCalls.Items) { if (lvi.Tag == call) { lvi.SubItems[COLUMNS_CALLER].Text = string.Format("{0} {1}", call.CallerId, call.CallerName); lvi.SubItems[COLUMNS_CALLED].Text = string.Format("{0} {1}", call.CalledId, call.CalledName); break; } } } }
private void button1_Click(object sender, EventArgs e) { if (comboBox1.SelectedItem != null) { TapiLine line = (TapiLine)comboBox1.SelectedItem; line.Config(this.Handle, null); } }
internal DeviceSpecificEventArgs(TapiCall call, IntPtr p1, IntPtr p2, IntPtr p3) { Line = call.Line; Call = call; Param1 = p1; Param2 = p2; Param3 = p3; }
internal TapiAddress(TapiLine line, int addressId) { _lineOwner = line; _addressId = addressId; _lineOwner.NewCall += HandleNewCall; GatherAddressCaps(); GatherAddressStatus(); }
public ActiveCallForm(TapiCall call) { TapiLine line = call.Line; _call = call; line.CallInfoChanged += OnCallInfoChange; line.CallStateChanged += OnCallStateChange; InitializeComponent(); }
private static void ShowCallingLocations(TapiManager mgr, TapiLine line) { foreach (CallingLocation li in mgr.LocationInformation.CallingLocations) { Console.WriteLine(li.ToString()); } mgr.LocationInformation.CurrentLocation = mgr.LocationInformation.CallingLocations[1]; Console.WriteLine("Current location: {0}", mgr.LocationInformation.CurrentLocation.Name); Console.WriteLine(line.TranslateNumber("+1 (310) 555-1212", TranslationOptions.CancelCallWaiting).DialableNumber); }
static void Main(string[] args) { TapiManager z = new TapiManager("SimpleCall"); z.Initialize(); TapiLine[] phone = z.Lines; TapiLine line = phone[16]; Console.WriteLine(line); line.Open(MediaModes.Modem); Console.WriteLine(line.Capabilities.MediaModes); }
static void RunCommTest() { TapiManager mgr = new TapiManager("EnumDevices"); mgr.Initialize(); foreach (TapiLine lineEx in mgr.Lines) { Console.WriteLine(lineEx.Name); } TapiLine line = mgr.GetLineByName("Conexant D110 MDC V.92 Modem", true); if (line != null) { line.Open(MediaModes.DataModem); TapiCall call = line.Addresses[0].MakeCall("2145551212"); Console.WriteLine(call.GetCommDevice()); try { using (FileStream fs = call.GetCommStream()) { byte[] data = ASCIIEncoding.ASCII.GetBytes("Hello"); fs.Write(data, 0, data.Length); using (StreamReader sr = new StreamReader(fs)) { Console.WriteLine(sr.ReadToEnd()); } } call.Drop(); } catch (Exception ex) { call.Drop(); while (ex != null) { Console.WriteLine("{0}", ex.ToString()); ex = ex.InnerException; } } } else { Console.WriteLine("Not found."); } Console.ReadLine(); mgr.Shutdown(); }
private static void OnNewCall(object sender, NewCallEventArgs e) { TapiLine line = (TapiLine)sender; TapiCall call = e.Call; Console.WriteLine(call.CallerId); StringBuilder sb = new StringBuilder(); sb.Append("http://127.0.0.1:15477/adresse-by-phone?msn="); sb.Append(call.CallerId); var result = new WebClient().DownloadString(sb.ToString()); Console.WriteLine(result); }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedItem != null) { TapiLine line = (TapiLine)comboBox1.SelectedItem; listBox1.DataSource = line.Addresses; // Fill in the capabilities textbox StringBuilder sb = new StringBuilder(); sb.AppendFormat("Device ID: {0}\n", line.Id); sb.AppendFormat("Negotiated Version: {0}.{1}", ((int)line.NegotiatedVersion & 0xffff0000) >> 16, (int)line.NegotiatedVersion & 0xffff); sb.Append("\n"); sb.Append(line.Capabilities.ToString("f")); sb.Replace("\n", Environment.NewLine); richTextBox1.Text = sb.ToString(); } }
/* is called when the item in the Device combobox has been changed */ public void setCurrentLine(string lineName) { if (lineCollection.Count() > 0) { TapiLine item = lineCollection.FirstOrDefault(i => i.Name == lineName); if (item != null) { if (currentLine != null) { if (currentLine.Name != lineName) { stopSession(); } } currentLine = item; currentLine.Changed += Line_Changed; currentLine.NewCall += Line_NewCall; currentLine.Ringing += Line_Ringing; App.log(String.Format("Selected TAPI line - current line is '{0}'", currentLine.Name)); addressCollection = (TapiAddress[])item.Addresses; App.Setup.Addresses.Clear(); if (addressCollection.Count() == 1) { App.log(String.Format("Selected TAPI line includes one address {0}", addressCollection[0].Address)); App.Setup.Addresses.Clear(); App.Setup.Addresses.Add(addressCollection[0].Address); // refresh Addresses combobox content setCurrentAddress(addressCollection[0].Address); } else { App.log(String.Format("Selected TAPI line includes {0}x addresses", addressCollection.Count())); App.Setup.Addresses.Clear(); foreach (var address in addressCollection) { App.Setup.Addresses.Add(address.Address); // refresh Addresses combobox content } } App.registry.write("Device", currentLine.Name); } else { App.log(String.Format("Unable to find line '{0}'", lineName)); } } }
public static void start() { // Console.ReadLine(); while (true) { // { if (_mgr.Initialize()) { // _mgr.NewCall += NewCall; // _mgr.LineChanged += LineChanged; // _mgr.CallInfoChanged += CallInfoChanged; // _mgr.CallStateChanged += CallStateChanged; TapiLine line = _mgr.GetLineByName("EXTENSION 200 Keyset", false); if (line != null) { try { // //line.Monitor(); Console.WriteLine("Line: {0} opened!", line.Name); line.NewCall += new EventHandler <NewCallEventArgs>(NewCall); ; line.Changed += new EventHandler <LineInfoChangeEventArgs>(Changed); line.CallInfoChanged += new EventHandler <CallInfoChangeEventArgs>(CallInfoChanged); line.CallStateChanged += new EventHandler <CallStateEventArgs>(CallStateChanged); line.AddressChanged += new EventHandler <AddressInfoChangeEventArgs>(AddressChanged); line.Monitor(); // line.Open(line.Capabilities.MediaModes); Console.WriteLine("Monitoring Started!"); } catch (TapiException e) { Console.WriteLine(e); throw; } _mgr.Shutdown(); } } } }
private void _btnStartStop_Click(object sender, EventArgs e) { TapiLine line = CurrentLine; if (line.IsOpen) { line.Close(); ChangeButtonStates(); } else { try { line.Open(line.Capabilities.MediaModes); } catch (TapiException) { line.Open(MediaModes.DataModem); } ChangeButtonStates(); } }
//line 2 private void button2_Click(object sender, EventArgs e) { try { objLine2 = (TapiLine)comboBox2.SelectedItem; if (objLine2 == null) { throw new NullReferenceException("LINE IS NULL"); } if (objLine2.IsOpen) { throw new ArgumentOutOfRangeException("Already Monitoring Line"); } objLine2.RingsToAnswer = 0; objLine2.Open(true, null); AddToLog("Started monitoring line " + objLine2.Name); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private int InitializeLineDevices() { var parms = new LINEINITIALIZEEXPARAMS(); parms.dwTotalSize = parms.dwNeededSize = parms.dwUsedSize = Marshal.SizeOf(parms); parms.dwOptions = NativeMethods.LINEINITIALIZEEXOPTION_USEEVENT; parms.dwCompletionKey = 0; parms.hEvent = IntPtr.Zero; int numDevices; uint hTapi; int rc = NativeMethods.lineInitializeEx(out hTapi, IntPtr.Zero, null, _appName, out numDevices, ref _lineVersion, ref parms); if (rc == NativeMethods.LINEERR_OK) { _hTapiLine = new HTLINEAPP(hTapi, true); _evtReceivedLineEvent.SafeWaitHandle = new SafeWaitHandle(parms.hEvent, false); _lineArray = new List <TapiLine>(); for (int i = 0; i < numDevices; i++) { var line = new TapiLine(this, i); line.NewCall += HandleNewCall; line.CallStateChanged += HandleCallStateChanged; line.CallInfoChanged += HandleCallInfoChanged; line.AddressChanged += HandleAddressChanged; line.Changed += HandleLineChanged; line.Ringing += HandleLineRinging; _lineArray.Add(line); } } else { numDevices = 0; } return(numDevices); }
private void ChangeButtonStates() { TapiLine line = CurrentLine; if (line.IsOpen) { _btnStartStop.Text = Properties.Resources.String_Stop; } else { _btnStartStop.Text = Properties.Resources.String_Start; } _tbNumber.Enabled = line.Status.CanMakeCall; _ckConn.Checked = line.Status.Connected; _ckLck.Checked = line.Status.Locked; _ckMwi.Checked = line.Status.MessageWaitingLampState; _ckSvc.Checked = line.Status.InService; _btnMakeCall.Enabled = (CurrentAddress != null && CurrentAddress.Status.CanMakeCall && _tbNumber.Text.Length > 0); _btnPickup.Enabled = (CurrentAddress != null && CurrentAddress.Status.CanPickupCall && _tbNumber.Text.Length > 0); _btnUnpark.Enabled = (CurrentAddress != null && CurrentAddress.Status.CanUnparkCall && _tbNumber.Text.Length > 0); btnForward.Enabled = (CurrentLine.Capabilities.SupportsForwarding && CurrentLine.IsOpen); }
private void btnDial_Click(object sender, EventArgs e) { timer1.Enabled = false; try { if (!String.IsNullOrEmpty(_internalAgentPhone)) { line = TapiApp.Lines.SingleOrDefault(q => q.Name.Contains(_internalAgentPhone)); } else if (!String.IsNullOrEmpty(comboBoxLine.Text)) { line = TapiApp.Lines.SingleOrDefault(q => q.Name.Contains(comboBoxLine.Text)); } if (line == null) { return; } if (!line.IsOpen) { line.Open(false, SimapleCallHandler); } line.DisconnectOnBusy = true; line.NoAnswerTimeout = 15; ActiveCall = line.Dial(_customerPhone_NoConf, false, TapiMediaMode.AutomatedVoice, line.Addresses[0]); string msg = String.Format("شماره گیری {0} بر روی خط '{1}'", _customerPhone_NoConf, line.Name); AddToLog(msg); } catch (TapiException exc) { MessageBox.Show(exc.Message, "TapiException!", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception exc) { MessageBox.Show(exc.Message, "Exception!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
internal LineRemovedEventArgs(TapiLine line) { Line = line; }
internal LineAddedEventArgs(TapiLine newLine) { Line = newLine; }
internal LineInfoChangeEventArgs(TapiLine line, LineInfoChangeTypes change) { Line = line; Change = change; }
private void ProcessTapiMessage(LINEMESSAGE msg) { switch (msg.dwMessageID) { case TapiEvent.LINE_CALLSTATE: { TapiCall call = TapiCall.FindCallByHandle(msg.hDevice); if (call != null) { call.OnCallStateChange(msg.dwParam1.ToInt32(), msg.dwParam2, (MediaModes)msg.dwParam3.ToInt32()); } else { // Call doesn't exist (yet), wait for a LINE_REPLY to add the call. lock (_pendingCallStateMessages) { _pendingCallStateMessages.Add(Tuple.Create(DateTime.Now, msg)); } } } break; case TapiEvent.LINE_CALLINFO: { TapiCall call = TapiCall.FindCallByHandle(msg.hDevice); if (call != null) { call.OnCallInfoChange(msg.dwParam1.ToInt32()); } } break; case TapiEvent.LINE_GATHERDIGITS: { TapiCall call = TapiCall.FindCallByHandle(msg.hDevice); if (call != null) { call.OnGatherDigitsComplete(msg.dwParam1.ToInt32()); } } break; case TapiEvent.LINE_GENERATE: { TapiCall call = TapiCall.FindCallByHandle(msg.hDevice); if (call != null) { call.OnGenerateDigitsOrToneComplete(msg.dwParam1.ToInt32()); } } break; case TapiEvent.LINE_MONITORDIGITS: { TapiCall call = TapiCall.FindCallByHandle(msg.hDevice); if (call != null) { call.OnDigitDetected(msg.dwParam1.ToInt32(), msg.dwParam2.ToInt32()); } } break; case TapiEvent.LINE_MONITORMEDIA: { TapiCall call = TapiCall.FindCallByHandle(msg.hDevice); if (call != null) { call.OnMediaModeDetected((MediaModes)msg.dwParam1.ToInt32()); } } break; case TapiEvent.LINE_MONITORTONE: { TapiCall call = TapiCall.FindCallByHandle(msg.hDevice); if (call != null) { call.OnToneDetected(msg.dwParam1.ToInt32()); } } break; case TapiEvent.LINE_LINEDEVSTATE: if (msg.dwParam1.ToInt32() == NativeMethods.LINEDEVSTATE_REINIT && msg.dwParam2.ToInt32() == 0) { if (ReinitRequired != null) { ReinitRequired(this, EventArgs.Empty); } } goto case TapiEvent.LINE_CLOSE; case TapiEvent.LINE_DEVSPECIFIC: { TapiCall call = TapiCall.FindCallByHandle(msg.hDevice); if (call != null) { ((TapiLine)call.Line).OnDeviceSpecific(call, msg.dwParam1, msg.dwParam2, msg.dwParam3); } else { goto case TapiEvent.LINE_CLOSE; } } break; case TapiEvent.LINE_DEVSPECIFICFEATURE: { TapiLine line = null; lock (_lineArray) { foreach (TapiLine currLine in _lineArray) { if (currLine.Handle.DangerousGetHandle() == (IntPtr)msg.hDevice) { line = currLine; break; } } } if (line != null) { line.OnDeviceSpecific(null, msg.dwParam1, msg.dwParam2, msg.dwParam3); } } break; case TapiEvent.LINE_AGENTSTATUS: case TapiEvent.LINE_AGENTSTATUSEX: case TapiEvent.LINE_AGENTSPECIFIC: case TapiEvent.LINE_AGENTSESSIONSTATUS: case TapiEvent.LINE_PROXYREQUEST: case TapiEvent.LINE_PROXYSTATUS: case TapiEvent.LINE_QUEUESTATUS: case TapiEvent.LINE_REQUEST: break; case TapiEvent.PHONE_BUTTON: case TapiEvent.PHONE_CLOSE: case TapiEvent.PHONE_DEVSPECIFIC: case TapiEvent.PHONE_REPLY: HandleCompletion(msg.dwParam1.ToInt32(), msg.dwParam2); break; case TapiEvent.PHONE_STATE: break; case TapiEvent.PHONE_CREATE: { var newPhone = new TapiPhone(this, msg.dwParam1.ToInt32()); lock (_phoneArray) { _phoneArray.Add(newPhone); } if (PhoneAdded != null) { PhoneAdded(this, new PhoneAddedEventArgs(newPhone)); } } break; case TapiEvent.PHONE_REMOVE: { TapiPhone phone = null; lock (_phoneArray) { if (msg.dwParam1.ToInt32() < _phoneArray.Count) { phone = _phoneArray[msg.dwParam1.ToInt32()]; } } if (phone != null) { phone.IsValid = false; if (PhoneRemoved != null) { PhoneRemoved(this, new PhoneRemovedEventArgs(phone)); } } } break; case TapiEvent.LINE_ADDRESSSTATE: case TapiEvent.LINE_CLOSE: case TapiEvent.LINE_APPNEWCALL: if (msg.dwCallbackInstance != IntPtr.Zero) { try { var callback = (TapiEventCallback)Marshal.GetDelegateForFunctionPointer(msg.dwCallbackInstance, typeof(TapiEventCallback)); callback.Invoke(msg.dwMessageID, msg.dwParam1, msg.dwParam2, msg.dwParam3); } catch (Exception ex) { Trace.WriteLine(ex); } } break; case TapiEvent.LINE_CREATE: { var newLine = new TapiLine(this, msg.dwParam1.ToInt32()); // Add event handlers newLine.NewCall += HandleNewCall; newLine.CallStateChanged += HandleCallStateChanged; newLine.CallInfoChanged += HandleCallInfoChanged; newLine.AddressChanged += HandleAddressChanged; newLine.Changed += HandleLineChanged; newLine.Ringing += HandleLineRinging; lock (_lineArray) { _lineArray.Add(newLine); } if (LineAdded != null) { LineAdded(this, new LineAddedEventArgs(newLine)); } } break; case TapiEvent.LINE_REMOVE: { TapiLine line = null; lock (_lineArray) { if (msg.dwParam1.ToInt32() < _lineArray.Count) { line = _lineArray[msg.dwParam1.ToInt32()]; } } if (line != null) { line.IsValid = false; if (LineRemoved != null) { LineRemoved(this, new LineRemovedEventArgs(line)); } } } break; case TapiEvent.LINE_REPLY: HandleCompletion(msg.dwParam1.ToInt32(), msg.dwParam2); break; default: break; } }
/* is called when main win is loaded */ public void init() { App.isMgrInitializationPhase = true; bool didInitalize = false; try { didInitalize = mgr.Initialize(); // CRITICAL - will remain in an endless loop, if the windows system CONTROL PANEL is opened and the current bound TAPI DRIVER configuration is opened! } catch (Exception ex) { App.log(ex.Message); } App.isMgrInitializationPhase = false; if (didInitalize) { App.Setup.Lines.Clear(); App.Setup.Addresses.Clear(); currentLine = null; currentAddress = null; addressCollection = null; currentOutgoingCall = null; currentIncomingCall = null; allLinesAndAddresses = ""; lineCollection = mgr.Lines; App.log(String.Format("{0}x TSP (Telephony service provider) lines detected", lineCollection.Count())); foreach (TapiLine line in lineCollection) { App.Setup.Lines.Add(line.Name); //line.Changed += Line_Changed; //line.NewCall += Line_NewCall; //line.Ringing += Line_Ringing; allLinesAndAddresses += "|" + line.Name; if (line.Addresses != null) { if (line.Addresses.Count() > 0) { foreach (TapiAddress adr in line.Addresses) { allLinesAndAddresses += "~" + adr.Address; } } else { App.log(String.Format("Line '{0}' addresses are empty!", line.Name)); } } else { App.log(String.Format("Line '{0}' addresses collection is NULL!", line.Name)); } } if (allLinesAndAddresses != "") { allLinesAndAddresses = allLinesAndAddresses.Substring(1); } if (App.Setup.Line != "") { setCurrentLine(App.Setup.Line); } if (App.Setup.Address != "") { setCurrentAddress(App.Setup.Address); } App.isRefreshingTapiSession = true; // start session } }
private void buttonDial_Click(object sender, EventArgs e) { startConference = false; timer1.Enabled = false; try { if (!String.IsNullOrEmpty(_internalAgentPhone)) { line = TapiApp.Lines.SingleOrDefault(q => q.Name.Contains(_internalAgentPhone)); } else { line = TapiApp.Lines.SingleOrDefault(q => q.Name.Contains(comboBoxLine.Text)); } if (line == null) { return; } if (!line.IsOpen) { line.Open(false, CallHandler); } line.DisconnectOnBusy = true; line.NoAnswerTimeout = 15; ActiveCall = line.Dial(txtPhone1.Text, false); string msg = String.Format("شماره گیری {0} بر روی خط '{1}'", txtPhone2.Text, line.Name); AddToLog(msg); bool completed = false; while (!completed) { Application.DoEvents(); if (ActiveCall.State == TapiCallState.Connected) { ActiveCall.Hold(); TapiCall consulationCall = line.Dial(txtPhone2.Text.Trim(), false); while (!completed) { if (consulationCall.State == TapiCallState.Connected) { ActiveCall.CompleteTransfer(consulationCall, false); ActiveCall.Disconnect(); completed = true; } else if (consulationCall.State == TapiCallState.Disconnected) { completed = true; Application.Exit(); } } } else if (ActiveCall.State == TapiCallState.Disconnected) { completed = true; Application.Exit(); } } } catch (TapiException exc) { MessageBox.Show(exc.Message, "TapiException!", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } catch (Exception exc) { MessageBox.Show(exc.Message, "Exception!", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } }
public ForwardInfoForm(TapiLine line) { _line = line; InitializeComponent(); }
public SelectCallForm(TapiLine line) { _line = line; InitializeComponent(); }