Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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);
        }
Exemple #6
0
 /// <summary>
 /// Constructor
 /// </summary>
 internal CallStateEventArgs(TapiCall call, CallState newState, CallState oldState, MediaModes modes)
 {
     Call         = call;
     CallState    = newState;
     OldCallState = oldState;
     MediaModes   = modes;
 }
Exemple #7
0
        private void _btnPickup_Click(object sender, EventArgs e)
        {
            TapiCall       tc  = CurrentAddress.Pickup(_tbNumber.Text, null);
            ActiveCallForm acf = new ActiveCallForm(tc);

            acf.Show();
        }
Exemple #8
0
        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());
            }
        }
Exemple #9
0
        /// <summary>
        /// This retrieves a call off a parked address
        /// </summary>
        /// <param name="parkedAddress">Address to retrieve call from</param>
        /// <returns>New <see cref="TapiCall"/> object.</returns>
        public TapiCall Unpark(string parkedAddress)
        {
            uint hCall;
            int  rc = NativeMethods.lineUnpark(Line.Handle, _addressId, out hCall, parkedAddress);

            if (rc < 0)
            {
                throw new TapiException("lineUnpark failed", rc);
            }

            // Wait for the LINE_REPLY .. same reason as lineMakeCall..
            var req = new PendingTapiRequest(rc, null, null);

            Line.TapiManager.AddAsyncRequest(req);
            req.AsyncWaitHandle.WaitOne();
            if (req.Result < 0)
            {
                throw new TapiException("lineUnpark failed", req.Result);
            }

            var call = new TapiCall(this, hCall);

            lock (_calls)
            {
                _calls.Add(call);
            }
            return(call);
        }
Exemple #10
0
        private void btnUnhold_Click(object sender, EventArgs e)
        {
            TapiCall call = GetActiveCall();

            if (call != null)
            {
                if (!AdjustCallPrivilege(call))
                {
                    return;
                }

                call.BeginUnhold(
                    delegate(IAsyncResult ar)
                {
                    try
                    {
                        call.EndUnhold(ar);
                    }
                    catch (TapiException ex)
                    {
                        LogError(ex.Message);
                    }
                }, null);
            }
        }
Exemple #11
0
        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);
        }
Exemple #12
0
 internal void AddCall(TapiCall call)
 {
     lock (_calls)
     {
         _calls.Add(call);
     }
 }
Exemple #13
0
 internal void RemoveCall(TapiCall call)
 {
     lock (_calls)
     {
         _calls.Remove(call);
     }
 }
Exemple #14
0
        /// <summary>
        /// This picks up a call alerting at the specified destination address and returns a call handle for the picked-up call.
        /// If invoked with null for the alertingAddress parameter, a group pickup is performed. If required by the device, groupId specifies the
        /// group identifier to which the alerting station belongs.
        /// </summary>
        /// <param name="alertingAddress">Address to retrieve call from</param>
        /// <param name="groupId">Optional group ID, can be null or empty</param>
        /// <returns>New <see cref="TapiCall"/> object.</returns>
        public ITapiCall Pickup(string alertingAddress, string groupId)
        {
            uint hCall;
            int  rc = NativeMethods.linePickup(_lineOwner.Handle, _addressId, out hCall, alertingAddress, groupId);

            if (rc < 0)
            {
                throw new TapiException("linePickup failed", rc);
            }

            // Wait for the LINE_REPLY .. same reason as lineMakeCall..
            var req = new PendingTapiRequest(rc, null, null);

            _lineOwner.TapiManager.AddAsyncRequest(req);
            req.AsyncWaitHandle.WaitOne();
            if (req.Result < 0)
            {
                throw new TapiException("linePickup failed", req.Result);
            }

            var call = new TapiCall(this, hCall);

            lock (_calls)
            {
                _calls.Add(call);
            }
            return(call);
        }
Exemple #15
0
        /// <summary>
        /// This is used to report LINE_CALLSTATE changes which got queued up due
        /// to an async request creating calls.
        /// </summary>
        internal void ReportQueuedCallStateChanges()
        {
            lock (_pendingCallStateMessages)
            {
                for (int i = 0; i < _pendingCallStateMessages.Count; i++)
                {
                    bool     remove = false;
                    var      entry  = _pendingCallStateMessages[i];
                    var      msg    = entry.Item2;
                    TapiCall call   = TapiCall.FindCallByHandle(msg.hDevice);
                    if (call != null)
                    {
                        call.OnCallStateChange(msg.dwParam1.ToInt32(), msg.dwParam2, (MediaModes)msg.dwParam3.ToInt32());
                        remove = true;
                    }
                    // Not found - has it been queued up too long?
                    else if ((DateTime.Now - entry.Item1).TotalSeconds > RequestTimeoutSeconds)
                    {
                        remove = true;
                    }

                    // Remove this item if it was processed, or timed out.
                    if (remove)
                    {
                        _pendingCallStateMessages.RemoveAt(i);
                        i--;
                    }
                }
            }
        }
