コード例 #1
0
        private XsdNs.GetObservationType ToXmlProxy()
        {
            // Using this to enable unique IDs within the XML document
            var idPrefix = "GetObsReq_i";

            var toSerialise = new XsdNs.GetObservationType
            {
                // Assigning mandatory attributes specified in the SWES standard.
                // These value follow the SOS specification.
                service = "SOS",
                version = "2.0.0",

                // Assigning measurement point information
                featureOfInterest = StringCollectionToStringArray(FeaturesOfInterest),
                observedProperty  = StringCollectionToStringArray(ObservedProperties),

                // Assigning extensions
                extension = new object[Items.Count]
            };

            int prefixCounter = 0;

            for (var a = 0; a < Items.Count; ++a)
            {
                var ext = Items[a];

                if (ext == null)
                {
                    throw new NullReferenceException("Item is null");
                }

                // Assigning the proxy object
                var idWithCounter = idPrefix + (prefixCounter + 1) + "-"; // This gives, e.g., "GetObsReq_i3-"
                toSerialise.extension[a] = ext.ToXmlProxyWithWrapper(idWithCounter);

                ++prefixCounter;
            }

            // Assigning temporal filters
            toSerialise.temporalFilter = new XsdNs.GetObservationTypeTemporalFilter[TemporalFilters.Count];

            for (int a = 0; a < TemporalFilters.Count; ++a)
            {
                // Create a proxy object for serialisation
                var idWithCounter = idPrefix + (prefixCounter + 1) + "-"; // This gives, e.g., "GetObsReq_i3-"
                var filterProxy   = TemporalFilters[a].ToXmlProxy(idWithCounter);

                toSerialise.temporalFilter[a] = filterProxy;

                ++prefixCounter;
            }

            return(toSerialise);
        }
コード例 #2
0
        /// <summary>
        /// Constructor. Use to process incoming requests.
        /// </summary>
        /// <param name="xmlBytes">XML data.</param>
        /// <exception cref="XNeut.InvalidMessageException">Thrown if the message is not valid.</exception>
        public GetObservationRequest(byte[] xmlBytes)
            : this()
        {
            XsdNs.GetObservationType proxy = null;

            try
            {
                // Deserialising
                proxy = (XsdNs.GetObservationType)XNeut.Helper.DeserialiseFromXml(typeof(XsdNs.GetObservationType), xmlBytes);
            }
            catch (InvalidOperationException e)
            {
                throw new XNeut.InvalidMessageException("Failed to deserialise XML data", e);
            }

            // Reading values from the proxy
            ReadFieldValuesFromXmlDoc(proxy);
        }
コード例 #3
0
        private void ReadFieldValuesFromXmlDoc(XsdNs.GetObservationType requestObjectRaw)
        {
            // Reading features of interest
            if (requestObjectRaw.featureOfInterest != null && requestObjectRaw.featureOfInterest.Length > 0)
            {
                FeaturesOfInterest = new HashSet <string>(requestObjectRaw.featureOfInterest);
            }

            // Reading observed properties
            if (requestObjectRaw.observedProperty != null && requestObjectRaw.observedProperty.Length > 0)
            {
                ObservedProperties = new HashSet <string>(requestObjectRaw.observedProperty);
            }

            // Reading extensions
            if (requestObjectRaw.extension != null)
            {
                foreach (var ext in requestObjectRaw.extension)
                {
                    if (ext.GetType() != typeof(XsdNs.DataRecordPropertyType))
                    {
                        throw new XNeut.InvalidMessageException("The type of the extension object is not supported: " + ext.GetType().ToString());
                    }

                    var dataRecordRaw = (XsdNs.DataRecordPropertyType)ext;
                    Items.Add(new Item_DataRecord(dataRecordRaw.DataRecord));
                }
            }

            // Reading temporal filters
            if (requestObjectRaw.temporalFilter != null)
            {
                foreach (var filterEl in requestObjectRaw.temporalFilter)
                {
                    var filterObj = new TemporalFilter(filterEl);
                    TemporalFilters.Add(filterObj);
                }
            }
        }
コード例 #4
0
        private TemporalFilter SerialiseAndRead(TemporalFilter input)
        {
            // Get proxy
            var filterProxy = input.ToXmlProxy("test_");

            // Wrap the proxy in a GetObservationRequest
            var requestProxy = new XsdNs.GetObservationType
            {
                temporalFilter = new XsdNs.GetObservationTypeTemporalFilter[] { filterProxy },
                service        = "SOS",
                version        = "2.0.0"
            };

            // Serialise the proxy
            byte[] xmlBytes = XNeut.Helper.ToXmlBytes(requestProxy);

            // XML validation
            Validate(xmlBytes);

            // Read XML data
            var proxyIn = DeserialiseAndGetProxy(xmlBytes);

            return(new TemporalFilter(proxyIn));
        }