private void Init(object sender, System.EventArgs e) { SySal.OperaDb.OperaDbCredentials oc = SySal.OperaDb.OperaDbCredentials.CreateFromRecord(); DBServerText.Text = oc.DBServer; DBUsernameText.Text = oc.DBUserName; DBPasswordText.Text = oc.DBPassword; OPERAUsernameText.Text = oc.OPERAUserName; OPERAPasswordText.Text = oc.OPERAPassword; }
private void OnLoad(object sender, System.EventArgs e) { SySal.OperaDb.OperaDbCredentials cred = SySal.OperaDb.OperaDbCredentials.CreateFromRecord(); System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(new TcpChannel(), false); Conn = new SySal.OperaDb.OperaDbConnection(cred.DBServer, cred.DBUserName, cred.DBPassword); Conn.Open(); System.Data.DataSet ds = new System.Data.DataSet(); new SySal.OperaDb.OperaDbDataAdapter("select name from tb_machines where id_site = (select to_number(value) from opera.lz_sitevars where name = 'ID_SITE') and isbatchserver = 1", Conn, null).Fill(ds); foreach (System.Data.DataRow dr in ds.Tables[0].Rows) { comboBatchManager.Items.Add(dr[0].ToString()); } new SySal.OperaDb.OperaDbCommand("alter session set nls_comp='LINGUISTIC'", Conn).ExecuteNonQuery(); new SySal.OperaDb.OperaDbCommand("alter session set NLS_SORT='BINARY_CI'", Conn).ExecuteNonQuery(); }
public MainForm() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // SySal.OperaDb.OperaDbCredentials oc = SySal.OperaDb.OperaDbCredentials.CreateFromRecord(); UsernameText.Text = oc.OPERAUserName; PasswordText.Text = oc.OPERAPassword; AliasUsernameText.Text = oc.DBUserName; AliasPasswordText.Text = oc.DBPassword; }
private void VerifyButton_Click(object sender, System.EventArgs e) { SySal.OperaDb.OperaDbCredentials oc = new SySal.OperaDb.OperaDbCredentials(); oc.DBServer = DBServerText.Text; oc.DBUserName = DBUsernameText.Text; oc.DBPassword = DBPasswordText.Text; oc.OPERAUserName = OPERAUsernameText.Text; oc.OPERAPassword = OPERAPasswordText.Text; try { oc.CheckDbAccess(); MessageBox.Show("OK", "Verification succeeded", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception x) { MessageBox.Show(x.Message, "Verification failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void OKButton_Click(object sender, System.EventArgs e) { SySal.OperaDb.OperaDbCredentials oc = new SySal.OperaDb.OperaDbCredentials(); oc.DBServer = DBServerText.Text; oc.DBUserName = DBUsernameText.Text; oc.DBPassword = DBPasswordText.Text; oc.OPERAUserName = OPERAUsernameText.Text; oc.OPERAPassword = OPERAPasswordText.Text; try { oc.Record(); Close(); } catch (Exception x) { MessageBox.Show(x.Message, "Credentials could not be recorded", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main(string[] args) { // // TODO: Add code to start application here // if (args.Length != 3 && args.Length != 4) { Console.WriteLine("usage: GetDBMarks <brick id> <plate id> <type-or-id> <mark set>"); Console.WriteLine("<type> can be either nominal or calibrated; as an alternative, the explicit Id of the calibration requested can be given."); Console.WriteLine("<mark set> can be " + SySal.DAQSystem.Drivers.MarkChar.SpotOptical + " (Spot Optical), " + SySal.DAQSystem.Drivers.MarkChar.LineXRay + " (X-ray lateral), " + SySal.DAQSystem.Drivers.MarkChar.SpotXRay + " (X-ray for CS-brick connection). This parameter is needed when the id is not directly specified."); return; } long id = 0; char mt = SySal.DAQSystem.Drivers.MarkChar.None; bool calibrated = String.Compare(args[2], "calibrated", true) == 0; if (!calibrated && String.Compare(args[2], "nominal", true) != 0) { id = Convert.ToInt64(args[2]); } else { mt = Convert.ToChar(args[3]); } SySal.OperaDb.OperaDbCredentials cred = SySal.OperaDb.OperaDbCredentials.CreateFromRecord(); SySal.OperaDb.OperaDbConnection conn = new SySal.OperaDb.OperaDbConnection(cred.DBServer, cred.DBUserName, cred.DBPassword); conn.Open(); if (id == 0) { long calibrationid; Console.WriteLine(SySal.OperaDb.Scanning.Utilities.GetMapString(Convert.ToInt64(args[0]), Convert.ToInt64(args[1]), calibrated, SySal.OperaDb.Scanning.Utilities.CharToMarkType(mt), out calibrationid, conn, null)); } else { Console.WriteLine(SySal.OperaDb.Scanning.Utilities.GetMapString(Convert.ToInt64(args[0]), Convert.ToInt64(args[1]), id, conn, null)); } conn.Close(); }
public override bool Execute() { SySal.DAQSystem.IDataProcessingServer DataProcSrv = (SySal.DAQSystem.IDataProcessingServer)System.Runtime.Remoting.RemotingServices.Connect(typeof(SySal.DAQSystem.IDataProcessingServer), "tcp://" + BatchServer + ":" + ((int)SySal.DAQSystem.OperaPort.BatchServer) + "/DataProcessingServer.rem"); SySal.DAQSystem.DataProcessingBatchDesc bd = new SySal.DAQSystem.DataProcessingBatchDesc(); SySal.OperaDb.OperaDbCredentials cred = SySal.OperaDb.OperaDbCredentials.CreateFromRecord(); bd.Username = cred.OPERAUserName; bd.Password = cred.OPERAPassword; bd.Description = "ListScan - " + LineNumber; bd.Id = DataProcSrv.SuggestId; bd.MachinePowerClass = MachinePowerClass; bd.OutputTextSaveFile = LogFile; bd.Filename = ExeFile; bd.AliasPassword = ""; bd.AliasUsername = ""; Console.Write("(batch=" + bd.Id.ToString("X16") + ")"); string s = ""; int i; for (i = 0; i < Arguments.Length; i++) { if (i > 0) { s += " "; } if (Arguments[i].StartsWith("\"") == false) { s += "\"" + Arguments[i] + "\""; } else { s += Arguments[i]; } } bd.CommandLineArguments = s; return(DataProcSrv.Enqueue(bd)); }
static void Main(string[] args) { // // TODO: Add code to start application here // if (args.Length != 3) { System.Xml.Serialization.XmlSerializer xmls = null; Console.WriteLine("BatchReconstruct - performs volume reconstruction using LinkedZones from TLG files or OPERA DB tables."); Console.WriteLine("usage: batchreconstruct <XML list file> <output Opera persistence path> <XML config Opera persistence path>"); Console.WriteLine("or: batchreconstruct <DB volume> <output Opera persistence path> <XML config Opera persistence path>"); Console.WriteLine("or: batchreconstruct <input OPERA persistence path> <output Opera persistence path> <XML config Opera persistence path>"); Console.WriteLine("Full volumes are reprocessed for topological reconstruction only."); Console.WriteLine("---------------- DB volume example: db:\\8\\17723900.vol"); Console.WriteLine("First number is ID_EVENTBRICK, second is ID_VOLUME"); Console.WriteLine("---------------- XML list file example (source = filesystem):"); Input inputlist = new Input(); inputlist.Zones = new Zone[3]; inputlist.Zones[0] = new Zone(); inputlist.Zones[0].SheetId = 8; inputlist.Zones[0].Source = @"\\myserver.mydomain\myshare\plate_08.tlg"; inputlist.Zones[0].Z = 0.0; inputlist.Zones[0].AlignmentIgnoreListPath = @"\\myserver\mydomain\myshare\alignignore_plate_08.txt"; inputlist.Zones[1] = new Zone(); inputlist.Zones[1].SheetId = 9; inputlist.Zones[1].Source = @"\\myserver.mydomain\myshare\plate_09.tlg"; inputlist.Zones[1].Z = -1300.0; inputlist.Zones[2] = new Zone(); inputlist.Zones[2].SheetId = 10; inputlist.Zones[2].Source = @"\\myserver.mydomain\myshare\plate_10.tlg"; inputlist.Zones[2].Z = -2600.0; xmls = new System.Xml.Serialization.XmlSerializer(typeof(BatchReconstruct.Input)); xmls.Serialize(Console.Out, inputlist); Console.WriteLine(); Console.WriteLine("---------------- XML list file example (source = OperaDB):"); inputlist.Zones[0].Source = @"db:\1002323.tlg"; inputlist.Zones[1].Source = @"db:\1006326.tlg"; inputlist.Zones[2].Source = @"db:\1009724.tlg"; xmls.Serialize(Console.Out, inputlist); Console.WriteLine(); Console.WriteLine("---------------- XML config file syntax:"); Console.WriteLine("XML configuration syntax:"); BatchReconstruct.Config C = new BatchReconstruct.Config(); C.ReconstructorConfig = (Configuration) new AlphaOmegaReconstructor().Config; xmls = new System.Xml.Serialization.XmlSerializer(typeof(BatchReconstruct.Config)); xmls.Serialize(Console.Out, C); Console.WriteLine(); return; } #if !(DEBUG) try #endif { AlphaOmegaReconstructor R = new AlphaOmegaReconstructor(); System.Xml.Serialization.XmlSerializer xmls = null; xmls = new System.Xml.Serialization.XmlSerializer(typeof(BatchReconstruct.Config)); Config config = (Config)xmls.Deserialize(new System.IO.StringReader(((SySal.OperaDb.ComputingInfrastructure.ProgramSettings)SySal.OperaPersistence.Restore(args[2], typeof(SySal.OperaDb.ComputingInfrastructure.ProgramSettings))).Settings)); R.Config = (SySal.Management.Configuration)config.ReconstructorConfig; R.Progress = new SySal.TotalScan.dProgress(Progress); R.Report = new SySal.TotalScan.dReport(Report); System.Text.RegularExpressions.Regex volrgx = new System.Text.RegularExpressions.Regex(@"db:\\(\d+)\\(\d+)\.vol"); System.Text.RegularExpressions.Match mrgx = volrgx.Match(args[0].ToLower()); Input inputlist = null; SySal.TotalScan.Volume OldVol = null; if (args[0].ToLower().EndsWith(".tsr")) { OldVol = (SySal.TotalScan.Volume)SySal.OperaPersistence.Restore(args[0], typeof(SySal.TotalScan.Volume)); } else { if (mrgx.Success && mrgx.Length == args[0].Length) { SySal.OperaDb.OperaDbCredentials cred = SySal.OperaDb.OperaDbCredentials.CreateFromRecord(); SySal.OperaDb.OperaDbConnection conn = new SySal.OperaDb.OperaDbConnection(cred.DBServer, cred.DBUserName, cred.DBPassword); conn.Open(); System.Data.DataSet ds = new System.Data.DataSet(); new SySal.OperaDb.OperaDbDataAdapter("SELECT TB_VOLUME_SLICES.ID_PLATE, TB_VOLUME_SLICES.ID_ZONE, VW_PLATES.Z FROM TB_VOLUME_SLICES INNER JOIN VW_PLATES ON (TB_VOLUME_SLICES.ID_EVENTBRICK = VW_PLATES.ID_EVENTBRICK AND TB_VOLUME_SLICES.ID_PLATE = VW_PLATES.ID) WHERE TB_VOLUME_SLICES.DAMAGED = 'N' AND TB_VOLUME_SLICES.ID_EVENTBRICK = " + mrgx.Groups[1].Value + " AND TB_VOLUME_SLICES.ID_VOLUME = " + mrgx.Groups[2].Value + " ORDER BY VW_PLATES.Z DESC", conn, null).Fill(ds); inputlist = new Input(); inputlist.Zones = new Zone[ds.Tables[0].Rows.Count]; int sli; for (sli = 0; sli < ds.Tables[0].Rows.Count; sli++) { inputlist.Zones[sli] = new Zone(); inputlist.Zones[sli].SheetId = Convert.ToInt32(ds.Tables[0].Rows[sli][0]); inputlist.Zones[sli].Source = "db:\\" + mrgx.Groups[1] + "\\" + ds.Tables[0].Rows[sli][1].ToString() + ".tlg"; inputlist.Zones[sli].Z = Convert.ToDouble(ds.Tables[0].Rows[sli][2]); } SySal.OperaPersistence.Connection = conn; SySal.OperaPersistence.LinkedZoneDetailLevel = SySal.OperaDb.Scanning.LinkedZone.DetailLevel.BaseFull; } else { System.IO.StreamReader r = new System.IO.StreamReader(args[0]); xmls = new System.Xml.Serialization.XmlSerializer(typeof(BatchReconstruct.Input)); inputlist = (Input)xmls.Deserialize(r); r.Close(); } int i, j, c; for (i = 0; i < inputlist.Zones.Length; i++) { for (j = i + 1; j < inputlist.Zones.Length; j++) { if (inputlist.Zones[i].SheetId == inputlist.Zones[j].SheetId) { Console.WriteLine("Duplicate SheetId found. Sheets will be renumbered with the default sequence."); for (j = 0; j < inputlist.Zones.Length; j++) { inputlist.Zones[j].SheetId = j; } i = inputlist.Zones.Length; break; } } } for (i = 0; i < inputlist.Zones.Length; i++) { SySal.Scanning.Plate.IO.OPERA.LinkedZone lz = (SySal.Scanning.Plate.IO.OPERA.LinkedZone)SySal.OperaPersistence.Restore(inputlist.Zones[i].Source, typeof(SySal.Scanning.Plate.IO.OPERA.LinkedZone)); c = lz.Length; SySal.TotalScan.Segment[] segs = new SySal.TotalScan.Segment[c]; double[] zcor = new double[c]; for (j = 0; j < c; j++) { zcor[j] = lz[j].Info.Intercept.Z; } double zmean = NumericalTools.Fitting.Average(zcor); double dgap; for (j = 0; j < c; j++) { SySal.Tracking.MIPEmulsionTrackInfo info = lz[j].Info; segs[j] = new SySal.TotalScan.Segment(info, new SySal.TotalScan.BaseTrackIndex(j)); dgap = zmean - info.Intercept.Z; info.Intercept.Z = zmean; info.Intercept.X += info.Slope.X * dgap; info.Intercept.Y += info.Slope.Y * dgap; info.TopZ += dgap; info.BottomZ += dgap; info.Intercept.Z = inputlist.Zones[i].Z; double tmptopz = info.TopZ; double tmpbotz = info.BottomZ; dgap = zmean - tmptopz; info.TopZ = inputlist.Zones[i].Z - dgap; info.BottomZ = inputlist.Zones[i].Z - (tmptopz - tmpbotz) - dgap; } SySal.BasicTypes.Vector refc = new SySal.BasicTypes.Vector(); refc.Z = inputlist.Zones[i].Z; SySal.TotalScan.Layer tmpLayer = new SySal.TotalScan.Layer(i, /*System.Convert.ToInt64(mrgx.Groups[1].Value)*/ 0, (int)inputlist.Zones[i].SheetId, 0, refc); tmpLayer.AddSegments(segs); R.AddLayer(tmpLayer); if (inputlist.Zones[i].AlignmentIgnoreListPath != null && inputlist.Zones[i].AlignmentIgnoreListPath.Trim().Length != 0) { if (inputlist.Zones[i].AlignmentIgnoreListPath.ToLower().EndsWith(".tlg")) { R.SetAlignmentIgnoreList(i, ((SySal.Scanning.Plate.IO.OPERA.LinkedZone.BaseTrackIgnoreAlignment)SySal.OperaPersistence.Restore(inputlist.Zones[i].AlignmentIgnoreListPath, typeof(SySal.Scanning.Plate.IO.OPERA.LinkedZone.BaseTrackIgnoreAlignment))).Ids); } else { System.IO.StreamReader r = new System.IO.StreamReader(inputlist.Zones[i].AlignmentIgnoreListPath.Trim()); System.Collections.ArrayList tmpignorelist = new System.Collections.ArrayList(); string line; while ((line = r.ReadLine()) != null) { try { tmpignorelist.Add(System.Convert.ToInt32(line)); } catch (Exception) { } } ; r.Close(); R.SetAlignmentIgnoreList(i, (int[])tmpignorelist.ToArray(typeof(int))); } } Console.WriteLine("Loaded sheet {0} Id {1} Tracks {2}", i, inputlist.Zones[i].SheetId, c); lz = null; } } SySal.TotalScan.Volume V = (OldVol == null) ? R.Reconstruct() : R.RecomputeVertices(OldVol); Console.WriteLine("Result written to: " + SySal.OperaPersistence.Persist(args[1], V)); } #if !(DEBUG) catch (Exception x) { Console.Error.WriteLine(x.ToString()); } #endif }
/// <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) { SySal.OperaDb.OperaDbCredentials cred = SySal.OperaDb.OperaDbCredentials.CreateFromRecord(); SySal.OperaDb.OperaDbConnection conn = new SySal.OperaDb.OperaDbConnection(cred.DBServer, cred.DBUserName, cred.DBPassword); conn.Open(); Console.WriteLine("namespace SySal.OperaDb"); Console.WriteLine("{"); Console.WriteLine("\t/// <summary>"); Console.WriteLine("\t/// Static class that allows access to schema components of the OPERA DB."); Console.WriteLine("\t/// Its DB field must be set before the class can be used."); Console.WriteLine("\t/// </summary>"); Console.WriteLine("\tpublic class Schema"); Console.WriteLine("\t{"); Console.WriteLine("\t\tprivate Schema() {}"); Console.WriteLine("\t\t/// <summary>"); Console.WriteLine("\t\t/// Retrieval order for query results."); Console.WriteLine("\t\t/// </summary>"); Console.WriteLine("\t\tpublic enum OrderBy { None, Ascending, Descending }"); string ondbsetprepared = ""; System.Data.DataSet ds_tb = new System.Data.DataSet(); new SySal.OperaDb.OperaDbDataAdapter("SELECT TABLE_NAME FROM ALL_TABLES WHERE OWNER = 'OPERA' AND (TABLE_NAME LIKE 'TB_%' OR TABLE_NAME LIKE 'LZ_%') ORDER BY TABLE_NAME ASC", conn, null).Fill(ds_tb); foreach (System.Data.DataRow dr_tb in ds_tb.Tables[0].Rows) { ondbsetprepared += "\t\t\t\tif (" + dr_tb[0].ToString() + ".Prepared) { " + dr_tb[0].ToString() + ".cmd.Connection = null; " + dr_tb[0].ToString() + ".Prepared = false; }\n"; string AutoIdColumn = null; try { AutoIdColumn = new SySal.OperaDb.OperaDbCommand("SELECT COLUMN_NAME FROM ALL_TRIGGER_COLS WHERE TABLE_NAME = '" + dr_tb[0].ToString() + "' AND TABLE_OWNER = 'OPERA' AND COLUMN_USAGE = 'NEW OUT'", conn, null).ExecuteScalar().ToString(); if (AutoIdColumn == "") { AutoIdColumn = null; } } catch (Exception) { AutoIdColumn = null; } Console.WriteLine("\t\t/// <summary>"); Console.WriteLine("\t\t/// Accesses the " + dr_tb[0].ToString() + " table in the DB."); if (AutoIdColumn == null) { Console.WriteLine("\t\t/// For data insertion, the Insert and Flush static methods are used. This class inserts data in batches."); } else { Console.WriteLine("\t\t/// For data insertion, the Insert method is used. Rows are inserted one by one."); } Console.WriteLine("\t\t/// An instance of the class is produced for data retrieval."); Console.WriteLine("\t\t/// </summary>"); Console.WriteLine("\t\tpublic class " + dr_tb[0].ToString()); Console.WriteLine("\t\t{"); Console.WriteLine("\t\t\tinternal " + dr_tb[0].ToString() + "() {}"); Console.WriteLine("\t\t\tSystem.Data.DataRowCollection m_DRC;"); if (AutoIdColumn == null) { Console.WriteLine("\t\t\tconst int ArraySize = 100;"); Console.WriteLine("\t\t\tstatic int index = 0;"); Console.WriteLine("\t\t\t/// <summary>"); Console.WriteLine("\t\t\t/// Since this class uses batch insertion, this method must be called to ensure that all rows are actually inserted into " + dr_tb[0].ToString() + ". Failure to do so will result in incomplete writes."); Console.WriteLine("\t\t\t/// </summary>"); Console.WriteLine("\t\t\tstatic public void Flush() { if (cmd == null || index == 0) return; cmd.ArrayBindCount = index; cmd.ExecuteNonQuery(); index = 0; }"); } ; System.Data.DataSet ds_col = new System.Data.DataSet(); new SySal.OperaDb.OperaDbDataAdapter("SELECT COLUMN_NAME, DATA_TYPE, DATA_PRECISION, DATA_SCALE, NULLABLE, DATA_LENGTH FROM ALL_TAB_COLUMNS WHERE OWNER = 'OPERA' AND TABLE_NAME = '" + dr_tb[0].ToString() + "' ORDER BY COLUMN_ID", conn, null).Fill(ds_col); object pk_obj = new SySal.OperaDb.OperaDbCommand("SELECT CONSTRAINT_NAME FROM ALL_CONSTRAINTS WHERE OWNER = 'OPERA' AND CONSTRAINT_TYPE = 'P' AND TABLE_NAME = '" + dr_tb[0].ToString() + "'", conn, null).ExecuteScalar(); string colstring = ""; string parstring = ""; string parslotstring = ""; int parcount = 0; string insertparamstring = ""; string insertparslotstring = ""; string inserthelpparamstring = ""; foreach (System.Data.DataRow dr_col in ds_col.Tables[0].Rows) { if (parcount > 0) { colstring += ","; parstring += ","; insertparamstring += ","; } parcount++; colstring += dr_col[0].ToString(); parstring += ":p_" + parcount; string array_type = "object"; string data_type = "UNKNOWN-" + dr_col[1].ToString(); string oratype_string = "UNKNOWN-" + dr_col[1].ToString(); string convertstr = "UNKNOWN"; bool isnullable = true; if (dr_col[1].ToString() == "NUMBER" && dr_col[3].ToString() == "0") { if (dr_col[2] == System.DBNull.Value || Convert.ToInt32(dr_col[2]) > 8) { data_type = "long"; oratype_string = "SySal.OperaDb.OperaDbType.Long"; convertstr = "Int64"; } else { data_type = "int"; oratype_string = "SySal.OperaDb.OperaDbType.Int"; convertstr = "Int32"; } } else if (dr_col[1].ToString() == "FLOAT" || dr_col[1].ToString() == "NUMBER") { data_type = "double"; oratype_string = "SySal.OperaDb.OperaDbType.Double"; convertstr = "Double"; } else if (dr_col[1].ToString() == "CHAR") { if (SySal.OperaDb.Convert.ToInt32(dr_col[5]) == 1) { data_type = "char"; oratype_string = "SySal.OperaDb.OperaDbType.String"; convertstr = "Char"; } else { data_type = "string"; oratype_string = "SySal.OperaDb.OperaDbType.String"; convertstr = "String"; } } else if (dr_col[1].ToString() == "VARCHAR2") { data_type = "string"; oratype_string = "SySal.OperaDb.OperaDbType.String"; convertstr = "String"; } else if (dr_col[1].ToString() == "DATE" || dr_col[1].ToString().StartsWith("TIMESTAMP")) { data_type = "System.DateTime"; oratype_string = "SySal.OperaDb.OperaDbType.DateTime"; convertstr = "DateTime"; } else if (dr_col[1].ToString() == "CLOB") { data_type = "string"; oratype_string = "SySal.OperaDb.OperaDbType.CLOB"; convertstr = "String"; } else if (dr_col[1].ToString() == "BLOB") { data_type = "byte []"; oratype_string = "SySal.OperaDb.OperaDbType.BLOB"; convertstr = "Bytes"; } if (dr_col[4].ToString() == "N") { array_type = data_type; isnullable = false; } parslotstring += "\t\t\t\tnewcmd.Parameters.Add(\"p_" + parcount + "\", " + oratype_string + ", System.Data.ParameterDirection.Input)" + ((AutoIdColumn != null) ? "" : (".Value = a_" + dr_col[0].ToString().Replace("#", "_SHARP_"))) + ";\n"; insertparamstring += array_type + " i_" + dr_col[0].ToString().Replace("#", "_SHARP_"); if (AutoIdColumn == null || AutoIdColumn != dr_col[0].ToString()) { inserthelpparamstring += "\t\t\t/// <param name=\"i_" + dr_col[0].ToString().Replace("#", "_SHARP_") + "\">the value to be inserted for " + dr_col[0].ToString() + (isnullable ? (". The value for this parameter can be " + data_type + " or System.DBNull.Value") : "") + ".</param>\n"; } else { inserthelpparamstring += "\t\t\t/// <param name=\"i_" + dr_col[0].ToString().Replace("#", "_SHARP_") + "\">the value to be inserted for " + dr_col[0].ToString() + (isnullable ? (". The value for this parameter can be " + data_type + " or System.DBNull.Value") : "") + ". This value is actually used only if this method call is involved in data publication/replication, otherwise the actual value is generated by the OPERA DB and the supplied value is ignored.</param>\n"; } if (AutoIdColumn == null) { insertparslotstring += "\t\t\t\ta_" + dr_col[0].ToString().Replace("#", "_SHARP_") + "[index] = i_" + dr_col[0].ToString().Replace("#", "_SHARP_") + ";\n"; Console.WriteLine("\t\t\tprivate static " + array_type + " [] a_" + dr_col[0].ToString().Replace("#", "_SHARP_") + " = new " + array_type + "[ArraySize];"); } else { insertparslotstring += "\t\t\t\tcmd.Parameters[" + (parcount - 1) + "].Value = i_" + dr_col[0].ToString().Replace("#", "_SHARP_") + ";\n"; } Console.WriteLine("\t\t\t/// <summary>"); Console.WriteLine("\t\t\t/// Retrieves " + dr_col[0].ToString() + " for the current row." + (isnullable ? (" The return value can be System.DBNull.Value or a value that can be cast to " + data_type + ".") : "")); Console.WriteLine("\t\t\t/// </summary>"); Console.WriteLine("\t\t\tpublic " + array_type + " _" + dr_col[0].ToString().Replace("#", "_SHARP_")); Console.WriteLine("\t\t\t{"); Console.WriteLine("\t\t\t\tget"); Console.WriteLine("\t\t\t\t{"); if (isnullable) { Console.WriteLine("\t\t\t\t\tif (m_DR[" + (parcount - 1) + "] == System.DBNull.Value) return System.DBNull.Value;"); } if (convertstr == "Bytes") { Console.WriteLine("\t\t\t\t\treturn SySal.OperaDb.Convert.To" + convertstr + "(m_DR[" + (parcount - 1) + "]);"); } else { Console.WriteLine("\t\t\t\t\treturn System.Convert.To" + convertstr + "(m_DR[" + (parcount - 1) + "]);"); } Console.WriteLine("\t\t\t\t}"); Console.WriteLine("\t\t\t}"); } if (AutoIdColumn != null) { parslotstring += "\t\t\t\tnewcmd.Parameters.Add(\"o_" + parcount + "\", SySal.OperaDb.OperaDbType.Long, System.Data.ParameterDirection.Output);\n"; Console.WriteLine("\t\t\t/// <summary>"); Console.WriteLine("\t\t\t/// Inserts one row into the DB. The row is inserted immediately."); Console.WriteLine("\t\t\t/// </summary>"); Console.Write(inserthelpparamstring); Console.WriteLine("\t\t\t/// <returns>the value of " + AutoIdColumn + " for the new row.</returns>"); Console.WriteLine("\t\t\tstatic public long Insert(" + insertparamstring + ")"); Console.WriteLine("\t\t\t{"); Console.WriteLine("\t\t\t\tif (!Prepared) { cmd.Connection = Schema.m_DB; Prepared = true; cmd.Prepare(); };"); Console.Write(insertparslotstring); Console.WriteLine("\t\t\t\tcmd.ExecuteNonQuery();"); Console.WriteLine("\t\t\t\treturn SySal.OperaDb.Convert.ToInt64(cmd.Parameters[" + parcount + "].Value);"); Console.WriteLine("\t\t\t}"); } else { Console.WriteLine("\t\t\t/// <summary>"); Console.WriteLine("\t\t\t/// Inserts one row into the DB. The row is actually inserted later, in a batch insertion command. The Flush method must be called to ensure all rows are actually written."); Console.WriteLine("\t\t\t/// </summary>"); Console.Write(inserthelpparamstring); Console.WriteLine("\t\t\tstatic public void Insert(" + insertparamstring + ")"); Console.WriteLine("\t\t\t{"); Console.WriteLine("\t\t\t\tif (!Prepared) { cmd.Connection = Schema.m_DB; Prepared = true; cmd.Prepare(); };"); Console.Write(insertparslotstring); Console.WriteLine("\t\t\t\tif (++index >= ArraySize) { cmd.ArrayBindCount = index; cmd.ExecuteNonQuery(); index = 0; }"); Console.WriteLine("\t\t\t}"); } if (pk_obj != null && pk_obj != System.DBNull.Value) { System.Data.DataSet dpks = new System.Data.DataSet(); new SySal.OperaDb.OperaDbDataAdapter("select column_name from all_cons_columns where all_cons_columns.owner = 'OPERA' and constraint_name = '" + pk_obj.ToString() + "'", conn, null).Fill(dpks); string selpkparams = ""; string orderbyascstring = ""; string orderbydescstring = ""; string selecthelpparamstring = ""; foreach (System.Data.DataRow dpkr in dpks.Tables[0].Rows) { if (selpkparams.Length == 0) { selpkparams = "object i_" + dpkr[0].ToString().Replace("#", "_SHARP_"); orderbyascstring = dpkr[0].ToString() + " ASC"; orderbydescstring = dpkr[0].ToString() + " DESC"; } else { selpkparams += ",object i_" + dpkr[0].ToString().Replace("#", "_SHARP_"); orderbyascstring += "," + dpkr[0].ToString() + " ASC"; orderbydescstring += "," + dpkr[0].ToString() + " DESC"; } selecthelpparamstring += "\t\t\t/// <param name=\"i_" + dpkr[0].ToString().Replace("#", "_SHARP_") + "\">if non-null, only rows that have this field equal to the specified value are returned.</param>\n"; } Console.WriteLine("\t\t\t/// <summary>"); Console.WriteLine("\t\t\t/// Reads a set of rows from " + dr_tb[0].ToString() + " and retrieves them into a new " + dr_tb[0].ToString() + " object."); Console.WriteLine("\t\t\t/// </summary>"); Console.Write(selecthelpparamstring); Console.WriteLine("\t\t\t/// <param name=\"order\">the ordering scheme to be applied to returned rows." + ((dpks.Tables[0].Rows.Count > 1) ? " This applies to all columns in the primary key." : "") + "</param>"); Console.WriteLine("\t\t\t/// <returns>a new instance of the " + dr_tb[0].ToString() + " class that can be used to read the retrieved data.</returns>"); Console.WriteLine("\t\t\tstatic public " + dr_tb[0].ToString() + " SelectPrimaryKey(" + selpkparams + ", OrderBy order)"); Console.WriteLine("\t\t\t{"); Console.WriteLine("\t\t\t\tstring wherestr = \"\";"); Console.WriteLine("\t\t\t\tstring wtempstr = \"\";"); foreach (System.Data.DataRow dpkr in dpks.Tables[0].Rows) { Console.WriteLine("\t\t\t\tif (i_" + dpkr[0].ToString().Replace("#", "_SHARP_") + " != null)"); Console.WriteLine("\t\t\t\t{"); Console.WriteLine("\t\t\t\t\tif (i_" + dpkr[0].ToString().Replace("#", "_SHARP_") + " == System.DBNull.Value) wtempstr = \"" + dpkr[0] + " IS NULL\";"); Console.WriteLine("\t\t\t\t\telse wtempstr = \"" + dpkr[0] + " = \" + i_" + dpkr[0].ToString().Replace("#", "_SHARP_") + ".ToString();"); Console.WriteLine("\t\t\t\t\tif (wherestr.Length == 0) wherestr = wtempstr; else wherestr += \" AND \" + wtempstr;"); Console.WriteLine("\t\t\t\t}"); } Console.WriteLine("\t\t\t\tif (order == OrderBy.Ascending) return SelectWhere(wherestr, \"" + orderbyascstring + "\");"); Console.WriteLine("\t\t\t\telse if (order == OrderBy.Descending) return SelectWhere(wherestr, \"" + orderbydescstring + "\");"); Console.WriteLine("\t\t\t\treturn SelectWhere(wherestr, null);"); Console.WriteLine("\t\t\t}"); } Console.WriteLine("\t\t\t/// <summary>"); Console.WriteLine("\t\t\t/// Reads a set of rows from " + dr_tb[0].ToString() + " and retrieves them into a new " + dr_tb[0].ToString() + " object."); Console.WriteLine("\t\t\t/// </summary>"); Console.WriteLine("\t\t\t/// <param name=\"wherestr\">the string to be used in the WHERE clause. If null or empty, no WHERE clause is generated and all rows are returned.</param>"); Console.WriteLine("\t\t\t/// <param name=\"orderstr\">the string to be used in the ORDER BY clause. If null or empty, no ORDER BY clause is generated and rows are returned in an unspecified, non-deterministic order.</param>"); Console.WriteLine("\t\t\t/// <returns>a new instance of the " + dr_tb[0].ToString() + " class that can be used to read the retrieved data.</returns>"); Console.WriteLine("\t\t\tstatic public " + dr_tb[0].ToString() + " SelectWhere(string wherestr, string orderstr)"); Console.WriteLine("\t\t\t{"); Console.WriteLine("\t\t\t\t" + dr_tb[0].ToString() + " newobj = new " + dr_tb[0].ToString() + "();"); Console.WriteLine("\t\t\t\tSystem.Data.DataSet ds = new System.Data.DataSet();"); Console.WriteLine("\t\t\t\tnew SySal.OperaDb.OperaDbDataAdapter(\"SELECT " + colstring + " FROM " + dr_tb[0] + "\" + ((wherestr == null || wherestr.Trim().Length == 0) ? \"\" : (\" WHERE(\" + wherestr + \")\" + ((orderstr != null && orderstr.Trim() != \"\") ? (\" ORDER BY \" + orderstr): \"\") )), Schema.m_DB).Fill(ds);"); Console.WriteLine("\t\t\t\tnewobj.m_DRC = ds.Tables[0].Rows;"); Console.WriteLine("\t\t\t\tnewobj.m_Row = -1;"); Console.WriteLine("\t\t\t\treturn newobj;"); Console.WriteLine("\t\t\t}"); Console.WriteLine("\t\t\t/// <summary>"); Console.WriteLine("\t\t\t/// the number of rows retrieved."); Console.WriteLine("\t\t\t/// </summary>"); Console.WriteLine("\t\t\tpublic int Count { get { return m_DRC.Count; } }"); Console.WriteLine("\t\t\tinternal int m_Row;"); Console.WriteLine("\t\t\tinternal System.Data.DataRow m_DR;"); Console.WriteLine("\t\t\t/// <summary>"); Console.WriteLine("\t\t\t/// the current row for which field values are exposed."); Console.WriteLine("\t\t\t/// </summary>"); Console.WriteLine("\t\t\tpublic int Row { get { return m_Row; } set { m_Row = value; m_DR = m_DRC[m_Row]; } }"); Console.WriteLine("\t\t\tinternal static bool Prepared = false;"); Console.WriteLine("\t\t\tinternal static SySal.OperaDb.OperaDbCommand cmd = InitCommand();"); Console.WriteLine("\t\t\tprivate static SySal.OperaDb.OperaDbCommand InitCommand()"); Console.WriteLine("\t\t\t{"); Console.WriteLine("\t\t\t\tSySal.OperaDb.OperaDbCommand newcmd = new SySal.OperaDb.OperaDbCommand(\"INSERT INTO " + dr_tb[0].ToString() + " (" + colstring + ") VALUES (" + parstring + ")" + ((AutoIdColumn != null) ? (" RETURNING " + AutoIdColumn + " INTO :o_" + parcount) : "") + "\");"); Console.Write(parslotstring); Console.WriteLine("\t\t\t\treturn newcmd;"); Console.WriteLine("\t\t\t}"); Console.WriteLine("\t\t}"); } System.Data.DataSet ds_pc = new System.Data.DataSet(); new SySal.OperaDb.OperaDbDataAdapter("SELECT OBJECT_NAME FROM ALL_PROCEDURES WHERE OWNER = 'OPERA' AND (OBJECT_NAME LIKE 'PC_%' OR OBJECT_NAME LIKE 'LP_%') ORDER BY OBJECT_NAME ASC", conn, null).Fill(ds_pc); foreach (System.Data.DataRow dr_pc in ds_pc.Tables[0].Rows) { ondbsetprepared += "\t\t\t\tif (" + dr_pc[0].ToString() + ".Prepared) { " + dr_pc[0].ToString() + ".cmd.Connection = null; " + dr_pc[0].ToString() + ".Prepared = false; }\n"; Console.WriteLine("\t\t/// <summary>"); Console.WriteLine("\t\t/// Accesses the " + dr_pc[0].ToString() + " procedure in the DB."); Console.WriteLine("\t\t/// </summary>"); Console.WriteLine("\t\tpublic class " + dr_pc[0].ToString()); Console.WriteLine("\t\t{"); Console.WriteLine("\t\t\tprivate " + dr_pc[0].ToString() + "() {}"); System.Data.DataSet ds_arg = new System.Data.DataSet(); new SySal.OperaDb.OperaDbDataAdapter("SELECT ARGUMENT_NAME, IN_OUT, DATA_TYPE FROM ALL_ARGUMENTS WHERE OWNER = 'OPERA' AND OBJECT_NAME = '" + dr_pc[0].ToString() + "' ORDER BY POSITION ASC", conn, null).Fill(ds_arg); string argstr = ""; string oratype_string = ""; string parslotstring = ""; string callslotstring = ""; string callargstring = ""; string paramretstring = ""; string paramhelpstring = ""; int parcount = 0; foreach (System.Data.DataRow dra in ds_arg.Tables[0].Rows) { parcount++; bool isout = false; bool isinout = false; if (dra[1].ToString() == "OUT") { isout = true; paramretstring += "\t\t\t\tif (" + dra[0].ToString() + " != null) " + dra[0].ToString() + " = cmd.Parameters[" + (parcount - 1).ToString() + "].Value;\n"; paramhelpstring += "\t\t\t/// <param name = \"" + dra[0].ToString() + "\">the value of " + dra[0].ToString() + " obtained from the procedure call as an output. If null, the output is ignored.</param>\n"; } else if (dra[1].ToString() == "IN/OUT") { isinout = true; paramretstring += "\t\t\t\tif (" + dra[0].ToString() + " != null) " + dra[0].ToString() + " = cmd.Parameters[" + (parcount - 1).ToString() + "].Value;\n"; paramhelpstring += "\t\t\t/// <param name = \"" + dra[0].ToString() + "\">the value of " + dra[0].ToString() + " to be used for the procedure call, which can be modified on procedure completion as an output. If null, the input is replaced with a <c>System.DBNull.Value</c> and the output is ignored.</param>\n"; } else if (dra[1].ToString() == "IN") { paramhelpstring += "\t\t\t/// <param name = \"" + dra[0].ToString() + "\">the value of " + dra[0].ToString() + " to be used for the procedure call.</param>\n"; } else { throw new Exception("Unsupported parameter direction " + dra[1].ToString()); } if (dra[2].ToString() == "NUMBER") { oratype_string = "SySal.OperaDb.OperaDbType.Long"; } else if (dra[2].ToString() == "FLOAT") { oratype_string = "SySal.OperaDb.OperaDbType.Double"; } else if (dra[2].ToString() == "CHAR") { oratype_string = "SySal.OperaDb.OperaDbType.String"; } else if (dra[2].ToString() == "VARCHAR2") { oratype_string = "SySal.OperaDb.OperaDbType.String"; } else if (dra[2].ToString() == "DATE" || dra[2].ToString().StartsWith("TIMESTAMP")) { oratype_string = "SySal.OperaDb.OperaDbType.DateTime"; } else if (dra[2].ToString() == "CLOB") { oratype_string = "SySal.OperaDb.OperaDbType.CLOB"; } else { oratype_string = "UNKNOWN-" + dra[2].ToString(); } if (argstr == "") { argstr = (isout ? "ref " : "") + ("object " + dra[0].ToString()); callargstring = ":p_" + parcount.ToString(); } else { argstr += ", " + (isout ? "ref " : "") + ("object " + dra[0].ToString()); callargstring += ",:p_" + parcount.ToString(); } parslotstring += "\t\t\t\tnewcmd.Parameters.Add(\"p_" + parcount + "\", " + oratype_string + ", System.Data.ParameterDirection." + (isout ? "Output" : (isinout ? "InputOutput" : "Input")) + ");\n"; if (!isout) { if (isinout) { callslotstring += "\t\t\t\tif (" + dra[0].ToString() + " == null) cmd.Parameters[" + (parcount - 1) + "].Value = System.DBNull.Value; else cmd.Parameters[" + (parcount - 1) + "].Value = " + dra[0].ToString() + ";\n"; } else { callslotstring += "\t\t\t\tcmd.Parameters[" + (parcount - 1) + "].Value = " + dra[0].ToString() + ";\n"; } } } Console.WriteLine("\t\t\tinternal static bool Prepared = false;"); Console.WriteLine("\t\t\tinternal static SySal.OperaDb.OperaDbCommand cmd = InitCommand();"); Console.WriteLine("\t\t\tprivate static SySal.OperaDb.OperaDbCommand InitCommand()"); Console.WriteLine("\t\t\t{"); Console.WriteLine("\t\t\t\tSySal.OperaDb.OperaDbCommand newcmd = new SySal.OperaDb.OperaDbCommand(\"CALL " + dr_pc[0].ToString() + "(" + callargstring + ")\");"); Console.Write(parslotstring); Console.WriteLine("\t\t\t\treturn newcmd;"); Console.WriteLine("\t\t\t}"); Console.WriteLine("\t\t\t/// <summary>"); Console.WriteLine("\t\t\t/// Calls the procedure."); Console.WriteLine("\t\t\t/// </summary>"); Console.Write(paramhelpstring); Console.WriteLine("\t\t\tpublic static void Call(" + argstr + ")"); Console.WriteLine("\t\t\t{"); Console.WriteLine("\t\t\t\tif (!Prepared) { cmd.Connection = Schema.m_DB; Prepared = true; cmd.Prepare(); };"); Console.Write(callslotstring); Console.WriteLine("\t\t\t\tcmd.ExecuteNonQuery();"); Console.Write(paramretstring); Console.WriteLine("\t\t\t}"); Console.WriteLine("\t\t}"); } Console.WriteLine("\t\tstatic internal SySal.OperaDb.OperaDbConnection m_DB = null;"); Console.WriteLine("\t\t/// <summary>"); Console.WriteLine("\t\t/// The DB connection currently used by the Schema class. Must be set before using any child class."); Console.WriteLine("\t\t/// </summary>"); Console.WriteLine("\t\tstatic public SySal.OperaDb.OperaDbConnection DB"); Console.WriteLine("\t\t{"); Console.WriteLine("\t\t\tget { return m_DB; }"); Console.WriteLine("\t\t\tset"); Console.WriteLine("\t\t\t{"); Console.Write(ondbsetprepared); Console.WriteLine("\t\t\t\tm_DB = value;"); Console.WriteLine("\t\t\t}"); Console.WriteLine("\t\t}"); Console.WriteLine("\t}"); Console.WriteLine("}"); }
public ProcOpInfo(SySal.OperaDb.OperaDbCredentials cred, long procopid, ref SySal.OperaDb.OperaDbConnection Conn) { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // //SySal.OperaDb.OperaDbConnection Conn = null; try { if (Conn == null) { Conn = new SySal.OperaDb.OperaDbConnection(cred.DBServer, cred.DBUserName, cred.DBPassword); Conn.Open(); } System.Data.DataSet dsprocop = new System.Data.DataSet(); new SySal.OperaDb.OperaDbDataAdapter("SELECT /*+INDEX (TB_PROC_OPERATIONS PK_PROC_OPERATIONS) */ ID_MACHINE, ID_PARENT_OPERATION, ID_PROGRAMSETTINGS, DRIVERLEVEL, ID_EVENTBRICK, ID_PLATE, STARTTIME, FINISHTIME, SUCCESS, ID_REQUESTER, ID_CALIBRATION_OPERATION FROM TB_PROC_OPERATIONS WHERE ID = " + procopid, Conn, null).Fill(dsprocop); IDText.Text = procopid.ToString(); ParentIDText.Text = dsprocop.Tables[0].Rows[0][1].ToString(); DriverLevelText.Text = ((SySal.DAQSystem.Drivers.DriverType)Convert.ToInt32(dsprocop.Tables[0].Rows[0][3])).ToString() + " (" + dsprocop.Tables[0].Rows[0][3].ToString() + ")"; BrickText.Text = dsprocop.Tables[0].Rows[0][4].ToString(); PlateText.Text = dsprocop.Tables[0].Rows[0][5].ToString(); StartTimeText.Text = Convert.ToDateTime(dsprocop.Tables[0].Rows[0][6]).ToString("dd/MM/yyyy HH:mm:ss"); if (dsprocop.Tables[0].Rows[0][7] != System.DBNull.Value) { FinishTimeText.Text = Convert.ToDateTime(dsprocop.Tables[0].Rows[0][7]).ToString("dd/MM/yyyy HH:mm:ss"); switch (dsprocop.Tables[0].Rows[0][8].ToString()) { case "N": ResultText.Text = "Failure"; break; case "Y": ResultText.Text = "Success"; break; case "R": ResultText.Text = "Running"; break; default: ResultText.Text = "Other (" + dsprocop.Tables[0].Rows[0][8].ToString() + ")"; break; } } MachineText.Text = new SySal.OperaDb.OperaDbCommand("SELECT /*+INDEX (TB_MACHINES PK_MACHINES) */ NAME FROM TB_MACHINES WHERE ID = " + dsprocop.Tables[0].Rows[0][0].ToString(), Conn, null).ExecuteScalar().ToString(); RequesterText.Text = new SySal.OperaDb.OperaDbCommand("SELECT /*+INDEX (TB_USERS PK_USERS) */ NAME || ' ' || SURNAME FROM VW_USERS WHERE ID = " + dsprocop.Tables[0].Rows[0][9].ToString(), Conn, null).ExecuteScalar().ToString(); CalibrationText.Text = (dsprocop.Tables[0].Rows[0][10] == System.DBNull.Value) ? "None" : dsprocop.Tables[0].Rows[0][10].ToString(); System.Data.DataSet dsprog = new System.Data.DataSet(); new SySal.OperaDb.OperaDbDataAdapter("SELECT /*+INDEX (TB_PROGRAMSETTINGS PK_PROGRAMSETTINGS) */ TEMPLATEMARKS, ID_AUTHOR, DESCRIPTION, EXECUTABLE, SETTINGS FROM TB_PROGRAMSETTINGS WHERE ID = " + dsprocop.Tables[0].Rows[0][2].ToString(), Conn, null).Fill(dsprog); //CalibrationText.Text = (Convert.ToInt32(dsprog.Tables[0].Rows[0][0]) == 0) ? "No" : "Yes"; AuthorText.Text = new SySal.OperaDb.OperaDbCommand("SELECT /*+INDEX (TB_USERS PK_USERS) */ NAME || ' ' || SURNAME FROM VW_USERS WHERE ID = " + dsprog.Tables[0].Rows[0][1].ToString(), Conn, null).ExecuteScalar().ToString(); DescriptionText.Text = dsprog.Tables[0].Rows[0][2].ToString(); ExeText.Text = dsprog.Tables[0].Rows[0][3].ToString(); SettingsText.Text = dsprog.Tables[0].Rows[0][4].ToString(); } catch (Exception x) { if (Conn != null) { Conn.Close(); Conn = null; } MessageBox.Show(x.ToString(), x.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <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); } }
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."); } }