Exemple #16
0
        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;
                }
            }
        }
Exemple #17
0
        private void _btnUnpark_Click(object sender, EventArgs e)
        {
            TapiCall       tc  = CurrentAddress.Unpark(_tbNumber.Text);
            ActiveCallForm acf = new ActiveCallForm(tc);

            acf.Show();
        }
Exemple #18
0
        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;
                    }
                }
            }
        }
Exemple #19
0
 internal DeviceSpecificEventArgs(TapiCall call, IntPtr p1, IntPtr p2, IntPtr p3)
 {
     Line   = call.Line;
     Call   = call;
     Param1 = p1;
     Param2 = p2;
     Param3 = p3;
 }
        private void btnSetupTransfer_Click(object sender, EventArgs e)
        {
            TapiCall newCall = _call.SetupTransfer(null);

            if (newCall != null)
            {
                ActiveCallForm acf = new ActiveCallForm(newCall);
                acf.Show();
            }
        }
Exemple #21
0
        public ActiveCallForm(TapiCall call)
        {
            TapiLine line = call.Line;

            _call = call;
            line.CallInfoChanged  += OnCallInfoChange;
            line.CallStateChanged += OnCallStateChange;

            InitializeComponent();
        }
Exemple #22
0
        /// <summary>
        /// This forwards calls destined for this address according to the specified forwarding instructions.
        /// Any specified incoming calls for that address are deflected to the other number by the switch.
        /// This function provides a combination of forward and do-not-disturb features.
        /// </summary>
        /// <param name="forwardInstructions">The forwarding instructions to apply</param>
        /// <param name="numRingsNoAnswer">Number of rings before a call is considered a "no answer." If dwNumRingsNoAnswer is out of range, the actual value is set to the nearest value in the allowable range.</param>
        /// <param name="param">Optional call parameters - only used if a consultation call is returned; otherwise ignored.  May be null for default parameters</param>
        public ITapiCall Forward(ForwardInfo[] forwardInstructions, int numRingsNoAnswer, MakeCallParams param)
        {
            if (!Line.IsOpen)
            {
                throw new TapiException("Line is not open", NativeMethods.LINEERR_OPERATIONUNAVAIL);
            }

            IntPtr lpCp    = IntPtr.Zero;
            IntPtr fwdList = ForwardInfo.ProcessForwardList(forwardInstructions);

            try
            {
                lpCp = MakeCallParams.ProcessCallParams(_addressId, param, 0);
                uint hCall;

                int rc = NativeMethods.lineForward(_lineOwner.Handle, 0, _addressId, fwdList, numRingsNoAnswer, out hCall, lpCp);
                if (rc < 0)
                {
                    throw new TapiException("lineForward failed", rc);
                }
                else
                {
                    // Wait for the LINE_REPLY so we don't need to deal with the value type
                    // issues of IntPtr being filled in async.
                    var req = new PendingTapiRequest(rc, null, null);
                    _lineOwner.TapiManager.AddAsyncRequest(req);
                    req.AsyncWaitHandle.WaitOne();
                    if (req.Result < 0)
                    {
                        throw new TapiException("lineForward failed", req.Result);
                    }

                    if (hCall != 0)
                    {
                        var call = new TapiCall(this, hCall);
                        AddCall(call);
                        return(call);
                    }
                }
            }
            finally
            {
                if (lpCp != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(lpCp);
                }
                if (fwdList != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(fwdList);
                }
            }

            return(null);
        }
