public bool Transfer(string callid, string caller, string destination) { TapiCall call = null; TapiAddress address = GetAddress(caller); bool success = false; if (address != null) { foreach (TapiCall tc in address.Calls) { if (tc.Id.ToString() == callid) { call = tc; break; } } if (call != null) { log.Debug("Transfering call " + callid + " from " + caller + " to " + destination); try { call.BlindTransfer(destination, 0); success = true; } catch (Exception e) { log.Debug("Unable to setup transfer, " + e.Message); } } } return(success); }
public bool UnHold(string callid, string caller) { TapiCall call = null; TapiAddress address = GetAddress(caller); bool success = false; if (address != null) { foreach (TapiCall tc in address.Calls) { if (tc.Id.ToString() == callid) { call = tc; break; } } if (call != null) { log.Debug("Unholding call " + callid + " from " + caller); call.Unhold(); success = true; } } return(success); }
public bool Divert(string callid, string caller) { TapiCall call = null; TapiAddress address = GetAddress(caller); bool success = false; if (address != null) { foreach (TapiCall tc in address.Calls) { if (tc.Id.ToString() == callid) { call = tc; break; } } if (call != null) { log.Debug("Divert call " + callid + " from " + caller); try { call.Drop(); success = true; } catch (Exception e) { log.Debug("Unable to drop call, " + e.Message); } } } return(success); }
public bool Hold(string callid, string caller) { TapiCall call = null; TapiAddress address = GetAddress(caller); bool success = false; log.Debug("Hold call " + callid + " from " + caller); if (address != null) { log.Debug("Parsing " + address.Calls.Length.ToString() + " from " + address.ToString()); foreach (TapiCall tc in address.Calls) { log.Debug("Call " + tc.ToString() + " from " + caller + " is being compared:" + tc.Id.ToString() + ": " + callid); if (tc.Id.ToString() == callid) { call = tc; break; } } if (call != null) { log.Debug("Holding call " + callid + " from " + caller); call.Hold(); success = true; } } return(success); }
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 { } }
public bool UnHook(string callee, string callid) { TapiCall call = null; TapiAddress address = GetAddress(callee); bool success = false; if (address != null) { foreach (TapiCall tc in address.Calls) { if (tc.Id.ToString() == callid) { call = tc; break; } } if (call != null) { log.Debug("Answering call " + callid + " from " + callee); call.Answer(); success = true; } } else { log.Debug("Can't get address: " + callee); } return(success); }
public bool Forward(string caller, string destination) { TapiAddress ad = GetAddress(caller); bool success = false; if (ad != null) { if (destination != "") { log.Debug("Unconditional forward from " + ad.ToString() + " to " + destination); ForwardInfo[] fis = new ForwardInfo[1]; fis[0] = new ForwardInfo(ForwardingMode.Unconditional, "", 0, destination); log.Debug("Forwarding " + ad.ToString() + ": " + fis[0].ToString()); try { MakeCallParams mcp = new MakeCallParams(); mcp.NoAnswerTimeout = 0; if (ad.Forward(fis, 3, mcp) != null) { success = true; } } catch (Exception e) { log.Error("Unable to forward " + ad.ToString() + " " + e.Message); } } else { ad.CancelForward(); success = true; } } return(success); }
private void btnOK_Click(object sender, EventArgs e) { if (lbEntries.Items.Count > 0) { _fwdInfo = new ForwardInfo[lbEntries.Items.Count]; for (int i = 0; i < lbEntries.Items.Count; i++) { _fwdInfo[i] = (ForwardInfo)lbEntries.Items[i]; } } else { _fwdInfo = new ForwardInfo[0]; } if (chkAllAddresses.Checked) { _selAddress = null; } else { _selAddress = (TapiAddress)cbAddresses.SelectedItem; } this.DialogResult = DialogResult.OK; this.Close(); }
private void cbAddresses_SelectedIndexChanged(object sender, EventArgs e) { TapiAddress addr = (TapiAddress)cbAddresses.SelectedItem; lbEntries.Items.Clear(); foreach (ForwardInfo fi in addr.Status.ForwardingInformation) { lbEntries.Items.Add(fi); } }
public string Call(string caller, string callee) { TapiAddress ad = GetAddress(caller); TapiCall call = null; if (ad != null) { log.Debug("Make call from " + ad.ToString() + " to " + callee); call = ad.MakeCall(callee); log.Debug("Call from " + ad.ToString() + " to " + callee + ": " + call.ToString()); } return(call.Id.ToString()); }
private string GetForward(TapiAddress address) { string forward = ""; foreach (ForwardInfo fi in address.Status.ForwardingInformation) { if (fi.ForwardMode == ForwardingMode.Unconditional) { forward = fi.DestinationAddress; break; } } return(forward); }
TapiAddress GetAddress(string extension) { TapiAddress address = null; foreach (TapiAddress ad in _addresses) { if (ad.Address == extension) { address = ad; break; } } return(address); }
/* is called when the item in the Address combobox has been changed */ public void setCurrentAddress(string addressName) { if (addressCollection != null) { TapiAddress item = addressCollection.FirstOrDefault(i => i.Address == addressName); if (item != null) { currentAddress = item; currentAddress.CallStateChanged += CurrentAddress_CallStateChanged; App.log(String.Format("Selected TAPI address '{0}'", currentAddress.Address)); App.registry.write("Address", currentAddress.Address); } else { App.log(String.Format("Unable to apply address '{0}'", addressName)); } } else { App.log("Collection of line addresses is not available"); } }
private LineControl GetLineControl(TapiAddress address) { LineControl lc = new LineControl(); lc.directoryNumber = address.Address; lc.doNotDisturb = false; lc.forward = GetForward(address); lc.mwiOn = false; lc.monitored = ""; if (address.Calls.Length > 0) { List <LineControlConnection> lcs = new List <LineControlConnection>(); foreach (TapiCall tc in address.Calls) { if (tc.CallState != CallState.Idle && tc.CallState != CallState.Unknown) { LineControlConnection lcc = new LineControlConnection(); lcc.callid = tc.Id.ToString(); if (tc.CallOrigin == CallOrigins.Outbound) { lcc.contact = tc.CalledId; } else { lcc.contact = tc.CallerId; } SetLineControlConnection(lcc, tc.CallState); lcs.Add(lcc); } } lc.lineControlConnection = lcs.ToArray(); if (address.Calls.Length > 1) { lc.status = Status.busy; } else { switch (address.Calls[0].CallState) { case CallState.Dialing: lc.status = Status.dialing; break; case CallState.Offering: lc.status = Status.ringing; break; case CallState.Idle: lc.status = Status.available; break; case CallState.Disconnected: lc.status = Status.available; break; case CallState.None: lc.status = Status.available; break; case CallState.Unknown: lc.status = Status.available; break; case CallState.Accepted: lc.status = Status.busy; break; case CallState.Busy: lc.status = Status.busy; break; default: lc.status = Status.busy; break; } } } else { lc.status = Status.available; } return(lc); }
private LineControl GetLineControl(TapiAddress address) { LineControl lc = new LineControl(); lc.directoryNumber = address.Address; lc.doNotDisturb = false; lc.forward = GetForward(address); lc.mwiOn = false; lc.monitored = ""; if (address.Calls.Length > 0) { List<LineControlConnection> lcs = new List<LineControlConnection>(); foreach (TapiCall tc in address.Calls) { if (tc.CallState != CallState.Idle && tc.CallState != CallState.Unknown) { LineControlConnection lcc = new LineControlConnection(); lcc.callid = tc.Id.ToString(); if (tc.CallOrigin == CallOrigins.Outbound) { lcc.contact = tc.CalledId; } else { lcc.contact = tc.CallerId; } SetLineControlConnection(lcc, tc.CallState); lcs.Add(lcc); } } lc.lineControlConnection = lcs.ToArray(); if (address.Calls.Length > 1) { lc.status = Status.busy; } else { switch (address.Calls[0].CallState) { case CallState.Dialing: lc.status = Status.dialing; break; case CallState.Offering: lc.status = Status.ringing; break; case CallState.Idle: lc.status = Status.available; break; case CallState.Disconnected: lc.status = Status.available; break; case CallState.None: lc.status = Status.available; break; case CallState.Unknown: lc.status = Status.available; break; case CallState.Accepted: lc.status = Status.busy; break; case CallState.Busy: lc.status = Status.busy; break; default: lc.status = Status.busy; break; } } } else { lc.status = Status.available; } return lc; }
private string GetForward(TapiAddress address) { string forward = ""; foreach (ForwardInfo fi in address.Status.ForwardingInformation) { if (fi.ForwardMode == ForwardingMode.Unconditional) { forward = fi.DestinationAddress; break; } } return forward; }
/* 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 } }