//-------------------------------------------------------------------------------------------------//
        public override ExperimentInfo RunExperiment(ExperimentInfo experimentInfo)
        {
            const string STRLOG_MethodName = "RunExperiment";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            // Create a result report ready to fill in
            experimentInfo.resultReport = new ResultReport();

            try
            {
                //
                // Parse the XML specification string to generate a validation report (should be accepted!)
                //
                Specification specification = new Specification(this.configuration, this.equipmentServiceProxy);
                ValidationReport validationReport = specification.Parse(experimentInfo.xmlSpecification);
                if (validationReport.accepted == false)
                {
                    throw new ArgumentException(validationReport.errorMessage);
                }
                experimentInfo.setupId = specification.SetupId;

                //
                // Create an instance of the driver for the specified setup and then
                // execute the experiment and return the result information
                //
                ResultInfo resultInfo = null;
                if (specification.SetupId.Equals(Consts.STRXML_SetupId_VoltageVsSpeed))
                {
                    DriverVoltageVsSpeed driver = new DriverVoltageVsSpeed(this.equipmentServiceProxy, this.configuration, this.labExperimentInfo.cancelExperiment);
                    resultInfo = (ResultInfo)driver.Execute(specification);
                }
                else if (specification.SetupId.Equals(Consts.STRXML_SetupId_VoltageVsField))
                {
                    DriverVoltageVsField driver = new DriverVoltageVsField(this.equipmentServiceProxy, this.configuration, this.labExperimentInfo.cancelExperiment);
                    resultInfo = (ResultInfo)driver.Execute(specification);
                }
                else if (specification.SetupId.Equals(Consts.STRXML_SetupId_VoltageVsLoad))
                {
                    DriverVoltageVsLoad driver = new DriverVoltageVsLoad(this.equipmentServiceProxy, this.configuration, this.labExperimentInfo.cancelExperiment);
                    resultInfo = (ResultInfo)driver.Execute(specification);
                }
                else if (specification.SetupId.Equals(Consts.STRXML_SetupId_SpeedVsVoltage))
                {
                    DriverSpeedVsVoltage driver = new DriverSpeedVsVoltage(this.equipmentServiceProxy, this.configuration, this.labExperimentInfo.cancelExperiment);
                    resultInfo = (ResultInfo)driver.Execute(specification);
                }
                else if (specification.SetupId.Equals(Consts.STRXML_SetupId_SpeedVsField))
                {
                    DriverSpeedVsField driver = new DriverSpeedVsField(this.equipmentServiceProxy, this.configuration, this.labExperimentInfo.cancelExperiment);
                    resultInfo = (ResultInfo)driver.Execute(specification);
                }

                //
                // Create an instance of LabExperimentResult to convert the experiment results to an XML string
                //
                ExperimentResult experimentResult = new ExperimentResult(
                    experimentInfo.experimentId, experimentInfo.sbName, DateTime.Now,
                    this.unitId, (Configuration)this.labConfiguration, specification, resultInfo);

                //
                // Fill in the result report
                //
                experimentInfo.resultReport.experimentResults = experimentResult.ToString();
                experimentInfo.resultReport.statusCode = (int)resultInfo.statusCode;
                experimentInfo.resultReport.errorMessage = resultInfo.errorMessage;
            }
            catch (Exception ex)
            {
                experimentInfo.resultReport.statusCode = (int)StatusCodes.Failed;
                experimentInfo.resultReport.errorMessage = ex.Message;
                Logfile.WriteError(ex.Message);
            }

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName);

            return experimentInfo;
        }
