//-------------------------------------------------------------------------------------------------// /// <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. Return 'accepted'. /// </summary> /// <param name="xmlSpecification"></param> public virtual ValidationReport Parse(string xmlSpecification) { const string STRLOG_MethodName = "Parse"; Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName); // // Create a new validation report ready to fill in // ValidationReport validationReport = new ValidationReport(); // // Process the XML specification string // try { // Load XML specification string XmlDocument xmlDocument = XmlUtilities.GetXmlDocument(xmlSpecification); // // Get a copy of the specification XML node // XmlNode xmlNode = XmlUtilities.GetXmlRootNode(xmlDocument, Consts.STRXML_experimentSpecification); this.xmlNodeSpecification = xmlNode.Clone(); // // Get the setup id and check that it exists - search is case-sensitive // this.setupId = XmlUtilities.GetXmlValue(this.xmlNodeSpecification, Consts.STRXML_setupId, false); int setupIndex = Array.IndexOf(this.labConfiguration.SetupIds, this.setupId); if (setupIndex < 0) { throw new ArgumentException(STRERR_SetupIdInvalid, this.setupId); } // // Get the specified setup XML node // XmlNodeList xmlNodeList = XmlUtilities.GetXmlNodeList(this.xmlNodeConfiguration, Consts.STRXML_setup, true); this.xmlNodeSetup = xmlNodeList.Item(setupIndex); // // 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_EquipmentGeneric)) { if (this.equipmentServiceProxy == null) { throw new ArgumentException(STRERR_EquipmentServiceNotAvailable, this.setupId); } DriverEquipmentGeneric driver = new DriverEquipmentGeneric(this.equipmentServiceProxy, this.labConfiguration); executionTime = driver.GetExecutionTime(this); } else if (this.SetupId.Equals(Consts.STRXML_SetupId_ModuleGeneric)) { DriverModuleGeneric driver = new DriverModuleGeneric(this.labConfiguration); executionTime = driver.GetExecutionTime(this); } // // Specification is valid // validationReport.estRuntime = executionTime; validationReport.accepted = true; } catch (Exception ex) { validationReport.errorMessage = ex.Message; } Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName); return(validationReport); }
//-------------------------------------------------------------------------------------------------// /// <summary> /// Run the experiment and fill in the result report. Override in a derived class. /// </summary> /// <param name="experimentInfo"></param> /// <returns></returns> public virtual 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!) // ExperimentSpecification experimentSpecification = new ExperimentSpecification(this.labConfiguration, this.equipmentServiceProxy); ValidationReport validationReport = experimentSpecification.Parse(experimentInfo.xmlSpecification); if (validationReport.accepted == false) { throw new ArgumentException(validationReport.errorMessage); } experimentInfo.setupId = experimentSpecification.SetupId; // // Create an instance of the driver for the specified setup and then // execute the experiment and return the result information // ExperimentResultInfo experimentResultInfo = null; if (experimentSpecification.SetupId.Equals(Consts.STRXML_SetupId_EquipmentGeneric)) { DriverEquipmentGeneric driver = new DriverEquipmentGeneric(this.equipmentServiceProxy, this.labConfiguration, this.labExperimentInfo.cancelExperiment); experimentResultInfo = driver.Execute(experimentSpecification); } else if (experimentSpecification.SetupId.Equals(Consts.STRXML_SetupId_ModuleGeneric)) { DriverModuleGeneric driver = new DriverModuleGeneric(this.labConfiguration, this.labExperimentInfo.cancelExperiment); experimentResultInfo = driver.Execute(experimentSpecification); } // // Create an instance of LabExperimentResult to convert the experiment results to an XML string // LabExperimentResult labExperimentResult = new LabExperimentResult( experimentInfo.experimentId, experimentInfo.sbName, DateTime.Now, experimentSpecification.SetupId, this.unitId, this.labConfiguration); // // Fill in the result report // experimentInfo.resultReport.experimentResults = labExperimentResult.ToString(); experimentInfo.resultReport.statusCode = (int)experimentResultInfo.statusCode; experimentInfo.resultReport.errorMessage = experimentResultInfo.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); }
//-------------------------------------------------------------------------------------------------// public SubmissionReport Submit(int experimentID, string sbName, string experimentSpecification, string userGroup, int priorityHint) { SubmissionReport submissionReport = null; // // Create a SubmissionReport object ready to fill in and return // submissionReport = new SubmissionReport(experimentID); // // Validate the experiment specification before submitting // ValidationReport validationReport = Validate(experimentSpecification, userGroup); if (validationReport.accepted == false) { // Experiment specification is invalid, cannot submit submissionReport.vReport = validationReport; return(submissionReport); } // // Create an instance of the experiment // ExperimentInfo experimentInfo = new ExperimentInfo(experimentID, sbName, userGroup, priorityHint, experimentSpecification, (int)validationReport.estRuntime); // // Add the experiment to the queue // QueuedExperimentInfo queuedExperimentInfo = this.experimentQueue.Enqueue(experimentInfo); if (queuedExperimentInfo != null) { // // Update submission report // submissionReport.vReport.accepted = true; submissionReport.vReport.estRuntime = queuedExperimentInfo.estExecutionTime; submissionReport.wait = new WaitEstimate(queuedExperimentInfo.queueLength, queuedExperimentInfo.waitTime); // // Get minimum remaining runtime of any currently running experiments and add into the wait estimate // int minRemainingRuntime = GetMinRemainingRuntime(); submissionReport.wait.estWait += minRemainingRuntime; // // Update the statistics with revised wait estimate // queuedExperimentInfo.waitTime = (int)submissionReport.wait.estWait; this.experimentStatistics.Submitted(queuedExperimentInfo, DateTime.Now); // Tell lab experiment manager thread that an experiment has been submitted this.SignalSubmitted(); } else { // // Failed to add experiment to the queue // submissionReport.vReport.accepted = true; submissionReport.vReport.errorMessage = STRERR_FailedToQueueExperiment; } return(submissionReport); }