/// <summary>
        /// This is a required override,
        /// This method is called by UII to Set the low level interface for CTI.
        /// This interface is also used to initialize the AgentState and CallState Managers
        /// </summary>
        /// <param name="ctiRoot">Pointer to the UII Cti Base Object</param>
        public override void SetRootCtiInterface(ICtiControl ctiRoot)
        {
            // Set up the AgentState Manager, and Set the internal UII Object Agent State object.
            localAgentStateManager = new AgentStateManager(ctiRoot);
            AgentStateManager      = (ICtiAgentStateManager)localAgentStateManager;

            // Set up the CallState Manager, and Set the internal UII Object Call State object.
            localCallStateManager = new CallStateManager(ctiRoot);
            CallStateManager      = (ICtiCallStateManager)localCallStateManager;

            // Wire base events for call management.
            if (CallStateManager != null)
            {
                CallStateManager.EnableAutoAnswer = true;
                CallStateManager.EnableOverrideAutoAnswerOnExistingCalls = true;
                CallStateManager.CallManagerStateNewCall += new EventHandler <NewCallEventArgs>(OnCallManagerStateNewCall);
                CallStateManager.CallManagerStateUpdate  += new EventHandler <CtiCallEventArgs>(OnCallManagerStateUpdate);
            }
            base.SetRootCtiInterface(ctiRoot);
        }
        /// <summary>
        /// This event is raised when a session is closed.
        /// in the case there is an Active call, the desktop manager can get in the way of the session close event
        ///    and determine if any action needs to be taken.
        /// For example, writing a Call Wrap Event to an Audit log
        /// </summary>
        /// <param name="session">Session that is being closed. </param>
        /// <returns>True allows the session to close,  false prevents the session from closing</returns>
        private bool localSessionManager_SessionCloseEvent(Session session)
        {
            try
            {
                if (session != null)
                {
                    // Blocking Command here
                    // Get a copy of the current session.
                    AgentDesktopSession aSess = (AgentDesktopSession)session;
                    // Get a handle to the Context that is in that session
                    Context lastSessionClosedContext = aSess.AppHost.GetContext();

                    // if there is a call on this session
                    if (aSess.CtiCallRefId != Guid.Empty)
                    {
                        // Check to see if there is a secondary call on the same session.
                        if (aSess.CtiCallRefIdChat != Guid.Empty)
                        {
                            // if they are equivalent, they it is the same call.
                            if (aSess.CtiCallRefIdChat != aSess.CtiCallRefId)
                            {
                                // if not,
                                //   we may need to trigger a hang-up event for both the child and the parent Calls.
                                // So here,  Issue a Hang-up event
                                CallStateManager.HangUpCall(aSess.CtiCallRefIdChat);
                            }
                        }
                        // Now issue the Hang-up event to the primary call
                        CallStateManager.HangUpCall(aSess.CtiCallRefId);
                    }
                }
            }
            catch (Exception ex)
            {
                // write a log event here.
            }
            return(true);
        }