Example #1
0
        /// <summary>
        /// Adds values to proxy.
        /// </summary>
        /// <param name="proxy">Proxy.</param>
        /// <param name="uid">Unique ID (for XML IDs).</param>
        protected override void AddSubclassDataToProxy(XsdNs.TimeseriesDomainRangeType proxy, string uid)
        {
            // No exception handling here as exceptions indicate bugs in this function

            var myUniqueId = uid + "_flex";

            // Checking in case the base class has already added this
            if (proxy.domainSet == null)
            {
                var domainSet = new XsdNs.DomainSetType();
                proxy.domainSet = domainSet;
            }

            // Adding time positions

            var timestampsList = new List <DateTime>();

            foreach (var obj in m_items)
            {
                timestampsList.Add(obj.Timestamp);
            }

            // domainSet/TimePositionList
            proxy.domainSet.TimePositionList = new XsdNs.TimePositionListType
            {
                id = myUniqueId + "_timestamps"                                   // Required by the schema
            };
            proxy.domainSet.TimePositionList.SetTimestampsHelper(timestampsList); // throws DateTimeException
        }
Example #2
0
        private void ReadFieldValuesFromXmlDoc(XsdNs.TimeseriesDomainRangeType proxy)
        {
            string partName       = "timestamps";
            var    timestampsList = new List <DateTime>();

            try
            {
                // May throw FormatException
                foreach (var dt in proxy.domainSet.TimePositionList.GetTimestampsHelper())
                {
                    timestampsList.Add(dt.ToUniversalTime());
                }
            }
            // Missing fields
            catch (IndexOutOfRangeException e)
            {
                throw new XNeut.InvalidMessageException("Failed to read " + partName + " from time series XML (required item missing?)", e);
            }
            // Missing fields
            catch (NullReferenceException e)
            {
                throw new XNeut.InvalidMessageException("Failed to read " + partName + " from time series XML (required item missing?)", e);
            }
            // Datetime values
            catch (FormatException e)
            {
                throw new XNeut.InvalidMessageException("Failed to read " + partName + " from time series XML (invalid value formatting?)", e);
            }

            // Checking that the size of each collection matches
            if (timestampsList.Count != DeserialisedValues.Count)
            {
                throw new XNeut.InvalidMessageException("The sizes of collections do not match in the XML document (something missing or too many)");
            }

            // Adding deserialised values
            for (int a = 0; a < timestampsList.Count; ++a)
            {
                Add(timestampsList[a], DeserialisedValues[a], DeserialiesdDataQualities[a]);
            }
        }
Example #3
0
        /// <summary>
        /// Adds subclass-specific values to the proxy.
        /// </summary>
        /// <param name="proxy">Proxy.</param>
        /// <param name="uid">Unique identifier for XML IDs.</param>
        protected override void AddSubclassDataToProxy(XsdNs.TimeseriesDomainRangeType proxy, string uid)
        {
            // (1) Creating a metadata element if it does not exist
            if (proxy.metadata1 == null || proxy.metadata1.Length == 0)
            {
                proxy.metadata1 = new XsdNs.TimeseriesMetadataExtensionPropertyType[]
                {
                    new XsdNs.TimeseriesMetadataExtensionPropertyType()
                };
            }
            else if (proxy.metadata1.Length > 1)
            {
                throw new ArgumentException("Cannot populate subclass data: expected exactly one metadata element");
            }

            if (proxy.metadata1[0].TimeseriesMetadataExtension == null)
            {
                proxy.metadata1[0].TimeseriesMetadataExtension = new XsdNs.TimeseriesMetadataExtensionType();
            }

            if (proxy.metadata1[0].TimeseriesMetadataExtension.timeseriesMetadata == null)
            {
                proxy.metadata1[0].TimeseriesMetadataExtension.timeseriesMetadata = new XsdNs.TimeseriesMetadataExtensionTypeTimeseriesMetadata();
            }

            if (proxy.metadata1[0].TimeseriesMetadataExtension.timeseriesMetadata.TimeseriesMetadata == null)
            {
                proxy.metadata1[0].TimeseriesMetadataExtension.timeseriesMetadata.TimeseriesMetadata = new XsdNs.TimeseriesMetadataType();
            }

            // (2) Setting timing information
            var metadataElement = proxy.metadata1[0].TimeseriesMetadataExtension.timeseriesMetadata.TimeseriesMetadata;

            metadataElement.baseTime = new XsdNs.TimePositionType
            {
                Value = XNeut.Helper.DateTimeToString(BaseTime) // throws DateTimeException
            };
            metadataElement.spacing = XNeut.Helper.TimeSpanToString(Spacing);
        }
