protected override void OnStart(string[] args) { myMetrics.Add(0, new TimingData("Dispatcher")); myMetrics.Add(1, new TimingData("Initiator")); myMetrics.Add(99, new TimingData("OVERALL")); // Create a timer with an initial 10 second interval. aTimer = new System.Timers.Timer(10000); // Hook up the Elapsed event for the timer. aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); // Set the Interval Initially to 10 seconds (10000 milliseconds). aTimer.Interval = 10000; aTimer.Enabled = true; try { myFileAgentCore = new XTRMFileAgent(eventLog1); xBotID = XTRMObject.getXTRMID(); Process execProcess = Process.GetCurrentProcess(); int rc = myFileAgentCore.Initialize(); if (rc >= 0) { string tempstr = string.Format("Starting...{0} Version={1} Built={2}.", AssemblyInfo.buildEnv, AssemblyInfo.buildVersion, AssemblyInfo.buildTime); myFileAgentCore.XLogger(0, tempstr, 9901); eventLog1.WriteEntry(tempstr); heartBeat(); Alert(string.Format("{0} Starting", AssemblyInfo.buildEnv), tempstr); } else { string tempstr = string.Format("Stopping...{0} Initialization Failed; code={1}.", AssemblyInfo.buildEnv, rc); myFileAgentCore.XLogger(0, tempstr, 9902); eventLog1.WriteEntry(tempstr); Alert(string.Format("{0} Stopping - Init Failed", AssemblyInfo.buildEnv), tempstr); ExitCode = -99; Stop(); } } catch (Exception ex) { string tempstr = string.Format("{0} Exception in Initialize(); Message={1}", AssemblyInfo.buildEnv, ex.Message); eventLog1.WriteEntry(tempstr); Alert(string.Format("{0} Stopping - Init Exception", AssemblyInfo.buildEnv), tempstr); ExitCode = -98; Stop(); } finally { if (xBotID.Equals("")) { // Cannot Start. string tempstr = string.Format("{0} XBotID Not Set; service terminating.", AssemblyInfo.buildEnv); eventLog1.WriteEntry(tempstr); Alert(string.Format("{0} Stopping - No XBotID", AssemblyInfo.buildEnv), tempstr); ExitCode = -96; Stop(); } } }
protected override void OnStart(string[] args) { myMetrics.Add(0, new TimingData("Dispatcher")); myMetrics.Add(1, new TimingData("Initiator")); myMetrics.Add(99, new TimingData("OVERALL")); // Create a timer with an initial 10 second interval. aTimer = new System.Timers.Timer(10000); // Hook up the Elapsed event for the timer. aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); // Set the Interval Initially to 10 seconds (10000 milliseconds). aTimer.Interval = 10000; aTimer.Enabled = true; try { myFileAgentCore = new XTRMFileAgent(eventLog1); xBotID = XTRMObject.getXTRMID(); Process execProcess = Process.GetCurrentProcess(); int rc = myFileAgentCore.Initialize(); if (rc >= 0) { string tempstr = string.Format("Starting...{0} Version={1} Built={2}.", AssemblyInfo.buildEnv, AssemblyInfo.buildVersion, AssemblyInfo.buildTime); myFileAgentCore.XLogger(0, tempstr, 9901); eventLog1.WriteEntry(tempstr); heartBeat(); Alert(string.Format("{0} Starting", AssemblyInfo.buildEnv), tempstr); } else { string tempstr = string.Format("Stopping...{0} Initialization Failed; code={1}.", AssemblyInfo.buildEnv, rc); myFileAgentCore.XLogger(0, tempstr, 9902); eventLog1.WriteEntry(tempstr); Alert(string.Format("{0} Stopping - Init Failed", AssemblyInfo.buildEnv), tempstr); ExitCode = -99; Stop(); } } catch (Exception ex) { string tempstr = string.Format("{0} Exception in Initialize(); Message={1}", AssemblyInfo.buildEnv, ex.Message); eventLog1.WriteEntry(tempstr); Alert(string.Format("{0} Stopping - Init Exception", AssemblyInfo.buildEnv), tempstr); ExitCode = -98; Stop(); } finally { if (xBotID.Equals("")) { // Cannot Start. string tempstr = string.Format("{0} XBotID Not Set; service terminating.", AssemblyInfo.buildEnv); eventLog1.WriteEntry(tempstr); Alert(string.Format("{0} Stopping - No XBotID", AssemblyInfo.buildEnv), tempstr); ExitCode = -96; Stop(); } } }