using System.Threading;
using log4net;
using NHibernate;
namespace TBF.BenchControl.Operations
{
public class LoadProcedureOp : IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(LoadProcedureOp));
Thread loaderThread;
bool error;
bool completed;
///
/// Events: Wait, ProcedureLoaded or Error
///
public LoadProcedureOp()
{
error = false;
completed = false;
}
/// Start this operation
public void Start()
{
if (loaderThread != null)
{
error = true;
return;
}
loaderThread = new Thread(Loader);
loaderThread.Start();
}
void Loader()
{
StateMachine.LoadProcedure(false);
StateMachine.LoadProcedureParams(StateMachine.Procedure);
completed = true;
}
/// Run this operation
///
/// Event.Error, Event.ProcedureLoaded or Event.Wait
///
public Event Run()
{
if (error) return Event.Error;
if (!completed) return Event.Wait;
///
/// Check for incomplete configuration mistakes
///
if (StateMachine.Tests.Count == 0) return Event.ConfigurationError;
foreach (var test in StateMachine.Tests)
{
if (test.FeedingPath == null || test.BenchPath == null ||
test.OutputPath == null || test.MetersPath == null)
{
return Event.ConfigurationError;
}
}
return Event.ProcedureLoaded;
}
/// Stop this operation
public void Stop()
{
}
}
}