예제 #1
0
        private static bool InitAsr(ILegacyLogger i_Logger, eAsrType i_eAsrType, out IASR o_Asr)
        {
            bool bRet = true;

            o_Asr = null;
            try
            {
                switch (i_eAsrType)
                {
                case eAsrType.lumenvox:
//						bRet = Init_Lumenvox(i_Logger, out o_Asr);
                    break;

                case eAsrType.lumenvox2:
//						bRet = Init_Lumenvox2(i_Logger, out o_Asr);
                    break;

                case eAsrType.vestec:
                    i_Logger.Log(Level.Exception, "InitAsr: That ASR is not yet implemented");
                    break;

                default:
                    i_Logger.Log(Level.Exception, "InitAsr: That ASR is not yet implemented");
                    break;
                }
            }
            catch (Exception exc)
            {
                bRet = false;
                i_Logger.Log(Level.Exception, "InitAsr caught exception: " + exc.ToString());
            }

            return(bRet);
        }
        public bool Log(Level i_Level, string i_sLogStr)
        {
            bool bRet = true;

            try
            {
                if (i_sLogStr != m_sLastLog)                            // This reference compare doesn't seem to work on Mono, there must be a problem with their hashtable.
                //if(i_sLogStr.CompareTo(m_sLastLog) != 0)	// This is a more expensive operation...
                {
                    // Been having an issue with AudioMgr logs stopping, so write non-LV exceptions to stderr, so we don't miss them.
                    // Skipping LV errors, because when testing with more ports than licenses will flood us with known errors.
                    if (((i_Level == Level.Exception) || (i_Level == Level.Warning)) && (i_sLogStr.IndexOf("LV_SRE") == -1) && (i_sLogStr.IndexOf("Didn't get any results") == -1))
                    {
                        Console.Error.WriteLine(DateTime.Now.ToString() + " " + i_sLogStr);
                    }

                    // Log to logger(s)
                    m_Logger.Log(i_Level, i_sLogStr);
                    m_sLastLog = i_sLogStr;
                }
            }
            catch (Exception exc)
            {
                bRet = false;
                Console.Error.WriteLine(DateTime.Now.ToString() + " ARMsgListenerThread.Log exception: " + exc.ToString());
            }

            return(bRet);
        }
예제 #3
0
        /// <summary>
        /// Retrieves the document from the requested URL.  (We're assuming that it is XML.)
        /// </summary>
        /// <param name="i_sURL">URL of the requested document.</param>
        /// <param name="o_sXml">String containing the document.</param>
        /// <returns></returns>
        public static bool GetXmlString(ILegacyLogger i_Logger, string i_sURL, out string o_sXml)
        {
            bool bRet = true;

            o_sXml = "";                // Had to be moved before try{} to shut compiler up.

            try
            {
                WebRequest  wrReq  = WebRequest.Create(new Uri(i_sURL));
                WebResponse wrResp = wrReq.GetResponse();

                using (StreamReader srXml = new StreamReader(wrResp.GetResponseStream(), Encoding.UTF8))
                {
                    o_sXml = srXml.ReadToEnd();
                }

                i_Logger.Log(Level.Info, String.Format("XmlDocParser.GetXmlString({0}) read {1} chars.", i_sURL, o_sXml.Length));
            }
            catch (Exception e)
            {
                bRet = false;
                i_Logger.Log(Level.Exception, String.Format("ERROR: XmlDocParser.GetXmlString({0}) caught exception '{1}'.", i_sURL, e.ToString()));
            }

            return(bRet);
        }
예제 #4
0
        }                                                                // UdpMsgListenerThread contstructor

        public void ThreadProc()
        {
            Thread.CurrentThread.Name = "LRMListenerT";
            m_Logger.Init(m_IPEndPoint.Address.ToString(), "", Thread.CurrentThread.Name, "", "", "");
            m_Logger.Log(Level.Verbose, "UdpMsgListenerThread started.");

            NetLoop();

            m_Logger.Log(Level.Verbose, "UdpMsgListenerThread exiting.");
        }         // ThreadProc
예제 #5
0
        public static string ScriptExtractElement(ILegacyLogger i_Logger, string i_sVmcId, string i_sStatement)
        {
            string sRet = "", sTmp = "";
            int    ii = 0, iIndexStop = 0;
            bool   bDone = false;
            char   cQuote;

            try
            {
                sTmp = i_sStatement.Trim();
                if ((sTmp[0] == '\'') || (sTmp[0] == '\"'))
                {
                    cQuote = sTmp[0];

                    for (ii = 1, bDone = false; ((ii < sTmp.Length) && (!bDone)); ii++)
                    {
                        if (sTmp[ii] == cQuote)
                        {
                            iIndexStop = ii;
                            bDone      = true;
                        }
                    }

                    if (!bDone)
                    {
                        i_Logger.Log(Level.Warning, "[" + i_sVmcId + "]" + "DialogEngine.ScriptExtractElement - Malformed quoted string '" + i_sStatement + "'.");
                        sRet = sTmp;
                    }
                    else
                    {
                        //sRet = sTmp.Substring(1, iIndexStop - 1);		// Return string without quotes
                        sRet = sTmp.Substring(0, iIndexStop + 1);                                               // Return string with quotes
                    }
                }
                else
                {
                    iIndexStop = sTmp.IndexOfAny(DialogEngine.VoiceXmlParser.s_acBreakNonVar);
                    if (iIndexStop < 0)
                    {
                        sRet = sTmp;
                    }
                    else
                    {
                        sRet = sTmp.Substring(0, iIndexStop);
                    }
                }
            }
            catch (Exception exc)
            {
                sRet = "";
                i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptExtractElement: " + exc.ToString());
            }

            return(sRet);
        }
