static internal SqlConnection GetNewConnection(string Server, string Database) { SqlConnection con = new SqlConnection("Server=" + Server + ";Database=" + Database + ";Integrated Security=SSPI;POOLING=FALSE"); con.Open(); try { string ls_pref; string ls_approlecred; string ls_sql; SqlCommand cmd = new SqlCommand("SELECT dbo.fn_get_global_preference('SYSTEM', 'system_bitmap') FROM c_1_Record", con); object dbValue = cmd.ExecuteScalar(); if (null == dbValue || dbValue.ToString().Length < 1) { ls_approlecred = "applesauce28"; } else { ls_pref = dbValue.ToString(); ls_approlecred = DecryptString(ls_pref); } ls_sql = "sp_setapprole 'cprsystem', '" + ls_approlecred + "'"; SqlCommand com = new SqlCommand(ls_sql, con); com.ExecuteNonQuery(); } catch (Exception exc) { EPSEventLog.WriteEntry("Error executing sp_setapprole:" + Environment.NewLine + exc.ToString(), EventLogEntryType.Error); } return(con); }
private void mainLoop() { while (!shutdown) { SqlConnection con = null; try { con = InternalMethods.GetNewConnection(dbConInfo[0], dbConInfo[1]); con.Close(); if (!running) { EPSEventLog.WriteEntry("Connection to " + dbConInfo[0] + "." + dbConInfo[1] + " is available. Starting service threads...", EventLogEntryType.Information); startServices(); } } catch (Exception exc) { if (running) { EPSEventLog.WriteEntry("Connection to " + dbConInfo[0] + "." + dbConInfo[1] + " is not available. Stopping service threads..." + Environment.NewLine + Environment.NewLine + exc.ToString(), EventLogEntryType.Warning); stopServices(); } } finally { try { con.Dispose(); } catch {} } Thread.Sleep(5000); GC.Collect(); } }
/* moved to InternalMethods * private SqlConnection GetNewConnection(string Server, string Database) * { * SqlConnection con = new SqlConnection("Server="+Server+";Database="+Database+";Integrated Security=SSPI;POOLING=FALSE"); * con.Open(); * try * { * string ls_pref; * string ls_approlecred; * string ls_sql; * * SqlCommand cmd = new SqlCommand("SELECT dbo.fn_get_global_preference('SYSTEM', 'system_bitmap') FROM c_1_Record",con); * object dbValue = cmd.ExecuteScalar(); * if(null==dbValue) * { * ls_approlecred = "applesauce28"; * } * else * { * ls_pref = dbValue.ToString(); * ls_approlecred = InternalMethods.DecryptString(ls_pref); * } * * ls_sql = "sp_setapprole 'cprsystem', '" + ls_approlecred + "'"; * SqlCommand com = new SqlCommand(ls_sql, con); * com.ExecuteNonQuery(); * } * catch(Exception exc) * { * EPSEventLog.WriteEntry("Error executing sp_setapprole:"+Environment.NewLine+exc.ToString(),EventLogEntryType.Error); * } * return con; * } */ private void monitorMyHealth() { try { int myPID = Process.GetCurrentProcess().Id; while (running) { uint workingSet = ProcUtils.GetProcessMemoryUsage(myPID).WorkingSetSize; if (workingSet > masterMemMax) { // If over limit for memory usage, stop and start self EPSEventLog.WriteEntry("MasterMemMaxMB=" + MasterMemMaxMB.ToString() + Environment.NewLine + "Current Memory Usage (MB)=" + (workingSet / Math.Pow(2d, 20d)).ToString() + Environment.NewLine + "Shutting down all processes.", EventLogEntryType.Warning); ServiceManager.StopServices(); GC.Collect(); EPSEventLog.WriteEntry("Restarting processes.", EventLogEntryType.Warning); ServiceManager.StartServices(Args); return; } Thread.Sleep(5000); GC.Collect(); // Perform garbage collection } } catch (ThreadAbortException) {} catch (Exception exc) { EPSEventLog.WriteEntry("Error in monitorHealth() " + Environment.NewLine + exc.ToString(), EventLogEntryType.Error); } }
private void shortPool_ProcessNotHealthy(object sender, EventArgs e) { AgentProcess p = (AgentProcess)sender; // Check whether service timed out if (p.Runtime > p.MaxRuntime) { // Service timed out // Attempt to add the process to the long pool. // Increase timeout p.MaxRuntime = longPool.MaxPerProcessRuntime; if (!longPool.AddProcess(p)) { EPSEventLog.WriteEntry("Extended queue rejected process. Process will be terminated." + Environment.NewLine + p.ToString(), System.Diagnostics.EventLogEntryType.Warning); p.Stop(); // Stop the process if the long pool will not accept it. } else { // Must call RemoveProcess AFTER any possible process stopping, //because RemoveProcess unregisters events shortPool.RemoveProcess(p); EPSEventLog.WriteEntry("Process was moved to extended queue." + Environment.NewLine + p.ToString(), System.Diagnostics.EventLogEntryType.Warning); } } else { // Service exceeded memory limit EPSEventLog.WriteEntry("Process has exceeded maximum allowed memory. Process will be terminated." + Environment.NewLine + p.ToString(), System.Diagnostics.EventLogEntryType.Warning); p.Stop(); } }
private void monitorHealth() { try { while (keepRunning) { if (p.IsRunning && !p.IsHealthy) { p.Stop(); } Thread.Sleep(500); } // while(!workerProcess.HasExited && keepRunning) // { // uint workingSet = ProcUtils.GetProcessMemoryUsage(workerProcess.Id).WorkingSetSize; // if(workingSet>serviceMemMax) // { // EPSEventLog.WriteEntry("ServiceMemMaxMB="+serviceMemMaxMB.ToString()+Environment.NewLine+ // "Current Memory Usage (MB)="+(workingSet/Math.Pow(2d,20d)).ToString()+ // Environment.NewLine+"Shutting down process."+Environment.NewLine+ // "ServiceID="+this.ServiceID.ToString(), EventLogEntryType.Warning); // // workerProcess.Kill(); // return; // } // Thread.Sleep(5000); // } } catch (ThreadAbortException) {} catch (Exception exc) { EPSEventLog.WriteEntry("Error in monitorHealth() " + Environment.NewLine + exc.ToString(), EventLogEntryType.Error); } }
static internal string DecryptString(string value) { try { byte[] resultBA = new byte[value.Length / 2], valueBA = new byte[value.Length / 2]; byte[] iv = new byte[] { 0x14, 0xD7, 0x5B, 0xA2, 0x47, 0x83, 0x0F, 0xC4 }; System.Text.ASCIIEncoding ascEncoding = new System.Text.ASCIIEncoding(); byte[] key = new byte[24] { 0x21, 0x24, 0x25, 0x23, 0x34, 0x32, 0x37, 0x34, 0x38, 0x6A, 0x73, 0x54, 0x54, 0x4C, 0x7A, 0X51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; MemoryStream memStream = new MemoryStream(); byte[] tempBA = InternalMethods.HexStringToBytes(value); memStream.Write(tempBA, 0, tempBA.Length); memStream.Position = 0; System.Security.Cryptography.TripleDES cryptoServiceProvider = System.Security.Cryptography.TripleDESCryptoServiceProvider.Create(); System.Security.Cryptography.ICryptoTransform decryptor = cryptoServiceProvider.CreateDecryptor(key, iv); System.Security.Cryptography.CryptoStream cStream = new System.Security.Cryptography.CryptoStream( memStream, decryptor, System.Security.Cryptography.CryptoStreamMode.Read); cStream.Read(resultBA, 0, resultBA.Length); cStream.Close(); // Find the first zero int i = 0; for (; i < resultBA.GetLength(0); i++) { if (resultBA[i] == 0) { break; } } return(ascEncoding.GetString(resultBA, 0, i)); } catch (Exception exc) { EPSEventLog.WriteEntry("Decryption failure. Returning original value" + Environment.NewLine + exc.Source, EventLogEntryType.Error); return(value); } }
public void ServiceError(long WorkplanItemID, string SystemUserID) { SqlConnection con = InternalMethods.GetNewConnection(Server, Database); SqlCommand cmd = new SqlCommand("EXEC jmj_set_service_error " + WorkplanItemID.ToString() + ", '" + SystemUserID + "','" + SystemUserID + "','N'", con); try { cmd.ExecuteNonQuery(); } catch (Exception exc) { EPSEventLog.WriteEntry("Error in ServiceError()" + Environment.NewLine + exc.ToString(), System.Diagnostics.EventLogEntryType.Error); } }
private void p_Exited() { if (VerboseLogging) { EPSEventLog.WriteEntry("Process Stopped" + Environment.NewLine + "Runtime = " + Runtime.TotalSeconds.ToString() + " seconds" + Environment.NewLine + "FileName = " + Application + Environment.NewLine + "Arguments = " + Arguments + Environment.NewLine + "Process ID = " + ProcessId.ToString() + Environment.NewLine + "Exit Code = " + p.ExitCode.ToString(), System.Diagnostics.EventLogEntryType.Information); } isRunning = false; p.Dispose(); p = null; OnStopped(); }
public static void Kill(int PID) { ProcessEntry32 pe; try { pe = GetProcess(PID); } catch (Exception exc) { EPSEventLog.WriteEntry("Error getting process entry." + Environment.NewLine + exc.ToString(), System.Diagnostics.EventLogEntryType.Error); goto Error; } int hProcess; try { hProcess = OpenProcess(ProcessRights.TERMINATE, false, pe.th32ProcessID); } catch (Exception exc) { EPSEventLog.WriteEntry("Error opening process." + Environment.NewLine + exc.ToString(), System.Diagnostics.EventLogEntryType.Error); goto Error; } try { if (TerminateProcess(hProcess, -1) == 0) { throw new Exception("Call to TerminateProcess() failed. The function returned 0."); } return; } catch (Exception exc) { EPSEventLog.WriteEntry("Could not kill process." + Environment.NewLine + exc.ToString(), System.Diagnostics.EventLogEntryType.Error); goto Error; } finally { CloseHandle(hProcess); } Error: return; }
// private void StartServiceThread() // { // string path = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath); //#if (DEBUG) // path = @"C:\Program Files\JMJ\EncounterPRO Server"; //#endif // while(keepRunning) // { // try // { // try // { // workerProcess = new Process(); // workerProcess.StartInfo = new ProcessStartInfo(System.IO.Path.Combine(path,"EproServer.exe"),"SERVICE="+ServiceID.ToString()); // workerProcess.StartInfo.UseShellExecute=false; // EPSEventLog.WriteEntry("Starting Service Process."+Environment.NewLine+ // "FileName="+workerProcess.StartInfo.FileName+Environment.NewLine+ // "Arguments="+workerProcess.StartInfo.Arguments,EventLogEntryType.Information); // workerProcess.Start(); // PID = workerProcess.Id; // if(verboseLogging) // EPSEventLog.WriteEntry("PID = "+workerProcess.Id.ToString()+Environment.NewLine+"EXECUTING:"+Environment.NewLine+"ServiceID = "+ServiceID.ToString()+ // Environment.NewLine+workerProcess.StartInfo.FileName+" "+workerProcess.StartInfo.Arguments,EventLogEntryType.Information); // // // start another thread to monitor process health // Thread healthMonThread = new Thread(new System.Threading.ThreadStart(monitorHealth)); // healthMonThread.Start(); // // switch(serviceProcessPriority) // { // case 1: // workerProcess.PriorityClass = ProcessPriorityClass.Idle; // break; // case 2: // workerProcess.PriorityClass = ProcessPriorityClass.BelowNormal; // break; // case 3: // workerProcess.PriorityClass = ProcessPriorityClass.Normal; // break; // case 4: // workerProcess.PriorityClass = ProcessPriorityClass.AboveNormal; // break; // case 5: // workerProcess.PriorityClass = ProcessPriorityClass.High; // break; // } // workerProcess.WaitForExit(); // } // catch(Exception exc) // { // EPSEventLog.WriteEntry(exc.ToString(),EventLogEntryType.Error); // } // keepRunning = CanContinueRunning() && keepRunning; // Thread.Sleep(10000); // } // catch(Exception exc) // { // EPSEventLog.WriteEntry(exc.ToString(), EventLogEntryType.Error); // } // } // } private bool CanContinueRunning() { exitTimes.Add(DateTime.Now); // Remove times older than exitInterval (milliseconds) for (int i = exitTimes.Count - 1; i >= 0; i--) { if (((DateTime)exitTimes[i]).AddMilliseconds((double)exitInterval) < DateTime.Now) { exitTimes.RemoveAt(i); } } EPSEventLog.WriteEntry("Service exited " + exitTimes.Count + " times in the last " + (exitInterval / 60000).ToString() + " minutes." + Environment.NewLine + "The maximum allowed is " + exitMax.ToString(), EventLogEntryType.Warning); return(exitTimes.Count <= exitMax); }
private void longPool_ProcessNotHealthy(object sender, EventArgs e) { // Stop unhealthy processes in long pool AgentProcess p = (AgentProcess)sender; // Check whether service timed out if (p.Runtime > p.MaxRuntime) { // Service timed out EPSEventLog.WriteEntry("Process timed out in extended queue. Process will be terminated." + Environment.NewLine + p.ToString(), System.Diagnostics.EventLogEntryType.Warning); p.Stop(); } else { // Service exceeded memory limit EPSEventLog.WriteEntry("Process has exceeded maximum allowed memory. Process will be terminated." + Environment.NewLine + p.ToString(), System.Diagnostics.EventLogEntryType.Warning); p.Stop(); } }
public void Stop() { try { OnStopping(); // Forcefully kill the application if (IsRunning) { ProcUtils.Kill(ProcessId); p.WaitForExit(); } } catch (Exception exc) { EPSEventLog.WriteEntry("Error in Stop()" + Environment.NewLine + exc.ToString(), System.Diagnostics.EventLogEntryType.Error); throw exc; } }
private ServiceManager(string[] Args) { args = Args; string databaseEntry = "<Default>"; if (args.Length > 0) { foreach (string arg in args) { if (arg.ToLower().StartsWith("database=")) { databaseEntry = arg.Substring("database=".Length); } } } dbConInfo = GetDBEntry(databaseEntry); EPSEventLog.WriteEntry("SERVER=" + dbConInfo[0] + Environment.NewLine + "DATABASE=" + dbConInfo[1]); }
private void stopServices() { running = false; try { // stop remoting try { ChannelServices.UnregisterChannel(channel); channel.StopListening(null); channel = null; } catch (Exception) {} //DateTime StopTime = DateTime.Now; try { serviceThreadManager.StopManager(); } catch (Exception exc) { EPSEventLog.WriteEntry("Error stopping threads" + Environment.NewLine + exc.ToString(), EventLogEntryType.Error); } // Wait until all processes have stopped to proceed do { Thread.Sleep(100); } while (serviceThreadManager.sRunningProcesses + serviceThreadManager.lRunningProcesses > 0); EPSEventLog.WriteEntry("Services stopped.", EventLogEntryType.Information); } catch (Exception exc) { EPSEventLog.WriteEntry("Error stopping services" + Environment.NewLine + exc.ToString(), EventLogEntryType.Error); } }
public void Start() { if (IsRunning) { throw new Exception("Process is already running."); } p = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(Application, Arguments); p.StartInfo = startInfo; p.Start(); startTime = DateTime.Now; isRunning = true; Monitor(); p.PriorityClass = Priority; if (VerboseLogging) { EPSEventLog.WriteEntry("Process Started" + Environment.NewLine + "FileName = " + Application + Environment.NewLine + "Arguments = " + Arguments + Environment.NewLine + "Process ID = " + ProcessId.ToString() + Environment.NewLine + "Priority = " + Priority.ToString(), System.Diagnostics.EventLogEntryType.Information); } OnStarted(); }
public static string getServiceInfo() { if (null == sm) { throw new Exception("No instance of ServiceManager is running"); } System.Data.SqlClient.SqlConnection con = InternalMethods.GetNewConnection(sm.dbConInfo[0], sm.dbConInfo[1]); SqlCommand cmd = null; try { System.IO.MemoryStream ms = new System.IO.MemoryStream(); System.Xml.XmlTextWriter w = new System.Xml.XmlTextWriter(ms, System.Text.Encoding.UTF8); w.WriteStartDocument(); w.WriteStartElement("ServiceInfo"); if (sm.serviceWrappers != null && sm.serviceWrappers.Length > 0) { foreach (ServiceWrapper sw in sm.serviceWrappers) { w.WriteStartElement("Service"); try { w.WriteElementString("ID", sw.ServiceID.ToString()); cmd = new SqlCommand("SELECT service_name FROM o_server_component WHERE service_id = " + sw.ServiceID.ToString(), con); string serviceName = (string)cmd.ExecuteScalar(); w.WriteElementString("Description", serviceName); w.WriteElementString("PID", sw.PID.ToString()); w.WriteElementString("RunningTime", Math.Round(sw.AgentProcess.Runtime.TotalHours, 2).ToString() + " hours"); w.WriteElementString("Memory", sw.CurrentMemoryMB.ToString() + " MB"); w.WriteElementString("MaxMemory", Math.Round(((double)sw.AgentProcess.MaxMemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB"); } catch {} w.WriteEndElement(); } } if (sm.serviceThreadManager != null) { ServiceThreadManager stm = sm.serviceThreadManager; w.WriteStartElement("ProcessPools"); w.WriteStartElement("ProcessPool"); w.WriteAttributeString("type", "short"); w.WriteElementString("MaxProcesses", stm.sMaxRunningProcesses.ToString()); w.WriteStartElement("QueuedProcesses"); if (stm.sQueuedProcessArray != null && stm.sQueuedProcessArray.Length > 0) { foreach (ProcessInfo pi in stm.sQueuedProcessArray) { w.WriteStartElement("QueuedProcess"); try { w.WriteElementString("Application", pi.Application); w.WriteElementString("Arguments", pi.Arguments); } catch {} w.WriteEndElement(); } } w.WriteEndElement(); w.WriteStartElement("RunningProcesses"); if (stm.sRunningProcessArray != null && stm.sRunningProcessArray.Length > 0) { foreach (AgentProcess ap in stm.sRunningProcessArray) { w.WriteStartElement("RunningProcess"); // WPItem try { if (ap.Arguments.IndexOf("WPITEM") > -1) { w.WriteElementString("Type", "WPItem"); w.WriteElementString("ID", ap.TaskId.ToString()); cmd = new SqlCommand("SELECT description FROM p_patient_wp_item WHERE patient_workplan_item_id = " + ap.TaskId.ToString(), con); string wpitem = (string)cmd.ExecuteScalar(); w.WriteElementString("Description", wpitem); w.WriteElementString("User", ap.TaskUser); w.WriteElementString("PID", ap.ProcessId.ToString()); w.WriteElementString("RunningTime", Math.Round(ap.Runtime.TotalMinutes, 2).ToString() + " minutes"); w.WriteElementString("MaxRunningTime", Math.Round(ap.MaxRuntime.TotalMinutes, 2).ToString() + " minutes"); w.WriteElementString("Memory", Math.Round(((double)ap.MemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB"); w.WriteElementString("MaxMemory", Math.Round(((double)ap.MaxMemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB"); cmd = new SqlCommand("SELECT retries FROM p_patient_wp_item WHERE patient_workplan_item_id = " + ap.TaskId.ToString(), con); string retries = cmd.ExecuteScalar().ToString(); w.WriteElementString("Retries", retries); } // Scheduled else if (ap.Arguments.IndexOf("SCHEDULE") > -1) { w.WriteElementString("Type", "Scheduled"); w.WriteElementString("ID", ap.TaskId.ToString()); cmd = new SqlCommand("SELECT service FROM o_service_schedule WHERE service_sequence = " + ap.TaskId.ToString(), con); string service = (string)cmd.ExecuteScalar(); w.WriteElementString("Description", service); w.WriteElementString("User", ap.TaskUser); w.WriteElementString("PID", ap.ProcessId.ToString()); w.WriteElementString("RunningTime", Math.Round(ap.Runtime.TotalMinutes, 2).ToString() + " minutes"); w.WriteElementString("MaxRunningTime", Math.Round(ap.MaxRuntime.TotalMinutes, 2).ToString() + " minutes"); w.WriteElementString("Memory", Math.Round(((double)ap.MemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB"); w.WriteElementString("MaxMemory", Math.Round(((double)ap.MaxMemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB"); w.WriteElementString("Retries", null); } } catch {} w.WriteEndElement(); } } w.WriteEndElement(); w.WriteEndElement(); w.WriteStartElement("ProcessPool"); w.WriteAttributeString("type", "long"); w.WriteElementString("MaxProcesses", stm.lMaxRunningProcesses.ToString()); w.WriteStartElement("QueuedProcesses"); if (stm.lQueuedProcessArray != null && stm.lQueuedProcessArray.Length > 0) { foreach (ProcessInfo pi in stm.lQueuedProcessArray) { w.WriteStartElement("QueuedProcess"); try { w.WriteElementString("Application", pi.Application); w.WriteElementString("Arguments", pi.Arguments); } catch {} w.WriteEndElement(); } } w.WriteEndElement(); w.WriteStartElement("RunningProcesses"); if (stm.lRunningProcessArray != null && stm.lRunningProcessArray.Length > 0) { foreach (AgentProcess ap in stm.lRunningProcessArray) { w.WriteStartElement("RunningProcess"); try { // WPItem if (ap.Arguments.IndexOf("WPITEM") > -1) { w.WriteElementString("Type", "WPItem"); w.WriteElementString("ID", ap.TaskId.ToString()); cmd = new SqlCommand("SELECT description FROM p_patient_wp_item WHERE patient_workplan_item_id = " + ap.TaskId.ToString(), con); string wpitem = (string)cmd.ExecuteScalar(); w.WriteElementString("Description", wpitem); w.WriteElementString("User", ap.TaskUser); w.WriteElementString("PID", ap.ProcessId.ToString()); w.WriteElementString("RunningTime", Math.Round(ap.Runtime.TotalMinutes, 2).ToString() + " minutes"); w.WriteElementString("MaxRunningTime", Math.Round(ap.MaxRuntime.TotalMinutes, 2).ToString() + " minutes"); w.WriteElementString("Memory", Math.Round(((double)ap.MemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB"); w.WriteElementString("MaxMemory", Math.Round(((double)ap.MaxMemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB"); cmd = new SqlCommand("SELECT retries FROM p_patient_wp_item WHERE patient_workplan_item_id = " + ap.TaskId.ToString(), con); string retries = cmd.ExecuteScalar().ToString(); w.WriteElementString("Retries", retries); } // Scheduled else if (ap.Arguments.IndexOf("SCHEDULE") > -1) { w.WriteElementString("Type", "Scheduled"); w.WriteElementString("ID", ap.TaskId.ToString()); cmd = new SqlCommand("SELECT service FROM o_service_schedule WHERE service_sequence = " + ap.TaskId.ToString(), con); string service = (string)cmd.ExecuteScalar(); w.WriteElementString("Description", service); w.WriteElementString("User", ap.TaskUser); w.WriteElementString("PID", ap.ProcessId.ToString()); w.WriteElementString("RunningTime", Math.Round(ap.Runtime.TotalMinutes, 2).ToString() + " minutes"); w.WriteElementString("MaxRunningTime", Math.Round(ap.MaxRuntime.TotalMinutes, 2).ToString() + " minutes"); w.WriteElementString("Memory", Math.Round(((double)ap.MemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB"); w.WriteElementString("MaxMemory", Math.Round(((double)ap.MaxMemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB"); w.WriteElementString("Retries", null); } } catch {} w.WriteEndElement(); } } w.WriteEndElement(); w.WriteEndElement(); w.WriteEndElement(); } w.WriteEndElement(); w.WriteEndDocument(); w.Flush(); ms.Position = 0; System.IO.StreamReader sr = new System.IO.StreamReader(ms, System.Text.Encoding.UTF8); string results = sr.ReadToEnd(); sr.Close(); return(results); } catch (Exception exc) { EPSEventLog.WriteEntry(exc.ToString(), EventLogEntryType.Error); return(null); } finally { try{ con.Close(); } catch {} } }
private void startServices() { running = true; startTryCount++; if (startTryCount > StartRetryMax) { running = false; EPSEventLog.WriteEntry("Failed to start service threads " + StartRetryMax + " times in a row." + Environment.NewLine + "No more attempts will be made until the service is restarted.", EventLogEntryType.Error); return; } try { GetConfigValue(ref RemotingPort, "RemotingPort"); GetConfigValue(ref MasterMemMaxMB, "MasterMemMaxMB"); GetConfigValue(ref MaintQuerySleepTime, "MaintQuerySleepTime"); GetConfigValue(ref MaintThreadMax, "MaintThreadMax"); GetConfigValue(ref MaintThreadSleepTime, "MaintThreadSleepTime"); GetConfigValue(ref MaintQueryWaitTime, "MaintQueryWaitTime"); GetConfigValue(ref MaintTimeout, "MaintTimeout"); GetConfigValue(ref ShortMaintTimeout, "ShortMaintTimeout"); GetConfigValue(ref MaintProcessPriority, "MaintProcessPriority"); GetConfigValue(ref MaintMemMaxMB, "MaintMemMaxMB"); GetConfigValue(ref TaskQuerySleepTime, "TaskQuerySleepTime"); GetConfigValue(ref TaskThreadMax, "TaskThreadMax"); GetConfigValue(ref TaskThreadSleepTime, "TaskThreadSleepTime"); GetConfigValue(ref TaskQueryWaitTime, "TaskQueryWaitTime"); GetConfigValue(ref TaskTimeout, "TaskTimeout"); GetConfigValue(ref ShortTaskTimeout, "ShortTaskTimeout"); GetConfigValue(ref TaskProcessPriority, "TaskProcessPriority"); GetConfigValue(ref TaskMemMaxMB, "TaskMemMaxMB"); GetConfigValue(ref ServiceExitInterval, "ServiceExitInterval"); GetConfigValue(ref ServiceExitMax, "ServiceExitMax"); GetConfigValue(ref ServiceProcessPriority, "ServiceProcessPriority"); GetConfigValue(ref ServiceMemMaxMB, "ServiceMemMaxMB"); GetConfigValue(ref StopProcessTimeout, "StopProcessTimeout"); GetConfigValue(ref StartRetryMax, "StartRetryMax"); GetConfigValueBoolean(ref VerboseLogging, "VerboseLogging"); // starting monitorMyHealthThread monitorMyHealthThread = new Thread(new ThreadStart(monitorMyHealth)); monitorMyHealthThread.Start(); // start remoting try { channel = new TcpChannel(RemotingPort); ChannelServices.RegisterChannel(channel); RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotingObject), "EncounterPROService", WellKnownObjectMode.SingleCall); } catch (Exception exc) { EPSEventLog.WriteEntry("Could not start remoting to support the EncounterPRO Agent monitor application. The port (" + RemotingPort.ToString() + ") may already be in use. Services will continue to function properly, but the monitor application will not work." + "To change the port that EncounterPRO Agent uses to enable remoting, refer to the following JMJ KB article:" + Environment.NewLine + "https://www.jmjtech.com/kb/Article.aspx?ArticleNumber=10178" + Environment.NewLine + Environment.NewLine + exc.ToString(), System.Diagnostics.EventLogEntryType.Warning); } int computerID; computerID = GetComputerID(); // Initiate ServiceThreadManager array serviceThreadManager = new ServiceThreadManager(dbConInfo[0], dbConInfo[1], computerID, MaintThreadMax, MaintQuerySleepTime, MaintThreadSleepTime, MaintQueryWaitTime, MaintTimeout, ShortMaintTimeout, MaintProcessPriority, MaintMemMaxMB, VerboseLogging, StopProcessTimeout); serviceThreadManager.StartManager(); EPSEventLog.WriteEntry("Service thread manager started.", EventLogEntryType.Information); startTryCount = 0; } catch (Exception exc) { EPSEventLog.WriteEntry("Failed to start service threads." + Environment.NewLine + exc.ToString(), EventLogEntryType.Error); stopServices(); } }