Exemple #23
0
        /// <summary>
        /// This method is used to establish a conference call
        /// </summary>
        /// <param name="conferenceCount"># of parties anticipated the conference</param>
        /// <param name="mcp">Call parameters for created consultation call</param>
        /// <param name="consultCall">Returning consultation call</param>
        /// <returns>Conference call</returns>
        public ITapiCall SetupConference(int conferenceCount, MakeCallParams mcp, out TapiCall consultCall)
        {
            IntPtr lpCp      = IntPtr.Zero;
            int    callFlags = 0;

            try
            {
                if (mcp != null && !String.IsNullOrEmpty(mcp.TargetAddress))
                {
                    callFlags |= NativeMethods.LINECALLPARAMFLAGS_NOHOLDCONFERENCE;
                }
                lpCp = MakeCallParams.ProcessCallParams(Id, mcp, callFlags);
                uint hCall, hConfCall;
                int  rc = NativeMethods.lineSetupConference(new HTCALL(), _lineOwner.Handle, out hConfCall, out hCall, conferenceCount, lpCp);
                if (rc < 0)
                {
                    throw new TapiException("lineSetupConference failed", rc);
                }
                else
                {
                    // Wait for the LINE_REPLY so we don't need to deal with the value type
                    // issues of IntPtr being filled in async.
                    var req = new PendingTapiRequest(rc, null, null);
                    _lineOwner.TapiManager.AddAsyncRequest(req);
                    req.AsyncWaitHandle.WaitOne();
                    if (req.Result < 0)
                    {
                        throw new TapiException("lineSetupConference failed", req.Result);
                    }

                    if (hCall != 0)
                    {
                        consultCall = new TapiCall(this, hCall);
                        AddCall(consultCall);
                    }
                    else
                    {
                        consultCall = null;
                    }

                    var confCall = new TapiCall(this, hConfCall);
                    AddCall(confCall);

                    return(confCall);
                }
            }
            finally
            {
                if (lpCp != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(lpCp);
                }
            }
        }
Exemple #24
0
 private bool AdjustCallPrivilege(TapiCall call)
 {
     try
     {
         call.Privilege = Privilege.Owner;
         return(true);
     }
     catch (TapiException ex)
     {
         LogError(string.Format("Cannot set ownership: {0}", ex.Message));
     }
     return(false);
 }
        private void btnCompleteTransfer_Click(object sender, EventArgs e)
        {
            SelectCallForm scf = new SelectCallForm(_call.Line);

            if (scf.ShowDialog() == DialogResult.OK)
            {
                TapiCall otherCall = scf.SelectedCall;
                if (otherCall != null && otherCall != _call)
                {
                    _call.CompleteTransfer(otherCall);
                }
            }
        }
Exemple #26
0
        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());
        }
Exemple #27
0
        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();
        }
Exemple #28
0
        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);
        }
Exemple #29
0
 private void AdjustButtonState(TapiCall tCall)
 {
     if (tCall != null)
     {
         btnAccept.Enabled = tCall.Features.CanAccept;
         btnAnswer.Enabled = tCall.Features.CanAnswer;
         btnDrop.Enabled   = tCall.Features.CanDrop;
         btnHold.Enabled   = tCall.Features.CanHold;
         btnUnhold.Enabled = tCall.Features.CanUnhold;
     }
     else
     {
         btnAccept.Enabled = false;
         btnAnswer.Enabled = false;
         btnDrop.Enabled   = false;
         btnHold.Enabled   = false;
         btnUnhold.Enabled = false;
     }
 }
Exemple #30
0
        /// <summary>
        /// Places a new call on the address
        /// </summary>
        /// <param name="address">Number to dial</param>
        /// <param name="countryCode">Country code</param>
        /// <param name="param">Optional <see>MakeCallParams</see> to use while dialing</param>
        /// <returns>New <see cref="TapiCall"/> object.</returns>
        public ITapiCall MakeCall(string address, int countryCode, MakeCallParams param)
        {
            if (!Line.IsOpen)
            {
                throw new TapiException("Line is not open", NativeMethods.LINEERR_OPERATIONUNAVAIL);
            }

            IntPtr lpCp = IntPtr.Zero;

            try
            {
                lpCp = MakeCallParams.ProcessCallParams(_addressId, param, 0);
                uint hCall;
                int  rc = NativeMethods.lineMakeCall(_lineOwner.Handle, out hCall, address, countryCode, lpCp);
                if (rc < 0)
                {
                    throw new TapiException("lineMakeCall failed", rc);
                }
                else
                {
                    // Wait for the LINE_REPLY so we don't need to deal with the value type
                    // issues of IntPtr being filled in async.
                    var req = new PendingTapiRequest(rc, null, null);
                    _lineOwner.TapiManager.AddAsyncRequest(req);
                    req.AsyncWaitHandle.WaitOne();
                    if (req.Result < 0)
                    {
                        throw new TapiException("lineMakeCall failed", req.Result);
                    }

                    var call = new TapiCall(this, hCall);
                    AddCall(call);
                    return(call);
                }
            }
            finally
            {
                if (lpCp != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(lpCp);
                }
            }
        }