Files
DP44/Common/DTS.Common.Serialization/Test/DasTimestamp.cs
2026-04-17 14:55:32 -04:00

280 lines
11 KiB
C#

using DTS.Common.Utilities;
using DTS.Common.Utilities.DotNetProgrammingConstructs;
using DTS.Common.Utilities.Xml;
using System;
using System.Globalization;
using System.Xml;
using System.Xml.Schema;
namespace DTS.Serialization
{
public partial class Test
{
/// <summary>
/// Representation of serializable das timestamp information.
/// </summary>
[XmlSerializationTag("DasTimestamp")]
public partial class DasTimestamp : Exceptional
{
/// <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(DasTimestamp).Namespace + ".Test.DasTimestamp.ParentTest",
null,
false
);
/// <summary>
/// Initialize an instance of the DTS.Serialization.Test.DasTimestamp class.
/// </summary>
///
/// <param name="parentTest">
/// The <see cref="DTS.Serialization.Test"/> containing this object.
/// </param>
///
public DasTimestamp(Test parentTest)
{
try
{
ParentTest = parentTest;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem constructing " + GetType().Name, ex);
}
}
/// <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(DasTimestamp).Namespace + ".Test.DasTimestamp.BaseSerialNumber",
"",
true
);
/// <summary>
/// Get/set the number of samples in this test das.
/// </summary>
[XmlSerializationTag("NumberOfSamples")]
public UInt64 NumberOfSamples
{
get => _NumberOfSamples.Value;
set => _NumberOfSamples.Value = value;
}
private readonly Property<UInt64> _NumberOfSamples
= new Property<UInt64>(
typeof(DasTimestamp).Namespace + ".Test.DasTimestamp.NumberOfSamples",
0,
false
);
/// <summary>
/// Get/set the number of bits per sample timestamp in this test.
/// </summary>
[XmlSerializationTag("NumberOfBitsPerSample")]
public UInt32 NumberOfBitsPerSample
{
get => _NumberOfBitsPerSample.Value;
set => _NumberOfBitsPerSample.Value = value;
}
private readonly Property<UInt32> _NumberOfBitsPerSample
= new Property<UInt32>(
typeof(DasTimestamp).Namespace + ".Test.DasTimestamp.NumberOfBitsPerSample",
0,
false
);
/// <summary>
/// The name of the .bin file in the Binary folder that corresponds to this set of timestamps.
/// </summary>
[XmlSerializationTag("FileName")]
public string FileName
{
get => _fileName.Value;
set => _fileName.Value = value;
}
private readonly Property<string> _fileName
= new Property<string>(
typeof(DasTimestamp).Namespace + ".Test.DasTimestamp.FileName",
"",
false
);
/// <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 das timestamp 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);
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, "NumberOfSamples").Value, NumberOfSamples.ToString(cult));
writer.WriteEndElement();
}
catch (System.Exception ex)
{
throw new Exception("encountered problem converting DTS.Serialization.Test.DasTimestamp object to XML", ex);
}
}
/// <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.
//
try
{
BaseSerialNumber = reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "BaseSerialNumber").Value);
}
catch (Exception)
{
throw new Exception("error reading BaseSerialNumber");
}
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 (
uint.TryParse(
reader.GetAttribute(
attributeExtractor.ExtractAttachedAttributeFromProperty(this, "NumberOfBitsPerSample").Value),
NumberStyles.Any, cult, out uint numberOfBitsPerSample))
{
NumberOfBitsPerSample = numberOfBitsPerSample;
}
else
{
//not written, set to standard size
NumberOfBitsPerSample = 8 * sizeof(ulong);
}
}
catch (System.Exception ex)
{
throw new Exception("encountered problem converting XML to DTS.Serialization.Test.DasTimestamp 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 DasTimestamp that
&& FileName.Equals(that.FileName)
&& NumberOfSamples.Equals(that.NumberOfSamples)
&& NumberOfBitsPerSample.Equals(that.NumberOfBitsPerSample)
&& BaseSerialNumber.Equals(that.BaseSerialNumber);
}
catch (System.Exception ex)
{
throw new Exception("encountered problem equality-testing object " + (null != obj ? "\"" + obj.ToString() + "\"" : "<<NULL>>"), ex);
}
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
}