/* Test.Module.cs Copyright © 2008 Diversified Technical Systems, Inc. All Rights Reserved */ using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Text; using System.Xml; using System.Xml.Schema; using System.Xml.Serialization; using DTS.Utilities; using DTS.Utilities.DotNetProgrammingConstructs; using DTS.Utilities.Xml; namespace DTS.Serialization { // *** See Test.cs *** public partial class Test : Exceptional, IXmlSerializable { /// /// Representation of serializable module information. /// [XmlSerializationTag( "Module" )] public partial class Module : Exceptional { /// /// The that contains this module. /// public Test ParentTest { get { return _ParentTest.Value; } private set { _ParentTest.Value = value; } } private Property _ParentTest = new Property( typeof( Test.Module ).Namespace + ".Test.Module.ParentTest", null, false ); /// /// Initialize an instance of the DTS.Serialization.Test.Module class. /// /// /// /// The containing this object. /// /// public Module( Test parentTest ) { try { this.ParentTest = parentTest; } catch ( System.Exception ex ) { throw new Test.Module.Exception( "encountered problem constructing " + this.GetType( ).Name, ex ); } } /// /// Get/set the list of channels on this module. /// [XmlSerializationTag( "Channels" )] public List Channels { get { return _Channels.Value; } set { _Channels.Value = value; } } private Property> _Channels = new Property>( typeof( Module ).Namespace + ".Test.Module.Channels", new List( ), true ); /// /// The list of modules in this test. /// [XmlSerializationTag("CalculatedChannels")] public List CalculatedChannels { get { return _CalculatedChannels.Value; } set { _CalculatedChannels.Value = value; } } private Property> _CalculatedChannels = new Property>( typeof(Module).Namespace + ".Test.Module.CalculatedChannels", new List(), true ); /// /// Get/set the module number of this module. /// [XmlSerializationTag( "Number" )] public int Number { get { return _Number.Value; } set { _Number.Value = value; } } private Property _Number = new Property( typeof( Module ).Namespace + ".Test.Module.Number", 0, false ); /// /// Get/set the serial number for this DAS. /// [XmlSerializationTag( "SerialNumber" )] public string SerialNumber { get { return _SerialNumber.Value; } set { _SerialNumber.Value = value; } } private Property _SerialNumber = new Property( typeof( Module ).Namespace + ".Test.Module.SerialNumber", "", true ); /// /// A string that describes the module, for example, to know if it was created for the /// purposes of adding it to the .dts file during download of Slice6 Distributor attributes. /// [XmlSerializationTag("Description")] public string Description { get { return _Description.Value; } set { _Description.Value = value; } } private Property _Description = new Property( typeof(Module).Namespace + ".Test.Module.Description", "", true ); /// /// Get/set the base serial number for this DAS. /// [XmlSerializationTag("BaseSerialNumber")] public string BaseSerialNumber { get { return _BaseSerialNumber.Value; } set { _BaseSerialNumber.Value = value; } } private Property _BaseSerialNumber = new Property( typeof(Module).Namespace + ".Test.Module.BaseSerialNumber", "", true ); /// /// Get/set the number of requested seconds pre-trigger for this module. /// [XmlSerializationTag("RequestedPreTriggerSeconds")] public double RequestedPreTriggerSeconds { get { return _RequestedPreTriggerSeconds.Value; } set { _RequestedPreTriggerSeconds.Value = value; } } private Property _RequestedPreTriggerSeconds = new Property( typeof(Module).Namespace + ".Test.Module.RequestedPreTriggerSeconds", 0.0, false ); /// /// Get/set the number of requested seconds post-trigger for this module. /// [XmlSerializationTag("RequestedPostTriggerSeconds")] public double RequestedPostTriggerSeconds { get { return _RequestedPostTriggerSeconds.Value; } set { _RequestedPostTriggerSeconds.Value = value; } } private Property _RequestedPostTriggerSeconds = new Property( typeof(Module).Namespace + ".Test.Module.RequestedPostTriggerSeconds", 0.0, false ); /// /// Get/set the number of seconds pre-trigger for this module. /// [XmlSerializationTag( "PreTriggerSeconds" )] public double PreTriggerSeconds { get { return _PreTriggerSeconds.Value; } set { _PreTriggerSeconds.Value = value; } } private Property _PreTriggerSeconds = new Property( typeof( Module ).Namespace + ".Test.Module.PreTriggerSeconds", 0.0, false ); /// /// Get/set the number of seconds post-trigger for this module. /// [XmlSerializationTag( "PostTriggerSeconds" )] public double PostTriggerSeconds { get { return _PostTriggerSeconds.Value; } set { _PostTriggerSeconds.Value = value; } } private Property _PostTriggerSeconds = new Property( typeof( Module ).Namespace + ".Test.Module.PostTriggerSeconds", 0.0, false ); /// /// Get/set the number of samples in this test modules. /// [XmlSerializationTag( "NumberOfSamples" )] public UInt64 NumberOfSamples { get { return _NumberOfSamples.Value; } set { if ( !_UnsubsampledNumberOfSamples.IsInitialized || value > UnsubsampledNumberOfSamples ) UnsubsampledNumberOfSamples = value; _NumberOfSamples.Value = value; } } private Property _NumberOfSamples = new Property( typeof( Module ).Namespace + ".Test.Module.NumberOfSamples", 0, false ); /// /// Get/set the unsubsampled number of samples in this test modules. /// [XmlSerializationTag( "UnsubsampledNumberOfSamples" )] public UInt64 UnsubsampledNumberOfSamples { get { return _UnsubsampledNumberOfSamples.Value; } set { _UnsubsampledNumberOfSamples.Value = value; } } private Property _UnsubsampledNumberOfSamples = new Property( typeof( Module ).Namespace + ".Test.Module.UnsubsampledNumberOfSamples", 0, false ); /// /// Get/set the trigger sample numbers for this module. /// private const int DataName = 0; private const int DatumName = 1; private const int DatumValueName = 2; [XmlSerializationTag( "TriggerSampleNumbers", DataName )] [XmlSerializationTag( "TriggerSampleNumber", DatumName )] [XmlSerializationTag( "Value", DatumValueName )] public List TriggerSampleNumbers { get { return _TriggerSampleNumbers.Value; } set { _TriggerSampleNumbers.Value = value; } } private Property> _TriggerSampleNumbers = new Property>( typeof( Module ).Namespace + ".Test.Module.TriggerSampleNumbers", null, false ); /// /// Get/set the unsubsampled trigger sample numbers for this module. /// [XmlSerializationTag( "UnsubsampledTriggerSampleNumbers", DataName )] [XmlSerializationTag( "UnsubsampledTriggerSampleNumber", DatumName )] [XmlSerializationTag( "Value", DatumValueName )] public List UnsubsampledTriggerSampleNumbers { get { return _UnsubsampledTriggerSampleNumbers.Value; } set { _UnsubsampledTriggerSampleNumbers.Value = value; } } private Property> _UnsubsampledTriggerSampleNumbers = new Property>( typeof( Module ).Namespace + ".Test.Module.UnsubsampledTriggerSampleNumbers", null, false ); /// /// Get/set the start record sample number for this module. /// [XmlSerializationTag( "StartRecordSampleNumber" )] public UInt64 StartRecordSampleNumber { get { return _StartRecordSampleNumber.Value; } set { _StartRecordSampleNumber.Value = value; } } private Property _StartRecordSampleNumber = new Property( typeof( Module ).Namespace + ".Test.Module.StartRecordSampleNumber", 0, false ); /// /// Get/set the sample rate for this test module. /// [XmlSerializationTag( "SampleRateHz" )] public float SampleRateHz { get { return _SampleRateHz.Value; } set { _SampleRateHz.Value = value; } } private Property _SampleRateHz = new Property( typeof( Module ).Namespace + ".Test.Module.SampleRateHz", 0, false ); /// /// /// [XmlSerializationTag("StartRecordTimestampSec")] public double StartRecordTimestampSec { get { return _StartRecordTimestampSec.Value; } set { _StartRecordTimestampSec.Value = value; } } private Property _StartRecordTimestampSec = new Property( typeof(Module).Namespace + ".Test.Module.StartRecordTimestampSec", 0, false ); /// /// /// [XmlSerializationTag("TriggerTimestampSec")] public double TriggerTimestampSec { get { return _TriggerTimestampSec.Value; } set { _TriggerTimestampSec.Value = value; } } private Property _TriggerTimestampSec = new Property( typeof(Module).Namespace + ".Test.Module.TriggerTimestampSec", 0, false ); /// /// /// [XmlSerializationTag("StartRecordTimestampNanoSec")] public double StartRecordTimestampNanoSec { get { return _StartRecordTimestampNanoSec.Value; } set { _StartRecordTimestampNanoSec.Value = value; } } private Property _StartRecordTimestampNanoSec = new Property( typeof(Module).Namespace + ".Test.Module.StartRecordTimestampNanoSec", 0, false ); /// /// /// [XmlSerializationTag("TriggerTimestampNanoSec")] public double TriggerTimestampNanoSec { get { return _TriggerTimestampNanoSec.Value; } set { _TriggerTimestampNanoSec.Value = value; } } private Property _TriggerTimestampNanoSec = new Property( typeof(Module).Namespace + ".Test.Module.TriggerTimestampNanoSec", 0, false ); /// /// /// [XmlSerializationTag("PTPMasterSync")] public bool PTPMasterSync { get { return _PTPMasterSync.Value; } set { _PTPMasterSync.Value = value; } } private Property _PTPMasterSync = new Property( typeof(Module).Namespace + ".Test.Module.PTPMasterSync", false, false ); /// /// The value for the X axis of a Slice6 tilt sensor /// [XmlSerializationTag("TiltSensorAxisXDegreesPre")] public double TiltSensorAxisXDegreesPre { get { return _TiltSensorAxisXDegreesPre.Value; } set { _TiltSensorAxisXDegreesPre.Value = value; } } private Property _TiltSensorAxisXDegreesPre = new Property( typeof(Module).Namespace + ".Test.Module.TiltSensorAxisXDegreesPre", 0, false ); /// /// The value for the Y axis of a Slice6 tilt sensor /// [XmlSerializationTag("TiltSensorAxisYDegreesPre")] public double TiltSensorAxisYDegreesPre { get { return _TiltSensorAxisYDegreesPre.Value; } set { _TiltSensorAxisYDegreesPre.Value = value; } } private Property _TiltSensorAxisYDegreesPre = new Property( typeof(Module).Namespace + ".Test.Module.TiltSensorAxisYDegreesPre", 0, false ); /// /// The value for the Z axis of a Slice6 tilt sensor /// [XmlSerializationTag("TiltSensorAxisZDegreesPre")] public double TiltSensorAxisZDegreesPre { get { return _TiltSensorAxisZDegreesPre.Value; } set { _TiltSensorAxisZDegreesPre.Value = value; } } private Property _TiltSensorAxisZDegreesPre = new Property( typeof(Module).Namespace + ".Test.Module.TiltSensorAxisZDegreesPre", 0, false ); /// /// The value for the X axis of a Slice6 tilt sensor /// [XmlSerializationTag("TiltSensorAxisXDegreesPost")] public double TiltSensorAxisXDegreesPost { get { return _TiltSensorAxisXDegreesPost.Value; } set { _TiltSensorAxisXDegreesPost.Value = value; } } private Property _TiltSensorAxisXDegreesPost = new Property( typeof(Module).Namespace + ".Test.Module.TiltSensorAxisXDegreesPost", 0, false ); /// /// The value for the Y axis of a Slice6 tilt sensor /// [XmlSerializationTag("TiltSensorAxisYDegreesPost")] public double TiltSensorAxisYDegreesPost { get { return _TiltSensorAxisYDegreesPost.Value; } set { _TiltSensorAxisYDegreesPost.Value = value; } } private Property _TiltSensorAxisYDegreesPost = new Property( typeof(Module).Namespace + ".Test.Module.TiltSensorAxisYDegreesPost", 0, false ); /// /// The value for the Z axis of a Slice6 tilt sensor /// [XmlSerializationTag("TiltSensorAxisZDegreesPost")] public double TiltSensorAxisZDegreesPost { get { return _TiltSensorAxisZDegreesPost.Value; } set { _TiltSensorAxisZDegreesPost.Value = value; } } private Property _TiltSensorAxisZDegreesPost = new Property( typeof(Module).Namespace + ".Test.Module.TiltSensorAxisZDegreesPost", 0, false ); /// /// The value for the 1st location of a Slice6 temperature sensor /// [XmlSerializationTag("TemperatureLocation1Pre")] public float TemperatureLocation1Pre { get { return _TemperatureLocation1Pre.Value; } set { _TemperatureLocation1Pre.Value = value; } } private Property _TemperatureLocation1Pre = new Property( typeof(Module).Namespace + ".Test.Module.TemperatureLocation1Pre", 0, false ); /// /// The value for the 2nd location of a Slice6 temperature sensor /// [XmlSerializationTag("TemperatureLocation2Pre")] public float TemperatureLocation2Pre { get { return _TemperatureLocation2Pre.Value; } set { _TemperatureLocation2Pre.Value = value; } } private Property _TemperatureLocation2Pre = new Property( typeof(Module).Namespace + ".Test.Module.TemperatureLocation2Pre", 0, false ); /// /// The value for the 3rd location of a Slice6 temperature sensor /// [XmlSerializationTag("TemperatureLocation3Pre")] public float TemperatureLocation3Pre { get { return _TemperatureLocation3Pre.Value; } set { _TemperatureLocation3Pre.Value = value; } } private Property _TemperatureLocation3Pre = new Property( typeof(Module).Namespace + ".Test.Module.TemperatureLocation3Pre", 0, false ); /// /// The value for the 4th location of a Slice6 temperature sensor /// [XmlSerializationTag("TemperatureLocation4Pre")] public float TemperatureLocation4Pre { get { return _TemperatureLocation4Pre.Value; } set { _TemperatureLocation4Pre.Value = value; } } private Property _TemperatureLocation4Pre = new Property( typeof(Module).Namespace + ".Test.Module.TemperatureLocation4Pre", 0, false ); /// /// The value for the 1st location of a Slice6 temperature sensor post-trigger /// [XmlSerializationTag("TemperatureLocation1Post")] public float TemperatureLocation1Post { get { return _TemperatureLocation1Post.Value; } set { _TemperatureLocation1Post.Value = value; } } private Property _TemperatureLocation1Post = new Property( typeof(Module).Namespace + ".Test.Module.TemperatureLocation1Post", 0, false ); /// /// The value for the 2nd location of a Slice6 temperature sensor post-trigger /// [XmlSerializationTag("TemperatureLocation2Post")] public float TemperatureLocation2Post { get { return _TemperatureLocation2Post.Value; } set { _TemperatureLocation2Post.Value = value; } } private Property _TemperatureLocation2Post = new Property( typeof(Module).Namespace + ".Test.Module.TemperatureLocation2Post", 0, false ); /// /// The value for the 3rd location of a Slice6 temperature sensor post-trigger /// [XmlSerializationTag("TemperatureLocation3Post")] public float TemperatureLocation3Post { get { return _TemperatureLocation3Post.Value; } set { _TemperatureLocation3Post.Value = value; } } private Property _TemperatureLocation3Post = new Property( typeof(Module).Namespace + ".Test.Module.TemperatureLocation3Post", 0, false ); /// /// The value for the 4th location of a Slice6 temperature sensor post-trigger /// [XmlSerializationTag("TemperatureLocation4Post")] public float TemperatureLocation4Post { get { return _TemperatureLocation4Post.Value; } set { _TemperatureLocation4Post.Value = value; } } private Property _TemperatureLocation4Post = new Property( typeof(Module).Namespace + ".Test.Module.TemperatureLocation4Post", 0, false ); /// /// Get/set the AA filter rate for this test module. /// [XmlSerializationTag( "AaFilterRateHz" )] public float AaFilterRateHz { get { return _AaFilterRateHz.Value; } set { _AaFilterRateHz.Value = value; } } private Property _AaFilterRateHz = new Property( typeof( Module ).Namespace + ".Test.Module.AaFilterRateHz", 0, false ); /// /// Get/set the recording mode of this module. /// [XmlSerializationTag( "RecordingMode" )] public DAS.Concepts.Test.Module.RecordingMode RecordingMode { get { return _RecordingMode.Value; } set { _RecordingMode.Value = value; } } private Property _RecordingMode = new Property( typeof( Module ).Namespace + ".Test.Module.RecordingMode", DAS.Concepts.Test.Module.RecordingMode.CircularBuffer, false ); /// /// Get the number of channels in the channel list. (Intended for de/serialization only!) /// [XmlSerializationTag( "NumberOfChannels" )] public int NumberOfChannels { get { return this.Channels.Count; } } /// /// Get/set inline serialized data switch. /// [XmlSerializationTag( "InlineSerializedData" )] public bool InlineSerializedData { get { return _InlineSerializedData.Value; } set { try { _InlineSerializedData.Value = value; foreach ( Test.Module.Channel channel in Channels ) channel.ExpressDataInlineOnXmlSerialization = value; } catch ( System.Exception ex ) { throw new Exception( "encountered problem setting module InlineSerializedData state", ex ); } } } private Property _InlineSerializedData = new Property( "InlineSerializedData", false, true ); /// /// Write XML serialization for this object to the specified writer. /// /// /// /// The to which this object's XML serialization /// will be written. /// /// public void WriteXml( XmlWriter writer ) { try { var cult = new System.Globalization.CultureInfo(""); AttributeExtractor attributeExtractor = new AttributeExtractor( ); // // Write simple module properties. // // NOTE: The way this really should be done is to examine this object using reflection and just automatically // assemble the list of properties that have been tagged with the serialization attribute. That way, when I // add in a property after the fact, I don't have to worry about any of this crap below. It would just automatically // get de/serialized. The equality check should also pick it's comparison properties that way. I'd do the conversion // now, but we're under pressure for a release so it'll have to wait. // writer.WriteStartElement ( attributeExtractor.ExtractAttachedAttributeFromObject ( this ).Value ); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "AaFilterRateHz").Value, this.AaFilterRateHz.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "Number").Value, this.Number.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "SerialNumber").Value, (null != this.SerialNumber ? this.SerialNumber : "").ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "NumberOfSamples").Value, this.NumberOfSamples.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "UnsubsampledNumberOfSamples").Value, this.UnsubsampledNumberOfSamples.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "RequestedPostTriggerSeconds").Value, this.RequestedPostTriggerSeconds.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "RequestedPreTriggerSeconds").Value, this.RequestedPreTriggerSeconds.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "PostTriggerSeconds").Value, this.PostTriggerSeconds.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "PreTriggerSeconds").Value, this.PreTriggerSeconds.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "RecordingMode").Value, this.RecordingMode.ToString()); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "SampleRateHz").Value, this.SampleRateHz.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "StartRecordSampleNumber").Value, this.StartRecordSampleNumber.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "NumberOfChannels").Value, this.NumberOfChannels.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "InlineSerializedData").Value, this.InlineSerializedData.ToString(cult)); try { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "BaseSerialNumber").Value, this.BaseSerialNumber.ToString(cult)); } catch (System.Exception) { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "BaseSerialNumber").Value, "NA"); } writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "StartRecordTimestampSec").Value, this.StartRecordTimestampSec.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "StartRecordTimestampNanoSec").Value, this.StartRecordTimestampNanoSec.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TriggerTimestampSec").Value, this.TriggerTimestampSec.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TriggerTimestampNanoSec").Value, this.TriggerTimestampNanoSec.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "PTPMasterSync").Value, this.PTPMasterSync.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisXDegreesPre").Value, this.TiltSensorAxisXDegreesPre.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisYDegreesPre").Value, this.TiltSensorAxisYDegreesPre.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisZDegreesPre").Value, this.TiltSensorAxisZDegreesPre.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisXDegreesPost").Value, this.TiltSensorAxisXDegreesPost.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisYDegreesPost").Value, this.TiltSensorAxisYDegreesPost.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisZDegreesPost").Value, this.TiltSensorAxisZDegreesPost.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation1Pre").Value, this.TemperatureLocation1Pre.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation2Pre").Value, this.TemperatureLocation2Pre.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation3Pre").Value, this.TemperatureLocation3Pre.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation4Pre").Value, this.TemperatureLocation4Pre.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation1Post").Value, this.TemperatureLocation1Post.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation2Post").Value, this.TemperatureLocation2Post.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation3Post").Value, this.TemperatureLocation3Post.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation4Post").Value, this.TemperatureLocation4Post.ToString(cult)); //// //// Write out trigger sample numbers list. //// //List triggerSampleNumberAttributes = attributeExtractor.ExtractAttachedAttributesFromProperty( this, "TriggerSampleNumbers" ); //triggerSampleNumberAttributes.Sort( ); //writer.WriteStartElement( triggerSampleNumberAttributes[ DataName ].Value ); //for ( int i=0; i < TriggerSampleNumbers.Count; i++ ) //{ // writer.WriteStartElement( triggerSampleNumberAttributes[ DatumName ].Value ); // writer.WriteAttributeString( triggerSampleNumberAttributes[ DatumValueName ].Value, this.TriggerSampleNumbers[ i ].ToString( ) ); // writer.WriteEndElement( ); //} //writer.WriteEndElement( ); // // Write out unsubsampled trigger sample numbers list. // List unsubsampledTriggerSampleNumberAttributes = attributeExtractor.ExtractAttachedAttributesFromProperty( this, "TriggerSampleNumbers" ); unsubsampledTriggerSampleNumberAttributes.Sort( ); writer.WriteStartElement( unsubsampledTriggerSampleNumberAttributes[ DataName ].Value ); for ( int i=0; i < UnsubsampledTriggerSampleNumbers.Count; i++ ) { writer.WriteStartElement( unsubsampledTriggerSampleNumberAttributes[ DatumName ].Value ); writer.WriteAttributeString(unsubsampledTriggerSampleNumberAttributes[DatumValueName].Value, this.UnsubsampledTriggerSampleNumbers[i].ToString(cult)); writer.WriteEndElement( ); } writer.WriteEndElement( ); // // Write out channel list, if it's not empty. // writer.WriteStartElement ( attributeExtractor.ExtractAttachedAttributeFromProperty( this, "Channels").Value ); foreach (var c in Channels) { c.WriteXml(writer); } writer.WriteEndElement(); writer.WriteStartElement(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "CalculatedChannels").Value); foreach (var c in CalculatedChannels) { c.WriteXml(writer); } writer.WriteEndElement(); writer.WriteEndElement(); } catch ( System.Exception ex ) { throw new Exception( "encountered problem converting DTS.Serialization.Test.Module object to XML", ex ); } } /// /// Read XML serialization for this object from the specified reader. /// /// /// /// The from which this object's XML serialization /// will be read. /// /// public void ReadXml(XmlReader reader) { try { var cult = new System.Globalization.CultureInfo(""); AttributeExtractor attributeExtractor = new AttributeExtractor(); reader.MoveToContent(); // // Read simple attributes. // float aafilterRateHz; if ( float.TryParse( reader.GetAttribute( attributeExtractor.ExtractAttachedAttributeFromProperty(this, "AaFilterRateHz").Value), NumberStyles.Any, cult, out aafilterRateHz)) { AaFilterRateHz = aafilterRateHz; } else { throw new Exception("error reading AaFilterRateHz"); } int number; if ( int.TryParse( reader.GetAttribute( attributeExtractor.ExtractAttachedAttributeFromProperty(this, "Number").Value), NumberStyles.Any, cult, out number)) { Number = number; } else { throw new Exception("error reading Number"); } try { SerialNumber = reader.GetAttribute( attributeExtractor.ExtractAttachedAttributeFromProperty(this, "SerialNumber").Value); } catch { throw new Exception("error reading SerialNumber"); } ulong numberOfSamples; if ( ulong.TryParse( reader.GetAttribute( attributeExtractor.ExtractAttachedAttributeFromProperty(this, "NumberOfSamples").Value), NumberStyles.Any, cult, out numberOfSamples)) { NumberOfSamples = numberOfSamples; } else { throw new Exception("error reading NumberOfSamples"); } double postTriggerSeconds; if ( double.TryParse( reader.GetAttribute( attributeExtractor.ExtractAttachedAttributeFromProperty(this, "PostTriggerSeconds").Value), NumberStyles.Any, cult, out postTriggerSeconds)) { PostTriggerSeconds = postTriggerSeconds; } else { throw new Exception("error reading PostTriggerSeconds"); } double preTriggerSeconds; if ( double.TryParse( reader.GetAttribute( attributeExtractor.ExtractAttachedAttributeFromProperty(this, "PreTriggerSeconds").Value), NumberStyles.Any, cult, out preTriggerSeconds)) { PreTriggerSeconds = preTriggerSeconds; } else { throw new Exception("error reading PreTriggerSeconds"); } double requestedPostTriggerSeconds; RequestedPostTriggerSeconds = double.TryParse( reader.GetAttribute( attributeExtractor.ExtractAttachedAttributeFromProperty(this, "RequestedPostTriggerSeconds").Value), NumberStyles.Any, cult, out requestedPostTriggerSeconds) ? requestedPostTriggerSeconds : PostTriggerSeconds; double requestedPreTriggerSeconds; RequestedPreTriggerSeconds = double.TryParse( reader.GetAttribute( attributeExtractor.ExtractAttachedAttributeFromProperty(this, "RequestedPreTriggerSeconds").Value), NumberStyles.Any, cult, out requestedPreTriggerSeconds) ? requestedPreTriggerSeconds : PreTriggerSeconds; float sampleRateHz; if (float.TryParse( reader.GetAttribute( attributeExtractor.ExtractAttachedAttributeFromProperty(this, "SampleRateHz").Value), NumberStyles.Any, cult, out sampleRateHz)) { SampleRateHz = sampleRateHz; } else { throw new Exception("error reading SampleRateHz"); } var startRecordTimestampSec = 0.0D; double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "StartRecordTimestampSec").Value), NumberStyles.Any, cult, out startRecordTimestampSec); StartRecordTimestampSec = startRecordTimestampSec; var triggerTimestampSec = 0.0D; double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TriggerTimestampSec").Value), NumberStyles.Any, cult, out triggerTimestampSec); TriggerTimestampSec = triggerTimestampSec; var startRecordTimestampNanoSec = 0.0D; double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "StartRecordTimestampNanoSec").Value), NumberStyles.Any, cult, out startRecordTimestampNanoSec); StartRecordTimestampNanoSec = startRecordTimestampNanoSec; var triggerTimestampNanoSec = 0.0D; double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TriggerTimestampNanoSec").Value), NumberStyles.Any, cult, out triggerTimestampNanoSec); TriggerTimestampNanoSec = triggerTimestampNanoSec; var pTpMasterSync = false; bool.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "PTPMasterSync").Value), out pTpMasterSync); PTPMasterSync = pTpMasterSync; var tiltSensorAxisXDegreesPre = 0.0D; double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisXDegreesPre").Value), NumberStyles.Any, cult, out tiltSensorAxisXDegreesPre); TiltSensorAxisXDegreesPre = tiltSensorAxisXDegreesPre; var tiltSensorAxisYDegreesPre = 0.0D; double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisYDegreesPre").Value), NumberStyles.Any, cult, out tiltSensorAxisYDegreesPre); TiltSensorAxisYDegreesPre = tiltSensorAxisYDegreesPre; var tiltSensorAxisZDegreesPre = 0.0D; double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisZDegreesPre").Value), NumberStyles.Any, cult, out tiltSensorAxisZDegreesPre); TiltSensorAxisZDegreesPre = tiltSensorAxisZDegreesPre; var tiltSensorAxisXDegreesPost = 0.0D; double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisXDegreesPost").Value), NumberStyles.Any, cult, out tiltSensorAxisXDegreesPost); TiltSensorAxisXDegreesPost = tiltSensorAxisXDegreesPost; var tiltSensorAxisYDegreesPost = 0.0D; double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisYDegreesPost").Value), NumberStyles.Any, cult, out tiltSensorAxisYDegreesPost); TiltSensorAxisYDegreesPost = tiltSensorAxisYDegreesPost; var tiltSensorAxisZDegreesPost = 0.0D; double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisZDegreesPost").Value), NumberStyles.Any, cult, out tiltSensorAxisZDegreesPost); TiltSensorAxisZDegreesPost = tiltSensorAxisZDegreesPost; var temperatureLocation1Pre = 0.0F; float.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation1Pre").Value), NumberStyles.Any, cult, out temperatureLocation1Pre); TemperatureLocation1Pre = temperatureLocation1Pre; var temperatureLocation2Pre = 0.0F; float.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation2Pre").Value), NumberStyles.Any, cult, out temperatureLocation2Pre); TemperatureLocation2Pre = temperatureLocation2Pre; var temperatureLocation3Pre = 0.0F; float.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation3Pre").Value), NumberStyles.Any, cult, out temperatureLocation3Pre); TemperatureLocation3Pre = temperatureLocation3Pre; var temperatureLocation4Pre = 0.0F; float.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation4Pre").Value), NumberStyles.Any, cult, out temperatureLocation4Pre); TemperatureLocation4Pre = temperatureLocation4Pre; var temperatureLocation1Post = 0.0F; float.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation1Post").Value), NumberStyles.Any, cult, out temperatureLocation1Post); TemperatureLocation1Post = temperatureLocation1Post; var temperatureLocation2Post = 0.0F; float.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation2Post").Value), NumberStyles.Any, cult, out temperatureLocation2Post); TemperatureLocation2Post = temperatureLocation2Post; var temperatureLocation3Post = 0.0F; float.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation3Post").Value), NumberStyles.Any, cult, out temperatureLocation3Post); TemperatureLocation3Post = temperatureLocation3Post; var temperatureLocation4Post = 0.0F; float.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation4Post").Value), NumberStyles.Any, cult, out temperatureLocation4Post); TemperatureLocation4Post = temperatureLocation4Post; ulong startRecordSampleNumber; if ( ulong.TryParse( reader.GetAttribute( attributeExtractor.ExtractAttachedAttributeFromProperty(this, "StartRecordSampleNumber") .Value), NumberStyles.Any, cult, out startRecordSampleNumber)) { StartRecordSampleNumber = startRecordSampleNumber; } else { throw new Exception("error reading StartRecordSampleNumber"); } bool inlineSerializedData; if (bool.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "InlineSerializedData").Value), out inlineSerializedData)) { InlineSerializedData = inlineSerializedData; } else { throw new Exception("error reading InlineSerializedData"); } try { RecordingMode = DAS.Concepts.Test.Module.GetRecordingModeFromString( reader.GetAttribute( attributeExtractor.ExtractAttachedAttributeFromProperty(this, "RecordingMode").Value)); } catch { throw new Exception("error reading RecordingMode"); } try { BaseSerialNumber = reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "BaseSerialNumber").Value); } catch (Exception e) { throw new Exception("error reading BaseSerialNumber"); } ulong unsubsampledNumberOfSamples; UnsubsampledNumberOfSamples = ulong.TryParse( reader.GetAttribute( attributeExtractor.ExtractAttachedAttributeFromProperty(this, "UnsubsampledNumberOfSamples").Value), NumberStyles.Any, cult, out unsubsampledNumberOfSamples) ? unsubsampledNumberOfSamples : NumberOfSamples; // Can't set the property from whence this came; but we should use it to initialize the channel list with // the proper number of entries so subsequent logic will know how many sequential channel files to gobble // up for this module. int numberOfChannelsToRead; if (int.TryParse( reader.GetAttribute( attributeExtractor.ExtractAttachedAttributeFromProperty(this, "NumberOfChannels").Value), NumberStyles.Any, cult, out numberOfChannelsToRead)) { // // Read unsubsampled trigger sample numbers list. // reader.Read(); reader.MoveToContent(); List unsubsampledTriggerSampleNumberAttributes = attributeExtractor.ExtractAttachedAttributesFromProperty(this, "TriggerSampleNumbers"); unsubsampledTriggerSampleNumberAttributes.Sort(); UnsubsampledTriggerSampleNumbers = new List(); if ( reader.Name.Equals(unsubsampledTriggerSampleNumberAttributes[DataName].Value, StringComparison.OrdinalIgnoreCase) && !reader.IsEmptyElement) { // // UnsubsampledTriggerSampleNumbers is populated, so spin through it. // for (reader.Read(), reader.MoveToContent(); reader.Name.Equals(unsubsampledTriggerSampleNumberAttributes[DatumName].Value, StringComparison.OrdinalIgnoreCase); reader.Read(), reader.MoveToContent()) UnsubsampledTriggerSampleNumbers.Add( UInt64.Parse( reader.GetAttribute( unsubsampledTriggerSampleNumberAttributes[DatumValueName].Value), cult)); reader.ReadEndElement(); reader.MoveToContent(); } else { // // UnsubsampledTriggerSampleNumbers is an empty tag, so consume it and move on. reader.Read(); reader.MoveToContent(); } try { // // Read channel list, if it exists. // this.Channels = new List(); if (!reader.IsEmptyElement && string.Equals( attributeExtractor.ExtractAttachedAttributeFromProperty(this, "Channels").Value, reader.Name, StringComparison.OrdinalIgnoreCase)) { while (reader.Read() && (XmlNodeType.Element == reader.MoveToContent())) { string channelType = new DTS.Utilities.Xml.PropertyAttributeDecoder( new Test.Module.AnalogInputChannel(this)) .ExtractStringProperty("ChannelType", reader); if (null == channelType) throw new Exception("expected channel type string but got " + (null != channelType ? ("\"" + channelType + "\"") : "<>")); else { Type channelClassType = Type.GetType(channelType); Test.Module.Channel deserializedChannel = Activator.CreateInstance(channelClassType, new object[] {this}) as Test.Module.Channel; // ( channelClassType, true ) as Test.Module.Channel; if ( !(deserializedChannel.ExpressDataInlineOnXmlSerialization = InlineSerializedData)) deserializedChannel.Data = new Channel.DataArray(); deserializedChannel.ReadXml(reader); this.Channels.Add(deserializedChannel); } } reader.ReadEndElement(); } } catch (System.Exception ex) { throw new Exception("encountered problem parsing channel list", ex); } try { // // Read calculated channel list, if it exists. // this.CalculatedChannels.Clear(); if (!reader.IsEmptyElement && string.Equals( attributeExtractor.ExtractAttachedAttributeFromProperty(this, "CalculatedChannels") .Value, reader.Name, StringComparison.OrdinalIgnoreCase)) { while (reader.Read() && (XmlNodeType.Element == reader.MoveToContent())) { string channelType = new DTS.Utilities.Xml.PropertyAttributeDecoder( new Test.Module.AnalogInputChannel(this)) .ExtractStringProperty("ChannelType", reader); if (null == channelType) throw new Exception("expected channel type string but got " + (null != channelType ? ("\"" + channelType + "\"") : "<>")); else { Type channelClassType = Type.GetType(channelType); Test.Module.Channel deserializedChannel = Activator.CreateInstance(channelClassType, new object[] {this}) as Test.Module.Channel; // ( channelClassType, true ) as Test.Module.Channel; if ( !(deserializedChannel.ExpressDataInlineOnXmlSerialization = InlineSerializedData)) deserializedChannel.Data = new Channel.DataArray(); deserializedChannel.ReadXml(reader); this.CalculatedChannels.Add(deserializedChannel); } } reader.ReadEndElement(); } } catch (System.Exception ex) { throw new Exception("encountered problem parsing channel list", ex); } reader.Read(); // consume attribute end tag. } else { throw new Exception("error reading NumberOfChannels"); } } catch (System.Exception ex) { throw new Exception("encountered problem converting XML to DTS.Serialization.Test.Module object", ex); } } /// /// Should normally return a schema representing the form of the XML /// generated/consumed by WriteXml/ReadXml, but it never called during /// the serialization process so ours just returns null. /// /// /// /// Null reference, always. /// /// public XmlSchema GetSchema( ) { // This method is never invoked during XML object serialization. return null; } /// /// Test the specified object for equality with this object. /// /// /// /// The to be tested for equality. /// /// /// /// true if the specified object has memeberwise equality with /// this object; false otherwise. /// /// public override bool Equals( object obj ) { try { Test.Module that = obj as Test.Module; return null != that && this.AaFilterRateHz.Equals( that.AaFilterRateHz ) && this.Number.Equals( that.Number ) && this.SerialNumber.Equals( that.SerialNumber ) && this.NumberOfSamples.Equals( that.NumberOfSamples ) && this.UnsubsampledNumberOfSamples.Equals( that.UnsubsampledNumberOfSamples ) && this.RequestedPostTriggerSeconds.Equals(that.RequestedPostTriggerSeconds) && this.RequestedPreTriggerSeconds.Equals(that.RequestedPreTriggerSeconds) && this.PostTriggerSeconds.Equals(that.PostTriggerSeconds) && this.PreTriggerSeconds.Equals(that.PreTriggerSeconds) && this.RecordingMode.Equals(that.RecordingMode) && this.SampleRateHz.Equals( that.SampleRateHz ) && this.StartRecordTimestampSec.Equals(that.StartRecordTimestampSec) && this.TriggerTimestampSec.Equals(that.TriggerTimestampSec) && this.StartRecordTimestampSec.Equals(that.StartRecordTimestampNanoSec) && this.TriggerTimestampSec.Equals(that.TriggerTimestampNanoSec) && this.PTPMasterSync.Equals(that.PTPMasterSync) && this.TiltSensorAxisXDegreesPre.Equals(that.TiltSensorAxisXDegreesPre) && this.TiltSensorAxisYDegreesPre.Equals(that.TiltSensorAxisYDegreesPre) && this.TiltSensorAxisZDegreesPre.Equals(that.TiltSensorAxisZDegreesPre) && this.TiltSensorAxisXDegreesPost.Equals(that.TiltSensorAxisXDegreesPost) && this.TiltSensorAxisYDegreesPost.Equals(that.TiltSensorAxisYDegreesPost) && this.TiltSensorAxisZDegreesPost.Equals(that.TiltSensorAxisZDegreesPost) && this.TemperatureLocation1Pre.Equals(that.TemperatureLocation1Pre) && this.TemperatureLocation2Pre.Equals(that.TemperatureLocation2Pre) && this.TemperatureLocation3Pre.Equals(that.TemperatureLocation3Pre) && this.TemperatureLocation4Pre.Equals(that.TemperatureLocation4Pre) && this.TemperatureLocation1Post.Equals(that.TemperatureLocation1Post) && this.TemperatureLocation2Post.Equals(that.TemperatureLocation2Post) && this.TemperatureLocation3Post.Equals(that.TemperatureLocation3Post) && this.TemperatureLocation4Post.Equals(that.TemperatureLocation4Post) && this.StartRecordSampleNumber.Equals(that.StartRecordSampleNumber) && this.TriggerSampleNumbersEquals( that.TriggerSampleNumbers ) && this.UnsubsampledTriggerSampleNumbersEquals( that.UnsubsampledTriggerSampleNumbers ) && this.ChannelsEquals( that.Channels ) && this.BaseSerialNumber.Equals( that.BaseSerialNumber ); } catch ( System.Exception ex ) { throw new Exception( "encountered problem equality-testing object " + ( null != obj ? "\"" + obj.ToString( ) + "\"" : "<>" ), ex ); } } /// /// Test the specified object's trigger sample number list for equality with this /// object's module list. /// /// /// /// The of object to be /// compared for equality with this test's equivalent. /// /// /// /// true if the two lists contain equivalent-valued members; /// false otherwise. /// /// private bool TriggerSampleNumbersEquals( List thoseTriggerSampleNumbers ) { try { if ( null == thoseTriggerSampleNumbers || this.TriggerSampleNumbers.Count != thoseTriggerSampleNumbers.Count ) return false; else for ( int i=0; i < thoseTriggerSampleNumbers.Count; i++ ) if ( !this.TriggerSampleNumbers[ i ].Equals( thoseTriggerSampleNumbers[ i ] ) ) return false; return true; } catch ( System.Exception ex ) { throw new Exception( "encountered problem equality-testing trigger sample numbers list ", ex ); } } /// /// Test the specified object's unsubsampled trigger sample number list for equality with this /// object's module list. /// /// /// /// The of object to be /// compared for equality with this test's equivalent. /// /// /// /// true if the two lists contain equivalent-valued members; /// false otherwise. /// /// private bool UnsubsampledTriggerSampleNumbersEquals( List thoseUnsubsampledTriggerSampleNumbers ) { try { if ( null == thoseUnsubsampledTriggerSampleNumbers || this.UnsubsampledTriggerSampleNumbers.Count != thoseUnsubsampledTriggerSampleNumbers.Count ) return false; else for ( int i=0; i < thoseUnsubsampledTriggerSampleNumbers.Count; i++ ) if ( !this.TriggerSampleNumbers[ i ].Equals( thoseUnsubsampledTriggerSampleNumbers[ i ] ) ) return false; return true; } catch ( System.Exception ex ) { throw new Exception( "encountered problem equality-testing unsubsampled trigger sample numbers list ", ex ); } } /// /// Test the specified object's module list for equality with this object's /// module list. /// /// /// /// The of object to be /// compared for equality with this test's equivalent. /// /// /// /// true if the two lists contain equivalent-valued members; /// false otherwise. /// /// private bool ChannelsEquals( List thoseChannels ) { try { if ( null == thoseChannels || this.Channels.Count != thoseChannels.Count ) return false; else for ( int i=0; i < thoseChannels.Count; i++ ) if ( !this.Channels[ i ].Equals( thoseChannels[ i ] ) ) { bool test = this.Channels[ i ].Equals( thoseChannels[ i ] ); Debug.Assert( test ); return false; } //return false; return true; } catch ( System.Exception ex ) { throw new Exception( "encountered problem equality-testing channel list", ex ); } } /// /// Return the hash code for this object. /// /// /// /// The hash code for this object. /// /// public override int GetHashCode( ) { return base.GetHashCode( ); } } } }