Exemplo n.º 2
0
        //-------------------------------------------------------------------------------------------------//
        /// <summary>
        /// Parse the XML specification string to check its validity. No exceptions are thrown back to the
        /// calling method. If an error occurs, 'accepted' is set to false and the error message is placed
        /// in 'errorMessage' where it can be examined by the calling method.
        /// </summary>
        /// <param name="xmlSpecification"></param>
        public override ValidationReport Parse(string xmlSpecification)
        {
            const string STRLOG_MethodName = "Parse";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            //
            // Catch all exceptions and log errors, don't throw back to caller
            //
            ValidationReport validationReport = null;
            try
            {
                //
                // Call the base class to parse its part
                //
                validationReport = base.Parse(xmlSpecification);
                if (validationReport.accepted == false)
                {
                    throw new Exception(validationReport.errorMessage);
                }

                // Create new validation report
                validationReport = new ValidationReport();

                //
                // Create an instance of the driver for the specified setup and then
                // get the driver's execution time for this specification
                //
                int executionTime = -1;
                if (this.SetupId.Equals(Consts.STRXML_SetupId_VoltageVsSpeed))
                {
                    //
                    // Get the speed range and validate
                    //
                    this.speed = new MinMaxStep();
                    this.speed.min = XmlUtilities.GetIntValue(this.xmlNodeSpecification, Consts.STRXML_speedMin);
                    this.speed.max = XmlUtilities.GetIntValue(this.xmlNodeSpecification, Consts.STRXML_speedMax);
                    this.speed.step = XmlUtilities.GetIntValue(this.xmlNodeSpecification, Consts.STRXML_speedStep);

                    this.validation.ValidateSpeed(this.speed);

                    DriverVoltageVsSpeed driver = new DriverVoltageVsSpeed(this.equipmentServiceProxy, this.configuration);
                    executionTime = driver.GetExecutionTime(this);
                }
                else if (this.SetupId.Equals(Consts.STRXML_SetupId_VoltageVsField))
                {
                    //
                    // Get the field range and validate
                    //
                    this.field = new MinMaxStep();
                    this.field.min = XmlUtilities.GetIntValue(this.xmlNodeSpecification, Consts.STRXML_fieldMin);
                    this.field.max = XmlUtilities.GetIntValue(this.xmlNodeSpecification, Consts.STRXML_fieldMax);
                    this.field.step = XmlUtilities.GetIntValue(this.xmlNodeSpecification, Consts.STRXML_fieldStep);

                    this.validation.ValidateField(this.field);

                    DriverVoltageVsField driver = new DriverVoltageVsField(this.equipmentServiceProxy, this.configuration);
                    executionTime = driver.GetExecutionTime(this);
                }
                else if (this.SetupId.Equals(Consts.STRXML_SetupId_VoltageVsLoad))
                {
                    //
                    // Get the load range and validate
                    //
                    this.load = new MinMaxStep();
                    this.load.min = XmlUtilities.GetIntValue(this.xmlNodeSpecification, Consts.STRXML_loadMin);
                    this.load.max = XmlUtilities.GetIntValue(this.xmlNodeSpecification, Consts.STRXML_loadMax);
                    this.load.step = XmlUtilities.GetIntValue(this.xmlNodeSpecification, Consts.STRXML_loadStep);

                    this.validation.ValidateLoad(this.load);

                    DriverVoltageVsLoad driver = new DriverVoltageVsLoad(this.equipmentServiceProxy, this.configuration);
                    executionTime = driver.GetExecutionTime(this);
                }
                else if (this.SetupId.Equals(Consts.STRXML_SetupId_SpeedVsVoltage))
                {
                    //
                    // Get the speed range and validate
                    //
                    this.speed = new MinMaxStep();
                    this.speed.min = XmlUtilities.GetIntValue(this.xmlNodeSpecification, Consts.STRXML_speedMin);
                    this.speed.max = XmlUtilities.GetIntValue(this.xmlNodeSpecification, Consts.STRXML_speedMax);
                    this.speed.step = XmlUtilities.GetIntValue(this.xmlNodeSpecification, Consts.STRXML_speedStep);

                    this.validation.ValidateSpeed(this.speed);

                    DriverSpeedVsVoltage driver = new DriverSpeedVsVoltage(this.equipmentServiceProxy, this.configuration);
                    executionTime = driver.GetExecutionTime(this);
                }
                else if (this.SetupId.Equals(Consts.STRXML_SetupId_SpeedVsField))
                {
                    //
                    // Get the field range and validate
                    //
                    this.field = new MinMaxStep();
                    this.field.min = XmlUtilities.GetIntValue(this.xmlNodeSpecification, Consts.STRXML_fieldMin);
                    this.field.max = XmlUtilities.GetIntValue(this.xmlNodeSpecification, Consts.STRXML_fieldMax);
                    this.field.step = XmlUtilities.GetIntValue(this.xmlNodeSpecification, Consts.STRXML_fieldStep);

                    this.validation.ValidateField(this.field);

                    DriverSpeedVsField driver = new DriverSpeedVsField(this.equipmentServiceProxy, this.configuration);
                    executionTime = driver.GetExecutionTime(this);
                }

                //
                // Specification is valid
                //
                validationReport.estRuntime = executionTime + TIME_SECS_AdministrationExecution;
                validationReport.accepted = true;
            }
            catch (Exception ex)
            {
                validationReport.errorMessage = ex.Message;
                Logfile.WriteError(ex.Message);
            }

            string logMessage = STRLOG_Accepted + validationReport.accepted.ToString();
            if (validationReport.accepted == true)
            {
                logMessage += Logfile.STRLOG_Spacer + STRLOG_ExecutionTime + validationReport.estRuntime.ToString() + STRLOG_seconds;
            }

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return validationReport;
        }