Example #4
0
        private void ReadValuesFromProxy(XsdNs.TimeseriesDomainRangeType proxy)
        {
            const string ERROR_MSG = "Failed to read the data of constant-interval time series";

            if (proxy.metadata1.Length != 1)
            {
                throw new XNeut.InvalidMessageException("Expected exactly one tsml:metadata element in a constant-interval time series");
            }

            try
            {
                var timeseriesMetadata = proxy.metadata1[0].TimeseriesMetadataExtension.timeseriesMetadata.TimeseriesMetadata;

                BaseTime = XNeut.Helper.DateTimeFromString(timeseriesMetadata.baseTime.Value);
                Spacing  = XNeut.Helper.TimeSpanFromString(timeseriesMetadata.spacing);
            }
            // Missing fields
            catch (IndexOutOfRangeException e)
            {
                throw new XNeut.InvalidMessageException(ERROR_MSG + " (required item missing?)", e);
            }
            // Missing fields
            catch (NullReferenceException e)
            {
                throw new XNeut.InvalidMessageException(ERROR_MSG + " (required item missing?)", e);
            }
            // Datetime values, timespan values
            catch (FormatException e)
            {
                throw new XNeut.InvalidMessageException(ERROR_MSG + " (invalid value formatting?)", e);
            }

            // Adding deserialised values from the base class
            for (int a = 0; a < DeserialisedValues.Count; ++a)
            {
                Add(DeserialisedValues[a], DeserialiesdDataQualities[a]);
            }
        }
Example #5
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="proxy"></param>
 internal Item_TimeSeriesConstant(XsdNs.TimeseriesDomainRangeType proxy) : base(XNeut.Helper.TypeUri_TimeSeriesConstant, proxy)
 {
     ReadValuesFromProxy(proxy);
 }
Example #6
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="typeUri">Type URI.</param>
 /// <param name="proxy">Proxy object.</param>
 protected Item_TimeSeries(string typeUri, XsdNs.TimeseriesDomainRangeType proxy) : base(typeUri)
 {
     UnitOfMeasure = ReadFieldValuesFromXmlDoc(proxy);
 }
Example #7
0
        private XsdNs.TimeseriesDomainRangeType ToXmlProxy(string idPrefix)
        {
            // No exception handling here as exceptions indicate bugs in this function

            var myUniqueId = idPrefix + "TimeSer";

            // Initialising objects
            var proxy = new XsdNs.TimeseriesDomainRangeType
            {
                id = myUniqueId, // Required by the schema

                // Adding a rangeType element as it is required by the XML schema
                rangeType = new XsdNs.DataRecordPropertyType(),

                description = new XsdNs.StringOrRefType(),

                // Adding an empty domain set (required by gml:AbstractCoverageType)
                domainSet = new XsdNs.DomainSetType()
            };

            proxy.description.Value = Description;

            List <double> valuesForDeser = new List <double>();

            for (int a = 0; a < ValueCount; ++a)
            {
                valuesForDeser.Add(GetValue(a));
            }

            // 1) Adding item values
            // rangeSet/QuantityList
            var measValues = new XsdNs.MeasureOrNilReasonListType
            {
                uom          = UnitOfMeasure,
                ValuesHelper = valuesForDeser
            };

            // rangeSet
            var rangeSetValues = new XsdNs.RangeSetType
            {
                Items = new object[] { measValues }
            };

            proxy.rangeSet = rangeSetValues;

            // 2) Adding data quality information
            var qualityStrings = new List <string>();

            for (int a = 0; a < ValueCount; ++a)
            {
                qualityStrings.Add(GetDataQuality(a).Value);
            }

            var qualityList = new XsdNs.CodeOrNilReasonListType
            {
                codeSpace = "http://cocop",
                TextAsSingleArrayHelper = qualityStrings
            };

            /*
             * The OGC example "timeseries-domain-range-example.xml" uses the gmlcov:metadata
             * field instead of this. However, this approach is better typed (no extension
             * elements used) and has one less of XML element layers.
             */
            // tsml:metadata/TimeseriesMetadataExtension/defaultPointMetadata/annotation/AnnotationCoverage/rangeSet (/CategoryList)
            var rangeSetQual = new XsdNs.RangeSetType
            {
                Items = new object[] { qualityList }
            };

            // tsml:metadata/TimeseriesMetadataExtension/defaultPointMetadata/annotation/AnnotationCoverage
            var annotationCoverage = new XsdNs.AnnotationCoverageType
            {
                id        = myUniqueId + "_qualCov",           // Required by the schema (inherited from AbstractGMLType)
                domainSet = new XsdNs.DomainSetType(),         // Required by the schema
                rangeSet  = rangeSetQual,
                rangeType = new XsdNs.DataRecordPropertyType() // Required by the schema
            };
            var annotationCoverageProp = new XsdNs.AnnotationCoveragePropertyType
            {
                AnnotationCoverage = annotationCoverage
            };

            // tsml:metadata/TimeseriesMetadataExtension
            var tsMetadataExt = new XsdNs.TimeseriesMetadataExtensionType
            {
                annotation = new XsdNs.AnnotationCoveragePropertyType[1]
            };

            tsMetadataExt.annotation[0] = annotationCoverageProp;

            // tsml:metadata
            var metadata = new XsdNs.TimeseriesMetadataExtensionPropertyType
            {
                TimeseriesMetadataExtension = tsMetadataExt
            };

            proxy.metadata1 = new XsdNs.TimeseriesMetadataExtensionPropertyType[] { metadata };

            // Adding items from the subclass
            AddSubclassDataToProxy(proxy, myUniqueId);

            return(proxy);
        }
