//-------------------------------------------------------------------------------------------------// public void ValidateSpeed(MinMaxStep speed) { try { // // Check minimum speed // if (speed.min < this.speed.min) { throw new ArgumentException(STRERR_MinimumSpeed + speed.min.ToString() + STRERR_IsLessThan + this.speed.min.ToString()); } if (speed.min > this.speed.max) { throw new ArgumentException(STRERR_MinimumSpeed + speed.min.ToString() + STRERR_IsGreaterThan + this.speed.max.ToString()); } // // Check maximum speed // if (speed.max < this.speed.min) { throw new ArgumentException(STRERR_MaximumSpeed + speed.max.ToString() + STRERR_IsLessThan + this.speed.min.ToString()); } if (speed.max > this.speed.max) { throw new ArgumentException(STRERR_MaximumSpeed + speed.max.ToString() + STRERR_IsGreaterThan + this.speed.max.ToString()); } if (speed.max < speed.min) { throw new ArgumentException(STRERR_MaxSpeedLessThanMinSpeed); } // // Check speed step // if (speed.step < this.speed.stepMin) { throw new ArgumentException(STRERR_SpeedStep + speed.step.ToString() + STRERR_IsLessThan + this.speed.stepMin.ToString()); } if (speed.step > this.speed.stepMax) { throw new ArgumentException(STRERR_SpeedStep + speed.step.ToString() + STRERR_IsGreaterThan + this.speed.stepMax.ToString()); } } catch (Exception) { // Throw error back to caller throw; } }
//-------------------------------------------------------------------------------------------------// public void ValidateLoad(MinMaxStep load) { try { // // Check minimum load // if (load.min < this.load.min) { throw new ArgumentException(STRERR_MinimumLoad + load.min.ToString() + STRERR_IsLessThan + this.load.min.ToString()); } if (load.min > this.load.max) { throw new ArgumentException(STRERR_MinimumLoad + load.min.ToString() + STRERR_IsGreaterThan + this.load.max.ToString()); } // // Check maximum load // if (load.max < this.load.min) { throw new ArgumentException(STRERR_MaximumLoad + load.max.ToString() + STRERR_IsLessThan + this.load.min.ToString()); } if (load.max > this.load.max) { throw new ArgumentException(STRERR_MaximumLoad + load.max.ToString() + STRERR_IsGreaterThan + this.load.max.ToString()); } if (load.max < load.min) { throw new ArgumentException(STRERR_MaxLoadLessThanMinLoad); } // // Check load step // if (load.step < this.load.stepMin) { throw new ArgumentException(STRERR_LoadStep + load.step.ToString() + STRERR_IsLessThan + this.load.stepMin.ToString()); } if (load.step > this.load.stepMax) { throw new ArgumentException(STRERR_LoadStep + load.step.ToString() + STRERR_IsGreaterThan + this.load.stepMax.ToString()); } } catch (Exception) { // Throw error back to caller throw; } }
//-------------------------------------------------------------------------------------------------// public void ValidateField(MinMaxStep field) { try { // // Check minimum field // if (field.min < this.field.min) { throw new ArgumentException(STRERR_MinimumField + field.min.ToString() + STRERR_IsLessThan + this.field.min.ToString()); } if (field.min > this.field.max) { throw new ArgumentException(STRERR_MinimumField + field.min.ToString() + STRERR_IsGreaterThan + this.field.max.ToString()); } // // Check maximum field // if (field.max < this.field.min) { throw new ArgumentException(STRERR_MaximumField + field.max.ToString() + STRERR_IsLessThan + this.field.min.ToString()); } if (field.max > this.field.max) { throw new ArgumentException(STRERR_MaximumField + field.max.ToString() + STRERR_IsGreaterThan + this.field.max.ToString()); } if (field.max < field.min) { throw new ArgumentException(STRERR_MaxFieldLessThanMinField); } // // Check field step // if (field.step < this.field.stepMin) { throw new ArgumentException(STRERR_FieldStep + field.step.ToString() + STRERR_IsLessThan + this.field.stepMin.ToString()); } if (field.step > this.field.stepMax) { throw new ArgumentException(STRERR_FieldStep + field.step.ToString() + STRERR_IsGreaterThan + this.field.stepMax.ToString()); } } catch (Exception) { // Throw error back to caller throw; } }
//-------------------------------------------------------------------------------------------------// /// <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; }
//-------------------------------------------------------------------------------------------------// /// <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); }