Exemplo n.º 1
0
        public void ExecuteComplete(EventChannelExecuteComplete evt)
        {
            Console.WriteLine(evt.AppName + "(" + evt.Arguments + ") is done.");

            if (_currentCommand != null && evt.AppName != _currentCommand.Command)
            {
                Console.WriteLine("Executed something that is not ours: " + _currentCommand.Command);
                return;
            }

            // run next command
            lock (_items)
            {
                _currentCommand = null;

                if (_items.Count > 0)
                {
                    // check if next cmd is waiting on dtmf, then trigger it to start.
                    if (_items.Peek().Command == "privdtmf")
                    {
                        ((PrivateWaitDtmf)_items.Peek()).Trigger();
                    }

                    SendNextCommand();
                }
            }
        }
Exemplo n.º 2
0
        private void OnEvent(EventBase receivedEvent)
        {
            if (!receivedEvent.IsChannelEvent)
            {
                return;
            }

            ChannelEvent channelEvent = (ChannelEvent)receivedEvent;

            if (channelEvent.UniqueId != _uuid)
            {
                return;
            }

            if (receivedEvent is EventChannelAnswer)
            {
                _answered = true;
            }
            else if (receivedEvent is EventDtmf)
            {
                EventDtmf evt = (EventDtmf)receivedEvent;
                Console.WriteLine("DTMF Event: " + evt.Digit);
                if (_queue.GotDtmf(evt.Digit))
                {
                    lock (_dtmf)
                        _dtmf += evt.Digit;

                    if (_dtmfWaitCount != 0 && _dtmf.Length >= _dtmfWaitCount)
                    {
                        Console.WriteLine("Got all DTMF: " + _dtmfWaitCount + "/" + _dtmf.Length);
                        _dtmfTimeout.Set();
                    }

                    if (DtmfReceived != null)
                    {
                        DtmfReceived(this, new DtmfEventArgs(_dtmf));
                    }
                }
            }
            else if (receivedEvent is EventChannelDestroy || receivedEvent is EventChannelHangup)
            {
                if (_mgr != null)
                {
                    _mgr.EventReceived -= OnEvent;
                    _mgr = null;
                }
            }
            else if (receivedEvent is EventChannelExecute)
            {
                EventChannelExecute exec = (EventChannelExecute)receivedEvent;
                _queue.Execute(exec);
            }
            else if (receivedEvent is EventChannelExecuteComplete)
            {
                EventChannelExecuteComplete exec = (EventChannelExecuteComplete)receivedEvent;
                _queue.ExecuteComplete(exec);
            }
        }