/// <summary> /// Helper function to read an XML element (not a full document) /// representing a cloud execution request. /// </summary> /// <remarks> /// Note that the XmlReader is expected to be positioned in the XML /// document such that the current node is a request element. /// </remarks> /// <param name="xr">The XmlReader object to read from.</param> /// <returns> /// A new request corresponding to the XML representation read. /// </returns> public static CloudExecutionRequest ReadXml(XmlReader xr) { Util.Assert(xr.Name.Equals(CloudExecutionRequest.XmlTag)); string versionText = xr.GetAttribute(CloudExecutionRequest.XmlVersionAttribute); int version = int.Parse(versionText, CultureInfo.InvariantCulture); string reportQueue = "reports"; string identifier = string.Empty; Operation operation = Operation.RunExecutable; string executable = string.Empty; string arguments = string.Empty; bool inInputFileMappings = false; List <BuildObjectValuePointer> inputFileMappings = new List <BuildObjectValuePointer>(); bool inOutputFiles = false; List <BuildObject> outputFiles = new List <BuildObject>(); while (xr.Read()) { if (xr.NodeType == XmlNodeType.Element) { switch (xr.Name) { case XmlReportQueueElement: reportQueue = xr.ReadElementContentAsString(); break; case XmlIdentifierElement: identifier = xr.ReadElementContentAsString(); break; case XmlOperationElement: operation = (Operation)Enum.Parse(typeof(Operation), xr.ReadElementContentAsString()); break; case XmlExecutableElement: executable = xr.ReadElementContentAsString(); break; case XmlArgumentsElement: arguments = xr.ReadElementContentAsString(); break; case XmlInputFileMappingsElement: inInputFileMappings = true; break; case BuildObjectValuePointer.XmlTag: Util.Assert(inInputFileMappings); inputFileMappings.Add(BuildObjectValuePointer.ReadXml(xr)); break; case XmlOutputFilesElement: inOutputFiles = true; break; case BuildObject.XmlTag: Util.Assert(inOutputFiles); outputFiles.Add(BuildObject.ReadXml(xr)); break; } } else if (xr.NodeType == XmlNodeType.EndElement) { if (xr.Name.Equals(CloudExecutionRequest.XmlTag)) { break; // All done. } switch (xr.Name) { case XmlInputFileMappingsElement: inInputFileMappings = false; break; case XmlOutputFilesElement: inOutputFiles = false; break; } } } // REVIEW: Require presence of (some/all) elements? Sanity check things here? return(new CloudExecutionRequest( version, reportQueue, identifier, operation, executable, arguments, inputFileMappings, outputFiles)); }