Files

1630 lines
79 KiB
C#
Raw Permalink Normal View History

2026-04-17 14:55:32 -04:00
/*
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.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using DTS.Common.Enums.DASFactory;
using DTS.Common.Utilities;
using DTS.Common.Utilities.DotNetProgrammingConstructs;
using DTS.Common.Utilities.Xml;
using DTS.Common.Utils;
namespace DTS.Serialization
{
// *** See Test.cs ***
public partial class Test : Exceptional, IXmlSerializable
{
/// <summary>
/// Representation of serializable module information.
/// </summary>
[XmlSerializationTag("Module")]
public partial class Module : Exceptional
{
/// <summary>
/// finds any trigger or start record timestamps to return
/// </summary>
public static IEnumerable<TestModuleTimeStamp> GetModuleTimeStamps(IEnumerable<Module> basemodules, out IEnumerable<TestModuleTimeStamp> starts)
{
var testModuleTimeStamps = new List<TestModuleTimeStamp>();
var startList = new List<TestModuleTimeStamp>();
var noMasterSync = !basemodules.Any(module => module.PTPMasterSync);
foreach (var module in basemodules)
{
//if there's no master sync, but we have RTC time stamps, use those
if (module.PTPMasterSync || noMasterSync)
{
//if there's a trigger timestamp, use that, otherwise use the start
if (module.TriggerTimestampNanoSec > 0 || module.TriggerTimestampSec > 0)
{
var testModuleTimeStamp = new TestModuleTimeStamp
{
TriggerTimestampSec = (int)module.TriggerTimestampSec,
TriggerTimestampNanoSec = (int)module.TriggerTimestampNanoSec
};
testModuleTimeStamps.Add(testModuleTimeStamp);
}
else if ((module.StartRecordTimestampNanoSec > 0 || module.StartRecordTimestampSec > 0))
{
var testModuleTimeStamp = new TestModuleTimeStamp
{
TriggerTimestampSec = (int)module.StartRecordTimestampSec,
TriggerTimestampNanoSec = (int)module.StartRecordTimestampNanoSec
};
startList.Add(testModuleTimeStamp);
}
}
}
starts = startList;
return testModuleTimeStamps;
}
/// <summary>
/// The <see cref="DTS.Serialization.Test"/> that contains this module.
/// </summary>
public Test ParentTest
{
get => _ParentTest.Value;
private set => _ParentTest.Value = value;
}
private readonly Property<Test> _ParentTest
= new Property<Test>(
typeof(Module).Namespace + ".Test.Module.ParentTest",
null,
false
);
/// <summary>
/// Initialize an instance of the DTS.Serialization.Test.Module class.
/// </summary>
///
/// <param name="parentTest">
/// The <see cref="DTS.Serialization.Test"/> containing this object.
/// </param>
///
public Module(Test parentTest)
{
try
{
ParentTest = parentTest;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem constructing " + GetType().Name, ex);
}
}
/// <summary>
/// Get/set the list of channels on this module.
/// </summary>
[XmlSerializationTag("Channels")]
public List<Channel> Channels
{
get => _Channels.Value;
set => _Channels.Value = value;
}
private readonly Property<List<Channel>> _Channels
= new Property<List<Channel>>(
typeof(Module).Namespace + ".Test.Module.Channels",
new List<Channel>(),
true
);
/// <summary>
/// The list of modules in this test.
/// </summary>
[XmlSerializationTag("CalculatedChannels")]
public List<Channel> CalculatedChannels
{
get => _CalculatedChannels.Value;
set => _CalculatedChannels.Value = value;
}
private readonly Property<List<Channel>> _CalculatedChannels
= new Property<List<Channel>>(
typeof(Module).Namespace + ".Test.Module.CalculatedChannels",
new List<Channel>(),
true
);
/// <summary>
/// Get/set the module number of this module.
/// </summary>
[XmlSerializationTag("Number")]
public int Number
{
get => _Number.Value;
set => _Number.Value = value;
}
private readonly Property<int> _Number
= new Property<int>(
typeof(Module).Namespace + ".Test.Module.Number",
0,
false
);
/// <summary>
/// Get/set the serial number <see cref="string"/> for this DAS.
/// </summary>
[XmlSerializationTag("SerialNumber")]
public string SerialNumber
{
get => _SerialNumber.Value;
set => _SerialNumber.Value = value;
}
private readonly Property<string> _SerialNumber
= new Property<string>(
typeof(Module).Namespace + ".Test.Module.SerialNumber",
"",
true
);
/// <summary>
/// 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.
/// </summary>
[XmlSerializationTag("Description")]
public string Description
{
get => _Description.Value;
set => _Description.Value = value;
}
private readonly Property<string> _Description
= new Property<string>(
typeof(Module).Namespace + ".Test.Module.Description",
"",
true
);
/// <summary>
/// Get/set the base serial number <see cref="string"/> for this DAS.
/// </summary>
[XmlSerializationTag("BaseSerialNumber")]
public string BaseSerialNumber
{
get => _BaseSerialNumber.Value;
set => _BaseSerialNumber.Value = value;
}
private readonly Property<string> _BaseSerialNumber
= new Property<string>(
typeof(Module).Namespace + ".Test.Module.BaseSerialNumber",
"",
true
);
/// <summary>
/// Get/set the number of requested seconds pre-trigger for this module.
/// </summary>
[XmlSerializationTag("RequestedPreTriggerSeconds")]
public double RequestedPreTriggerSeconds
{
get => _RequestedPreTriggerSeconds.Value;
set => _RequestedPreTriggerSeconds.Value = value;
}
private readonly Property<double> _RequestedPreTriggerSeconds
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.RequestedPreTriggerSeconds",
0.0,
false
);
/// <summary>
/// Get/set the number of requested seconds post-trigger for this module.
/// </summary>
[XmlSerializationTag("RequestedPostTriggerSeconds")]
public double RequestedPostTriggerSeconds
{
get => _RequestedPostTriggerSeconds.Value;
set => _RequestedPostTriggerSeconds.Value = value;
}
private readonly Property<double> _RequestedPostTriggerSeconds
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.RequestedPostTriggerSeconds",
0.0,
false
);
/// <summary>
/// Get/set the number of seconds pre-trigger for this module.
/// </summary>
[XmlSerializationTag("PreTriggerSeconds")]
public double PreTriggerSeconds
{
get => _PreTriggerSeconds.Value;
set => _PreTriggerSeconds.Value = value;
}
private readonly Property<double> _PreTriggerSeconds
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.PreTriggerSeconds",
0.0,
false
);
/// <summary>
/// Get/set the number of seconds post-trigger for this module.
/// </summary>
[XmlSerializationTag("PostTriggerSeconds")]
public double PostTriggerSeconds
{
get => _PostTriggerSeconds.Value;
set => _PostTriggerSeconds.Value = value;
}
private readonly Property<double> _PostTriggerSeconds
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.PostTriggerSeconds",
0.0,
false
);
/// <summary>
/// Get/set the number of samples in this test modules.
/// </summary>
[XmlSerializationTag("NumberOfSamples")]
public UInt64 NumberOfSamples
{
get => _NumberOfSamples.Value;
set
{
if (!_UnsubsampledNumberOfSamples.IsInitialized || value > UnsubsampledNumberOfSamples)
UnsubsampledNumberOfSamples = value;
_NumberOfSamples.Value = value;
}
}
private readonly Property<UInt64> _NumberOfSamples
= new Property<UInt64>(
typeof(Module).Namespace + ".Test.Module.NumberOfSamples",
0,
false
);
/// <summary>
/// Get/set the unsubsampled number of samples in this test modules.
/// </summary>
[XmlSerializationTag("UnsubsampledNumberOfSamples")]
public UInt64 UnsubsampledNumberOfSamples
{
get => _UnsubsampledNumberOfSamples.Value;
set => _UnsubsampledNumberOfSamples.Value = value;
}
private readonly Property<UInt64> _UnsubsampledNumberOfSamples
= new Property<UInt64>(
typeof(Module).Namespace + ".Test.Module.UnsubsampledNumberOfSamples",
0,
false
);
/// <summary>
/// Get/set the trigger sample numbers for this module.
/// </summary>
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<UInt64> TriggerSampleNumbers
{
get => _TriggerSampleNumbers.Value;
set => _TriggerSampleNumbers.Value = value;
}
private readonly Property<List<UInt64>> _TriggerSampleNumbers
= new Property<List<UInt64>>(
typeof(Module).Namespace + ".Test.Module.TriggerSampleNumbers",
null,
false
);
/// <summary>
/// Get/set the unsubsampled trigger sample numbers for this module.
/// </summary>
[XmlSerializationTag("UnsubsampledTriggerSampleNumbers", DataName)]
[XmlSerializationTag("UnsubsampledTriggerSampleNumber", DatumName)]
[XmlSerializationTag("Value", DatumValueName)]
public List<UInt64> UnsubsampledTriggerSampleNumbers
{
get => _UnsubsampledTriggerSampleNumbers.Value;
set => _UnsubsampledTriggerSampleNumbers.Value = value;
}
private readonly Property<List<UInt64>> _UnsubsampledTriggerSampleNumbers
= new Property<List<UInt64>>(
typeof(Module).Namespace + ".Test.Module.UnsubsampledTriggerSampleNumbers",
null,
false
);
/// <summary>
/// Get/set the start record sample number for this module.
/// </summary>
[XmlSerializationTag("StartRecordSampleNumber")]
public UInt64 StartRecordSampleNumber
{
get => _StartRecordSampleNumber.Value;
set => _StartRecordSampleNumber.Value = value;
}
private readonly Property<UInt64> _StartRecordSampleNumber
= new Property<UInt64>(
typeof(Module).Namespace + ".Test.Module.StartRecordSampleNumber",
0,
false
);
/// <summary>
/// Get/set the sample rate for this test module.
/// </summary>
[XmlSerializationTag("SampleRateHz")]
public float SampleRateHz
{
get => _SampleRateHz.Value;
set => _SampleRateHz.Value = value;
}
private readonly Property<float> _SampleRateHz
= new Property<float>(
typeof(Module).Namespace + ".Test.Module.SampleRateHz",
0,
false
);
/// <summary>
///
/// </summary>
[XmlSerializationTag("StartRecordTimestampSec")]
public double StartRecordTimestampSec
{
get => _StartRecordTimestampSec.Value;
set => _StartRecordTimestampSec.Value = value;
}
private readonly Property<double> _StartRecordTimestampSec
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.StartRecordTimestampSec",
0,
false
);
/// <summary>
///
/// </summary>
[XmlSerializationTag("TriggerTimestampSec")]
public double TriggerTimestampSec
{
get => _TriggerTimestampSec.Value;
set => _TriggerTimestampSec.Value = value;
}
private readonly Property<double> _TriggerTimestampSec
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.TriggerTimestampSec",
0,
false
);
/// <summary>
///
/// </summary>
[XmlSerializationTag("StartRecordTimestampNanoSec")]
public double StartRecordTimestampNanoSec
{
get => _StartRecordTimestampNanoSec.Value;
set => _StartRecordTimestampNanoSec.Value = value;
}
private readonly Property<double> _StartRecordTimestampNanoSec
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.StartRecordTimestampNanoSec",
0,
false
);
/// <summary>
///
/// </summary>
[XmlSerializationTag("TriggerTimestampNanoSec")]
public double TriggerTimestampNanoSec
{
get => _TriggerTimestampNanoSec.Value;
set => _TriggerTimestampNanoSec.Value = value;
}
private readonly Property<double> _TriggerTimestampNanoSec
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.TriggerTimestampNanoSec",
0,
false
);
/// <summary>
///
/// </summary>
[XmlSerializationTag("PTPMasterSync")]
public bool PTPMasterSync
{
get => _PTPMasterSync.Value;
set => _PTPMasterSync.Value = value;
}
private readonly Property<bool> _PTPMasterSync
= new Property<bool>(
typeof(Module).Namespace + ".Test.Module.PTPMasterSync",
false,
false
);
/// <summary>
/// A string that represents the System ID.
/// </summary>
[XmlSerializationTag("SystemID")]
public string SystemID
{
get => _SystemID.Value;
set => _SystemID.Value = value ?? string.Empty;
}
private readonly Property<string> _SystemID
= new Property<string>(
typeof(Module).Namespace + ".Test.Module.SystemID",
"",
true
);
/// <summary>
/// A string that represents the System Location.
/// </summary>
[XmlSerializationTag("SystemLocation")]
public string SystemLocation
{
get => _SystemLocation.Value;
set => _SystemLocation.Value = value ?? string.Empty;
}
private readonly Property<string> _SystemLocation
= new Property<string>(
typeof(Module).Namespace + ".Test.Module.SystemLocation",
"",
true
);
/// <summary>
/// A string that represents the first target axis.
/// </summary>
[XmlSerializationTag("TargetAxisOne")]
public double TargetAxisOne
{
get => _TargetAxisOne.Value;
set => _TargetAxisOne.Value = value;
}
private readonly Property<double> _TargetAxisOne
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.TargetAxisOne",
0,
false
);
/// <summary>
/// A string that represents the second target axis.
/// </summary>
[XmlSerializationTag("TargetAxisTwo")]
public double TargetAxisTwo
{
get => _TargetAxisTwo.Value;
set => _TargetAxisTwo.Value = value;
}
private readonly Property<double> _TargetAxisTwo
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.TargetAxisTwo",
0,
false
);
/// <summary>
/// A string that represents the X target axis.
/// </summary>
[XmlSerializationTag("TargetAxisX")]
public double TargetAxisX
{
get => _TargetAxisX.Value;
set => _TargetAxisX.Value = value;
}
private readonly Property<double> _TargetAxisX
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.TargetAxisX",
double.NaN,
false
);
/// <summary>
/// A string that represents the Y target axis.
/// </summary>
[XmlSerializationTag("TargetAxisY")]
public double TargetAxisY
{
get => _TargetAxisY.Value;
set => _TargetAxisY.Value = value;
}
private readonly Property<double> _TargetAxisY
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.TargetAxisY",
double.NaN,
false
);
/// <summary>
/// A string that represents the Z target axis.
/// </summary>
[XmlSerializationTag("TargetAxisZ")]
public double TargetAxisZ
{
get => _TargetAxisZ.Value;
set => _TargetAxisZ.Value = value;
}
private readonly Property<double> _TargetAxisZ
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.TargetAxisZ",
double.NaN,
false
);
/// <summary>
/// The value for the X axis of a Slice6 tilt sensor
/// </summary>
[XmlSerializationTag("TiltSensorAxisXDegreesPre")]
public double TiltSensorAxisXDegreesPre
{
get => _TiltSensorAxisXDegreesPre.Value;
set => _TiltSensorAxisXDegreesPre.Value = value;
}
private readonly Property<double> _TiltSensorAxisXDegreesPre
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.TiltSensorAxisXDegreesPre",
0,
false
);
/// <summary>
/// The value for the Y axis of a Slice6 tilt sensor
/// </summary>
[XmlSerializationTag("TiltSensorAxisYDegreesPre")]
public double TiltSensorAxisYDegreesPre
{
get => _TiltSensorAxisYDegreesPre.Value;
set => _TiltSensorAxisYDegreesPre.Value = value;
}
private readonly Property<double> _TiltSensorAxisYDegreesPre
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.TiltSensorAxisYDegreesPre",
0,
false
);
/// <summary>
/// The value for the Z axis of a Slice6 tilt sensor
/// </summary>
[XmlSerializationTag("TiltSensorAxisZDegreesPre")]
public double TiltSensorAxisZDegreesPre
{
get => _TiltSensorAxisZDegreesPre.Value;
set => _TiltSensorAxisZDegreesPre.Value = value;
}
private readonly Property<double> _TiltSensorAxisZDegreesPre
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.TiltSensorAxisZDegreesPre",
0,
false
);
/// <summary>
/// The value for the X axis of a Slice6 tilt sensor
/// </summary>
[XmlSerializationTag("TiltSensorAxisXDegreesPost")]
public double TiltSensorAxisXDegreesPost
{
get => _TiltSensorAxisXDegreesPost.Value;
set => _TiltSensorAxisXDegreesPost.Value = value;
}
private readonly Property<double> _TiltSensorAxisXDegreesPost
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.TiltSensorAxisXDegreesPost",
0,
false
);
/// <summary>
/// The value for the Y axis of a Slice6 tilt sensor
/// </summary>
[XmlSerializationTag("TiltSensorAxisYDegreesPost")]
public double TiltSensorAxisYDegreesPost
{
get => _TiltSensorAxisYDegreesPost.Value;
set => _TiltSensorAxisYDegreesPost.Value = value;
}
private readonly Property<double> _TiltSensorAxisYDegreesPost
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.TiltSensorAxisYDegreesPost",
0,
false
);
/// <summary>
/// The value for the Z axis of a Slice6 tilt sensor
/// </summary>
[XmlSerializationTag("TiltSensorAxisZDegreesPost")]
public double TiltSensorAxisZDegreesPost
{
get => _TiltSensorAxisZDegreesPost.Value;
set => _TiltSensorAxisZDegreesPost.Value = value;
}
private readonly Property<double> _TiltSensorAxisZDegreesPost
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.TiltSensorAxisZDegreesPost",
0,
false
);
/// <summary>
/// The value for the 1st location of a Slice6 temperature sensor
/// </summary>
[XmlSerializationTag("TemperatureLocation1Pre")]
public float TemperatureLocation1Pre
{
get => _TemperatureLocation1Pre.Value;
set => _TemperatureLocation1Pre.Value = value;
}
private readonly Property<float> _TemperatureLocation1Pre
= new Property<float>(
typeof(Module).Namespace + ".Test.Module.TemperatureLocation1Pre",
0,
false
);
/// <summary>
/// The value for the 2nd location of a Slice6 temperature sensor
/// </summary>
[XmlSerializationTag("TemperatureLocation2Pre")]
public float TemperatureLocation2Pre
{
get => _TemperatureLocation2Pre.Value;
set => _TemperatureLocation2Pre.Value = value;
}
private readonly Property<float> _TemperatureLocation2Pre
= new Property<float>(
typeof(Module).Namespace + ".Test.Module.TemperatureLocation2Pre",
0,
false
);
/// <summary>
/// The value for the 3rd location of a Slice6 temperature sensor
/// </summary>
[XmlSerializationTag("TemperatureLocation3Pre")]
public float TemperatureLocation3Pre
{
get => _TemperatureLocation3Pre.Value;
set => _TemperatureLocation3Pre.Value = value;
}
private readonly Property<float> _TemperatureLocation3Pre
= new Property<float>(
typeof(Module).Namespace + ".Test.Module.TemperatureLocation3Pre",
0,
false
);
/// <summary>
/// The value for the 4th location of a Slice6 temperature sensor
/// </summary>
[XmlSerializationTag("TemperatureLocation4Pre")]
public float TemperatureLocation4Pre
{
get => _TemperatureLocation4Pre.Value;
set => _TemperatureLocation4Pre.Value = value;
}
private readonly Property<float> _TemperatureLocation4Pre
= new Property<float>(
typeof(Module).Namespace + ".Test.Module.TemperatureLocation4Pre",
0,
false
);
/// <summary>
/// The value for the 1st location of a Slice6 temperature sensor post-trigger
/// </summary>
[XmlSerializationTag("TemperatureLocation1Post")]
public float TemperatureLocation1Post
{
get => _TemperatureLocation1Post.Value;
set => _TemperatureLocation1Post.Value = value;
}
private readonly Property<float> _TemperatureLocation1Post
= new Property<float>(
typeof(Module).Namespace + ".Test.Module.TemperatureLocation1Post",
0,
false
);
/// <summary>
/// The value for the 2nd location of a Slice6 temperature sensor post-trigger
/// </summary>
[XmlSerializationTag("TemperatureLocation2Post")]
public float TemperatureLocation2Post
{
get => _TemperatureLocation2Post.Value;
set => _TemperatureLocation2Post.Value = value;
}
private readonly Property<float> _TemperatureLocation2Post
= new Property<float>(
typeof(Module).Namespace + ".Test.Module.TemperatureLocation2Post",
0,
false
);
/// <summary>
/// The value for the 3rd location of a Slice6 temperature sensor post-trigger
/// </summary>
[XmlSerializationTag("TemperatureLocation3Post")]
public float TemperatureLocation3Post
{
get => _TemperatureLocation3Post.Value;
set => _TemperatureLocation3Post.Value = value;
}
private readonly Property<float> _TemperatureLocation3Post
= new Property<float>(
typeof(Module).Namespace + ".Test.Module.TemperatureLocation3Post",
0,
false
);
/// <summary>
/// The value for the 4th location of a Slice6 temperature sensor post-trigger
/// </summary>
[XmlSerializationTag("TemperatureLocation4Post")]
public float TemperatureLocation4Post
{
get => _TemperatureLocation4Post.Value;
set => _TemperatureLocation4Post.Value = value;
}
private readonly Property<float> _TemperatureLocation4Post
= new Property<float>(
typeof(Module).Namespace + ".Test.Module.TemperatureLocation4Post",
0,
false
);
/// <summary>
/// The value for the input voltage
/// </summary>
[XmlSerializationTag("InputVoltage")]
public double InputVoltage
{
get => _inputVoltage.Value;
set => _inputVoltage.Value = value;
}
private readonly Property<double> _inputVoltage
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.InputVoltage",
0,
false
);
/// <summary>
/// The value for the battery voltage
/// </summary>
[XmlSerializationTag("BatteryVoltage")]
public double BatteryVoltage
{
get => _batteryVoltage.Value;
set => _batteryVoltage.Value = value;
}
private readonly Property<double> _batteryVoltage
= new Property<double>(
typeof(Module).Namespace + ".Test.Module.BatteryVoltage",
0,
false
);
/// <summary>
/// Get/set the AA filter rate for this test module.
/// </summary>
[XmlSerializationTag("AaFilterRateHz")]
public float AaFilterRateHz
{
get => _AaFilterRateHz.Value;
set => _AaFilterRateHz.Value = value;
}
private readonly Property<float> _AaFilterRateHz
= new Property<float>(
typeof(Module).Namespace + ".Test.Module.AaFilterRateHz",
0,
false
);
/// <summary>
/// Get/set the recording mode of this module.
/// </summary>
[XmlSerializationTag("RecordingMode")]
public DFConstantsAndEnums.RecordingMode RecordingMode
{
get => _RecordingMode.Value;
set => _RecordingMode.Value = value;
}
private readonly Property<DFConstantsAndEnums.RecordingMode> _RecordingMode
= new Property<DFConstantsAndEnums.RecordingMode>(
typeof(Module).Namespace + ".Test.Module.RecordingMode",
DFConstantsAndEnums.RecordingMode.CircularBuffer,
false
);
/// <summary>
/// Get the number of <see cref="int"/> channels in the channel list. (Intended for de/serialization only!)
/// </summary>
[XmlSerializationTag("NumberOfChannels")]
public int NumberOfChannels => Channels.Count;
/// <summary>
/// Get/set inline serialized data switch.
/// </summary>
[XmlSerializationTag("InlineSerializedData")]
public bool InlineSerializedData
{
get => _InlineSerializedData.Value;
set
{
try
{
_InlineSerializedData.Value = value;
foreach (var channel in Channels)
channel.ExpressDataInlineOnXmlSerialization = value;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem setting module InlineSerializedData state", ex);
}
}
}
private readonly Property<bool> _InlineSerializedData = new Property<bool>("InlineSerializedData", false, true);
/// <summary>
/// Write XML serialization for this object to the specified writer.
/// </summary>
///
/// <param name="writer">
/// The <see cref="XmlWriter"/> to which this object's XML serialization
/// will be written.
/// </param>
///
public void WriteXml(XmlWriter writer)
{
try
{
var cult = new CultureInfo("");
var attributeExtractor = new AttributeExtractor<XmlSerializationTagAttribute>();
//
// 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, AaFilterRateHz.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "Number").Value, Number.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "SerialNumber").Value, (SerialNumber ?? "").ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "NumberOfSamples").Value, NumberOfSamples.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "UnsubsampledNumberOfSamples").Value, UnsubsampledNumberOfSamples.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "RequestedPostTriggerSeconds").Value, RequestedPostTriggerSeconds.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "RequestedPreTriggerSeconds").Value, RequestedPreTriggerSeconds.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "PostTriggerSeconds").Value, PostTriggerSeconds.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "PreTriggerSeconds").Value, PreTriggerSeconds.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "RecordingMode").Value, RecordingMode.ToString());
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "SampleRateHz").Value, SampleRateHz.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "StartRecordSampleNumber").Value, StartRecordSampleNumber.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "NumberOfChannels").Value, NumberOfChannels.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "InlineSerializedData").Value, InlineSerializedData.ToString(cult));
try
{
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "BaseSerialNumber").Value, BaseSerialNumber.ToString(cult));
}
catch (System.Exception)
{
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "BaseSerialNumber").Value, "NA");
}
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "StartRecordTimestampSec").Value, StartRecordTimestampSec.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "StartRecordTimestampNanoSec").Value, StartRecordTimestampNanoSec.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TriggerTimestampSec").Value, TriggerTimestampSec.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TriggerTimestampNanoSec").Value, TriggerTimestampNanoSec.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "PTPMasterSync").Value, PTPMasterSync.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisXDegreesPre").Value, TiltSensorAxisXDegreesPre.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisYDegreesPre").Value, TiltSensorAxisYDegreesPre.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisZDegreesPre").Value, TiltSensorAxisZDegreesPre.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisXDegreesPost").Value, TiltSensorAxisXDegreesPost.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisYDegreesPost").Value, TiltSensorAxisYDegreesPost.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisZDegreesPost").Value, TiltSensorAxisZDegreesPost.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation1Pre").Value, TemperatureLocation1Pre.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation2Pre").Value, TemperatureLocation2Pre.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation3Pre").Value, TemperatureLocation3Pre.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation4Pre").Value, TemperatureLocation4Pre.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation1Post").Value, TemperatureLocation1Post.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation2Post").Value, TemperatureLocation2Post.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation3Post").Value, TemperatureLocation3Post.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation4Post").Value, TemperatureLocation4Post.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "SystemID").Value, SystemID.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "SystemLocation").Value, SystemLocation.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TargetAxisX").Value, TargetAxisX.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TargetAxisY").Value, TargetAxisY.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TargetAxisZ").Value, TargetAxisZ.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "InputVoltage").Value, InputVoltage.ToString(cult));
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "BatteryVoltage").Value, BatteryVoltage.ToString(cult));
////
//// Write out trigger sample numbers list.
////
//List<XmlSerializationTagAttribute> 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.
//
var unsubsampledTriggerSampleNumberAttributes = attributeExtractor.ExtractAttachedAttributesFromProperty(this, "TriggerSampleNumbers");
unsubsampledTriggerSampleNumberAttributes.Sort();
writer.WriteStartElement(unsubsampledTriggerSampleNumberAttributes[DataName].Value);
for (var i = 0; i < UnsubsampledTriggerSampleNumbers.Count; i++)
{
writer.WriteStartElement(unsubsampledTriggerSampleNumberAttributes[DatumName].Value);
writer.WriteAttributeString(unsubsampledTriggerSampleNumberAttributes[DatumValueName].Value, 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);
}
}
/// <summary>
/// parses out channels from xml document, if empty advances to next element
/// </summary>
private void ReadChannels(XmlReader reader, AttributeExtractor<XmlSerializationTagAttribute> attributeExtractor)
{
try
{
//
// Read channel list, if it exists.
//
Channels = new List<Channel>();
var isChannels = string.Equals(
attributeExtractor.ExtractAttachedAttributeFromProperty(this, "Channels").Value,
reader.Name, StringComparison.OrdinalIgnoreCase);
if (!reader.IsEmptyElement && isChannels)
{
ReadChannelElements(reader);
reader.ReadEndElement();
}
else if ( reader.IsEmptyElement && isChannels)
{
reader.Read();
}
}
catch (System.Exception ex)
{
throw new Exception("encountered problem parsing channel list", ex);
}
}
private void ReadChannelElements(XmlReader reader)
{
while (reader.Read() && (XmlNodeType.Element == reader.MoveToContent()))
{
var channelType
= new PropertyAttributeDecoder<Channel>(
new AnalogInputChannel(this))
.ExtractStringProperty("ChannelType", reader);
if (null == channelType)
throw new Exception("expected channel type string but got " +
(null != channelType
? ("\"" + channelType + "\"")
: "<<NULL>>"));
var channelClassType = Type.GetType(channelType);
var deserializedChannel =
Activator.CreateInstance(channelClassType, new object[] { this }) as
Channel;
if (
!(deserializedChannel.ExpressDataInlineOnXmlSerialization =
InlineSerializedData))
deserializedChannel.Data = new Channel.DataArray<short>();
deserializedChannel.ReadXml(reader);
Channels.Add(deserializedChannel);
}
}
/// <summary>
/// Read XML serialization for this object from the specified reader.
/// </summary>
///
/// <param name="reader">
/// The <see cref="XmlReader"/> from which this object's XML serialization
/// will be read.
/// </param>
///
public void ReadXml(XmlReader reader)
{
try
{
var cult = new CultureInfo("");
var attributeExtractor = new AttributeExtractor<XmlSerializationTagAttribute>();
reader.MoveToContent();
//
// Read simple attributes.
//
if (
float.TryParse(
reader.GetAttribute(
attributeExtractor.ExtractAttachedAttributeFromProperty(this, "AaFilterRateHz").Value),
NumberStyles.Any, cult, out float aafilterRateHz))
{
AaFilterRateHz = aafilterRateHz;
}
else
{
throw new Exception("error reading AaFilterRateHz");
}
if (
int.TryParse(
reader.GetAttribute(
attributeExtractor.ExtractAttachedAttributeFromProperty(this, "Number").Value),
NumberStyles.Any, cult, out int 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");
}
if (
ulong.TryParse(
reader.GetAttribute(
attributeExtractor.ExtractAttachedAttributeFromProperty(this, "NumberOfSamples").Value),
NumberStyles.Any, cult, out ulong numberOfSamples))
{
NumberOfSamples = numberOfSamples;
}
else
{
throw new Exception("error reading NumberOfSamples");
}
if (
double.TryParse(
reader.GetAttribute(
attributeExtractor.ExtractAttachedAttributeFromProperty(this, "PostTriggerSeconds").Value),
NumberStyles.Any, cult, out double postTriggerSeconds))
{
PostTriggerSeconds = postTriggerSeconds;
}
else
{
throw new Exception("error reading PostTriggerSeconds");
}
if (
double.TryParse(
reader.GetAttribute(
attributeExtractor.ExtractAttachedAttributeFromProperty(this, "PreTriggerSeconds").Value),
NumberStyles.Any, cult, out double preTriggerSeconds))
{
PreTriggerSeconds = preTriggerSeconds;
}
else
{
throw new Exception("error reading PreTriggerSeconds");
}
RequestedPostTriggerSeconds = double.TryParse(
reader.GetAttribute(
attributeExtractor.ExtractAttachedAttributeFromProperty(this,
"RequestedPostTriggerSeconds").Value), NumberStyles.Any, cult,
out double requestedPostTriggerSeconds) ? requestedPostTriggerSeconds : PostTriggerSeconds;
RequestedPreTriggerSeconds = double.TryParse(
reader.GetAttribute(
attributeExtractor.ExtractAttachedAttributeFromProperty(this,
"RequestedPreTriggerSeconds").Value), NumberStyles.Any, cult,
out double requestedPreTriggerSeconds) ? requestedPreTriggerSeconds : PreTriggerSeconds;
if (float.TryParse(
reader.GetAttribute(
attributeExtractor.ExtractAttachedAttributeFromProperty(this,
"SampleRateHz").Value), NumberStyles.Any, cult,
out float sampleRateHz))
{
SampleRateHz = sampleRateHz;
}
else
{
throw new Exception("error reading SampleRateHz");
}
double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "StartRecordTimestampSec").Value), NumberStyles.Any, cult, out double startRecordTimestampSec);
StartRecordTimestampSec = startRecordTimestampSec;
double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TriggerTimestampSec").Value), NumberStyles.Any, cult, out double triggerTimestampSec);
TriggerTimestampSec = triggerTimestampSec;
double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "StartRecordTimestampNanoSec").Value), NumberStyles.Any, cult, out double startRecordTimestampNanoSec);
StartRecordTimestampNanoSec = startRecordTimestampNanoSec;
double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TriggerTimestampNanoSec").Value), NumberStyles.Any, cult, out double triggerTimestampNanoSec);
TriggerTimestampNanoSec = triggerTimestampNanoSec;
bool.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "PTPMasterSync").Value), out bool pTpMasterSync);
PTPMasterSync = pTpMasterSync;
try
{
SystemID = reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "SystemID").Value);
}
catch
{
SystemID = string.Empty;
}
try
{
SystemLocation = reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "SystemLocation").Value);
}
catch
{
SystemLocation = string.Empty;
}
double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "InputVoltage").Value), NumberStyles.Any, cult, out double inputVoltage);
InputVoltage = inputVoltage;
double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "BatteryVoltage").Value), NumberStyles.Any, cult, out double batteryVoltage);
BatteryVoltage = batteryVoltage;
double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TargetAxisOne").Value), NumberStyles.Any, cult, out double targetAxisOne);
TargetAxisOne = targetAxisOne;
double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TargetAxisTwo").Value), NumberStyles.Any, cult, out double targetAxisTwo);
TargetAxisTwo = targetAxisTwo;
double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisXDegreesPre").Value), NumberStyles.Any, cult, out double tiltSensorAxisXDegreesPre);
TiltSensorAxisXDegreesPre = tiltSensorAxisXDegreesPre;
double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisYDegreesPre").Value), NumberStyles.Any, cult, out double tiltSensorAxisYDegreesPre);
TiltSensorAxisYDegreesPre = tiltSensorAxisYDegreesPre;
double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisZDegreesPre").Value), NumberStyles.Any, cult, out double tiltSensorAxisZDegreesPre);
TiltSensorAxisZDegreesPre = tiltSensorAxisZDegreesPre;
double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisXDegreesPost").Value), NumberStyles.Any, cult, out double tiltSensorAxisXDegreesPost);
TiltSensorAxisXDegreesPost = tiltSensorAxisXDegreesPost;
double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisYDegreesPost").Value), NumberStyles.Any, cult, out double tiltSensorAxisYDegreesPost);
TiltSensorAxisYDegreesPost = tiltSensorAxisYDegreesPost;
double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TiltSensorAxisZDegreesPost").Value), NumberStyles.Any, cult, out double tiltSensorAxisZDegreesPost);
TiltSensorAxisZDegreesPost = tiltSensorAxisZDegreesPost;
float.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation1Pre").Value), NumberStyles.Any, cult, out float temperatureLocation1Pre);
TemperatureLocation1Pre = temperatureLocation1Pre;
float.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation2Pre").Value), NumberStyles.Any, cult, out float temperatureLocation2Pre);
TemperatureLocation2Pre = temperatureLocation2Pre;
float.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation3Pre").Value), NumberStyles.Any, cult, out float temperatureLocation3Pre);
TemperatureLocation3Pre = temperatureLocation3Pre;
float.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation4Pre").Value), NumberStyles.Any, cult, out float temperatureLocation4Pre);
TemperatureLocation4Pre = temperatureLocation4Pre;
float.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation1Post").Value), NumberStyles.Any, cult, out float temperatureLocation1Post);
TemperatureLocation1Post = temperatureLocation1Post;
float.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation2Post").Value), NumberStyles.Any, cult, out float temperatureLocation2Post);
TemperatureLocation2Post = temperatureLocation2Post;
float.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation3Post").Value), NumberStyles.Any, cult, out float temperatureLocation3Post);
TemperatureLocation3Post = temperatureLocation3Post;
float.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TemperatureLocation4Post").Value), NumberStyles.Any, cult, out float temperatureLocation4Post);
TemperatureLocation4Post = temperatureLocation4Post;
if (
ulong.TryParse(
reader.GetAttribute(
attributeExtractor.ExtractAttachedAttributeFromProperty(this, "StartRecordSampleNumber")
.Value), NumberStyles.Any, cult, out ulong startRecordSampleNumber))
{
StartRecordSampleNumber = startRecordSampleNumber;
}
else
{
throw new Exception("error reading StartRecordSampleNumber");
}
if (bool.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "InlineSerializedData").Value), out bool inlineSerializedData))
{
InlineSerializedData = inlineSerializedData;
}
else
{
throw new Exception("error reading InlineSerializedData");
}
try
{
RecordingMode =
Common.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)
{
throw new Exception("error reading BaseSerialNumber");
}
UnsubsampledNumberOfSamples = ulong.TryParse(
reader.GetAttribute(
attributeExtractor.ExtractAttachedAttributeFromProperty(this,
"UnsubsampledNumberOfSamples").Value), NumberStyles.Any, cult,
out ulong 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.
if (int.TryParse(
reader.GetAttribute(
attributeExtractor.ExtractAttachedAttributeFromProperty(this, "NumberOfChannels").Value),
NumberStyles.Any, cult, out int numberOfChannelsToRead))
{
//
// Read unsubsampled trigger sample numbers list.
//
reader.Read();
reader.MoveToContent();
var unsubsampledTriggerSampleNumberAttributes =
attributeExtractor.ExtractAttachedAttributesFromProperty(this, "TriggerSampleNumbers");
unsubsampledTriggerSampleNumberAttributes.Sort();
UnsubsampledTriggerSampleNumbers = new List<ulong>();
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();
}
ReadChannels(reader, attributeExtractor);
try
{
//
// Read calculated channel list, if it exists.
//
CalculatedChannels.Clear();
if (!reader.IsEmptyElement &&
string.Equals(
attributeExtractor.ExtractAttachedAttributeFromProperty(this, "CalculatedChannels")
.Value, reader.Name, StringComparison.OrdinalIgnoreCase))
{
while (reader.Read() && (XmlNodeType.Element == reader.MoveToContent()))
{
var channelType
= new PropertyAttributeDecoder<Channel>(
new AnalogInputChannel(this))
.ExtractStringProperty("ChannelType", reader);
if (null == channelType)
throw new Exception("expected channel type string but got " +
(null != channelType
? ("\"" + channelType + "\"")
: "<<NULL>>"));
var channelClassType = Type.GetType(channelType);
var deserializedChannel =
Activator.CreateInstance(channelClassType, new object[] { this }) as
Channel;
// ( channelClassType, true ) as Test.Module.Channel;
if (
!(deserializedChannel.ExpressDataInlineOnXmlSerialization =
InlineSerializedData))
deserializedChannel.Data = new Channel.DataArray<short>();
deserializedChannel.ReadXml(reader);
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);
}
}
/// <summary>
/// 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.
/// </summary>
///
/// <returns>
/// Null <see cref="XmlSchema"/> reference, always.
/// </returns>
///
public XmlSchema GetSchema()
{
// This method is never invoked during XML object serialization.
return null;
}
/// <summary>
/// Test the specified object for equality with this object.
/// </summary>
///
/// <param name="obj">
/// The <see cref="object"/> to be tested for equality.
/// </param>
///
/// <returns>
/// <see cref="bool"/> true if the specified object has memeberwise equality with
/// this object; false otherwise.
/// </returns>
///
public override bool Equals(object obj)
{
try
{
return obj is Module that
&& AaFilterRateHz.Equals(that.AaFilterRateHz)
&& Number.Equals(that.Number)
&& SerialNumber.Equals(that.SerialNumber)
&& NumberOfSamples.Equals(that.NumberOfSamples)
&& UnsubsampledNumberOfSamples.Equals(that.UnsubsampledNumberOfSamples)
&& RequestedPostTriggerSeconds.Equals(that.RequestedPostTriggerSeconds)
&& RequestedPreTriggerSeconds.Equals(that.RequestedPreTriggerSeconds)
&& PostTriggerSeconds.Equals(that.PostTriggerSeconds)
&& PreTriggerSeconds.Equals(that.PreTriggerSeconds)
&& RecordingMode.Equals(that.RecordingMode)
&& SampleRateHz.Equals(that.SampleRateHz)
&& StartRecordTimestampSec.Equals(that.StartRecordTimestampSec)
&& TriggerTimestampSec.Equals(that.TriggerTimestampSec)
&& StartRecordTimestampSec.Equals(that.StartRecordTimestampNanoSec)
&& TriggerTimestampSec.Equals(that.TriggerTimestampNanoSec)
&& PTPMasterSync.Equals(that.PTPMasterSync)
&& SystemID.Equals(that.SystemID)
&& SystemLocation.Equals(that.SystemLocation)
&& TargetAxisOne.Equals(that.TargetAxisOne)
&& TargetAxisTwo.Equals(that.TargetAxisTwo)
&& TiltSensorAxisXDegreesPre.Equals(that.TiltSensorAxisXDegreesPre)
&& TiltSensorAxisYDegreesPre.Equals(that.TiltSensorAxisYDegreesPre)
&& TiltSensorAxisZDegreesPre.Equals(that.TiltSensorAxisZDegreesPre)
&& TiltSensorAxisXDegreesPost.Equals(that.TiltSensorAxisXDegreesPost)
&& TiltSensorAxisYDegreesPost.Equals(that.TiltSensorAxisYDegreesPost)
&& TiltSensorAxisZDegreesPost.Equals(that.TiltSensorAxisZDegreesPost)
&& TemperatureLocation1Pre.Equals(that.TemperatureLocation1Pre)
&& TemperatureLocation2Pre.Equals(that.TemperatureLocation2Pre)
&& TemperatureLocation3Pre.Equals(that.TemperatureLocation3Pre)
&& TemperatureLocation4Pre.Equals(that.TemperatureLocation4Pre)
&& TemperatureLocation1Post.Equals(that.TemperatureLocation1Post)
&& TemperatureLocation2Post.Equals(that.TemperatureLocation2Post)
&& TemperatureLocation3Post.Equals(that.TemperatureLocation3Post)
&& TemperatureLocation4Post.Equals(that.TemperatureLocation4Post)
&& StartRecordSampleNumber.Equals(that.StartRecordSampleNumber)
&& TriggerSampleNumbersEquals(that.TriggerSampleNumbers)
&& UnsubsampledTriggerSampleNumbersEquals(that.UnsubsampledTriggerSampleNumbers)
&& ChannelsEquals(that.Channels)
&& BaseSerialNumber.Equals(that.BaseSerialNumber);
}
catch (System.Exception ex)
{
throw new Exception("encountered problem equality-testing object " + (null != obj ? "\"" + obj.ToString() + "\"" : "<<NULL>>"), ex);
}
}
/// <summary>
/// Test the specified object's trigger sample number list for equality with this
/// object's module list.
/// </summary>
///
/// <param name="thoseTriggerSampleNumbers">
/// The <see cref="List"/> of <see cref="UInt64"/> object to be
/// compared for equality with this test's equivalent.
/// </param>
///
/// <returns>
/// <see cref="bool"/> true if the two lists contain equivalent-valued members;
/// false otherwise.
/// </returns>
///
private bool TriggerSampleNumbersEquals(List<UInt64> thoseTriggerSampleNumbers)
{
try
{
if (null == thoseTriggerSampleNumbers || TriggerSampleNumbers.Count != thoseTriggerSampleNumbers.Count)
return false;
for (var i = 0; i < thoseTriggerSampleNumbers.Count; i++)
if (!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);
}
}
/// <summary>
/// Test the specified object's unsubsampled trigger sample number list for equality with this
/// object's module list.
/// </summary>
///
/// <param name="thoseUnsubsampledTriggerSampleNumbers">
/// The <see cref="List"/> of <see cref="UInt64"/> object to be
/// compared for equality with this test's equivalent.
/// </param>
///
/// <returns>
/// <see cref="bool"/> true if the two lists contain equivalent-valued members;
/// false otherwise.
/// </returns>
///
private bool UnsubsampledTriggerSampleNumbersEquals(List<UInt64> thoseUnsubsampledTriggerSampleNumbers)
{
try
{
if (null == thoseUnsubsampledTriggerSampleNumbers || UnsubsampledTriggerSampleNumbers.Count != thoseUnsubsampledTriggerSampleNumbers.Count)
return false;
for (var i = 0; i < thoseUnsubsampledTriggerSampleNumbers.Count; i++)
if (!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);
}
}
/// <summary>
/// Test the specified object's module list for equality with this object's
/// module list.
/// </summary>
///
/// <param name="thoseChannels">
/// The <see cref="List"/> of <see cref="Dts.Serialization.Test.Module.Channel"/> object to be
/// compared for equality with this test's equivalent.
/// </param>
///
/// <returns>
/// <see cref="bool"/> true if the two lists contain equivalent-valued members;
/// false otherwise.
/// </returns>
///
private bool ChannelsEquals(List<Channel> thoseChannels)
{
try
{
if (null == thoseChannels || Channels.Count != thoseChannels.Count)
return false;
for (var i = 0; i < thoseChannels.Count; i++)
if (!Channels[i].Equals(thoseChannels[i]))
{
var test = Channels[i].Equals(thoseChannels[i]);
return false;
}
//return false;
return true;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem equality-testing channel list", ex);
}
}
/// <summary>
/// Return the hash code for this object.
/// </summary>
///
/// <returns>
/// The <see cref="int"/> hash code for this object.
/// </returns>
///
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
}