예제 #6
0
        private static bool LoadCustomAssemblies(ILegacyLogger i_Logger)
        {
            bool             bRet = true, bRes = true;
            string           sConfigLine = "";
            StringCollection asCustAssys = null;
            Assembly         aAssy       = null;

            try
            {
                sConfigLine = ConfigurationManager.AppSettings["CustomAssemblies"];
                sConfigLine = (sConfigLine == null) ? "" : sConfigLine;
                if (sConfigLine.Length > 0)
                {
                    asCustAssys = new StringCollection();
                    bRes        = Utilities.GetItemsFromString(sConfigLine, ';', asCustAssys);
                    if (bRes)
                    {
                        foreach (string sAssyName in asCustAssys)
                        {
                            try
                            {
                                aAssy = Assembly.Load(sAssyName);                                       // Note: there is no corresponding 'Unload' in the FCL.  See http://www.google.com/search?as_q=assembly+unload
                                if (aAssy == null)
                                {
                                    i_Logger.Log(Level.Warning, "LoadCustomAssemblies: Load of '" + sAssyName + "' failed!");
                                }
                                else
                                {
                                    i_Logger.Log(Level.Info, "LoadCustomAssemblies: Loaded '" + aAssy.FullName + "' from '" + aAssy.Location + "'.");
                                }
                            }
                            catch (Exception exc)
                            {
                                i_Logger.Log(Level.Warning, "LoadCustomAssemblies: Load of '" + sAssyName + "' failed!  Exception: " + exc.ToString());
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                bRet = false;
                //Console.Error.WriteLine("ERROR DialogEngine.RemotingInit:  Caught exception '{0}'.", e.ToString());
                i_Logger.Log(e);
            }

            return(bRet);
        }         // LoadCustomAssemblies
예제 #7
0
        public static string ScriptExtractValue(ILegacyLogger i_Logger, string i_sVmcId, ISubdocContext i_SubdocContext, string i_sString)
        {
            string sRet = "";

            // FIX - Should also check for integers
            if ((i_sString[0] == '\"') || (i_sString[0] == '\''))
            {
                sRet = ScriptExtractStringValue(i_sString);
            }
            else
            {
                DVariable dvTmp = DialogEngine.DialogEngine.FindVariableByName(i_SubdocContext, i_sString);

                if (dvTmp == null)
                {
                    i_Logger.Log(Level.Exception, String.Format("[{0}]DialogEngine.ScriptExtractValue - Couldn't find variable named '{1}' in {2} '{3}'.", i_sVmcId, i_sString, ((i_SubdocContext.GetType() == typeof(DForm)) ? "form" : "field"), i_SubdocContext.ID));
                }
                else
                {
                    sRet = dvTmp.SValue;
                }
            }

            return(sRet);
        }
예제 #8
0
        public ResourceMgr_local(ILegacyLogger i_Logger)
        {
            int    ii;
            ISMVMC vmc;

            try
            {
                m_Logger       = i_Logger;
                m_iMaxSessions = ConfigParams.GetNumExt();

                m_VMCs = new VMCList();

                Monitor.Enter(m_Lock);

                for (ii = 0; ii < m_iMaxSessions; ii++)
                {
                    vmc = new ISMVMC();
                    vmc.Clear();
                    m_VMCs.Add(new VMCInfo(ref vmc));
                }
            }
            catch (Exception exc)
            {
                m_Logger.Log(Level.Exception, "RMl ctor caught exception: " + exc.ToString());
            }
            finally
            {
                Monitor.Exit(m_Lock);
            }
        }         // ctor
예제 #9
0
        private static bool RemotingConfig(ILegacyLogger i_Logger)
        {
            bool bRet = true;
            //string		sHostCfgFile, sAECfgFile;
            string sTmp;

            try
            {
                /* Mono doesn't yet support reading remoting config files (as of 1.1.10).  Change this back when they do.
                 * // Load the server configuration file
                 * sHostCfgFile = "DialogMgr_host.Config";
                 * RemotingConfiguration.Configure(sHostCfgFile);
                 *
                 * // Load the client configuration files
                 * sAECfgFile = "AudioEngine_client.Config";			// The AudioEngine config file
                 * RemotingConfiguration.Configure(sAECfgFile);
                 */

                // Mono compatible remoting configuration
                // Server config
                sTmp = ConfigurationManager.AppSettings["RemotingServerPort"];
                sTmp = (sTmp == null) ? "" : sTmp;
                if (sTmp.Length <= 0)
                {
                    bRet = false;
                    i_Logger.Log(Level.Exception, "DialogMgr.RemotingConfig: Invalid 'RemotingServerPort'.");
                }
                else
                {
                    ChannelServices.RegisterChannel(new TcpChannel(int.Parse(sTmp)), false);
                    RemotingConfiguration.RegisterWellKnownServiceType(typeof(DialogMgr_Console.DMMessaging), "DialogMgr.rem", WellKnownObjectMode.SingleCall);

                    // Client config
                    sTmp = ConfigurationManager.AppSettings["RemotingAudioMgrUrl"];
                    RemotingConfiguration.RegisterWellKnownClientType(typeof(ISMessaging.Delivery.ISMReceiverImpl), sTmp);
                }
            }
            catch (Exception exc)
            {
                i_Logger.Log(Level.Exception, "DialogMgr.RemotingConfig: Exception:" + exc.ToString());
                bRet = false;
            }

            return(bRet);
        }
예제 #10
0
 private void Log(Level i_Level, string i_sMessage)
 {
     if (m_Logger != null)
     {
         m_Logger.Log(i_Level, i_sMessage);
     }
     else
     {
         Console.Error.WriteLine(String.Format("{0} {1}: {2}", DateTime.Now, i_Level, i_sMessage));
     }
 }
예제 #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="i_Level"></param>
 /// <param name="i_sLogStr"></param>
 /// <returns></returns>
 public void Log(Level i_Level, string i_sLogStr)
 {
     if (m_Logger != null)
     {
         m_Logger.Log(i_Level, i_sLogStr);
     }
     else
     {
         Console.Error.WriteLine($"[{DateTime.Now}] AMSockData: {i_sLogStr}");
     }
 }
예제 #12
0
 private void Log(Level i_Level, string i_sMessage)
 {
     if (m_Logger != null)
     {
         m_Logger.Log(i_Level, String.Format("[{0}]{1} - {2}", m_iThreadIndex, m_sTimerName, i_sMessage));
     }
     else
     {
         Console.Error.WriteLine(String.Format("{0} {1} [{2}]{3} - {4}", DateTime.Now, i_Level, m_iThreadIndex, m_sTimerName, i_sMessage));
     }
 }
예제 #13
0
        public void ThreadProc()
        {
            string sThreadName = Thread.CurrentThread.Name = m_iIndex.ToString();

//			m_Log.Init("", "", m_iIndex.ToString(), "", "LoggingThread", "");
//			m_Log.Init("", "", sThreadName, "VMC-" + sThreadName, "LoggingThread", "");
            m_Log.Init("", "", sThreadName, "VMC-" + sThreadName, "", "");                              // Let logger look up the component name

            for (int ii = 0; ii < m_iNumIterations; ii++)
            {
                m_Log.Log(Level.Info, string.Format("Thread #{0}, iteration {1}.", sThreadName, ii));
                if (m_iSleep > 0)
                {
                    Thread.Sleep(m_iSleep);
                }
            }
        }
예제 #14
0
        }         // Start Loggers

        protected static Thread StartListenerThread(ILegacyLogger i_Logger, MsgQueue i_aqMsgIn)
        {
            Thread tRet = null;
            UdpMsgListenerThread listener = null;

            try
            {
                listener = new UdpMsgListenerThread(i_Logger, i_aqMsgIn);
                tRet     = new Thread(new ThreadStart(listener.ThreadProc));
                tRet.Start();
            }
            catch (Exception exc)
            {
                i_Logger.Log(Level.Exception, "SBLocalRM.StartListenerThread caught exception: " + exc.ToString());
            }

            return(tRet);
        }         // StartListenerThread
예제 #15
0
        }         // StartListenerThread

        protected static Thread StartWorkerThread(ILegacyLogger i_Logger, MsgQueue i_aqMsgIn, bool i_bDesktopRuntime)
        {
            Thread          tRet   = null;
            LRMWorkerThread worker = null;

            try
            {
                worker = new LRMWorkerThread(i_Logger, i_aqMsgIn, i_bDesktopRuntime);
                tRet   = new Thread(new ThreadStart(worker.ThreadProc));
                tRet.Start();
            }
            catch (Exception exc)
            {
                i_Logger.Log(Level.Exception, "SBLocalRM.StartWorkerThread caught exception: " + exc.ToString());
            }

            return(tRet);
        }         // StartWorkerThread
예제 #16
0
//		private static StringCollection ScriptGetParams(ILegacyLogger i_Logger, string i_sVmcId, DField i_dfField, string i_sParams)
        private static StringCollection ScriptGetParams(ILegacyLogger i_Logger, string i_sVmcId, ISubdocContext i_SubdocContext, string i_sParams)
        {
            StringCollection scRet = null;
            int    iIndex = 0;
            string sParams = "", sTmp = "";;

            try
            {
                sParams = i_sParams;
                scRet   = new StringCollection();

                while (sParams.Length > 0)
                {
                    iIndex = sParams.IndexOf(',');
                    if (iIndex < 0)
                    {
                        sTmp    = sParams;
                        sParams = "";
                    }
                    else
                    {
                        sTmp    = sParams.Substring(0, iIndex);
                        sParams = sParams.Substring(iIndex + 1).Trim();
                    }

                    sTmp.Trim();
                    sTmp = ScriptExtractValue(i_Logger, i_sVmcId, i_SubdocContext, sTmp);

                    scRet.Add(sTmp);
                }
            }
            catch (Exception exc)
            {
                i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptGetParams: " + exc.ToString());
            }

            return(scRet);
        }
예제 #17
0
        private static bool RemotingConfig(ILegacyLogger i_Logger)
        {
            //string				sHostCfgFile, sDMCfgFile;
            bool   bRet = true;
            string sTmp;

            try
            {
                /*
                 * // Load the server configuration file
                 * sHostCfgFile = "AudioEngine_host.Config";
                 * RemotingConfiguration.Configure(sHostCfgFile);
                 *
                 * // Load the client configuration files
                 * sDMCfgFile = "DialogMgr_client.Config";		// The DialogMgr config file
                 * RemotingConfiguration.Configure(sDMCfgFile);
                 */

                // Mono compatible remoting configuration
                // Server config
                sTmp = ConfigurationManager.AppSettings[cs_RemotingServerPort];
                sTmp = (sTmp == null) ? "" : sTmp;
                ChannelServices.RegisterChannel(new TcpChannel(int.Parse(sTmp)), false);
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(AudioMgr.AEMessaging), "AudioEngine.rem", WellKnownObjectMode.SingleCall);

                // Client config
                sTmp = ConfigurationManager.AppSettings[cs_RemotingDialogMgrUrl];
                sTmp = (sTmp == null) ? "" : sTmp;
                RemotingConfiguration.RegisterWellKnownClientType(typeof(ISMessaging.Delivery.ISMReceiverImpl), sTmp);
            }
            catch (Exception exc)
            {
                i_Logger.Log(exc);
                bRet = false;
            }

            return(bRet);
        }
예제 #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="i_Logger"></param>
        /// <returns></returns>
        public bool LoadASR(ILegacyLogger i_Logger)
        {
            bool             bRet = true, bRes = true;
            string           sConfigLine = "";
            StringCollection asASRs      = null;
            Assembly         aASR        = null;

            try
            {
                asASRs = new StringCollection();

                sConfigLine = ConfigurationManager.AppSettings[AudioEngine.cs_AsrToLoad];
                sConfigLine = (sConfigLine == null) ? "" : sConfigLine;

                if (sConfigLine.Length == 0)
                {
                    // No ASR was specified, load the default by adding it to the string collection.  (Roundabout, but didn't want to duplicate the Assembly.Load() code.)
                    i_Logger.Log(Level.Warning, string.Format(" AudioInThread.LoadASR No ASR was specified in config file, loading default '{0}'.", m_csDefaultAsr));
                    asASRs.Add(m_csDefaultAsr);
                    bRes = true;
                }
                else
                {
                    // Parse out the entries from the semicolon separated string
                    bRes = Utilities.GetItemsFromString(sConfigLine, ';', asASRs);
                }

                if (bRes)
                {
                    // FIX - This loads multiple ASR facades if specified, but will need more work to know how to handle more than one.
                    if (asASRs.Count > 1)
                    {
                        i_Logger.Log(Level.Warning, "AudioInThread.LoadASR More than one ASR in config file.");
                    }

                    foreach (string sAsrName in asASRs)
                    {
                        try
                        {
                            aASR = Assembly.Load(sAsrName);                             // Note: there is no corresponding 'Unload' in the FCL, you have to unload all appdomains that contain it.  See http://www.google.com/search?as_q=assembly+unload, http://msdn.microsoft.com/en-us/library/ms173101%28v=vs.80%29.aspx
                            if (aASR == null)
                            {
                                i_Logger.Log(Level.Exception, string.Format(" AudioInThread.LoadASR Load of '{0}' failed!", sAsrName));
                            }
                            else
                            {
                                i_Logger.Log(Level.Info, string.Format(" AudioInThread.LoadASR Loaded '{0}' from '{1}'.", aASR.FullName, aASR.Location));

                                // Save identifier to a list to be used to create instance of ASR
                                m_aASRs.Add(aASR);
                            }
                        }
                        catch (Exception exc)
                        {
                            i_Logger.Log(Level.Exception, string.Format(" AudioInThread.LoadASR Load of '{0}' failed!  Exception: {1}", sAsrName, exc.ToString()));
                        }
                    }
                }
                else
                {
                    i_Logger.Log(Level.Warning, " AudioInThread.LoadASR No ASRs in config file to load.");
                }
            }
            catch (Exception exc)
            {
                bRet = false;
                //Console.Error.WriteLine("ERROR AudioInThread.LoadASR:  Caught exception '{0}'.", e.ToString());
                i_Logger.Log(Level.Warning, string.Format(" AudioInThread.LoadASR Exception: {0}", exc.ToString()));
            }

            return(bRet);
        }         // LoadASR
예제 #19
0
        public void NewMsg(Object i_sender, ISMessaging.Delivery.ISMDistributer.ISMDistributerEventArgs i_args)
        {
            ISMessaging.ISMsg mMsg = null;

            lock (this)
            {
                try
                {
                    //Console.WriteLine("AudioMgr_srv.NewMsg received on TID {0}.", AppDomain.GetCurrentThreadId());

                    // Copy and release the original message (so that we don't have to call back to the remote client.)
                    switch (i_args.m_Msg.GetType().ToString())                                  // FIX - There has to be a better way to do this...
                    {
                    /////////////////////////////////////
                    // Audio in messages
                    case "ISMessaging.SpeechRec.ISMResults":
                    {
                        ISMessaging.SpeechRec.ISMResults mTmp, mClone;

                        mTmp   = (ISMessaging.SpeechRec.ISMResults)i_args.m_Msg;
                        mClone = (ISMessaging.SpeechRec.ISMResults)mTmp.Clone();
                        mMsg   = (ISMessaging.ISMsg)mClone;

                        m_aqAudioIn[mMsg.m_Dest.m_VMC.m_iKey].Push(mMsg);
                    }
                    break;

                    case "ISMessaging.SpeechRec.ISMLoadPhrases":
                    {
                        ISMessaging.SpeechRec.ISMLoadPhrases mTmp, mClone;

                        mTmp   = (ISMessaging.SpeechRec.ISMLoadPhrases)i_args.m_Msg;
                        mClone = (ISMessaging.SpeechRec.ISMLoadPhrases)mTmp.Clone();
                        mMsg   = (ISMessaging.ISMsg)mClone;

                        m_aqAudioIn[mMsg.m_Dest.m_VMC.m_iKey].Push(mMsg);
                    }
                    break;

                    case "ISMessaging.SpeechRec.ISMLoadGrammarFile":
                    {
                        ISMessaging.SpeechRec.ISMLoadGrammarFile mTmp, mClone;

                        mTmp   = (ISMessaging.SpeechRec.ISMLoadGrammarFile)i_args.m_Msg;
                        mClone = (ISMessaging.SpeechRec.ISMLoadGrammarFile)mTmp.Clone();
                        mMsg   = (ISMessaging.ISMsg)mClone;

                        m_aqAudioIn[mMsg.m_Dest.m_VMC.m_iKey].Push(mMsg);
                    }
                    break;

                    case "ISMessaging.Audio.ISMSetProperty":
                    {
                        ISMessaging.Audio.ISMSetProperty mTmp   = (ISMessaging.Audio.ISMSetProperty)i_args.m_Msg;
                        ISMessaging.Audio.ISMSetProperty mClone = (ISMessaging.Audio.ISMSetProperty)mTmp.Clone();
                        mMsg = mClone;

                        m_aqAudioIn[mMsg.m_Dest.m_VMC.m_iKey].Push(mMsg);
                    }
                    break;

                    /////////////////////////////////////
                    // Audio out messages
                    case "ISMessaging.Audio.ISMPlayPrompts":
                    {
                        ISMessaging.Audio.ISMPlayPrompts mTmp, mClone;

                        mTmp   = (ISMessaging.Audio.ISMPlayPrompts)i_args.m_Msg;
                        mClone = (ISMessaging.Audio.ISMPlayPrompts)mTmp.Clone();
                        mMsg   = (ISMessaging.ISMsg)mClone;

                        m_aqAudioOut[mMsg.m_Dest.m_VMC.m_iKey].Push(mMsg);
                    }
                    break;

                    /////////////////////////////////////
                    // Audio out messages
                    case "ISMessaging.Session.ISMTransferSession":
                    {
                        ISMessaging.Session.ISMTransferSession mTmp, mClone;

                        mTmp   = (ISMessaging.Session.ISMTransferSession)i_args.m_Msg;
                        mClone = (ISMessaging.Session.ISMTransferSession)mTmp.Clone();
                        mMsg   = (ISMessaging.ISMsg)mClone;

                        m_aqAudioOut[mMsg.m_Dest.m_VMC.m_iKey].Push(mMsg);
                    }
                    break;

                    // Other session messages (always Audio Out messages?)
                    case "ISMessaging.Session.ISMTerminateSession":
                    {
                        ISMessaging.Session.ISMTerminateSession mTmp, mClone;

                        mTmp   = (ISMessaging.Session.ISMTerminateSession)i_args.m_Msg;
                        mClone = (ISMessaging.Session.ISMTerminateSession)mTmp.Clone();
                        mMsg   = (ISMessaging.ISMsg)mClone;

                        m_aqAudioOut[mMsg.m_Dest.m_VMC.m_iKey].Push(mMsg);
                    }
                    break;

                    case "ISMessaging.Session.ISMTerminateSessionAfterPrompts":
                    {
                        ISMessaging.Session.ISMTerminateSessionAfterPrompts mTmp, mClone;

                        mTmp   = (ISMessaging.Session.ISMTerminateSessionAfterPrompts)i_args.m_Msg;
                        mClone = (ISMessaging.Session.ISMTerminateSessionAfterPrompts)mTmp.Clone();
                        mMsg   = (ISMessaging.ISMsg)mClone;

                        m_aqAudioOut[mMsg.m_Dest.m_VMC.m_iKey].Push(mMsg);
                    }
                    break;

                    case "ISMessaging.Session.ISMDialogManagerIdle":
                    {
                        ISMessaging.Session.ISMDialogManagerIdle mTmp, mClone;

                        mTmp   = (ISMessaging.Session.ISMDialogManagerIdle)i_args.m_Msg;
                        mClone = (ISMessaging.Session.ISMDialogManagerIdle)mTmp.Clone();
                        mMsg   = (ISMessaging.ISMsg)mClone;

                        m_aqAudioOut[mMsg.m_Dest.m_VMC.m_iKey].Push(mMsg);
                    }
                    break;

                    /////////////////////////////////////
                    // Unknown destination messages
                    case "ISMessaging.ISMsg":
                    {
                        //Console.Error.WriteLine("WARNING:  AudioMgr_Srv.NewMsg() - Message type was ISMsg.");
                        m_Logger.Log(Level.Warning, "AudioMgr_Srv.NewMsg() - Message type was ISMsg.");
                        mMsg = (ISMessaging.ISMsg)i_args.m_Msg.Clone();

                        // Where would this message go?
                    }
                    break;

                    default:
                    {
                        //Console.Error.WriteLine("ERROR:  AudioMgr_Srv.NewMsg() - Message type was not recognized: '{0}'.", i_args.m_Msg.GetType().ToString());
                        m_Logger.Log(Level.Exception, "AudioMgr_Srv.NewMsg() - Message type was not recognized: " + i_args.m_Msg.GetType().ToString());
                    }
                    break;
                    }                     // switch

                    // Release remote object
                    i_args = null;
                }
                catch (Exception exc)
                {
                    m_Logger.Log(Level.Exception, "AudioMgr_Srv.NewMsg() caught exception: " + exc.ToString());
                }
            }             // lock
        }
예제 #20
0
        }         // GetMaxSessions

        public virtual int GetNumSessions()
        {
            int iRes = 0;

            try
            {
                // Probably unnecessary to lock, but just in case...
                Monitor.Enter(m_Lock);
                iRes = m_iNumSessions;
            }
            catch (Exception exc)
            {
                m_Logger.Log(Level.Exception, "RMl GetNumSessions caught exception: " + exc.ToString());
            }
            finally
            {
                Monitor.Exit(m_Lock);
            }

            return(iRes);
        }         // GetNumSessions
