public LRMWorkerThread(ILegacyLogger i_Logger, MsgQueue i_aqMsgIn, bool i_bDesktopRuntime) { m_Logger = i_Logger; m_aqMsgIn = i_aqMsgIn; m_aProcs = new SBProcesses(); m_bDesktopRuntime = i_bDesktopRuntime; } // LRMWorkerThread constructor
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 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
/// <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); }
public LoggingThread(ILegacyLogger i_Log, int i_iThreadIndex, int i_iNumIterations, int i_iSleep) { m_Log = i_Log; m_iIndex = i_iThreadIndex; m_iNumIterations = i_iNumIterations; m_iSleep = i_iSleep; }
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); }
public ARMsgListenerThread(ILegacyLogger i_Logger, IResourceMgr i_RM, int i_iThreadIndex, AMSockConns.AMSockConn i_SockConn, MsgQueue[] i_aqAudioIn, AudioOutMsgQueue[] i_aqAudioOut) { m_Logger = i_Logger; m_iThreadIndex = i_iThreadIndex; m_SockConn = i_SockConn; m_RM = i_RM; m_aqAudioIn = i_aqAudioIn; m_aqAudioOut = i_aqAudioOut; m_asSessionIds = new StringCollection(); }
public UdpMsgListenerThread(ILegacyLogger i_Logger, MsgQueue i_aqMsgIn) { int iPort = 0; m_Logger = i_Logger; m_aqMsgIn = i_aqMsgIn; iPort = int.Parse(ConfigurationManager.AppSettings["UdpListenPort"]); m_IPEndPoint = new IPEndPoint(IPAddress.Any, iPort); // Accept any source m_receivingUdpClient = new UdpClient(m_IPEndPoint); } // UdpMsgListenerThread contstructor
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); }
public AudioEngine_srv(ILegacyLogger i_Logger) { m_Logger = i_Logger; m_SockMsgs = new AMSockData[0]; m_RM = new ResourceMgr_local(m_Logger); m_aASRs = new ArrayList(); m_NumAudioStreams = m_RM.GetMaxSessions(); CreateAudioRouterSockets(); }
public AudioOutTimer(string i_sTimerName, AudioOutTimerElapsedHandler i_TimerElapsedHandler, TimerArmMode i_eTimerArmMode, int i_iThreadIndex, ILegacyLogger i_Logger) { m_sTimerName = i_sTimerName; m_TimerElapsedHandler = i_TimerElapsedHandler; m_eTimerArmMode = i_eTimerArmMode; m_iThreadIndex = i_iThreadIndex; m_Logger = i_Logger; m_timer = new Timer(); m_timer.Enabled = false; m_timer.AutoReset = false; m_timer.Elapsed += new ElapsedEventHandler(OnTimerElapsed); }
} // Main /// <summary> /// /// </summary> /// <param name="i_logConsole"></param> /// <param name="i_logFile"></param> /// <param name="i_logger"></param> /// <returns></returns> protected static bool StartLoggers(out ILegacyLogger o_logger) { bool bRet = true; string sPath = ""; // Set up the logger(s) sPath = ConfigurationManager.AppSettings["DefaultLogFilePath"]; o_logger = new LegacyLogger(); o_logger.Init("", "", Thread.CurrentThread.Name, "", "", sPath); bRet = o_logger.Open(); return(bRet); } // Start Loggers
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
public DialogThread(ILegacyLogger i_Logger, int i_iThreadIndex, string i_sScriptUrl, ISMessaging.MsgQueue i_qMsg) { bool bRes; m_Logger = i_Logger; m_iThreadIndex = i_iThreadIndex; m_sScriptUrl = i_sScriptUrl; m_qMsg = i_qMsg; m_DEngine = new DialogEngine.DialogEngine(m_Logger, i_iThreadIndex); // FIX - Get VMC from RM, threadindex isn't valid in distributed/redundant installations. bRes = m_DEngine.Init(); if (!bRes) { // FIX - Continue on? Try to load from a 'safe' URL? } }
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); }
} // 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
} // 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
public JobHostContextFactory( ILegacyLogger legacyLogger, IFunctionExecutor functionExecutor, IFunctionIndexProvider functionIndexProvider, ITriggerBindingProvider triggerBindingProvider, SingletonManager singletonManager, IJobActivator activator, IHostIdProvider hostIdProvider, INameResolver nameResolver, IExtensionRegistry extensions, ILoggerFactory loggerFactory, IWebJobsExceptionHandler exceptionHandler, SharedQueueHandler sharedQueueHandler, IOptions <JobHostOptions> jobHostOptions, IHostInstanceLogger hostInstanceLogger, IFunctionInstanceLogger functionInstanceLogger, IFunctionOutputLogger functionOutputLogger, IConverterManager converterManager, IAsyncCollector <FunctionInstanceLogEntry> eventCollector) { _legacyLogger = legacyLogger; _functionExecutor = functionExecutor; _functionIndexProvider = functionIndexProvider; _triggerBindingProvider = triggerBindingProvider; _singletonManager = singletonManager; _activator = activator; _hostIdProvider = hostIdProvider; _nameResolver = nameResolver; _extensions = extensions; _loggerFactory = loggerFactory; _exceptionHandler = exceptionHandler; _sharedQueueHandler = sharedQueueHandler; _jobHostOptions = jobHostOptions; _hostInstanceLogger = hostInstanceLogger; _functionInstanceLogger = functionInstanceLogger; _functionOutputLogger = functionOutputLogger; _converterManager = converterManager; _eventCollector = eventCollector; }
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); }
// 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); }
public VxmlGenerationDAL(ILegacyLogger i_Logger) { m_Logger = i_Logger; }
/// <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
public bool Init(ILegacyLogger i_Logger, GrammarBuilder.eGramFormat i_GrammarFormat) { // TODO: Add NullFacade.Init implementation return(true); }
static void Main(string[] args) { ILegacyLogger logger = null; bool bRes = true; string sAsr = "", sGramPath = "", sUttPath = ""; int iRes, iNumIt = 0, iPause = 0, iNumArgsExpected = 5, iAsrIdx = 0, iGramIdx = 1, iUttIdx = 2, iItIdx = 3, iPauseIdx = 4; eAsrType eAsr = eAsrType.unknown; try { for (int ii = 0; ii < args.Length; ii++) { Console.Error.WriteLine("Arg {0}: '{1}'", ii, args[ii].ToString()); } Thread.CurrentThread.Name = "asrtest"; logger = new LegacyLogger(); logger.Init("", "", Thread.CurrentThread.Name, "", "", "/opt/speechbridge/logs"); bRes = logger.Open(); if (!bRes || (args.Length != iNumArgsExpected)) { if (!bRes) { Console.Error.WriteLine("Unable to open the console logger!"); } else { logger.Log(Level.Warning, "Usage: asrtest AsrType GrammarFile UttWav NumIterations PauseInSecs"); logger.Log(Level.Warning, " AsrType can be: lumenvox, lumenvox2, OR vestec"); } return; } else { sAsr = args[iAsrIdx]; sGramPath = args[iGramIdx]; sUttPath = args[iUttIdx]; iNumIt = int.Parse(args[iItIdx]); iPause = int.Parse(args[iPauseIdx]); if ((sAsr == eAsrType.julius.ToString()) || (sAsr == eAsrType.loquendo.ToString()) || (sAsr == eAsrType.pocketsphinx.ToString())) { logger.Log(Level.Exception, "That AsrType is not yet supported."); } else if (sAsr == eAsrType.lumenvox.ToString()) { eAsr = eAsrType.lumenvox; } else if (sAsr == eAsrType.lumenvox2.ToString()) { eAsr = eAsrType.lumenvox2; } else if (sAsr == eAsrType.vestec.ToString()) { eAsr = eAsrType.vestec; } if (eAsr != eAsrType.unknown) { iRes = RunTestBuffer(logger, eAsr, sGramPath, sUttPath, iNumIt, iPause); logger.Log(Level.Info, "Successfully completed " + iRes.ToString() + " iterations."); } } logger.Close(); } catch (Exception exc) { logger.Log(Level.Exception, "Main caught exception: " + exc.ToString()); } return; }
public AMSockData(ref ILegacyLogger i_Logger) { m_Logger = i_Logger; Clear(); }
public UserDirectoryDAL(ILegacyLogger i_Logger) { m_Logger = i_Logger; }
} // 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
/// <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); }
/// <summary> /// Parses the XML into a more easily accessible node tree. /// </summary> /// <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_sXml, ref XElement io_xeRootElem) { return(ParseXml(i_Logger, "", i_sXml, ref io_xeRootElem)); }
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