private void CallHandler(TapiCall call) { try { string msg = String.Format("تماس به {0}.", call.CalledID); listBoxLog.Invoke(m_addToLogDelegate, msg); } catch (TapiDisconnectException) { listBoxLog.Invoke(m_addToLogDelegate, "طرف دعوت شده تلفن را قطع کرد."); } catch (Exception exc) { string msg = String.Format("Exception in CallHandler! {0}", exc.Message); listBoxLog.Invoke(m_addToLogDelegate, msg); } finally { call.Disconnect(); } }
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(); } }