Esempio n. 1
0
        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
            {
                xBotID = XTRMObject.getXTRMID();
                Process execProcess = Process.GetCurrentProcess();
                int     rc          = myExecutiveCore.Initialize();
                if (rc >= 0)
                {
                    string tempstr = string.Format("Starting...{0} Version={1} Built={2}.", AssemblyInfo.buildEnv, AssemblyInfo.buildVersion, AssemblyInfo.buildTime);
                    myExecutiveCore.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);
                    myExecutiveCore.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();
                }
            }
        }
Esempio n. 2
0
        protected int checkParms()
        {
            int     rc          = 0;
            Process execProcess = Process.GetCurrentProcess();

            if (XTRMObject.getDictionaryEntry("ReloadDictionary", "Y").Equals("Y"))
            {
                XTRMObject.XDictionary = XTRMObject.createDictionary();
            }
            int heartbeatFrequency = Convert.ToInt32(XTRMObject.getDictionaryEntry("HeartbeatFrequency", "60"));

            if (beats % heartbeatFrequency == 0)
            {
                rc = 1; // Time for a heart beat!
            }
            xBotID = XTRMObject.getXTRMID();
            //int interval = Convert.ToInt32(XObject.getDictionaryEntry("DefaultInterval", "60"));
            int interval = Convert.ToInt32(XTRMObject.getDictionaryEntry("FileAgentInterval", "60"));

            agentHoldTime = Convert.ToInt32(XTRMObject.getDictionaryEntry("FileAgentHoldTime", "10"));
            int restartAfterSeconds = Convert.ToInt32(XTRMObject.getDictionaryEntry("RestartAfterSeconds", "82400"));
            int restartOverMemory   = Convert.ToInt32(XTRMObject.getDictionaryEntry("RestartOverMemory", "500000000"));

            memorySize = execProcess.VirtualMemorySize64;
            if (!aTimer.Interval.Equals(interval * 1000))
            {
                // Make Change, log message.
                string tempstr = string.Format("{0} Interval = {1} Seconds.", AssemblyInfo.buildEnv, interval);
                myFileAgentCore.XLogger(0, tempstr, 9907);
                eventLog1.WriteEntry(tempstr);
                aTimer.Interval = interval * 1000;
            }
            if (pendingStop == 1)
            {
                string tempstr = string.Format("{0} Pending Shutdown Due to Initialization Exception.", AssemblyInfo.buildEnv);
                eventLog1.WriteEntry(tempstr);
                myFileAgentCore.XLogger(0, tempstr, 9913);
                rc = -5;
            }
            else if (pendingStop == 2)
            {
                string tempstr = string.Format("{0} Pending Shutdown Due to Missing XBotID.", AssemblyInfo.buildEnv);
                eventLog1.WriteEntry(tempstr);
                myFileAgentCore.XLogger(0, tempstr, 9914);
                rc = -6;
            }
            else if (xBotID.Equals(""))
            {
                string tempstr = string.Format("{0} XBotID Not Set.", AssemblyInfo.buildEnv);
                myFileAgentCore.XLogger(0, tempstr, 9911);
                eventLog1.WriteEntry(tempstr);
                Alert(string.Format("{0} Stopping - No Version", AssemblyInfo.buildEnv), tempstr);
                rc = -4;
            }
            else if (Convert.ToInt32(serviceLife / 1000) >= restartAfterSeconds)
            {
                // Time to re-start!
                string tempstr = string.Format("Restarting {0} Service; Uptime = {1} Seconds.", AssemblyInfo.buildEnv, Convert.ToInt32(serviceLife / 1000));
                myFileAgentCore.XLogger(0, tempstr, 9908);
                eventLog1.WriteEntry(tempstr);
                Alert(string.Format("{0} Stopping - Uptime", AssemblyInfo.buildEnv), tempstr);
                rc = -2;
            }
            else if (memorySize > restartOverMemory)
            {
                // Time to re-start!
                string tempstr = string.Format("Restarting {0} Service; Memory = {1} Bytes.", AssemblyInfo.buildEnv, execProcess.VirtualMemorySize64);
                myFileAgentCore.XLogger(0, tempstr, 9909);
                eventLog1.WriteEntry(tempstr);
                Alert(string.Format("{0} Stopping - Memory", AssemblyInfo.buildEnv), tempstr);
                rc = -3;
            }
            return(rc);
        }