Exemple #1
0
        public void Get()
        {
            // Creating a request object
            var requestObj = new MsgMeas.GetObservationRequest();

            // Setting the conditions of the request
            requestObj.FeaturesOfInterest.Add("myplant/myprocess/mytemperature");

            // Adding a data record; use this to whatever additional parameters you need.
            // This naturally depends on the server.
            var extensionObj = new MsgMeas.Item_DataRecord()
            {
                { "parameter_x", new MsgMeas.Item_Count(3) }
            };

            requestObj.Items.Add(extensionObj);

            // Adding a temporal filter: retrieve all observation after given time
            var tempFilter1 = new MsgMeas.TemporalFilter(
                MsgMeas.TemporalFilter.ValueReferenceType.PhenomenonTime,
                MsgMeas.TemporalFilter.OperatorType.After,
                new MsgMeas.Item_TimeInstant(DateTime.Parse("2018-05-18T08:05:44Z").ToUniversalTime())
                );

            requestObj.TemporalFilters.Add(tempFilter1);

            // Serialising the request object
            byte[] requestXml = requestObj.ToXmlBytes();

            // Sending the requestXml to the server and waiting for a response...
            SendRequest(requestXml);
            byte[] responseXml = WaitForResponse();

            // Processing the response
            MsgMeas.GetObservationResponse responseObj;
            try
            {
                responseObj = new MsgMeas.GetObservationResponse(responseXml);
            }
            catch (MsgMeas.Neutral.InvalidMessageException e)
            {
                throw new InvalidOperationException("Failed to read server response: " + e.Message, e);
            }

            if (responseObj.RequestResult != MsgMeas.RequestResultType.Ok)
            {
                throw new InvalidOperationException("Unexpected response from server");
            }

            foreach (var obs in responseObj.Observations)
            {
                // Processing the observations...
                // ...
            }
        }
Exemple #2
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);
                }
            }
        }