Beispiel #1
0
        private void ReadFieldValuesFromXmlDoc(XsdNs.OM_ObservationType observationRaw)
        {
            try
            {
                // Getting observation type Uri
                var typeUri = GetTypeUri(observationRaw);

                // Name specified?
                var nameList = observationRaw.name;

                Name = (nameList != null && nameList.Length > 0) ?
                       nameList[0].Value : null;

                // Description
                Description = (observationRaw.description != null && observationRaw.description.Value != null) ?
                              observationRaw.description.Value : null;

                // Phenomenon time; this is a required field
                PhenomenonTime = new Item_TimeInstant(observationRaw.PhenomenonTime).Value;

                // Result time; this is a required field
                ResultTime = new Item_TimeInstant(observationRaw.resultTime).Value;

                // These fields are required per the schema, but this processing enables non-specified values
                Procedure = (observationRaw.procedure != null && observationRaw.procedure.Title != null) ?
                            observationRaw.procedure.Title : null;
                ObservedProperty = (observationRaw.observedProperty != null && observationRaw.observedProperty.Title != null) ?
                                   observationRaw.observedProperty.Title : null;
                ReadFeatureOfInterest(observationRaw);

                // Explicit result quality defined?
                if (observationRaw.resultQuality != null && observationRaw.resultQuality.Length > 0)
                {
                    var qualityStringRaw = observationRaw.resultQuality[0].Title;
                    ResultQuality = new DataQuality(qualityStringRaw);
                }
                else
                {
                    ResultQuality = DataQuality.CreateGood();
                }

                // Processing result information
                Result = ResultTypeManager.BuildResultFromXml(typeUri, observationRaw.result);
            }
            // If the document lacks required data:
            catch (ArgumentNullException e)
            {
                throw new XNeut.InvalidMessageException(ErrorMsgPopulation + " (required data missing?)", e);
            }
            catch (NullReferenceException e)
            {
                throw new XNeut.InvalidMessageException(ErrorMsgPopulation + " (required data missing?)", e);
            }
            // new DataQuality:
            catch (ArgumentException e)
            {
                throw new XNeut.InvalidMessageException(ErrorMsgPopulation, e);
            }
            // ResultTypeManager.buildResultFromXml:
            catch (NotSupportedException e)
            {
                throw new XNeut.InvalidMessageException(ErrorMsgPopulation + " (XML typing error?)", e);
            }
            catch (InvalidCastException e)
            {
                throw new XNeut.InvalidMessageException(ErrorMsgPopulation + " (XML typing error?)", e);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Generates 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>
        internal XsdNs.OM_ObservationType ToXmlProxy(string idPrefix)
        {
            // No exception handling because an exception would indicate a bug

            // Creating an ID prefix to enable unique IDs within the XML doc
            var myUniqueId = idPrefix + "Obs";

            // Result quality
            var resultQuality = new XsdNs.DQ_Element_PropertyType {
                Title = ResultQuality.Value
            };

            if (PhenomenonTime == null)
            {
                // Default: using result time as the phenomenon time
                PhenomenonTime = ResultTime;
            }

            // Phenomenon time
            var phenoInstant = new Item_TimeInstant(PhenomenonTime);
            var phenoProp    = (XsdNs.TimeInstantPropertyType)phenoInstant.GetObjectForXml_Result(myUniqueId + "_phenoTime");

            // Result time
            var resultTimeInstant = new Item_TimeInstant(ResultTime);
            var resultTimeProp    = (XsdNs.TimeInstantPropertyType)resultTimeInstant.GetObjectForXml_Result(myUniqueId + "_resTime");

            // Assigning values to a raw observation object
            var obsToSerialise = new XsdNs.OM_ObservationType
            {
                id   = myUniqueId,
                type = new XsdNs.ReferenceType {
                    Href = Result.ObservationTypeUri
                },
                procedure = new XsdNs.OM_ProcessPropertyType {
                    Title = Procedure
                },
                PhenomenonTime   = phenoProp,
                resultTime       = resultTimeProp,
                observedProperty = new XsdNs.ReferenceType {
                    Title = ObservedProperty
                },
                featureOfInterest = WriteFeatureOfInterest(myUniqueId + "_complexFeature"),
                resultQuality     = new XsdNs.DQ_Element_PropertyType[] { resultQuality },
                result            = Result.GetObjectForXml_Result(myUniqueId + "_result_")
            };

            // Name
            if (!string.IsNullOrEmpty(Name))
            {
                var nameCodeObj = new XsdNs.CodeType {
                    Value = Name
                };
                obsToSerialise.name = new XsdNs.CodeType[] { nameCodeObj };
            }

            // Description
            if (!string.IsNullOrEmpty(Description))
            {
                XsdNs.StringOrRefType desc = new XsdNs.StringOrRefType {
                    Value = Description
                };
                obsToSerialise.description = desc;
            }

            return(obsToSerialise);
        }