Batch results written into the built in Results database.

This commit is contained in:
Milan Hanajik 2016-01-08 13:51:54 +01:00
parent f5642a2676
commit b131ba01a8
3 changed files with 96 additions and 15 deletions

View File

@ -9,6 +9,7 @@ using log4net;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using Results.Entities;
namespace Results
{
@ -180,5 +181,75 @@ namespace Results
ComponentsList = session.CreateQuery("FROM Components").List<Entities.Components>();
WaterMeterDataList = session.CreateQuery("FROM WaterMeterData").List<Entities.WaterMeterData>();
}
/// <summary>
/// Update TestData, Components and WaterMeterData fo tests and water meters in batch results
/// with existing data in static lists TestDataList, ComponentsList and WaterMeterDataList.
/// </summary>
/// <param name="batch">Batch results</param>
/// <returns>true when any data modiifed</returns>
public static bool UpdateBatchData(Entities.Batch batch)
{
ISession session = DB.CreateSession();
if (session == null) return false;
foreach (var tr in batch.TestRslts)
{
/// Search in TestDataList and update test data in the new batch
TestData td = TestData.UpdateList(TestDataList, tr.TestData);
tr.TestData = td;
/// Search in ComponentsList and update components in the new batch
Components cd = Components.UpdateList(ComponentsList, tr.Components);
tr.Components = cd;
}
foreach (var wm in batch.WaterMeters)
{
/// Search in WaterMeterDataList and update water meter data in the new batch
WaterMeterData wmd = WaterMeterData.UpdateList(WaterMeterDataList, wm.WaterMeterData);
wm.WaterMeterData = wmd;
}
return true; /// TODO: Really check for modifications
}
public static bool SaveNewBatch(Entities.Batch batch)
{
ISession session = DB.CreateSession();
if (session == null) return false;
TestDataList = session.CreateQuery("FROM TestData").List<Entities.TestData>();
ComponentsList = session.CreateQuery("FROM Components").List<Entities.Components>();
WaterMeterDataList = session.CreateQuery("FROM WaterMeterData").List<Entities.WaterMeterData>();
UpdateBatchData(batch);
ITransaction transaction = session.BeginTransaction();
if (transaction == null) return false;
try
{
session.SaveOrUpdate(TestDataList);
session.SaveOrUpdate(ComponentsList);
session.SaveOrUpdate(WaterMeterDataList);
session.SaveOrUpdate(batch);
transaction.Commit();
}
catch (Exception exc)
{
transaction.Rollback();
log.FatalFormat("Saving results of batch #{0} into the results DB failed: {1}", batch.BatchNr, exc.Message);
return false;
}
return true;
}
}
}

View File

@ -664,19 +664,21 @@ namespace TBF.BenchControl.Sequences
}
while (e.Contains(Event.Busy));
/// TODO: Reimplement !!!!!!!!!!!
/////
///// Save to database and to 'summary results' logger
/////
//IList<TestResult> sortedResults = Utils.GetSortedTestResults(StateMachine.Procedure, results, 0);
//foreach (var rslt in sortedResults)
//{
// if (rslt != null)
// {
// Config.FluentCommon.SaveToDb(StateMachine.WtSession, rslt);
// summaryResults.Info(TestResult2CsvLine(rslt));
// }
//}
bool resultsSent = !e.Contains(Event.Error);
ProcessData.BatchRslts.Batch.RsltsSent = resultsSent;
///
/// Save results to the built in 'Results' database
///
Results.DB.SaveNewBatch(ProcessData.BatchRslts.Batch);
///
/// Save results to 'summary results' logger
///
foreach (var tr in ProcessData.BatchRslts.Batch.TestRslts)
{
summaryResults.Info(TestResult2CsvLine(tr));
}
Program.LocalSettings.BatchNr++;

View File

@ -692,6 +692,14 @@ namespace TBF.BenchControl.Sequences
{
Results.Entities.TestRslt tstRslt = ProcessData.BatchRslts.GetTestRslt(testName, part);
if (tstRslt == null) return string.Empty;
return TestResult2CsvLine(tstRslt);
}
protected string TestResult2CsvLine(Results.Entities.TestRslt tstRslt)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(tstRslt.StartTime);
@ -776,7 +784,7 @@ namespace TBF.BenchControl.Sequences
{
if (!ProcessData.BatchRslts.WaterMeters[i].Compound())
{
Results.Entities.MeterTestRslt mtrRslt = ProcessData.BatchRslts.GetMeterTestRslt(testName, i, CompoundMeterId.Single);
Results.Entities.MeterTestRslt mtrRslt = ProcessData.BatchRslts.GetMeterTestRslt(tstRslt.Name(), i, CompoundMeterId.Single);
if (mtrRslt != null)
{
@ -810,7 +818,7 @@ namespace TBF.BenchControl.Sequences
{
for (byte b = (byte)CompoundMeterId.CompoundMain; b <= (byte)CompoundMeterId.Compound; b++)
{
Results.Entities.MeterTestRslt mtrRslt = ProcessData.BatchRslts.GetMeterTestRslt(testName, i, (CompoundMeterId)b);
Results.Entities.MeterTestRslt mtrRslt = ProcessData.BatchRslts.GetMeterTestRslt(tstRslt.Name(), i, (CompoundMeterId)b);
if (mtrRslt != null)
{