Example #8
0
        private string ReadFieldValuesFromXmlDoc(XsdNs.TimeseriesDomainRangeType proxy)
        {
            string unitOfMeasure = null;
            string partName      = "measurement values";

            DeserialisedValues        = new List <double>();
            DeserialiesdDataQualities = new List <DataQuality>();

            try
            {
                // Reading description
                if (proxy.description != null)
                {
                    Description = proxy.description.Value;
                }

                var measValues = (XsdNs.MeasureOrNilReasonListType)proxy.rangeSet.Items[0];

                // Reading the unit of measure
                unitOfMeasure = measValues.uom;

                // Getting measurement values
                foreach (var d in measValues.ValuesHelper)
                {
                    DeserialisedValues.Add(d);
                }

                // Reading data qualities
                partName = "data qualities";

                if (proxy.metadata1.Length != 1)
                {
                    throw new XNeut.InvalidMessageException("Expected exactly one tsml:metadata element in a time series");
                }

                /*
                 * The OGC example "timeseries-domain-range-example.xml" uses the gmlcov:metadata
                 * field instead of this. However, this approach is better typed (no extension
                 * elements used) and has one less of XML element layers.
                 */
                // Path: proxy.metadata1.TimeseriesMetadataExtension.annotation[0].AnnotationCoverage.rangeSet.CategoryList
                var metadataExt    = proxy.metadata1[0].TimeseriesMetadataExtension;
                var rangeSet       = metadataExt.annotation[0].AnnotationCoverage.rangeSet;
                var qualityListRaw = (XsdNs.CodeOrNilReasonListType)rangeSet.Items[0];

                // The first item in the quality list contains the quality values
                var qualityItemsRaw = qualityListRaw.TextAsSingleArrayHelper;

                // Parsing data quality values
                foreach (var s in qualityItemsRaw)
                {
                    DeserialiesdDataQualities.Add(new DataQuality(s));
                }
            }
            // Missing fields
            catch (IndexOutOfRangeException e)
            {
                throw new XNeut.InvalidMessageException("Failed to read " + partName + " from time series XML (required item missing?)", e);
            }
            // Missing fields
            catch (NullReferenceException e)
            {
                throw new XNeut.InvalidMessageException("Failed to read " + partName + " from time series XML (required item missing?)", e);
            }
            // Datetime values
            catch (FormatException e)
            {
                throw new XNeut.InvalidMessageException("Failed to read " + partName + " from time series XML (invalid value formatting?)", e);
            }

            // Checking that the size of each collection matches
            if (DeserialiesdDataQualities.Count != DeserialisedValues.Count)
            {
                throw new XNeut.InvalidMessageException("The sizes of collections do not match in the XML document (something missing or too many)");
            }

            return(unitOfMeasure);
        }
Example #9
0
 /// <summary>
 /// Adds subclass data to a proxy object. In the implementation, the subclass *must not*
 /// re-instantiate any proxy class members if they already exist, as it would erase
 /// the data set by the superclass.
 /// </summary>
 /// <param name="proxy">Proxy object.</param>
 /// <param name="uid">Unique ID (for XML IDs).</param>
 protected abstract void AddSubclassDataToProxy(XsdNs.TimeseriesDomainRangeType proxy, string uid);
Example #10
0
 /// <summary>
 /// Constructor. Use to populate from XML proxy.
 /// </summary>
 /// <param name="proxy">Proxy object.</param>
 internal Item_TimeSeriesFlexible(XsdNs.TimeseriesDomainRangeType proxy) : base(XNeut.Helper.TypeUri_TimeSeriesFlexible, proxy)
 {
     // Reading values from XML
     ReadFieldValuesFromXmlDoc(proxy);
 }