SIPSorcery.AppServer.DialPlan.DialPlanEngine.Execute C# (CSharp) Method

Execute() public method

public Execute ( DialPlanContext dialPlanContext, ISIPServerUserAgent uas, SIPCallDirection callDirection, DialogueBridgeCreatedDelegate createBridgeDelegate, ISIPCallManager callManager ) : void
dialPlanContext DialPlanContext
uas ISIPServerUserAgent
callDirection SIPCallDirection
createBridgeDelegate DialogueBridgeCreatedDelegate
callManager ISIPCallManager
return void
        public void Execute(
            DialPlanContext dialPlanContext,
            ISIPServerUserAgent uas,
            SIPCallDirection callDirection,
            DialogueBridgeCreatedDelegate createBridgeDelegate,
            ISIPCallManager callManager)
        {
            if (dialPlanContext == null)
            {
                throw new ArgumentNullException("The DialPlanContext parameter cannot be null when attempting to execute a dialplan.");
            }

            if (uas.IsUASAnswered)
            {
                // This can occur if the call is cancelled by the caller between when the INVITE was received and when the dialplan execution was ready.
                logger.Warn("Dialplan execution for " + dialPlanContext.SIPDialPlan.DialPlanName + " for " + uas.CallDirection + " call to " + uas.CallDestination + " did not proceed as call already answered.");
                dialPlanContext.DialPlanExecutionFinished();
            }
            else
            {
                if (dialPlanContext.ContextType == DialPlanContextsEnum.Line)
                {
                    ThreadPool.QueueUserWorkItem(delegate { ExecuteDialPlanLine((DialPlanLineContext)dialPlanContext, uas, callDirection, createBridgeDelegate, callManager); });
                }
                else
                {
                    ExecuteDialPlanScript((DialPlanScriptContext)dialPlanContext, uas, callDirection, createBridgeDelegate, callManager);
                }
            }
        }

Usage Example

        /// <summary>
        /// Executes a new instance of the current dialplan as a result of receiving a redirect response.
        /// </summary>
        public void ExecuteDialPlanForRedirect(SIPResponse redirectResponse)
        {
            SIPURI redirectURI = redirectResponse.Header.Contact[0].ContactURI;

            if (m_hasBeenRedirected)
            {
                FireProxyLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Redirect response to " + redirectURI.ToString() + " rejcted, only a single redirect dialplan execution allowed.", Owner));
            }
            else
            {
                m_hasBeenRedirected = true;
                FireProxyLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Redirect response to " + redirectURI.ToString() + " accepted, new dialplan execution commencing.", Owner));

                m_redirectResponse = redirectResponse;
                m_redirectURI      = redirectURI;

                m_dialPlanEngine.Execute(this, m_sipServerUserAgent, SIPCallDirection.Redirect, CreateBridge_External, null);
            }
        }