/// <summary> /// Constructor. Use this to deserialise the object from XML. /// </summary> /// <param name="xmlBytes">XML data.</param> /// <exception cref="XNeut.InvalidMessageException">Thrown in an error is encountered.</exception> public TaskStatusReport(byte[] xmlBytes) { XsdNs.StatusReportType proxy = null; try { // Deserialising proxy = (XsdNs.StatusReportType)XNeut.Helper.DeserialiseFromXml(typeof(XsdNs.StatusReportType), xmlBytes); } catch (InvalidOperationException e) { throw new XNeut.InvalidMessageException("Failed to deserialise TaskStatusReport from XML", e); } // Reading values from XML ReadFieldValuesFromXmlDoc(proxy); }
/// <summary> /// Creates an XML proxy from the object. /// </summary> /// <param name="idPrefix">A prefix to be appended to the IDs of any child XML elements that /// require an ID. For certain XML elements, the schema requires an ID that is unique within /// the XML document. Instead of generating random IDs, these are systematic and hierarchical /// in this software. To ensure uniqueness, each ID prefix can occur only once. The ID is of /// type xsd:id. This derives from xsd:NCName, so not all characters are allowed.</param> /// <returns>Proxy.</returns> public XsdNs.StatusReportType ToXmlProxy(string idPrefix) { var proxy = new XsdNs.StatusReportType() { // #1 in XML schema: task task = TaskId, // #3 in XML schema: event (not implemented) // #5 in XML schema: procedure procedure = ProcedureId, // #6 in XML schema: requestStatus requestStatus = RequestStatus.ToString(), // #9 in XML schema: updateTime updateTime = UpdateTime // #10 in XML schema: alternative (not implemented) }; // #2 in XML schema: estimatedToC // Assign if defined if (EstimatedTimeOfCompletion.HasValue) { // UTC not expected because already supposedly checked in the setter, but check just in case XNeut.Helper.ExpectDateTimeIsUtc(EstimatedTimeOfCompletion.Value); // throws DateTimeException proxy.estimatedToC = EstimatedTimeOfCompletion.Value; } proxy.estimatedToCSpecified = EstimatedTimeOfCompletion.HasValue; // #4 in XML schema: percentCompletion if (PercentCompletion.HasValue) { proxy.percentCompletion = PercentCompletion.Value; } proxy.percentCompletionSpecified = PercentCompletion.HasValue; // #7 in XML schema: statusMessage if (StatusMessages != null && StatusMessages.Count > 0) { proxy.statusMessage = new XsdNs.LanguageStringType[StatusMessages.Count]; for (int a = 0; a < StatusMessages.Count; ++a) { proxy.statusMessage[a] = new XsdNs.LanguageStringType { Value = StatusMessages[a] }; } } // Assign status code only if known // #8 in XML schema: taskStatus if (TaskStatusCode != TaskStatusCodeType.Unknown) { proxy.taskStatus = TaskStatusCode.ToString(); } // Assign tasking parameters if defined // #11 in XML schema: taskingParameters if (TaskingParameters.ItemNames.Count > 0) { var paramsProc = new TaskingParameterProcessor(TaskingParameters); proxy.taskingParameters = new XsdNs.ParameterDataPropertyType() { ParameterData = paramsProc.ToXmlProxy(idPrefix + "TaskPar-") }; } return(proxy); }
private void ReadFieldValuesFromXmlDoc(XsdNs.StatusReportType proxy) { try { // #1 in XML schema: task // The schema requires a value for this field. TaskId = proxy.task; // #2 in XML schema: estimatedToC if (proxy.estimatedToCSpecified) { EstimatedTimeOfCompletion = XNeut.Helper.DateTimeToUtcIfPossible(proxy.estimatedToC); } else { EstimatedTimeOfCompletion = null; } // #3 in XML schema: event (not implemented) // #4 in XML schema: percentCompletion if (proxy.percentCompletionSpecified) { PercentCompletion = proxy.percentCompletion; } else { PercentCompletion = null; } // #5 in XML schema: procedure // The schema requires a value for this field. ProcedureId = proxy.procedure; // #6 in XML schema: requestStatus // The schema requires a value for this field. try { RequestStatus = (TaskingRequestStatusCodeType)Enum.Parse(typeof(TaskingRequestStatusCodeType), proxy.requestStatus); } catch (ArgumentException e) { throw new XNeut.InvalidMessageException("Failed to parse request status", e); } // #7 in XML schema: statusMessage StatusMessages = new System.Collections.Generic.List <string>(); if (proxy.statusMessage != null) { foreach (var s in proxy.statusMessage) { StatusMessages.Add(s.Value.Trim()); } } // #8 in XML schema: taskStatus try { if (!string.IsNullOrEmpty(proxy.taskStatus)) { TaskStatusCode = (TaskStatusCodeType)Enum.Parse(typeof(TaskStatusCodeType), proxy.taskStatus); } else { // Default TaskStatusCode = TaskStatusCodeType.Unknown; } } catch (ArgumentException e) { throw new XNeut.InvalidMessageException("Failed to parse task status", e); } // #9 in XML schema: updateTime // The schema requires a value for this field. UpdateTime = XNeut.Helper.DateTimeToUtcIfPossible(proxy.updateTime); // #10 in XML schema: alternative (not implemented) // Tasking parameters defined? // #11 in XML schema: taskingParameters if (proxy.taskingParameters != null && proxy.taskingParameters.ParameterData != null) { var paramsProxy = proxy.taskingParameters.ParameterData; TaskingParameters = new TaskingParameterProcessor(paramsProxy).Parameters; } else { TaskingParameters = new Item_DataRecord(); } } catch (NullReferenceException e) { throw new XNeut.InvalidMessageException("Failed to read status report from XML (something required missing?)", e); } }
/// <summary> /// Constructor. Use this to populate the object from a proxy. /// </summary> /// <param name="proxy">Proxy.</param> /// <exception cref="XNeut.InvalidMessageException">Thrown in an error is encountered.</exception> internal TaskStatusReport(XsdNs.StatusReportType proxy) { // Reading values from XML ReadFieldValuesFromXmlDoc(proxy); }