示例#1
1
 protected override void OnStart(string[] args)
 {
     log.Debug("Starting AsteriskConnector...");
     try
     {
         manager.Login();
         log.Debug("Getting sip peers...");
         SIPPeersAction sipaction = new SIPPeersAction();
         manager.SendAction(sipaction);
         CommandAction ca = new CommandAction("sip show users");
         CommandResponse cr = (CommandResponse)manager.SendAction(ca, 10000);
         char[] splitter = { ' ' };
         
         foreach (string user in cr.Result)
         {
             string[] usersplit = user.Split(splitter);
             List<string> userprop = new List<string>();
             foreach (string split in usersplit)
             {
                 if (split.Length != 0)
                 {
                     userprop.Add(split);
                 }
             }
             if (userprop.Count == 5)
             {
                 log.Debug("User " + userprop.ToArray()[0] + " password: "******"Exception while starting AsteriskConnector: " + e.Message);
     }
 }
示例#2
0
        private static void checkManagerAPI()
        {
            manager = new ManagerConnection(ASTERISK_HOST, ASTERISK_PORT, ASTERISK_LOGINNAME, ASTERISK_LOGINPWD);

            // Register user event class
            manager.RegisterUserEventClass(typeof(UserAgentLoginEvent));

            // Add or Remove events
            manager.UserEvents += new UserEventHandler(dam_UserEvents);

            // Dont't display this event
            //manager.NewExten += new NewExtenEventHandler(manager_IgnoreEvent);
            manager.NewExten += new NewExtenEventHandler(manager_HandleNewExtentEvent);

            // Display all other
            manager.UnhandledEvent += new ManagerEventHandler(dam_Events);

            // Handle the response from AGI Exec
            manager.AGIExec += new AGIExecHandler(manager_AgiEvent);

            // +++ Only to debug purpose
            manager.FireAllEvents = true;
            // manager.DefaultEventTimeout = 0;
            // manager.DefaultResponseTimeout = 0;
            manager.PingInterval = 0;
            // +++
            try
            {
                manager.Login();			// Login only (fast)

                Console.WriteLine("Asterisk version : " + manager.Version);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.ReadLine();
                manager.Logoff();
                return;
            }

            {
                Console.WriteLine("\nGetConfig action");
                ManagerResponse response = manager.SendAction(new GetConfigAction("manager.conf"));
                if (response.IsSuccess())
                {
                    GetConfigResponse responseConfig = (GetConfigResponse)response;
                    foreach (int key in responseConfig.Categories.Keys)
                    {
                        Console.WriteLine(string.Format("{0}:{1}", key, responseConfig.Categories[key]));
                        foreach (int keyLine in responseConfig.Lines(key).Keys)
                        {
                            Console.WriteLine(string.Format("\t{0}:{1}", keyLine, responseConfig.Lines(key)[keyLine]));
                        }
                    }
                }
                else
                    Console.WriteLine(response);
            }

            {
                Console.WriteLine("\nUpdateConfig action");
                UpdateConfigAction config = new UpdateConfigAction("manager.conf", "manager.conf");
                config.AddCommand(UpdateConfigAction.ACTION_NEWCAT, "testadmin");
                config.AddCommand(UpdateConfigAction.ACTION_APPEND, "testadmin", "secret", "blabla");
                ManagerResponse response = manager.SendAction(config);
                Console.WriteLine(response);
            }

            // Originate call example
            Console.WriteLine("\nPress ENTER key to originate call.\n"
                + "Start phone (or connect) or make a call to see events.\n"
                + "After all events press a key to originate call.");
            Console.ReadLine();

            OriginateAction oc = new OriginateAction();
            oc.Context = ORIGINATE_CONTEXT;
            oc.Priority = "1"; // can be int in quotes or also be a label specified in the dial plan
            oc.Channel = ORIGINATE_CHANNEL;
            oc.CallerId = ORIGINATE_CALLERID;
            oc.Exten = ORIGINATE_EXTEN;
            oc.Timeout = ORIGINATE_TIMEOUT;
            // oc.Variable = "VAR1=abc|VAR2=def";
            // oc.SetVariable("VAR3", "ghi");
            ManagerResponse originateResponse = manager.SendAction(oc, oc.Timeout);
            Console.WriteLine("Response:");
            Console.WriteLine(originateResponse);

            Console.WriteLine("Press ENTER key to next test.");
            Console.ReadLine();

            //
            // Display result of Show Queues command
            //
            {
                CommandAction command = new CommandAction();
                CommandResponse response = new CommandResponse();
                if (manager.AsteriskVersion == AsteriskVersion.ASTERISK_1_6)
                    command.Command = "queue show";
                else
                    command.Command = "show queues";
                try
                {
                    response = (CommandResponse)manager.SendAction(command);
                    Console.WriteLine("Result of " + command.Command);
                    foreach (string str in response.Result)
                        Console.WriteLine("\t" + str);
                }
                catch (Exception err)
                {
                    Console.WriteLine("Response error: " + err);
                }
                Console.WriteLine("Press ENTER to next test or CTRL-C to exit.");
                Console.ReadLine();
            }
            //
            // Display Queues and Members
            //
            ResponseEvents re;
            try
            {
                re = manager.SendEventGeneratingAction(new QueueStatusAction());
            }
            catch (EventTimeoutException e)
            {
                // this happens with Asterisk 1.0.x as it doesn't send a QueueStatusCompleteEvent
                re = e.PartialResult;
            }

            foreach (ManagerEvent e in re.Events)
            {
                if (e is QueueParamsEvent)
                {
                    QueueParamsEvent qe = (QueueParamsEvent)e;
                    Console.WriteLine("QueueParamsEvent" + "\n\tQueue:\t\t" + qe.Queue + "\n\tServiceLevel:\t" + qe.ServiceLevel);
                }
                else if (e is QueueMemberEvent)
                {
                    QueueMemberEvent qme = (QueueMemberEvent)e;
                    Console.WriteLine("QueueMemberEvent" + "\n\tQueue:\t\t" + qme.Queue + "\n\tLocation:\t" + qme.Location);
                }
                else if (e is QueueEntryEvent)
                {
                    QueueEntryEvent qee = (QueueEntryEvent)e;
                    Console.WriteLine("QueueEntryEvent" + "\n\tQueue:\t\t" + qee.Queue + "\n\tChannel:\t" + qee.Channel + "\n\tPosition:\t" + qee.Position);
                }
            }

            Console.WriteLine("Press ENTER to next test or CTRL-C to exit.");
            Console.ReadLine();

            //
            //	To test create 3 extensions:
            //	1 - SIP/4012 w/o voicemail (with eyeBeam softphone)
            //	2 - IAX2/4008 w/o voicemail (with iaxComm softphone)
            //	3 - SIP/4010 w/ voicemal but no phone connect

            //	RedirectCall: call from IAX2/4008 to SIP/4012
            //	Don't answer on SIP/4012 and call must redirect to SIP/4010 (to voicemail really)
            //	Dial event used to define redirect channel

            Console.WriteLine("Redirect Call from " + ORIGINATE_CHANNEL + " to " + ORIGINATE_EXTRA_CHANNEL + " or press ESC.");
            // Wait for Dial Event from ORIGINATE_CHANNEL
            DialEventHandler de = new DialEventHandler(dam_Dial);
            manager.Dial += de;
            while (transferChannel == null)
            {
                System.Threading.Thread.Sleep(100);
                if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape)
                    break;
            }
            manager.Dial -= de;

            // Now send Redirect action
            RedirectAction ra = new RedirectAction();
            ra.Channel = transferChannel;
            ra.ExtraChannel = ORIGINATE_EXTRA_CHANNEL;
            ra.Context = ORIGINATE_CONTEXT;
            ra.Exten = ORIGINATE_EXTRA_EXTEN;
            ra.Priority = 1;
            try
            {
                ManagerResponse mr = manager.SendAction(ra, 10000);
                Console.WriteLine("Transfer Call"
                    + "\n\tResponse:" + mr.Response
                    + "\n\tMessage:" + mr.Message
                    );
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            //	Monitor call.
            //	Call from IA2/4008 to SIP/4012
            //	Link event used to define monitor channel
            Console.WriteLine("Monitor call. Please call " + ORIGINATE_CHANNEL + " and answer or press ESC.");
            // Wait for Link event
            LinkEventHandler le = new LinkEventHandler(dam_Link);
            manager.Link += le;
            while (monitorChannel == null)
            {
                System.Threading.Thread.Sleep(100);
                if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape)
                    break;
            }
            manager.Link -= le;
            // Now send Monitor action
            MonitorAction ma = new MonitorAction();
            ma.Channel = monitorChannel;
            ma.File = "voicefile";
            ma.Format = "gsm";
            ma.Mix = true;
            try
            {
                ManagerResponse mr = manager.SendAction(ma, 10000);
                Console.WriteLine("Monitor Call"
                    + "\n\tResponse:" + mr.Response);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            manager.Logoff();
        }
示例#3
0
        private static void callPager(string pagerNum, string messageNum)
        {
            manager = new ManagerConnection(ASTERISK_HOST, ASTERISK_PORT, ASTERISK_LOGINNAME, ASTERISK_LOGINPWD);

            // Register user event class
            manager.RegisterUserEventClass(typeof(UserAgentLoginEvent));
            // Add or Remove events
            manager.UserEvents += new UserEventHandler(dam_UserEvents);
            // Dont't display this event
            manager.NewExten += new NewExtenEventHandler(manager_IgnoreEvent);
            // Display all other
            manager.UnhandledEvent += new ManagerEventHandler(dam_Events);
            manager.PingInterval = 0;

            try
            {
                manager.Login();			// Login only (fast)
                Console.WriteLine("Asterisk version : " + manager.Version);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.ReadLine();
                manager.Logoff();
                return;
            }

            {
                //Console.WriteLine("\nGetConfig action");
                ManagerResponse response = manager.SendAction(new GetConfigAction("manager.conf"));
                if (response.IsSuccess())
                {
                    GetConfigResponse responseConfig = (GetConfigResponse)response;
                    foreach (int key in responseConfig.Categories.Keys)
                    {
                        Console.WriteLine(string.Format("{0}:{1}", key, responseConfig.Categories[key]));
                        foreach (int keyLine in responseConfig.Lines(key).Keys)
                        {
                            Console.WriteLine(string.Format("\t{0}:{1}", keyLine, responseConfig.Lines(key)[keyLine]));
                        }
                    }
                }
                else { }
                Console.WriteLine(response);

            }

            {
                // Console.WriteLine("\nUpdateConfig action");
                UpdateConfigAction config = new UpdateConfigAction("manager.conf", "manager.conf");
                config.AddCommand(UpdateConfigAction.ACTION_NEWCAT, "testadmin");
                config.AddCommand(UpdateConfigAction.ACTION_APPEND, "testadmin", "secret", "blabla");
                ManagerResponse response = manager.SendAction(config);
                //Console.WriteLine(response);
            }

            OriginateAction oc = new OriginateAction();

            oc.Context = ORIGINATE_CONTEXT;
            oc.Priority = 1;
            oc.Channel = @"SIP/SOFTPHONE001";
            oc.CallerId = "Hello";
            oc.Exten = "9793616700";
            oc.Timeout = ORIGINATE_TIMEOUT;

            ManagerResponse originateResponse = manager.SendAction(oc, oc.Timeout);

                CommandAction ca = new CommandAction("Dial 9793616700,180,D(w8w3w2w3w6w8w7w3w8w7)");
                ManagerResponse commandResponse = manager.SendAction(ca, ORIGINATE_TIMEOUT);
                Console.WriteLine("Command Response:");
                Console.WriteLine(commandResponse);

            Console.WriteLine("Hello Press ENTER key to next test.");
            Console.ReadLine();
        }
示例#4
0
        void manager_UnhandledEvent(object sender, ManagerEvent e)
        {
            log.Debug("New unhandled event received: " + e.GetType().Name);
            LineControl lc = null;
            
            //StateServer
            switch (e.GetType().Name)
            {
                case "AGIExecEvent":
                    AGIExecEvent agievent = e as AGIExecEvent;
                    break;
                case "AlarmClearEvent":
                    AlarmClearEvent alarmclear = e as AlarmClearEvent;
                    break;
                case "AlarmEvent":
                    AlarmEvent alarmevent = e as AlarmEvent;
                    break;
                case "AsyncAGIEvent":
                    AsyncAGIEvent asyncagievent = e as AsyncAGIEvent;
                    break;
                case "BridgeEvent":
                    BridgeEvent bridgeevent = e as BridgeEvent;
                    break;
                case "CdrEvent":
                    CdrEvent cdrevent = e as CdrEvent;
                    break;
                case "ChannelReloadEvent":
                    ChannelReloadEvent channelreload = e as ChannelReloadEvent;
                    break;
                case "ChannelUpdateEvent":
                    ChannelUpdateEvent channelupdate = e as ChannelUpdateEvent;
                    break;
                case "ConnectEvent":
                    ConnectEvent connectevent = e as ConnectEvent;
                    break;
                case "ConnectionStateEvent":
                    ConnectionStateEvent connectionstate = e as ConnectionStateEvent;
                    break;
                case "DBGetResponseEvent":
                    DBGetResponseEvent dbget = e as DBGetResponseEvent;
                    log.Debug("DBGet response: " + dbget.ToString());
                    switch (dbget.Family)
                    {
                        case "DND":
                            ss.SetLineControl(setLineControlDND(dbget.Key, true));
                            break;
                        case "CF":
                            ss.SetLineControl(setLineControlForward(dbget.Key, dbget.Val));
                            break;
                    }
                    break;
                case "DialEvent":
                    DialEvent dial = e as DialEvent;
                    log.Debug("Dial event: " + dial.ToString());
                    break;
                case "DisconnectEvent":
                    DisconnectEvent disconnect = e as DisconnectEvent;
                    log.Debug("Disconnect event: " + disconnect.ToString());
                    break;
                case "DNDStateEvent":
                    DNDStateEvent dndstate = e as DNDStateEvent;
                    log.Debug("DND state event: " + dndstate.ToString());
                    break;
                case "ExtensionStatusEvent":
                    ExtensionStatusEvent extensionstatus = e as ExtensionStatusEvent;
                    log.Debug("Extension status event: " + extensionstatus.ToString() + ", status: " + extensionstatus.Status + ", hint: " + extensionstatus.Hint);
                    ss.SetLineControl(getLineControlFromExtensionStatusEvent(extensionstatus));
                    break;
                case "FaxReceivedEvent":
                    FaxReceivedEvent faxreceived = e as FaxReceivedEvent;
                    break;
                case "HangupEvent":
                    HangupEvent hangup = e as HangupEvent;
                    log.Debug("Hangup event: " + hangup.ToString() + " callerid: " + hangup.CallerId + " calleridnum: " + hangup.CallerIdNum);
                    //line control
                    if (channels.Contains(hangup.Channel))
                    {

                        lc = getLineControl((string)channels[hangup.Channel]);
                        int hi = 0;
                        LineControlConnection[] newLCC = null;
                        if (lc.lineControlConnection.Length > 1)
                        {
                            newLCC = new LineControlConnection[lc.lineControlConnection.Length - 1];
                            foreach (LineControlConnection hlcc in lc.lineControlConnection)
                            {
                                if (hlcc.callid != hangup.Channel)
                                {
                                    newLCC[hi] = hlcc;
                                    hi++;
                                }
                            }
                        }
                        lc.lineControlConnection = newLCC;
                        ss.SetLineControl(lc);
                        channels.Remove(hangup.Channel);
                    }
                    
                    //missed calls
                    callToFind = hangup.UniqueId.Substring(0, 6) + "," + hangup.UniqueId.Substring(6);
                    Call mCall = missedCalls.Find(FindCall);
                    if (mCall != null)
                    {
                        log.Debug("Missed call finded for callid: " + hangup.UniqueId);
                        AddCallLogs(mCall.callee, mCall);
                        if (missedCalls.Remove(mCall))
                        {
                            log.Debug("Call " + mCall.callId + " successfully removed from missedcall cache");
                        }
                        else
                        {
                            log.Debug("Call " + mCall.callId + " cannot be removed from missedcall cache");
                        }
                    }
                    break;
                case "HoldedCallEvent":
                    HoldedCallEvent holdedcall = e as HoldedCallEvent;
                    break;
                case "HoldEvent":
                    HoldEvent holdevent = e as HoldEvent;
                    break;
                case "JabberEvent":
                    JabberEvent jabberevent = e as JabberEvent;
                    break;
                case "JitterBufStatsEvent":
                    JitterBufStatsEvent jitter = e as JitterBufStatsEvent;
                    break;
                case "JoinEvent":
                    JoinEvent join = e as JoinEvent;
                    break;
                case "LeaveEvent":
                    LeaveEvent leave = e as LeaveEvent;
                    break;
                case "LinkEvent":
                    LinkEvent link = e as LinkEvent;
                    log.Debug("Link event: " + link.ToString());
                    lc = getLineControl(link.CallerId1);
                    if (lc != null)
                    {
                        foreach (LineControlConnection linklcc in lc.lineControlConnection)
                        {
                            if (linklcc.callid == link.Channel1)
                            {
                                linklcc.contact = link.CallerId2;
                                ss.SetLineControl(lc);
                                break;
                            }
                        }
                    }
                    lc = getLineControl(link.CallerId2);
                    if (lc != null)
                    {
                        foreach (LineControlConnection linklcc in lc.lineControlConnection)
                        {
                            if (linklcc.callid == link.Channel2)
                            {
                                linklcc.contact = link.CallerId1;
                                ss.SetLineControl(lc);
                                break;
                            }
                        }
                    }
                    break;
                case "LogChannelEvent":
                    LogChannelEvent logchannel = e as LogChannelEvent;
                    break;
                case "ManagerEvent":
                    ManagerEvent managerevent = e;
                    break;
                case "MeetmeEndEvent":
                    MeetmeEndEvent meetmeend = e as MeetmeEndEvent;
                    break;
                case "MeetmeJoinEvent":
                    MeetmeJoinEvent meetmejoin = e as MeetmeJoinEvent;
                    break;
                case "MeetmeLeaveEvent":
                    MeetmeLeaveEvent meetmeleave = e as MeetmeLeaveEvent;
                    break;
                case "MeetmeMuteEvent":
                    MeetmeMuteEvent meetmemute = e as MeetmeMuteEvent;
                    break;
                case "MeetmeStopTalkingEvent":
                    MeetmeStopTalkingEvent meetmestoptalking = e as MeetmeStopTalkingEvent;
                    break;
                case "MeetmeTalkingEvent":
                    MeetmeTalkingEvent meetmetalking = e as MeetmeTalkingEvent;
                    break;
                case "MeetmeTalkRequestEvent":
                    MeetmeTalkRequestEvent meetmetalkrequest = e as MeetmeTalkRequestEvent;
                    break;
                case "MessageWaitingEvent":
                    MessageWaitingEvent messagewaiting = e as MessageWaitingEvent;
                    log.Debug("Message waiting event: " + messagewaiting.ToString());
                    lc = getLineControl(messagewaiting.Mailbox.Substring(0, messagewaiting.Mailbox.IndexOf("@")));
                    if (lc != null)
                    {
                        if (messagewaiting.Waiting > 0)
                        {
                            lc.mwiOn = true;
                        }
                        else
                        {
                            lc.mwiOn = false;
                        }
                        ss.SetLineControl(lc);
                    }
                    break;
                case "MobileStatusEvent":
                    MobileStatusEvent mobilestatus = e as MobileStatusEvent;
                    break;
                case "ModuleLoadReportEvent":
                    ModuleLoadReportEvent moduleload = e as ModuleLoadReportEvent;
                    break;
                case "MonitorStartEvent":
                    MonitorStartEvent monitorstart = e as MonitorStartEvent;
                    break;
                case "MonitorStopEvent":
                    MonitorStopEvent monitorstop = e as MonitorStopEvent;
                    break;
                case "NewAccountCodeEvent":
                    NewAccountCodeEvent newaccountcode = e as NewAccountCodeEvent;
                    break;
                case "NewCallerIdEvent":
                    NewCallerIdEvent newcallerid = e as NewCallerIdEvent;
                    log.Debug("New caller id envent: " + newcallerid.ToString());
                    break;
                case "NewChannelEvent":
                    NewChannelEvent newchannel = e as NewChannelEvent;
                    log.Debug("New Channel event: " + newchannel.ToString());
                    CommandAction ca = new CommandAction("core show channel " + newchannel.Channel);
                    CommandResponse cr = (CommandResponse)manager.SendAction(ca, 10000);
                    log.Debug("Channel info: " + cr.ToString());
                    string dn = newchannel.CallerIdNum;
                    log.Debug("Retreive call information...");
                    bool callerIdUnknown = true;
                    if (newchannel.CallerIdNum != "<unknown>")
                    {
                        callerIdUnknown = false;
                    }
                    else
                    {
                        foreach (string s in cr.Result)
                        {
                            if (s.Contains("Caller ID:"))
                            {
                                dn = s.Substring(s.LastIndexOf(" "));
                                break;
                            }
                        }
                    }
                    Call newOutboundCall = getOutboundCallFromChannelInfo(cr.Result, callerIdUnknown);
                    if (newOutboundCall != null)
                    {
                        Call missedCall = newOutboundCall;
                        AddCallLogs(dn, newOutboundCall);
                        dnToFind = newOutboundCall.callee;
                        if (linecontrols.Find(FindLineControl) != null)
                        {
                            
                            log.Debug("This call will be put in missedcall cache: " + missedCall.callId);
                            missedCall.type = CallType.missed;
                            missedCalls.Add(missedCall);
                        }
                        
                    }
                    break;
                case "NewExtenEvent":
                    NewExtenEvent newexten = e as NewExtenEvent;
                    log.Debug("New exten event: " + newexten.ToString());
                    string channel = "";
                    char[] splitter = { '/' };
                    string[] splitchannel = newexten.Channel.Split(splitter);
                    splitter[0] = '-';
                    splitchannel = splitchannel[1].Split(splitter);
                    channel = splitchannel[0];
                    //DND?
                    if (newexten.Extension == Properties.Settings.Default.FeatureCodeDNDToggle && newexten.Application == "Playback")
                    {
                        switch (newexten.AppData)
                            {
                                case "do-not-disturb&activated":
                                    log.Debug("Successfully activate dnd for channel: " + channel);
                                    ss.SetLineControl(setLineControlDND(channel, true));
                                    break;
                                case "do-not-disturb&de-activated":
                                    log.Debug("Successfully deactivate dnd for channel: " + channel);
                                    ss.SetLineControl(setLineControlDND(channel, false));
                                    break;
                            }
                    }
                        //Forward all?
                    else if (newexten.Extension.Contains(Properties.Settings.Default.FeatureCodeCallForwardAllActivate) && newexten.Application == "Playback" && newexten.AppData == "call-fwd-unconditional&for&extension") 
                    {
                        string forward = newexten.Extension.Substring(Properties.Settings.Default.FeatureCodeCallForwardAllActivate.Length);
                        log.Debug("Call forward all from channel: " + channel + " to " + forward);
                        ss.SetLineControl(setLineControlForward(channel, forward));
                    }
                    // UnForwardAll
                    else if (newexten.Extension == Properties.Settings.Default.FeatureCodeCallForwardAllDeactivate && newexten.Application == "Playback" && newexten.AppData == "call-fwd-unconditional&de-activated")
                    {
                        log.Debug("Call unforward all from channel: " + channel);
                        ss.SetLineControl(setLineControlForward(channel,""));
                    }
                    break;
                case "NewStateEvent":
                    NewStateEvent newstate = e as NewStateEvent;
                    log.Debug("New State event: " + newstate.ToString());
                    LineControl newstateLc = getLineControl(newstate.CallerId);
                    LineControlConnection[] newStateLccs = null;
                    int i = 0;
                    if (newstateLc.lineControlConnection != null)
                    {
                        bool isContained = false;
                        foreach (LineControlConnection elcc in newstateLc.lineControlConnection)
                        {
                            if (elcc.callid == newstate.Channel)
                            {
                                isContained = true;
                                newStateLccs = newstateLc.lineControlConnection;
                                break;
                            }
                            i++;
                        }
                        if (!isContained)
                        {
                            i = 0;
                            newStateLccs = new LineControlConnection[newstateLc.lineControlConnection.Length + 1];
                            foreach (LineControlConnection newstateLcc in newstateLc.lineControlConnection)
                            {
                                newStateLccs[i] = newstateLcc;
                                i++;
                            }
                        }
                    }
                    else
                    {
                        newStateLccs = new LineControlConnection[1];
                        newStateLccs[0] = new LineControlConnection();
                    }
                    try
                    {
                        switch (newstate.State)
                        {
                            case "Up":
                                //received call?
                                callToFind = newstate.UniqueId;
                                Call rCall = missedCalls.Find(FindCall);
                                if (rCall != null)
                                {
                                    log.Debug("Missed call finded: " + callToFind + ", this call will be received");
                                    rCall.type = CallType.received;
                                    AddCallLogs(rCall.callee, rCall);
                                    missedCalls.Remove(rCall);
                                }
                                if (newStateLccs != null)
                                {
                                    if (!channels.Contains(newstate.Channel))
                                    {
                                        channels.Add(newstate.Channel, newstate.CallerId);
                                    }
                                    newStateLccs[i].callid = newstate.Channel;
                                    newStateLccs[i].remoteState = Wybecom.TalkPortal.CTI.Proxy.ConnectionState.established;
                                    newStateLccs[i].state = Wybecom.TalkPortal.CTI.Proxy.ConnectionState.established;
                                    newStateLccs[i].terminalState = TerminalState.talking;
                                }
                                break;
                            case "Ringing":
                                if (newStateLccs != null)
                                {
                                    if (!channels.Contains(newstate.Channel))
                                    {
                                        channels.Add(newstate.Channel, newstate.CallerId);
                                    }
                                    newStateLccs[i].callid = newstate.Channel;
                                    newStateLccs[i].remoteState = Wybecom.TalkPortal.CTI.Proxy.ConnectionState.established;
                                    newStateLccs[i].state = Wybecom.TalkPortal.CTI.Proxy.ConnectionState.alerting;
                                    newStateLccs[i].terminalState = TerminalState.ringing;
                                }
                                break;
                            case "Ring":
                                if (newStateLccs != null)
                                {
                                    if (!channels.Contains(newstate.Channel))
                                    {
                                        channels.Add(newstate.Channel, newstate.CallerId);
                                    }
                                    newStateLccs[i].callid = newstate.Channel;
                                    newStateLccs[i].remoteState = Wybecom.TalkPortal.CTI.Proxy.ConnectionState.alerting;
                                    newStateLccs[i].state = Wybecom.TalkPortal.CTI.Proxy.ConnectionState.dialing;
                                    newStateLccs[i].terminalState = TerminalState.inuse;
                                }
                                break;
                        }
                    }
                    catch (Exception stateException)
                    {
                        log.Debug("NewState exception: " + stateException.Message);
                    }
                    if (newstateLc != null)
                    {
                        newstateLc.lineControlConnection = newStateLccs;
                        ss.SetLineControl(newstateLc);
                    }
                    break;
                case "OriginateResponseEvent":
                    OriginateResponseEvent originateresponse = e as OriginateResponseEvent;
                    break;
                case "ParkedCallEvent":
                    ParkedCallEvent parkedcall = e as ParkedCallEvent;
                    break;
                case "ParkedCallGiveUpEvent":
                    ParkedCallGiveUpEvent parkedcallgiveup = e as ParkedCallGiveUpEvent;
                    break;
                case "ParkedCallsCompleteEvent":
                    ParkedCallsCompleteEvent parkedcallscomplete = e as ParkedCallsCompleteEvent;
                    break;
                case "ParkedCallTimeOutEvent":
                    ParkedCallTimeOutEvent parkedcalltimeout = e as ParkedCallTimeOutEvent;
                    break;
                case "PeerEntryEvent":
                    log.Debug("SipAction: one peer entry event received, " + e.ToString());
                    PeerEntryEvent peerentry = e as PeerEntryEvent;
                    peers.Add(peerentry);
                    ss.SetLineControl(getLineControlFromPeerEntry(peerentry));
                    break;
                case "PeerlistCompleteEvent":
                    log.Debug("SipAction: peer list completed " + e.ToString());
                    PeerlistCompleteEvent peerlistcomplete = e as PeerlistCompleteEvent;
                    acs.setPeers(peers);
                    break;
                case "PeerStatusEvent":
                    PeerStatusEvent peerstatus = e as PeerStatusEvent;
                    log.Debug("Peer status: " + peerstatus.ToString());
                    break;
                case "PRIEvent":
                    PRIEvent pri = e as PRIEvent;
                    break;
                case "RegistryEvent":
                    RegistryEvent registry = e as RegistryEvent;
                    break;
                case "ReloadEvent":
                    ReloadEvent reload = e as ReloadEvent;
                    break;
                case "RenameEvent":
                    RenameEvent rename = e as RenameEvent;
                    break;
                case "ResponseEvent":
                    ResponseEvent response = e as ResponseEvent;
                    break;
                case "RTCPReceivedEvent":
                    RTCPReceivedEvent rtcpreceived = e as RTCPReceivedEvent;
                    break;
                case "RTCPSentEvent":
                    RTCPSentEvent rtcpsent = e as RTCPSentEvent;
                    break;
                case "RTPReceiverStatEvent":
                    RTPReceiverStatEvent rtpreceiver = e as RTPReceiverStatEvent;
                    break;
                case "RTPSenderStatEvent":
                    RTPSenderStatEvent rtpsender = e as RTPSenderStatEvent;
                    break;
                case "ShowDialPlanCompleteEvent":
                    ShowDialPlanCompleteEvent showdialplan = e as ShowDialPlanCompleteEvent;
                    break;
                case "ShutdownEvent":
                    ShutdownEvent shutdown = e as ShutdownEvent;
                    break;
                case "StatusCompleteEvent":
                    StatusCompleteEvent statuscomplete = e as StatusCompleteEvent;
                    break;
                case "StatusEvent":
                    StatusEvent status = e as StatusEvent;
                    break;
                case "TransferEvent":
                    TransferEvent transfer = e as TransferEvent;
                    break;
                case "UnholdEvent":
                    UnholdEvent unhold = e as UnholdEvent;
                    break;
                case "UnknownEvent":
                    UnknownEvent unknown = e as UnknownEvent;
                    break;
                case "UnlinkEvent":
                    UnlinkEvent unlink = e as UnlinkEvent;
                    log.Debug("Unlink event : " + unlink.ToString());
                    LineControlConnection[] lccs = null;
                    i = 0;
                    lc = getLineControl(unlink.CallerId1);
                    if (lc != null)
                    {
                        if (lc.lineControlConnection.Length > 1)
                        {
                            lccs = new LineControlConnection[lc.lineControlConnection.Length - 1];
                            foreach (LineControlConnection linklcc in lc.lineControlConnection)
                            {
                                if (linklcc.callid != unlink.Channel1)
                                {
                                    lccs[i] = linklcc;
                                    i++;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            lc.lineControlConnection = null;
                        }
                        ss.SetLineControl(lc);
                    }
                    i = 0;
                    lc = getLineControl(unlink.CallerId2);
                    if (lc != null)
                    {
                        if (lc.lineControlConnection.Length > 1)
                        {
                            lccs = new LineControlConnection[lc.lineControlConnection.Length - 1];
                            foreach (LineControlConnection linklcc in lc.lineControlConnection)
                            {
                                if (linklcc.callid != unlink.Channel2)
                                {
                                    lccs[i] = linklcc;
                                    i++;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            lc.lineControlConnection = null;
                        }
                        ss.SetLineControl(lc);
                    }
                    break;
                case "UnparkedCallEvent":
                    UnparkedCallEvent unparked = e as UnparkedCallEvent;
                    break;
                case "UserEvent":
                    UserEvent user = e as UserEvent;
                    break;
                case "VarSetEvent":
                    VarSetEvent varset = e as VarSetEvent;
                    break;
                case "ZapShowChannelsCompleteEvent":
                    ZapShowChannelsCompleteEvent zapshowchannelscomplete = e as ZapShowChannelsCompleteEvent;
                    break;
                case "ZapShowChannelsEvent":
                    ZapShowChannelsEvent zapshowchannels = e as ZapShowChannelsEvent;
                    break;
            }
            //ACDConnector
            switch (e.GetType().Name)
            {
                case "AgentCallbackLoginEvent":
                    AgentCallbackLoginEvent agentcallbacklogin = e as AgentCallbackLoginEvent;
                    break;
                case "AgentCallbackLogoffEvent":
                    AgentCallbackLogoffEvent agentcallbacklogoff = e as AgentCallbackLogoffEvent;
                    break;
                case "AgentCalledEvent":
                    AgentCalledEvent agentcalled = e as AgentCalledEvent;
                    break;
                case "AgentCompleteEvent":
                    AgentCompleteEvent agentcomplete = e as AgentCompleteEvent;
                    break;
                case "AgentConnectEvent":
                    AgentConnectEvent agentconnect = e as AgentConnectEvent;
                    break;
                case "AgentDumpEvent":
                    AgentDumpEvent agentdump = e as AgentDumpEvent;
                    break;
                case "AgentLoginEvent":
                    AgentLoginEvent agentlogin = e as AgentLoginEvent;
                    break;
                case "AgentLogoffEvent":
                    AgentLogoffEvent agentlogoff = e as AgentLogoffEvent;
                    break;
                case "AgentsCompleteEvent":
                    AgentsCompleteEvent agentscomplete = e as AgentsCompleteEvent;
                    break;
                case "AgentsEvent":
                    AgentsEvent agentevent = e as AgentsEvent;
                    break;
                case "QueueCallerAbandonEvent":
                    QueueCallerAbandonEvent queuecallerabandon = e as QueueCallerAbandonEvent;
                    break;
                case "QueueEntryEvent":
                    QueueEntryEvent queueentry = e as QueueEntryEvent;
                    break;
                case "QueueEvent":
                    QueueEvent queue = e as QueueEvent;
                    break;
                case "QueueMemberEvent":
                    QueueMemberEvent queuemember = e as QueueMemberEvent;
                    break;
                case "QueueMemberPausedEvent":
                    QueueMemberPausedEvent queuememberpaused = e as QueueMemberPausedEvent;
                    break;
                case "QueueMemberPenaltyEvent":
                    QueueMemberPenaltyEvent queuememberpenalty = e as QueueMemberPenaltyEvent;
                    break;
                case "QueueMemberRemovedEvent":
                    QueueMemberRemovedEvent queuememberremoved = e as QueueMemberRemovedEvent;
                    break;
                case "QueueMemberStatusEvent":
                    QueueMemberStatusEvent queuememberstatus = e as QueueMemberStatusEvent;
                    break;
                case "QueueParamsEvent":
                    QueueParamsEvent queueparams = e as QueueParamsEvent;
                    break;
                case "QueueStatusCompleteEvent":
                    QueueStatusCompleteEvent queuestatuscomplete = e as QueueStatusCompleteEvent;
                    break;
            }
        }