Order of saving results to MySql DB and to other destinations changed, try-catch for other destinations, ver. 2.31.2014
This commit is contained in:
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("2.31.2011.0")]
|
||||
[assembly: AssemblyFileVersion("2.31.2011.0")]
|
||||
[assembly: AssemblyVersion("2.31.2014.0")]
|
||||
[assembly: AssemblyFileVersion("2.31.2014.0")]
|
||||
|
||||
@@ -1306,6 +1306,10 @@ namespace TBF.Rig.Sequences
|
||||
Bridge.OnActivity(this, Strings.Saving_and_printing_results);
|
||||
//------------------------------------------------------
|
||||
|
||||
/// Save results to 'Results' MySQL DB with RsltsSent = 0 before saving and printing elswhere
|
||||
ProcessData.BatchRslts.Batch.RsltsSent = false;
|
||||
Results.DB.SaveNewBatch(ProcessData.BatchRslts.Batch);
|
||||
|
||||
string[] writers = (StateMachine.Procedure.ResultsWriter != null) ? StateMachine.Procedure.ResultsWriter.Split(new char[] { '~' }) : new string[0];
|
||||
string[] printers = (StateMachine.Procedure.ResultsPrinter != null) ? StateMachine.Procedure.ResultsPrinter.Split(new char[] { '~' }) : new string[0];
|
||||
string[] eventTriggers = (StateMachine.Procedure.EventTriggers != null) ? StateMachine.Procedure.EventTriggers.Split(new char[] { '~' }) : new string[0];
|
||||
@@ -1315,36 +1319,61 @@ namespace TBF.Rig.Sequences
|
||||
printers.CopyTo(rsltProcessors, writers.Length);
|
||||
eventTriggers.CopyTo(rsltProcessors, writers.Length + printers.Length);
|
||||
///
|
||||
State savingAndPrintingRslts = State.Create("MainSeq : Saving and printing results");
|
||||
foreach (var rpName in rsltProcessors)
|
||||
int rpix = 0; /// Component index in AddOperation() loop, afterwards rsltProcessors.Length
|
||||
try
|
||||
{
|
||||
IResultsProcessor rsltProcessor = TbfComponents.FindComponent(rpName) as IResultsProcessor;
|
||||
if (rsltProcessor != null)
|
||||
State st = State.Create("MainSeq : Saving and printing results");
|
||||
for (rpix = 0; rpix < rsltProcessors.Length; rpix++ )
|
||||
{
|
||||
try
|
||||
var rp = TbfComponents.FindComponent(rsltProcessors[rpix]) as IResultsProcessor;
|
||||
if (rp != null) st.AddOperation(rp.ProcessResultsOp(ProcessData.BatchRslts.Batch));
|
||||
}
|
||||
st.EnterState();
|
||||
do {
|
||||
e = StateMachine.WaitRunDevsRunOps();
|
||||
if (e.Contains(Event.Error)) break;
|
||||
}
|
||||
while (e.Contains(Event.Busy));
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
string rpName = (rpix < rsltProcessors.Length) ? rsltProcessors[rpix] : "???";
|
||||
Bridge.OnError(this, string.Format(Strings.Component_0_crashed_Results_not_saved, rpName));
|
||||
log.FatalFormat("FileWriter {0} crashed: {1}", rpName, exc.Message);
|
||||
goto error;
|
||||
}
|
||||
if (e.Contains(Event.Error)) goto error;
|
||||
///
|
||||
if (!e.Contains(Event.ErrorProcessingResults))
|
||||
{
|
||||
/// Results successfully saved and printed => update Batch record in Results DB in MySQL
|
||||
try
|
||||
{
|
||||
var dbConn = new MySql.Data.MySqlClient.MySqlConnection(Results.DB.ConnectionString);
|
||||
dbConn.Open();
|
||||
var cmd = dbConn.CreateCommand();
|
||||
cmd.CommandText = string.Format("UPDATE `batch` SET `RsltsSent` = '1' WHERE `batch`.`BatchNr` = {0};", ProcessData.BatchRslts.Batch.BatchNr);
|
||||
int rowsUpdated = cmd.ExecuteNonQuery();
|
||||
cmd.Dispose();
|
||||
dbConn.Close();
|
||||
if (rowsUpdated != 1)
|
||||
{
|
||||
savingAndPrintingRslts.AddOperation(rsltProcessor.ProcessResultsOp(ProcessData.BatchRslts.Batch));
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Bridge.OnError(this, string.Format(Strings.Component_0_crashed_Results_not_saved, rpName));
|
||||
log.FatalFormat("FileWriter {0} crashed: {1}", rpName, exc.Message);
|
||||
string msg = string.Format("Unable to update Batch.RsltsSent in local MySQL DB, BatchNr = {0}",
|
||||
ProcessData.BatchRslts.Batch.BatchNr);
|
||||
Bridge.OnError(this, msg);
|
||||
log.Fatal(msg);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
string msg = string.Format("Unable to update Batch.RsltsSent in local MySQL DB, BatchNr = {0}",
|
||||
ProcessData.BatchRslts.Batch.BatchNr);
|
||||
Bridge.OnError(this, msg);
|
||||
log.FatalFormat("{0}: {1}", msg, exc.Message);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
savingAndPrintingRslts.EnterState();
|
||||
do {
|
||||
e = StateMachine.WaitRunDevsRunOps();
|
||||
if (e.Contains(Event.Error)) goto error;
|
||||
}
|
||||
while (e.Contains(Event.Busy));
|
||||
///
|
||||
ProcessData.BatchRslts.Batch.RsltsSent = !e.Contains(Event.ErrorProcessingResults);
|
||||
|
||||
///
|
||||
/// Save results to 'Results' MySQL database
|
||||
///
|
||||
Results.DB.SaveNewBatch(ProcessData.BatchRslts.Batch);
|
||||
|
||||
///
|
||||
/// Save results to 'summary results' logger
|
||||
|
||||
Reference in New Issue
Block a user