/// <summary> /// Execution thread method. /// </summary> protected void ExecThread() { while (m_QueueNotEmpty.WaitOne()) { while (m_Queue.Count > 0) { SySal.OperaDb.OperaDbCredentials cred = new SySal.OperaDb.OperaDbCredentials(); DataProcessingBatchDesc desc = null; System.Exception retX = null; string textout = ""; string retXstr = ""; m_ExecProc = new System.Diagnostics.Process(); lock (m_ExecProc) { m_ExecProcKilled = false; lock (m_Queue) { desc = (DataProcessingBatchDesc)m_Queue[0]; } m_ExecProc.StartInfo.Arguments = desc.CommandLineArguments; m_ExecProc.StartInfo.FileName = desc.Filename; m_ExecProc.StartInfo.UseShellExecute = false; m_ExecProc.StartInfo.RedirectStandardError = true; m_ExecProc.StartInfo.RedirectStandardOutput = true; desc.Started = desc.Finished = System.DateTime.Now; try { cred.DBUserName = (desc.AliasUsername == null) ? "" : desc.AliasUsername; cred.DBPassword = (desc.AliasPassword == null) ? "" : desc.AliasPassword; cred.DBServer = OperaDataProcessingServer.DBServer; cred.OPERAUserName = (desc.Username == null) ? "" : desc.Username; cred.OPERAPassword = (desc.Password == null) ? "" : desc.Password; cred.RecordToEnvironment(m_ExecProc.StartInfo.EnvironmentVariables); desc.Started = System.DateTime.Now; m_ExecProc.Start(); } catch (Exception x) { retX = new DataProcessingException("Internal error occurred during process start.", x); } try { m_ExecProc.PriorityClass = OperaDataProcessingServer.LowPriority ? System.Diagnostics.ProcessPriorityClass.BelowNormal : System.Diagnostics.ProcessPriorityClass.Normal; //m_ExecProc.MaxWorkingSet = new System.IntPtr(OperaDataProcessingServer.PeakWorkingSetMB * 1048576); } catch (Exception) {} } int c = -1; if (retX == null) { do { try { m_ExecProc.Refresh(); System.DateTime nextw = System.DateTime.Now.AddSeconds(OutputUpdateSeconds); while ((c = m_ExecProc.StandardOutput.Read()) >= 0) { textout += (char)c; if (textout.Length > OperaDataProcessingServer.MaxOutputText) { textout = textout.Remove(0, textout.Length - OperaDataProcessingServer.MaxOutputText); } if (System.DateTime.Now >= nextw) { try { if (desc.OutputTextSaveFile != null && desc.OutputTextSaveFile.Length > 0) { System.IO.File.WriteAllText(desc.OutputTextSaveFile, textout); } } catch (Exception) { } } finally { nextw = System.DateTime.Now.AddSeconds(OutputUpdateSeconds); } } while ((c = m_ExecProc.StandardError.Read()) >= 0) { retXstr += (char)c; } desc.TotalProcessorTime = m_ExecProc.TotalProcessorTime; desc.PeakVirtualMemorySize = m_ExecProc.PeakVirtualMemorySize; desc.PeakWorkingSet = m_ExecProc.PeakWorkingSet; if (desc.OutputTextSaveFile != null && desc.OutputTextSaveFile.Length > 0) { System.IO.File.WriteAllText(desc.OutputTextSaveFile, textout); } }
/// <summary> /// Execution thread method. /// </summary> protected void ExecThread() { while (m_QueueNotEmpty.WaitOne()) { while (m_Queue.Count > 0) { SySal.OperaDb.OperaDbCredentials cred = new SySal.OperaDb.OperaDbCredentials(); DataProcessingBatchDesc desc = null; System.Exception retX = null; string retXstr = ""; m_ExecProc = new System.Diagnostics.Process(); lock (m_ExecProc) { m_ExecProcKilled = false; lock (m_Queue) { desc = (DataProcessingBatchDesc)m_Queue[0]; } m_ExecProc.StartInfo.Arguments = desc.CommandLineArguments; m_ExecProc.StartInfo.FileName = desc.Filename; m_ExecProc.StartInfo.UseShellExecute = false; m_ExecProc.StartInfo.RedirectStandardError = true; desc.Started = desc.Finished = System.DateTime.Now; try { cred.DBUserName = (desc.AliasUsername == null) ? "" : desc.AliasUsername; cred.DBPassword = (desc.AliasPassword == null) ? "" : desc.AliasPassword; cred.DBServer = OperaDataProcessingServer.DBServer; cred.OPERAUserName = (desc.Username == null) ? "" : desc.Username; cred.OPERAPassword = (desc.Password == null) ? "" : desc.Password; cred.RecordToEnvironment(m_ExecProc.StartInfo.EnvironmentVariables); desc.Started = System.DateTime.Now; m_ExecProc.Start(); } catch (Exception x) { retX = new DataProcessingException("Internal error occurred during process start.", x); } try { m_ExecProc.PriorityClass = OperaDataProcessingServer.LowPriority ? System.Diagnostics.ProcessPriorityClass.BelowNormal : System.Diagnostics.ProcessPriorityClass.Normal; //m_ExecProc.MaxWorkingSet = new System.IntPtr(OperaDataProcessingServer.PeakWorkingSetMB * 1048576); } catch (Exception) { } } if (retX == null) { //do { try { m_ExecProc.Refresh(); retXstr += m_ExecProc.StandardError.ReadToEnd(); desc.TotalProcessorTime = m_ExecProc.TotalProcessorTime; desc.PeakVirtualMemorySize = m_ExecProc.PeakVirtualMemorySize; desc.PeakWorkingSet = m_ExecProc.PeakWorkingSet; } catch (Exception) {} } //while (m_ExecProc.WaitForExit(1000) == false); desc.Finished = System.DateTime.Now; lock (m_ExecProc) { /* * try * { * retXstr += m_ExecProc.StandardError.ReadToEnd(); * } * catch (Exception) {}*/ if (retXstr == null || retXstr.Length == 0) { retX = null; } else { retX = new DataProcessingException(retXstr); } if (m_ExecProcKilled) { retX = new Exception("Process has been killed."); } } } else { try { retXstr += m_ExecProc.StandardError.ReadToEnd(); } catch (Exception) {} } m_ExecProc = null; SySal.OperaDb.OperaDbConnection conn = null; lock (m_ResultList) lock (m_Queue) { DataProcessingResult dpr = new DataProcessingResult(desc, m_ResultLiveTime); dpr.Processed = true; dpr.X = retX; m_ResultList.Add(dpr); m_Queue.RemoveAt(0); } } } }
static void Main(string[] args) { // // TODO: Add code to start application here // if (args.Length != 1 && args.Length != 6) { Console.WriteLine("Batch Test - test program for data processing servers."); Console.WriteLine("Keeps the CPU busy for the time specified (in seconds)."); Console.WriteLine("usage: batchtest <time to wait in seconds>"); Console.WriteLine("or: batchtest <time to wait in seconds> <dbserver> <dbuser> <dbpwd> <operauser> <operapwd>"); return; } if (args.Length == 6) { SySal.OperaDb.OperaDbCredentials cred = new SySal.OperaDb.OperaDbCredentials(); cred.DBServer = args[1]; cred.DBUserName = args[2]; cred.DBPassword = args[3]; cred.OPERAUserName = args[4]; cred.OPERAPassword = args[5]; System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.UseShellExecute = false; cred.RecordToEnvironment(proc.StartInfo.EnvironmentVariables); proc.StartInfo.FileName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; proc.StartInfo.Arguments = args[0]; Console.WriteLine("Spawning child and closing"); proc.Start(); proc.WaitForExit(); return; } string dbserver = ""; string dbuser = ""; string operauser = ""; try { SySal.OperaDb.OperaDbCredentials cred = SySal.OperaDb.OperaDbCredentials.CreateFromRecord(); dbserver = cred.DBServer; dbuser = cred.DBUserName; operauser = cred.OPERAUserName; SySal.OperaDb.OperaDbConnection conn = cred.Connect(); conn.Open(); Console.WriteLine("DBTest: " + new SySal.OperaDb.OperaDbCommand("SELECT * FROM DUAL", conn).ExecuteScalar().ToString()); Console.Write("Check access: "); Console.WriteLine(SySal.OperaDb.ComputingInfrastructure.User.CheckLogin(operauser, cred.OPERAPassword, conn, null)); } catch (Exception x) { Console.WriteLine("Exception: " + x.ToString()); } Console.WriteLine("Running with:\r\nDBServer-> " + dbserver + "\r\nDBUser-> " + dbuser + "\r\nOPERAUser-> " + operauser); Console.WriteLine("TEMPDIR=\"" + System.Environment.GetEnvironmentVariable("TEMP") + "\""); string escalatefile = System.Environment.ExpandEnvironmentVariables("%TEMP%/batchtest.escalate"); Console.WriteLine("Create the file: \"" + escalatefile + "\" to escalate the powerclass."); System.DateTime end = System.DateTime.Now.AddSeconds(Convert.ToDouble(args[0])); while (System.DateTime.Now.CompareTo(end) < 0) { ; } if (System.IO.File.Exists(escalatefile)) { throw new System.OutOfMemoryException("Batch escalation required."); } }