public TestRunWorker()
 {
     this.Exception = null;
     this.ExecuteOnModel = TestModel.ProjectModel;
     this.InitialDesired = 0;
     this.FinalDesired = 0;
     this.WorkerReportsProgress = true;
     this.DoWork += testRunWorker_DoWork;
 }
        private void testRunWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                this.Exception = null;

                string message = "";
                ControllerComparisonFaultModel fm = e.Argument as ControllerComparisonFaultModel;

                fm.ExecutionEngine.AcquireProcess();

                // Sets up the environment of the execution engine
                fm.SetUpEnvironment();

                fm.SetTestRunParameters(InitialDesired, FinalDesired);

                switch(ExecuteOnModel)
                {
                    case TestModel.ProjectModel:
                        message = (string)fm.Run("TestRun");
                        break;
                    case TestModel.ComparedModel:
                        message = (string)fm.Run("TestRun_Compared");
                        break;
                    case TestModel.Both:
                        message = (string)fm.Run("CompareRun");
                        break;
                }

                // Tears down the environment
                fm.TearDownEnvironment(false);

                // Relinquishes control of the execution engine
                fm.ExecutionEngine.RelinquishProcess();

                if (message.ToLower().Contains("success"))
                {
                    e.Result = true;
                }
                else
                {
                    e.Result = false;
                    this.Exception = new FM4CCException(message);
                }

                this.ReportProgress(100);
                e.Result = true;
            }
            catch(TargetInvocationException)
            {
                e.Result = false;
            }
        }
        private void generationWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                this.Exception = null;
                isRunning = false;
                fm = e.Argument as AllowedOscillationFaultModel;
                ExecutionInstance currentTestProject = fm.ExecutionInstance;

                string message = null;
                fm.ExecutionEngine.AcquireProcess();

                // Sets up the environment of the execution engine
                fm.ExecutionInstance = currentTestProject;
                fm.SetUpEnvironment();

                passedDuration = 0.0;
                estimatedDuration = fm.GetEstimatedDuration("SearchSpaceExploration").TotalMilliseconds;

                aTimer = new System.Timers.Timer(100);
                aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
                aTimer.Enabled = true;
                aTimer.AutoReset = true;

                double stepSize = (double)fm.FaultModelConfiguration.GetValue("DesiredValueStepSize");
                double from = Convert.ToDouble(fm.SimulationSettings.DesiredVariable.FromValue);
                double to = Convert.ToDouble(fm.SimulationSettings.DesiredVariable.ToValue);

                isRunning = true;
                message = (string)fm.Run("SearchSpaceExploration");

                // Tears down the environment
                fm.TearDownEnvironment(false);

                // Relinquishes control of the execution engine
                fm.ExecutionEngine.RelinquishProcess();
                aTimer.Enabled = false;

                if (message.ToLower().Contains("success"))
                {
                    e.Result = true;
                }
                else
                {
                    e.Result = false;
                    this.Exception = new FM4CCException(message);
                }
            }
            catch(TargetInvocationException)
            {
                e.Result = false;
            }
        }
        private void generationWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                this.Exception = null;

                isRunning = false;
                fm = e.Argument as ControllerComparisonFaultModel;
                ExecutionInstance currentTestProject = fm.ExecutionInstance;

                string message = null;
                fm.ExecutionEngine.AcquireProcess();

                // Sets up the environment of the execution engine
                fm.ExecutionInstance = currentTestProject;
                fm.SetUpEnvironment();

                passedDuration = 0.0;
                estimatedDuration = fm.GetEstimatedDuration("RandomExploration").TotalMilliseconds;

                aTimer = new System.Timers.Timer(100);
                aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
                aTimer.Enabled = true;
                aTimer.AutoReset = true;

                isRunning = true;
                message = (string)fm.Run("RandomExploration");

                // Tears down the environment
                fm.TearDownEnvironment(false);

                // Relinquishes control of the execution engine
                fm.ExecutionEngine.RelinquishProcess();
                aTimer.Enabled = false;

                if (message.ToLower().Contains("success"))
                {
                    e.Result = true;
                }
                else
                {
                    e.Result = false;
                    this.Exception = new FM4CCException(message);
                }
            }
            catch(TargetInvocationException)
            {
                e.Result = false;
            }
        }
        private void testRunWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                this.Exception = null;
                DisturbanceFaultModel fm = e.Argument as DisturbanceFaultModel;

                fm.ExecutionEngine.AcquireProcess();

                // Sets up the environment of the execution engine
                fm.SetUpEnvironment();

                fm.SetTestRunParameters(Desired, DisturbanceStartTime);
                string message = (string)fm.Run("TestRun");

                // Tears down the environment
                fm.TearDownEnvironment(false);

                // Relinquishes control of the execution engine
                fm.ExecutionEngine.RelinquishProcess();

                if (message.ToLower().Contains("success"))
                {
                    e.Result = true;
                }
                else
                {
                    e.Result = false;
                    this.Exception = new FM4CCException(message);
                }

                this.ReportProgress(100);
            }
            catch (TargetInvocationException)
            {
                e.Result = false;
            }
        }