コード例 #1
0
 private string GetTypeUri(XsdNs.OM_ObservationType observationRaw)
 {
     try
     {
         return(observationRaw.type.Href);
     }
     catch (NullReferenceException e)
     {
         throw new XNeut.InvalidMessageException("Failed to recognise observation type", e);
     }
 }
コード例 #2
0
        private void ReadFeatureOfInterest(XsdNs.OM_ObservationType observationRaw)
        {
            var featureProxy = observationRaw.featureOfInterest;

            // Feature of interest specified?
            if (featureProxy == null)
            {
                // No feature of interest specified at all
                FeatureOfInterest        = null;
                FeatureOfInterestDetails = new Item_DataRecord();
                return;
            }

            // Consistency check: there must not be both xlink attrs and a complex feature of interest
            if (featureProxy.AbstractFeature != null && featureProxy.XLinkHelperObj.XLinkSpecified)
            {
                throw new XNeut.InvalidMessageException("Inconsistent feature of interest: complex feature must not have xlink attributes");
            }

            // Simple feature of interest?
            if (featureProxy.Title != null)
            {
                // No additional metadata expected, just reading the xlink:title attribute
                FeatureOfInterest        = featureProxy.Title;
                FeatureOfInterestDetails = new Item_DataRecord();
                return;
            }

            if (featureProxy.AbstractFeature == null)
            {
                // No feature of interest specified at all
                FeatureOfInterest        = null;
                FeatureOfInterestDetails = new Item_DataRecord();
                return;
            }

            try
            {
                // Processing complex feature of interest
                var featureCasted = (XsdNs.SweDataComponentAsFeatureType)featureProxy.AbstractFeature;
                var dataRecordRaw = featureCasted.DataRecord;

                FeatureOfInterestDetails = new Item_DataRecord(dataRecordRaw);
                FeatureOfInterest        = FeatureOfInterestDetails.Identifier;
            }
            catch (Exception e)
            {
                throw new XNeut.InvalidMessageException(ErrorMsgPopulation + " (failed to process complex feature)", e);
            }
        }
コード例 #3
0
        /// <summary>
        /// Constructor to populate the information from XML.
        /// </summary>
        /// <param name="xmlBytes">Serialised XML document.</param>
        /// <exception cref="XNeut.InvalidMessageException">Thrown if an error is encountered.</exception>
        public Observation(byte[] xmlBytes)
        {
            SetDefaults();

            XsdNs.OM_ObservationType proxy = null;

            try
            {
                // Deserialising
                proxy = (XsdNs.OM_ObservationType)XNeut.Helper.DeserialiseFromXml(typeof(XsdNs.OM_ObservationType), xmlBytes);
            }
            catch (InvalidOperationException e)
            {
                throw new XNeut.InvalidMessageException(ErrorMsgPopulation, e);
            }

            // Reading values from XML
            ReadFieldValuesFromXmlDoc(proxy);
        }
コード例 #4
0
 /// <summary>
 /// Constructor to populate the object from an XML proxy object.
 /// </summary>
 /// <param name="proxy">Proxy.</param>
 /// <exception cref="XNeut.InvalidMessageException">Thrown if an error is encountered.</exception>
 internal Observation(XsdNs.OM_ObservationType proxy)
 {
     ReadFieldValuesFromXmlDoc(proxy);
 }
コード例 #5
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);
            }
        }
コード例 #6
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);
        }