protected void RunJava(int JobKey, string JobFileName, string RawJobFileName) { String args = String.Format("-s {0} -d {1} JobKey={2} DefinitionFile={3}", MiscUtilities.WrapSpaces(_SettingsFile), MiscUtilities.WrapSpaces(JobFileName), JobKey, RawJobFileName); using (Process clientProcess = new Process()) { clientProcess.StartInfo.UseShellExecute = false; clientProcess.StartInfo.RedirectStandardOutput = true; clientProcess.StartInfo.RedirectStandardError = true; clientProcess.StartInfo.CreateNoWindow = true; clientProcess.StartInfo.WorkingDirectory = MiscUtilities.AppParentPath(); clientProcess.StartInfo.FileName = MiscUtilities.WrapSpaces(_JavaHome + "java.exe"); clientProcess.StartInfo.Arguments = @"-jar " + MiscUtilities.WrapSpaces(_JarPath) + " " + args; lock (_lock) { LocalLog.AddLine(String.Format("Command line: {0} {1}", MiscUtilities.WrapSpaces(_JavaHome + "java.exe"), @"-jar " + MiscUtilities.WrapSpaces(_JarPath) + " " + args)); } clientProcess.Start(); string output = clientProcess.StandardOutput.ReadToEnd(); string errorOutput = clientProcess.StandardError.ReadToEnd(); clientProcess.WaitForExit(); int exitcode = clientProcess.ExitCode; LocalLog.AddLine("Console Output: " + System.Environment.NewLine + output); if (exitcode > 0) { LocalLog.AddLine("ERROR OUTPUT: " + System.Environment.NewLine + errorOutput); throw new Exception(String.Format("Run JAVA error ExitCode {0} running {1} {2}", exitcode, clientProcess.StartInfo.FileName, clientProcess.StartInfo.Arguments)); } } }
protected override void OnStart(string[] args) { LocalLog.AddLine("Starting the mutliprocessor scheduler service."); logEnvironment(); String path = MiscUtilities.AppParentPath() + Path.DirectorySeparatorChar; _taskManager = new ScanManager.TaskManager(); _CleanupLogs = _taskManager.CleanupLogs; _threadPool = new ScanManager.BackgroundProcessing[_taskManager.ThreadPoolSize]; try { LocalLog.AddLine("Starting Timer: Interval is 30 seconds"); _timer = new System.Timers.Timer(30000); // every 30 seconds _timer.Elapsed += new System.Timers.ElapsedEventHandler(pieJobCheck); _timer.Start(); LocalLog.AddLine("Service is running."); } catch (Exception ex) { LocalLog.AddLine("Error while starting timer. " + ex.Message); } }
//protected Boolean RunScan() //{ // Dictionary<String, Object> aParams = new Dictionary<string, object>(); // aParams.Add(":jobkey", _JobKey); // aParams.Add(":jobstatus", "Ready"); // aParams.Add(":statusdescription", "Ready"); // aParams.Add(":machinename", Environment.MachineName); // try // { // // Set any definitions left in_progress from previous run to error. // SqlUtilities.ExcecuteNonQuery(_ConnectionString, _SqlErrorOutInProgress, aParams); // //// Look for the next rescan request. // SqlUtilities.ExcecuteNonQuery(_ConnectionString, _SqlTakeNextRequest, aParams); // DataTable requests = SqlUtilities.GetData(_ConnectionString, _SqlNextJob); // //if ((requests == null) || (requests.Rows.Count == 0)) return false; // //_JobKey = (int)requests.Rows[0]["pkey"]; // //_JobFileName = (String)requests.Rows[0]["definition_name"]; // aParams[":jobkey"] = _JobKey; // // Run the definition and wait till it finishes. // aParams[":jobstatus"] = "Processing"; // aParams[":statusdescription"] = String.Format("Started: {0:MMMM d, yyyy HH:mm:ss}", DateTime.Now); // SqlUtilities.ExcecuteNonQuery(_ConnectionString, _SqlUpdateStatus, aParams); // // Shell to the JAVA program and run it. // RunJava(); // // Job finished update record. // aParams[":jobstatus"] = "Completed"; // aParams[":statusdescription"] = String.Format("Completed: {0:MMMM d, yyyy HH:mm:ss}", DateTime.Now); // } // catch (Exception ex) // { // LocalLog.AddLine("Code Scan Error: " + ex.Message); // aParams[":jobstatus"] = "Error"; // aParams[":statusdescription"] = String.Format("Recorded: {0:MMMM d, yyyy HH:mm:ss}, Message: {1} ", DateTime.Now, ex.Message).Substring(0, 99); // // Error out this queue item and rest for this application. // SqlUtilities.ExcecuteNonQuery(_ConnectionString, String.Format("UPDATE fnma_measure8.automated_queue SET ready=false, status='ERROR' WHERE ready and scan_manager_pkey={0}", _JobKey)); // } // SqlUtilities.ExcecuteNonQuery(_ConnectionString, _SqlJobFinished, aParams); // return false; //} protected void RunJava() { String args = String.Format("-s {0} -d {1} JobKey={2} DefinitionFile={3}", WrapSpaces(_SettingsFile), WrapSpaces(_JobFileName), _JobKey, _RawJobFileName); using (Process clientProcess = new Process()) { clientProcess.StartInfo.UseShellExecute = false; clientProcess.StartInfo.RedirectStandardOutput = true; clientProcess.StartInfo.RedirectStandardError = true; clientProcess.StartInfo.CreateNoWindow = true; clientProcess.StartInfo.WorkingDirectory = MiscUtilities.AppParentPath(); clientProcess.StartInfo.FileName = WrapSpaces(_JavaHome + "java.exe"); clientProcess.StartInfo.Arguments = @"-jar " + WrapSpaces(_JarPath) + " " + args; LocalLog.AddLine(String.Format("Command line: {0} {1}", WrapSpaces(_JavaHome + "java.exe"), @"-jar " + WrapSpaces(_JarPath) + " " + args)); clientProcess.Start(); string output = clientProcess.StandardOutput.ReadToEnd(); clientProcess.WaitForExit(); int exitcode = clientProcess.ExitCode; if (exitcode > 0) { throw new Exception(String.Format("Run JAVA error ExitCode {0} running {1} {2}", exitcode, clientProcess.StartInfo.FileName, clientProcess.StartInfo.Arguments)); } } }