예제 #21
0
        }         // LRMWorkerThread constructor

        public void ThreadProc()
        {
            string sTmp = "";
            bool   bRes = true;

            Thread.CurrentThread.Name = "LRMWorkerT";
            m_Logger.Init("", "", Thread.CurrentThread.Name, "", "", "");
            m_Logger.Log(Level.Verbose, "LRMWorkerThread started.");

            // Check cfg file if we are to auto-start
            sTmp = ConfigurationManager.AppSettings["AutoStart"];
            if (sTmp.ToLower() == true.ToString().ToLower())
            {
                bRes = StartSBComponents();
            }

            MsgLoop();

            m_Logger.Log(Level.Verbose, "LRMWorkerThread exiting.");
        }         // ThreadProc
예제 #22
0
        /// <summary>
        /// Parses the XML into a more easily accessible node tree.
        /// </summary>
        /// <param name="i_sFileName">The file from which XML was obtained (used for error reporting only).</param>
        /// <param name="i_sXml">The XML string</param>
        /// <param name="io_xeRootElem">The root node of the tree.</param>
        public static bool ParseXml(ILegacyLogger i_Logger, string i_sFileName, string i_sXml, ref XElement io_xeRootElem)
        {
            bool     bRet = true;
            int      iCurrDepth = 0;
            XElement xeCurrElem, xeParentElem;

            try
            {
                // Create the XmlNamespaceManager.
                NameTable           nt    = new NameTable();
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);

                // Create the XmlParserContext.
                XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);

                // Create the reader.
                using (XmlTextReader reader = new XmlTextReader(i_sXml, XmlNodeType.Element, context))
                {
                    // Set up the node tree
                    xeParentElem       = xeCurrElem = io_xeRootElem;
                    io_xeRootElem.Name = "ROOTNAME - IGNORE";

                    int lineNumber = 1;

                    // Parse the XML and display each node.
                    while (reader.Read())
                    {
                        ++lineNumber;

                        switch (reader.NodeType)
                        {
                        case XmlNodeType.XmlDeclaration:
                        {
                            // Ignore for now.
                        }
                        break;

                        case XmlNodeType.Element:
                        {
                            xeCurrElem = new XElement(i_sFileName, lineNumber);

                            if (reader.Depth > iCurrDepth)
                            {
                                // Add the element
                                xeParentElem.m_alElements[xeParentElem.m_alElements.Count - 1].m_alElements.Add(xeCurrElem);
                                // Go down a level
                                xeParentElem = xeParentElem.m_alElements[xeParentElem.m_alElements.Count - 1];
                            }
                            else if (reader.Depth < iCurrDepth)
                            {
                                // Go back up
                                while (iCurrDepth >= reader.Depth)
                                {
                                    xeParentElem = xeParentElem.m_xeParentElem;
                                    iCurrDepth   = xeParentElem.Depth;
                                }

                                // Add the element
                                xeParentElem.m_alElements.Add(xeCurrElem);
                            }
                            else
                            {
                                // Add the element
                                xeParentElem.m_alElements.Add(xeCurrElem);
                            }

                            xeCurrElem.m_xeParentElem = xeParentElem;
                            xeCurrElem.Name           = reader.Name;

                            iCurrDepth = xeCurrElem.Depth = reader.Depth;

                            if (reader.HasAttributes)
                            {
                                XAttribute xeTmpAttr;

                                for (int ii = 0; ii < reader.AttributeCount; ii++)
                                {
                                    reader.MoveToAttribute(ii);

                                    xeTmpAttr       = new XAttribute(i_sFileName, lineNumber);
                                    xeTmpAttr.Name  = reader.Name;
                                    xeTmpAttr.Value = reader.Value;
                                    xeCurrElem.m_alAttributes.Add(xeTmpAttr);
                                }
                            }
                        }
                        break;

                        case XmlNodeType.Text:
                        {
                            xeCurrElem.Value = reader.Value;
                        }
                        break;

                        case XmlNodeType.EndElement:
                        {
                            --lineNumber;
                        }
                        break;

                        case XmlNodeType.Whitespace:
                        {
                            // It's safe/desired to ignore whitespace and comments.
                            --lineNumber;
                        }
                        break;

                        case XmlNodeType.Comment:
                        {
                            // It's safe/desired to ignore whitespace and comments.
                        }
                        break;

                        case XmlNodeType.CDATA:
                        {
                            xeCurrElem.Value = reader.Value;
                        }
                        break;

                        default:
                        {
                            i_Logger.Log(Level.Warning, "XmlDocParser.XmlParser read unexpected XmlNodeType: " + reader.NodeType.ToString());
                        }
                        break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                bRet = false;
                i_Logger.Log(Level.Exception, "XmlDocParser.XmlParser caught exception: " + e.ToString());
            }

            return(bRet);
        }
예제 #23
0
//		private static bool ScriptAssignVariable(ILegacyLogger i_Logger, string i_sVmcId, DField i_dfField, DVariable io_dvVar, string i_sStatement)
        private static bool ScriptAssignVariable(ILegacyLogger i_Logger, string i_sVmcId, ISubdocContext i_SubdocContext, DVariable io_dvVar, string i_sStatement)
        {
            bool   bRet = true, bRes = true;
            int    iTmp = 0, iIndexNew = 0, iIndexOpen = 0, iIndexClose = 0;
            string sTmp;

            try
            {
                // Assign variable's value (string, integer or new object)
                iIndexNew = i_sStatement.IndexOf("new ");                       // Indicates an object instantiation
                if (iIndexNew >= 0)
                {
                    // Object instantiation
                    sTmp            = i_sStatement.Substring(iIndexNew + 4).Trim();
                    sTmp            = sTmp.TrimEnd(DialogEngine.VoiceXmlParser.s_acTerminator);
                    io_dvVar.OValue = ScriptCreateObject(i_Logger, i_sVmcId, i_SubdocContext, sTmp);
                }
                else
                {
                    iIndexOpen = i_sStatement.IndexOf('(');
                    if (iIndexOpen >= 0)
                    {
                        // Function call
                        io_dvVar.SValue = ScriptCallFunction(i_Logger, i_sVmcId, i_SubdocContext, i_sStatement.TrimEnd(DialogEngine.VoiceXmlParser.s_acTerminator));
                    }
                    else
                    {                           // Variable, string, or integer assignment
                        iIndexOpen = i_sStatement.IndexOf('\"');
                        if (iIndexOpen >= 0)
                        {
                            // String literal
                            iIndexOpen++;
                            iIndexClose     = i_sStatement.IndexOf('\"', iIndexOpen);
                            io_dvVar.SValue = i_sStatement.Substring(iIndexOpen, iIndexClose - iIndexOpen);
                        }
                        else
                        {
                            // Variable or integer
                            sTmp = i_sStatement.TrimStart(null).TrimEnd(DialogEngine.VoiceXmlParser.s_acTerminator);
                            try
                            {
                                iTmp = System.Int32.Parse(sTmp);
                                bRes = true;
                            }
                            catch (FormatException)
                            {
                                bRes = false;
                            }
                            if (bRes)
                            {
                                // Integer literal
                                io_dvVar.IValue = iTmp;
                            }
                            else
                            {
                                // variable to variable assignment
                                sTmp = ScriptEvaluateExpression(i_Logger, i_sVmcId, i_SubdocContext, i_sStatement);
                                try
                                {
                                    iTmp            = System.Int32.Parse(sTmp);
                                    io_dvVar.IValue = iTmp;
                                }
                                catch (Exception)
                                {
                                    io_dvVar.SValue = sTmp;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                bRet = false;
                i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptAssignVariable: " + exc.ToString());
            }

            return(bRet);
        }
예제 #24
0
        static int Main(string[] args)
        {
            bool          bRes = true;
            ILegacyLogger logger = null;
            string        sDisableKeyboard = "";
            string        sPrompt = "LRM> ", sCmd = "";
            string        sMonoBinPath = "", sBinPath = "", sArgs = "";
            bool          bDesktopRuntime = false;
            Process       oProc           = null;

            try
            {
                Console.Error.WriteLine(DateTime.Now.ToString() + ": In main.");
                if ((RunningSystem.RunningPlatform == CLRPlatform.Mono) && (args != null) && (args.Length > 0))
                {
                    foreach (string sArg in args)
                    {
                        if (sArg.IndexOf(g_sDesktopArg) >= 0)
                        {
                            bDesktopRuntime = true;
                        }
                    }
                }

                if ((args != null) && (args.Length > 0) && (args[0].IndexOf(g_sConsoleArg) >= 0))
                {
                    // This is the forked copy, carry on...
                    try
                    {
                        Console.Error.WriteLine(DateTime.Now.ToString() + ": (F) Setting up event handlers...");
                        // Set up abnormal shutdown handlers
                        AppDomain.CurrentDomain.DomainUnload       += new EventHandler(CurrentDomain_DomainUnload);
                        AppDomain.CurrentDomain.ProcessExit        += new EventHandler(CurrentDomain_ProcessExit);
                        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                        Console.Error.WriteLine(DateTime.Now.ToString() + ": (F) Setting up logging...");
                        // Name the main thread
                        Thread.CurrentThread.Name = "LocalRM-ForkedT";

                        // Start logging
                        bRes = StartLoggers(out logger);

                        logger.Log(Level.Info, "LRM logger started.");

                        // Check if IP address should be auto-saved to DB and config files.
                        bRes = CheckIPAutoSave(logger);

                        m_aqMsgIn = new MsgQueue(0);

                        // Start threads
                        m_tListener = StartListenerThread(logger, m_aqMsgIn);
                        m_tWorker   = StartWorkerThread(logger, m_aqMsgIn, bDesktopRuntime);

                        // Start CLI
                        sDisableKeyboard = ConfigurationManager.AppSettings["DisableKeyboard"];
                        if (sDisableKeyboard == "false")
                        {
                            Console.Write(sPrompt);
                            sCmd = Console.ReadLine();
                            while (bRes)
                            {
                                //					bRes = ProcessCmdString(sCmd);
                                if (bRes)
                                {
                                    Console.Write(sPrompt);
                                    sCmd = Console.ReadLine();
                                }
                            }
                        }

                        if (m_tListener == null)
                        {
                            logger.Log(Level.Exception, "LRM(F): Listener thread didn't start!");
                        }
                        else if (m_tWorker == null)
                        {
                            logger.Log(Level.Exception, "LRM(F): Worker thread didn't start!");
                        }
                        else
                        {
                            // Wait for threads to complete
                            m_tListener.Join();
                            m_tWorker.Join();
                        }
                    }
                    catch (Exception exc)
                    {
                        if (logger != null)
                        {
                            logger.Log(exc);
                        }
                        else
                        {
                            Console.Error.WriteLine(DateTime.Now.ToString() + ": (F) " + exc.ToString());
                        }
                    }

                    if (logger != null)
                    {
                        logger.Log(Level.Info, "(F) LRM shutdown.");
                        logger.Close();
                    }
                }
                else
                {
                    // This is the parent, so "fork".  // Is MainWindowTitle the only way that works to get the current program file???
                    Console.Error.WriteLine(DateTime.Now.ToString() + ": (P) Setting up logging...");
                    // Name the main thread
                    Thread.CurrentThread.Name = "LocalRMT-Parent";

                    // Start logging
                    bRes = StartLoggers(out logger);

                    logger.Log(Level.Info, "LRM (P) logger started.");

                    if (RunningSystem.RunningPlatform == CLRPlatform.DotNet)
                    {
                        logger.Log(Level.Info, "LRM (P) Windows start.");

                        sBinPath = ConfigurationManager.AppSettings["DefaultBinPath"];
                        if (!(sBinPath.EndsWith("/")) && !(sBinPath.EndsWith("\\")))
                        {
                            sBinPath += "/";
                        }
                        sBinPath += "SBLocalRM.exe";
                        //Process.Start(sBinPath, g_sConsoleArg);
                        sArgs = g_sConsoleArg;
                    }
                    else if (RunningSystem.RunningPlatform == CLRPlatform.Mono)
                    {
                        logger.Log(Level.Info, "LRM (P) Mono start.");

                        sMonoBinPath = ConfigurationManager.AppSettings["MonoBinPath"];
                        if (!(sMonoBinPath.EndsWith("/")) && !(sMonoBinPath.EndsWith("\\")))
                        {
                            sMonoBinPath += "/";
                        }
                        sMonoBinPath += "mono";

                        if (bDesktopRuntime)
                        {
                            sBinPath = g_sDesktopArg + " ";
                        }
                        else
                        {
                            sBinPath = "";
                        }
                        sBinPath += ConfigurationManager.AppSettings["DefaultBinPath"];
                        if (!(sBinPath.EndsWith("/")) && !(sBinPath.EndsWith("\\")))
                        {
                            sBinPath += "/";
                        }
                        sBinPath += "SBLocalRM.exe ";

                        if (bDesktopRuntime)
                        {
                            logger.Log(Level.Info, "LRM (P) Desktop run.");

                            //Process.Start(sMonoBinPath, sBinPath + g_sConsoleArg + " " + g_sDesktopArg);
                            sArgs    = sBinPath + g_sConsoleArg + " " + g_sDesktopArg;
                            sBinPath = sMonoBinPath;
                        }
                        else
                        {
                            logger.Log(Level.Info, "LRM (P) Daemon run.");

                            //Process.Start(sMonoBinPath, sBinPath + g_sConsoleArg);
                            sArgs    = sBinPath + g_sConsoleArg;
                            sBinPath = sMonoBinPath;
                        }
                    }
                    else
                    {
                        sBinPath = "";
                        sArgs    = "";
                        logger.Log(Level.Exception, "(P) Main Start: Unknown platform '" + RunningSystem.RunningPlatform + "'.");
                    }

                    if (sBinPath.Length > 0)
                    {
                        logger.Log(Level.Info, "(P) Main Start-ing('" + sBinPath + "', '" + sArgs + "')...");
                        oProc = Process.Start(sBinPath, sArgs);
                        if (oProc == null)
                        {
                            logger.Log(Level.Exception, "(P) Main Failed to Start('" + sBinPath + "', '" + sArgs + "')!");
                        }
                        else
                        {
                            logger.Log(Level.Info, "(P) Main Start-ed('" + sBinPath + "', '" + sArgs + "').");
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                Console.Error.WriteLine(DateTime.Now.ToString() + ": " + exc.ToString());
                Console.ReadLine();
            }

            return(0);
        }         // Main
예제 #25
0
//		private static object ScriptCreateObject(ILegacyLogger i_Logger, string i_sVmcId, DField i_dfField, string i_sStatement)
        private static object ScriptCreateObject(ILegacyLogger i_Logger, string i_sVmcId, ISubdocContext i_SubdocContext, string i_sStatement)
        {
            object           oRet = null;
            string           sObjName = "";
            StringCollection scParams = null;
            int    ii, iIndex = 0;
            string sParams = "";

            object[] aoParams = null;
            Type     tObj;

            try
            {
                sObjName = ScriptGetFuncName(i_sStatement);

                // Format .NET assembly qualified name
                // The convention required for plugins is that the namespace is the same as the assembly name.
                // Thus, if the namespace is xxx.yyy and the class is zzz then this method is called for a line that reads
                //
                //         variable = new xxx.yyy.zzz();
                //
                // where the class definition is contained in an assembly called xxx.yyy (which means there exists a file called xxx.yyy.dll).
                // In this case ScriptGetFuncName() will return "xxx.yyy.zzz" and thus the namespace (and assembly name) is everything up to the last period.

                iIndex = sObjName.LastIndexOf('.');
                if (iIndex >= 0)
                {
                    sObjName = sObjName + "," + sObjName.Substring(0, iIndex);
                }

                iIndex   = i_sStatement.IndexOf('(');
                sParams  = i_sStatement.Substring((iIndex + 1), (i_sStatement.Length - iIndex - 2));
                scParams = ScriptGetParams(i_Logger, i_sVmcId, i_SubdocContext, sParams);

                if (scParams.Count > 0)
                {
                    aoParams = new object[scParams.Count];
                }

                tObj = Type.GetType(sObjName);
                if (tObj == null)
                {
                    i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "The type '" + sObjName + "' could not be found.");
                }
                else
                {
                    for (ii = 0; ii < scParams.Count; ii++)
                    {
                        aoParams[ii] = scParams[ii];
                    }

                    oRet = tObj.InvokeMember("",
                                             BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.CreateInstance,
                                             null, null, aoParams);
                }
            }
            catch (Exception exc)
            {
                i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptCreateObject: " + exc.ToString());
            }

            return(oRet);
        }         // ScriptCreateObject
예제 #26
0
        }         // StartWorkerThread

        protected static bool CheckIPAutoSave(ILegacyLogger i_Logger)
        {
            // FIX - As with the constants in GetPbxValue(), these constants should be pulled out.
            const string csProxyServer  = "SpeechBridge SIP Proxy";
            const string csAudiomgrAddr = "AudioMgr IP address";

            bool   bRet = true, bRes = true;
            string sCheck = "", sPath = "", sCurrAddr = "";

            System.Net.IPHostEntry tmpIpHost = null;
            System.Net.IPAddress[] tmpIpAddrs = null;
            string[] asAddrs = null;
            int      ii = 0, iNumAddrs = 0;

            ConfigParams cfgs = null;

            SBConfigStor.SIP sipTmp = null;
            int    iNumElems = 0;
            string sProxyAddr = "", sAMAddr = "";

            try
            {
                sCheck = ConfigurationManager.AppSettings["CheckIpOnStartup"];
                if ((sCheck == null) || (sCheck.Length == 0) || (sCheck.ToLower() == false.ToString().ToLower()))
                {
                    // Default or 'false' is to do nothing.
                    i_Logger.Log(Level.Info, "CheckIPAutoSave - Not checking/saving IP address.");
                }
                else
                {
                    // Get current IP address and compare it against what is stored in the DB.
                    tmpIpHost  = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
                    tmpIpAddrs = tmpIpHost.AddressList;
                    iNumAddrs  = tmpIpAddrs.Length;

                    asAddrs = new string[iNumAddrs];
                    for (ii = 0; ii < iNumAddrs; ii++)
                    {
                        asAddrs[ii] = tmpIpAddrs[ii].ToString();
                    }
                    sCurrAddr = asAddrs[0];                             // FIX - Assumes active NIC is 1'st one

                    cfgs = new ConfigParams();
                    cfgs.LoadFromTableByComponent(ConfigParams.e_Components.SIP.ToString());
                    iNumElems = cfgs.Count;
                    if (iNumElems <= 0)
                    {
                        i_Logger.Log(Level.Exception, "SBLocalRM.CheckIPAutoSave Couldn't load settings from DB.");
                    }
                    else
                    {
                        sProxyAddr = cfgs[csProxyServer].Value;
                        sAMAddr    = cfgs[csAudiomgrAddr].Value;

                        // If address is different, save it to SIP Proxy and AudioMgr values, and save config files.
                        if ((sCurrAddr != sProxyAddr) || (sCurrAddr != sAMAddr))
                        {
                            sPath = ConfigurationManager.AppSettings["DefaultConfigPath"];
                            cfgs[csProxyServer].Value  = sCurrAddr;
                            cfgs[csAudiomgrAddr].Value = sCurrAddr;
                            bRes = cfgs.SaveToTableByComponent(ConfigParams.e_Components.SIP.ToString());
                            if (!bRes)
                            {
                                i_Logger.Log(Level.Exception, "SBLocalRM.CheckIPAutoSave Error saving settings to DB.");
                            }
                            else
                            {
                                i_Logger.Log(Level.Info, "CheckIPAutoSave Saved settings to DB.");
                            }


                            // Get the PBX Type information and append it to the other configuration data before
                            // regenerating the configuration files for the Proxy Server and the Audio Routers.
                            //
                            // NOTE: This code is very similar to what exists in ServerSettings.aspx.cs (m_buttonUpdate_Click())
                            //       so it should be refactored to a common location.
                            //       Also, as per the comment in ServerSettings.aspx.cs, if more elements are added to SIP2 then
                            //       those will also have to be added to the configuration data passed to SIP.Persist().

                            ConfigParams cfgs2 = new ConfigParams();
                            cfgs2.LoadFromTableByComponent(ConfigParams.e_Components.SIP2.ToString());
                            cfgs.Add(GetPbxValue(cfgs2));

                            // Get the load-balancing/failover information and append it to the other configuration data before
                            // regenerating the configuration files for the Proxy Server and the Audio Routers.

                            ConfigParams cfgs3 = new ConfigParams();
                            cfgs3.LoadFromTableByComponent(ConfigParams.e_Components.SIP3.ToString());

                            foreach (ConfigParams.ConfigParam cfg in cfgs3)
                            {
                                cfgs.Add(cfg);
                            }

                            sipTmp = new SIP();
                            bRes   = sipTmp.Persist(cfgs, sPath);
                            if (!bRes)
                            {
                                i_Logger.Log(Level.Exception, "SBLocalRM.CheckIPAutoSave Error saving settings to config files.");
                            }
                            else
                            {
                                i_Logger.Log(Level.Info, "CheckIPAutoSave Saved settings to config files.");
                            }

                            // Write addr to /etc/hosts, hostname to /etc/sysconfig/network
                        }
                        else
                        {
                            i_Logger.Log(Level.Info, "CheckIPAutoSave - IP addresses matched.");
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                i_Logger.Log(Level.Exception, "SBLocalRM.CheckIPAutoSave caught exception: " + exc.ToString());
                bRet = false;
            }

            return(bRet);
        }         // CheckIPAutoSave
예제 #27
0
        /// <summary>
        /// Note:  Until javascript in Mono is complete and stable, this will interpret the script code.
        /// For simplicity's sake, the only supported format is:
        ///		variable = FullQualifiedObject(param0, param1, ...);
        /// The variable is expected to be in field scope, and is optional.  Parameters can only be of
        /// type string, and are always passed by value.
        /// </summary>
        /// <param name="i_dfActive"></param>
        /// <param name="i_iOptionIndex"></param>
        /// <returns></returns>
//		public static bool ScriptExecute(ILegacyLogger i_Logger, string i_sVmcId, DField i_dfField, DAction i_daAction)
        public static bool ScriptExecute(ILegacyLogger i_Logger, string i_sVmcId, ISubdocContext i_SubdocContext, DAction i_daAction)
        {
            bool bRet = true, bRes = true;
            int  ii = 0, iIndexStart = 0;

            System.Int32 iTmp = 0;                      // I know, same as 'int', but...
            DScript      dsCode;
            string       sStatement, sVarName, sVarNameShort, sRes = "";
            DVariable    dvTmp = null;

            try
            {
                // FIX - The parsing code is currently a hack to get a demo working.
                // FIX - The variables we look for in the javascript may be VoiceXML variables.
                // Right now we only handle two types of statements: variable declarations (with or
                // without assignment) and function calls (w/ or w/out assignment.)  All parameters and
                // return values from function calls are of type string.  Any text results to be TTSed
                // need to be done through the reserved statement 'document.writeln(svar);'.
                //

                dsCode = (DScript)i_daAction.m_oValue;
                for (ii = 0; ii < dsCode.Code.Count; ii++)
                {
                    dvTmp      = null;
                    sStatement = dsCode.Code[ii];

                    // Check if there is a variable declared
                    if (sStatement.IndexOf("var ") >= 0)
                    {
                        sVarName = ScriptExtractVariableName(sStatement.Substring(4));
                        iTmp     = sVarName.IndexOf('.');
                        if (iTmp < 0)
                        {
                            sVarNameShort = sVarName;
                        }
                        else
                        {
                            sVarNameShort = sVarName.Substring(iTmp + 1);
                        }

                        dvTmp = DialogEngine.DialogEngine.FindVariableByName(i_SubdocContext, sVarName);                                // Reuse variable if it exists, even though script has (erroneously) declared a new one.
                        if (dvTmp == null)
                        {
                            // Allocate variable and put it in proper scope.
                            dvTmp      = new DVariable();
                            dvTmp.Name = sVarNameShort;

                            iIndexStart = sStatement.IndexOf("var ") + 4;

                            if (i_SubdocContext.GetType() == typeof(DField))
                            {
                                DField dfField = (DField)i_SubdocContext;

                                if (sVarName.IndexOf("session.") >= 0)
                                {
                                    dfField.m_dfParentForm.m_ddParentDocument.m_dsParentSession.m_DVariables.Add(dvTmp);
                                }
                                else if (sVarName.IndexOf("application.") >= 0)
                                {
                                    // FIX - Keep it in session since we don't currently have an "application" in USCs?
                                    dfField.m_dfParentForm.m_ddParentDocument.m_dsParentSession.m_DVariables.Add(dvTmp);
                                }
                                else if (sVarName.IndexOf("document.") >= 0)
                                {
                                    dfField.m_dfParentForm.m_ddParentDocument.m_DVariables.Add(dvTmp);
                                }
                                else if (sVarName.IndexOf("dialog.") >= 0)
                                {
                                    dfField.m_dfParentForm.Variables.Add(dvTmp);
                                }
                                else
                                {
                                    i_SubdocContext.Variables.Add(dvTmp);
                                }
                            }
                            else if (i_SubdocContext.GetType() == typeof(DForm))
                            {
                                DForm dfForm = (DForm)i_SubdocContext;

                                if (sVarName.IndexOf("session.") >= 0)
                                {
                                    dfForm.m_ddParentDocument.m_dsParentSession.m_DVariables.Add(dvTmp);
                                }
                                else if (sVarName.IndexOf("application.") >= 0)
                                {
                                    // FIX - Keep it in session since we don't currently have an "application" in USCs?
                                    dfForm.m_ddParentDocument.m_dsParentSession.m_DVariables.Add(dvTmp);
                                }
                                else if (sVarName.IndexOf("document.") >= 0)
                                {
                                    dfForm.m_ddParentDocument.m_DVariables.Add(dvTmp);
                                }
                                else if (sVarName.IndexOf("dialog.") >= 0)
                                {
                                    dfForm.Variables.Add(dvTmp);
                                }
                                else
                                {
                                    i_SubdocContext.Variables.Add(dvTmp);
                                }
                            }
                            else
                            {
                                i_Logger.Log(Level.Exception, string.Format("[{0}]DialogEngine.ScriptExecute - invalid type '{1}'.", i_sVmcId, i_SubdocContext.GetType().ToString()));
                            }
                        }
                    }
                    else if (sStatement.IndexOf(m_csBoolEqual) >= 0)
                    {
                        i_Logger.Log(Level.Warning, "[" + i_sVmcId + "]" + "DialogEngine.ScriptExecute - Boolean conditions not yet supported.");
                    }
                    else if (sStatement.IndexOf('=') >= 0)
                    {
                        sVarName = sStatement.Substring(0, sStatement.IndexOfAny(DialogEngine.VoiceXmlParser.s_acBreakNonVar));
                        dvTmp    = DialogEngine.DialogEngine.FindVariableByName(i_SubdocContext, sVarName);
                        if (dvTmp == null)
                        {
                            i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptExecute - Variable named '" + sVarName + "' was not found, line " + ii + " '" + sStatement + "'.");
                            // Create a new temporary variable so we can keep going
                            // FIX - probably ought to return a failure if we get here...
                            dvTmp      = new DVariable();
                            dvTmp.Name = sVarName;
                        }
                    }
                    else
                    {
                        // No variable assigned to the return value, so create a temporary variable
                        dvTmp = new DVariable("TEMPORARY", "");
                    }                     // if 'var'

                    // Check if there is an assignment
                    iIndexStart = sStatement.IndexOf('=');
                    if (iIndexStart >= 0)
                    {
                        iIndexStart++;
                        bRes = ScriptAssignVariable(i_Logger, i_sVmcId, i_SubdocContext, dvTmp, sStatement.Substring(iIndexStart).Trim());
                    }
                    else
                    {
                        // Check for a function call that doesn't assign a return value to a variable
                        if (sStatement.IndexOf('(') >= 0)
                        {
                            sRes = ScriptCallFunction(i_Logger, i_sVmcId, i_SubdocContext, sStatement.TrimEnd(DialogEngine.VoiceXmlParser.s_acTerminator));
                        }
                        else
                        {
                            i_Logger.Log(Level.Info, "[" + i_sVmcId + "]" + "DialogEngine.ExecuteScript - Seem to have found a no-op on line " + ii + ": '" + sStatement + "'.");
                        }
                    }
                }                 // for
            }
            catch (Exception e)
            {
                bRet = false;
                i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptExecute: " + e.ToString());
            }

            return(bRet);
        }
예제 #28
0
        }         // ScriptCreateObject

//		private static string ScriptEvaluateExpression(ILegacyLogger i_Logger, string i_sVmcId, DField i_dfField, string i_sStatement)
        private static string ScriptEvaluateExpression(ILegacyLogger i_Logger, string i_sVmcId, ISubdocContext i_SubdocContext, string i_sStatement)
        {
            string    sRet = "", sVar = "";
            DVariable dvTmp = null;
            int       iIndex, iTmp;

            try
            {
                // For now, just look for integer increments.
                iIndex = i_sStatement.IndexOfAny(s_acOperators);
                if (iIndex < 0)
                {
                    i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptEvaluateExpression - Unsupported syntax: '" + i_sStatement + "'.");
                }
                else
                {
                    // FIX - Here begins the hack
                    iIndex = i_sStatement.IndexOf(" + 1");
                    if (iIndex < 0)
                    {
                        iIndex = i_sStatement.IndexOf(" - 1");
                        if (iIndex < 0)
                        {
                            i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptEvaluateExpression - Unsupported syntax: '" + i_sStatement + "'.");
                        }
                        else
                        {
                            sVar  = ScriptExtractVariableName(i_sStatement);
                            dvTmp = DialogEngine.DialogEngine.FindVariableByName(i_SubdocContext, sVar);
                            if (dvTmp == null)
                            {
                                i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptEvaluateExpression - Couldn't find variable named '" + sVar + "' in field '" + i_SubdocContext.ID + "'.");
                            }
                            else
                            {
                                if (dvTmp.Type == DVariable.eType.USCInt)
                                {
                                    iTmp = dvTmp.IValue;
                                    iTmp--;
                                    sRet = iTmp.ToString();
                                }
                                else if (dvTmp.Type == DVariable.eType.USCString)
                                {
                                    try
                                    {
                                        iTmp = System.Int32.Parse(dvTmp.SValue);
                                        iTmp--;
                                        sRet = iTmp.ToString();
                                    }
                                    catch (Exception)
                                    {
                                        i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptEvaluateExpression - Unsupported syntax: '" + i_sStatement + "'.");
                                    }
                                }
                                else
                                {
                                    i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptEvaluateExpression - Unsupported syntax: '" + i_sStatement + "'.");
                                }
                            }
                        }
                    }
                    else
                    {
                        sVar  = ScriptExtractVariableName(i_sStatement);
                        dvTmp = DialogEngine.DialogEngine.FindVariableByName(i_SubdocContext, sVar);
                        if (dvTmp == null)
                        {
                            i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptEvaluateExpression - Couldn't find variable named '" + sVar + "' in field '" + i_SubdocContext.ID + "'.");
                        }
                        else
                        {
                            if (dvTmp.Type == DVariable.eType.USCInt)
                            {
                                iTmp = dvTmp.IValue;
                                iTmp++;
                                sRet = iTmp.ToString();
                            }
                            else if (dvTmp.Type == DVariable.eType.USCString)
                            {
                                try
                                {
                                    iTmp = System.Int32.Parse(dvTmp.SValue);
                                    iTmp++;
                                    sRet = iTmp.ToString();
                                }
                                catch (Exception)
                                {
                                    i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptEvaluateExpression - Unsupported syntax: '" + i_sStatement + "'.");
                                }
                            }
                            else
                            {
                                i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptEvaluateExpression - Unsupported syntax: '" + i_sStatement + "'.");
                            }
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptEvaluateExpression: " + exc.ToString());
            }

            return(sRet);
        }         // ScriptEvaluateExpression
예제 #29
0
        }         // ScriptEvaluateExpression

//		private static string ScriptCallFunction(ILegacyLogger i_Logger, string i_sVmcId, DField i_dfField, string i_sStatement)
        private static string ScriptCallFunction(ILegacyLogger i_Logger, string i_sVmcId, ISubdocContext i_SubdocContext, string i_sStatement)
        {
            string           sRet = "";
            string           sFuncNameFull = "", sInstanceName = "", sFuncName = "", sParams = "";
            StringCollection scParams = null;

            object[]  aoParams = null;
            object    oRes = null;
            int       ii, iIndex = 0;
            DVariable dvObject = null;

            try
            {
                sFuncNameFull = ScriptGetFuncName(i_sStatement);
                iIndex        = sFuncNameFull.IndexOf('.');
                if (iIndex < 0)
                {
                    i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptCallFunction - Can't currently call a non-object based function.  From: '" + i_sStatement + "'.");
                }
                else
                {
                    sInstanceName = sFuncNameFull.Substring(0, iIndex);
                    sFuncName     = sFuncNameFull.Substring(iIndex + 1);

                    dvObject = DialogEngine.DialogEngine.FindVariableByName(i_SubdocContext, sInstanceName);
                    if (dvObject == null)
                    {
                        i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptCallFunction - Can't find instance variable '" + sInstanceName + "'.");
                    }
                    else
                    {
                        iIndex   = i_sStatement.IndexOf('(');
                        sParams  = i_sStatement.Substring((iIndex + 1), (i_sStatement.Length - iIndex - 2));
                        scParams = ScriptGetParams(i_Logger, i_sVmcId, i_SubdocContext, sParams);

                        if (scParams.Count > 0)
                        {
                            aoParams = new object[scParams.Count];
                            for (ii = 0; ii < scParams.Count; ii++)
                            {
                                aoParams[ii] = scParams[ii];
                            }
                        }

                        try
                        {
                            oRes = dvObject.OValue.GetType().InvokeMember(sFuncName,
                                                                          BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.InvokeMethod,
                                                                          null, dvObject.OValue, aoParams);
                            if (oRes == null)
                            {
                                i_Logger.Log(Level.Warning, "[" + i_sVmcId + "]" + "DialogEngine.ScriptCallFunction - There was no return value in the call to '" + i_sStatement + "'.");
                            }
                            else
                            {
                                sRet = oRes.ToString();
                            }
                        }
                        catch (TargetInvocationException exc)
                        {
                            i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptCallFunction: " + exc.ToString());
                        }
                        catch (Exception exc)
                        {
                            i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptCallFunction: " + exc.ToString());
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptCallFunction: " + exc.ToString());
            }

            return(sRet);
        }
예제 #30
0
        private static int RunTestBuffer(ILegacyLogger i_Logger, eAsrType i_eAsrType, string i_sGramPath, string i_sUttPath, int i_iNumIt, int i_iPause)
        {
            StreamReader srGram = null;
            FileInfo     fiUtt  = null;
            FileStream   fsUtt  = null;

            byte[]        abUtt = null;
            StringBuilder sbGram = null;
            string        sTmp = "", sGram = "";
            int           ii = 0, iRead = 0, iLen = 0, iRem = 0, jj = 0;
            bool          bRes = true;
            IASR          oAsr = null;

            RecognitionResult[] aResults = null;

            try
            {
                // Load grammar file and utterance WAV into buffers
                sbGram = new StringBuilder();
                srGram = new StreamReader(i_sGramPath, Encoding.UTF8);
                while ((sTmp = srGram.ReadLine()) != null)
                {
                    sbGram.Append(sTmp + System.Environment.NewLine);
                }
                sGram = sbGram.ToString();

                i_Logger.Log(Level.Info, "Grammar:  " + sGram + "");

                fiUtt = new FileInfo(i_sUttPath);
                fsUtt = fiUtt.OpenRead();
                abUtt = new byte[fsUtt.Length];
                iLen  = iRem = (int)fsUtt.Length;
                do
                {
                    iRead = fsUtt.Read(abUtt, 0, iRem);
                    iRem -= iRead;
                } while (iRem > 0);

                // Do ASR init
                bRes = InitAsr(i_Logger, i_eAsrType, out oAsr);
                if (!bRes)
                {
                    i_Logger.Log(Level.Exception, "InitAsr failed.");
                }
                else
                {
                    // Run test
                    for (ii = 0; ii < i_iNumIt; ii++)
                    {
                        bRes = oAsr.Open();
                        if (!bRes)
                        {
                            i_Logger.Log(Level.Exception, "Asr.Open failed.");
                        }
                        bRes = oAsr.ResetGrammar();
                        if (!bRes)
                        {
                            i_Logger.Log(Level.Exception, "Asr.ResetGrammar failed.");
                        }
                        bRes = oAsr.LoadGrammar(false, "main", sGram);
                        if (!bRes)
                        {
                            i_Logger.Log(Level.Exception, "Asr.LoadGrammar failed.");
                            bRes = oAsr.Close();
                            return(ii);
                        }

                        SendData(oAsr, abUtt, true);                            // Use streaming
//						SendData(oAsr, abUtt, false);	// Doesn't stream

                        bRes = oAsr.Results(out aResults);
                        if (!bRes)
                        {
                            i_Logger.Log(Level.Exception, "Asr.Results failed.");
                        }
                        else
                        {
                            for (jj = 0; jj < aResults.Length; jj++)
                            {
                                i_Logger.Log(Level.Info, "Iteration #" + ii.ToString() + ", result #" + jj.ToString() + ", decoded '" + aResults[jj].Result + "' with confidence " + aResults[jj].Probability + "%.");
                            }
                        }

                        // Pause between iterations
                        if ((i_iNumIt > 0) && (i_iPause > 0))
                        {
                            Thread.Sleep(i_iPause * 1000);
                        }
                    }                     // for
                }
            }
            catch (Exception exc)
            {
                i_Logger.Log(Level.Exception, "RunTestBuffer Iteration #" + ii + ", caught exception: " + exc.ToString());
            }

            return(ii);
        }         // RunTestBuffer