private void ExecuteScript(
DialPlanExecutingScript executingScript,
DialPlanContext dialPlanContext,
DialPlanScriptFacade planFacade,
string script)
{
try
{
Thread.CurrentThread.Name = "dialplanscript-" + executingScript.ScriptNumber;
if (m_impersonationUsername != null && m_impersonationPassword != null)
{
WrapperImpersonationContext impersonationConext = new WrapperImpersonationContext(null, m_impersonationUsername, m_impersonationPassword);
impersonationConext.Enter();
}
//logger.Debug(Thread.CurrentThread.Name + " identity=" + WindowsIdentity.GetCurrent().Name + ".");
FireProxyLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Dial plan execution starting on thread " + Thread.CurrentThread.Name + " for " + dialPlanContext.Owner + ".", null));
executingScript.DialPlanScriptEngine.Execute(script, executingScript.DialPlanScriptScope);
//FireProxyLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Dial plan execution finished after full script run on thread " + Thread.CurrentThread.Name + " for " + dialPlanContext.Owner + ".", null));
}
catch (ApplicationException appExcp)
{
if (appExcp.Message != "Script was halted by external intervention.")
{
logger.Error("ApplicationException ExecuteScript. " + appExcp.Message);
FireProxyLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "There was an exception executing your dial plan script: " + appExcp.Message, executingScript.Owner));
FireProxyLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "ApplicationException on user " + executingScript.Owner + "'s dial plan script. " + appExcp.Message, null));
executingScript.ExecutionError = appExcp.Message;
}
else
{
FireProxyLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Dial plan execution finished after being halted due to execution interrupt on thread " + Thread.CurrentThread.Name + " for " + dialPlanContext.Owner + ".", null));
}
}
//catch (System.Scripting.SyntaxErrorException)
catch (SyntaxErrorException syntaxExcp)
{
logger.Warn("SyntaxErrorException. Owner=" + dialPlanContext.Owner + ", DialPlanName=" + dialPlanContext.SIPDialPlan.DialPlanName + ", Line=" + syntaxExcp.Line + ".");
FireProxyLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "There was a syntax error in your dial plan on line " + syntaxExcp.Line + ", please check.", executingScript.Owner));
executingScript.ExecutionError = "Dial plan syntax error";
}
catch (MissingMethodException missingExcp)
{
logger.Warn("MissingMethodException. " + missingExcp.Message);
FireProxyLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "There was a missing method exception in your dial plan: " + missingExcp.Message + ".", executingScript.Owner));
executingScript.ExecutionError = "Dial plan missing method";
}
catch (ThreadAbortException) { }
catch (Exception excp)
{
logger.Error("Exception ExecuteScript (" + excp.GetType() + "). " + excp.Message);
FireProxyLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "There was an exception executing your dial plan script: " + excp.Message, executingScript.Owner));
FireProxyLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Exception on user " + executingScript.Owner + "'s dial plan script (" + excp.GetType() + "). " + excp.Message, null));
executingScript.ExecutionError = "Dial plan exception";
}
finally
{
executingScript.StopExecution();
}
}