public void Create() { // Create columns (3 in total). // Please see the documentation of constructors in Item_Array.ArrayColumn to // see which data types are supported. var myColumns = new SysColl.List<MsgMeas.Item_Array.ArrayColumn>() { new MsgMeas.Item_Array.ArrayColumn(typeof(DateTime), "timestamp"), new MsgMeas.Item_Array.ArrayColumn(typeof(double), "temperature", "Cel"), new MsgMeas.Item_Array.ArrayColumn(typeof(long), "batchcount") }; // Create the array item and its rows (2 rows in total). // These must match respective column types. var myArray = new MsgMeas.Item_Array(myColumns) { { DateTime.Now.ToUniversalTime().AddHours(-1), -4.2, (long)29 }, { DateTime.Now.ToUniversalTime(), -3.8, (long)32 } }; // You can also use the "Add" method instead of the array initialiser shown above. // The Add method can take any number of arguments. myArray.Add(DateTime.Now.ToUniversalTime(), -2.1, (long)36); // Now, you can enclose the array in an Observation or Item_DataRecord. E.g., var myObservation = new MsgMeas.Observation(myArray); byte[] xmlBytes = myObservation.ToXmlBytes(); }
private void ProcessOneField(XsdNs.DataRecordTypeField field) { string fieldName = field.name; var fieldObj = field.dataComponent; Item itemRead = null; DataQuality dataQuality = null; var simpleComponent = true; try { if (fieldObj is XsdNs.AbstractSimpleComponentType) { // Simple component (as of SWE schemata) simpleComponent = true; itemRead = ReadSimpleData(field); } else { // Complex component simpleComponent = false; switch (field.dataComponentTypeInfo) { case XsdNs.DataRecordFieldTypeType.DataRecord: var dataRec = (XsdNs.DataRecordType)fieldObj; itemRead = new Item_DataRecord(dataRec); break; case XsdNs.DataRecordFieldTypeType.AbstractGmlAsSweDataComponent: itemRead = ProcessTimeSeriesField((XsdNs.AbstractGmlAsSweDataComponentType)fieldObj); break; case XsdNs.DataRecordFieldTypeType.DataArray: itemRead = new Item_Array((XsdNs.DataArrayType)fieldObj); break; default: // For robustness, just skip unknown field types itemRead = null; break; } } } // Datetime values catch (FormatException e) { throw new XNeut.InvalidMessageException("Data record field is invalid: " + fieldName, e); } // Other errors catch (XNeut.InvalidMessageException e) { throw new XNeut.InvalidMessageException("Data record field is invalid: " + fieldName, e); } if (itemRead == null) { // Unknown field type -> skip for robustness return; } if (simpleComponent) { // Getting data quality var simpleComp = (XsdNs.AbstractSimpleComponentType)fieldObj; if (simpleComp.quality != null && simpleComp.quality.Length > 0) { var qualityProp = simpleComp.quality[0]; dataQuality = new DataQuality(qualityProp.Title); } } if (dataQuality == null) { Add(fieldName, itemRead); } else { Add(fieldName, itemRead, dataQuality); } }