Esempio n. 1
0
 /// <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);
                 }
         }
     }
 }
Esempio n. 2
0
 /// <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);
                         }
                     }