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
{
///
/// Representation of serializable das timestamp information.
///
[XmlSerializationTag("DasTimestamp")]
public partial class DasTimestamp : Exceptional
{
///
/// The that contains this module.
///
public Test ParentTest
{
get => _ParentTest.Value;
private set => _ParentTest.Value = value;
}
private readonly Property _ParentTest
= new Property(
typeof(DasTimestamp).Namespace + ".Test.DasTimestamp.ParentTest",
null,
false
);
///
/// Initialize an instance of the DTS.Serialization.Test.DasTimestamp class.
///
///
///
/// The containing this object.
///
///
public DasTimestamp(Test parentTest)
{
try
{
ParentTest = parentTest;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem constructing " + GetType().Name, ex);
}
}
///
/// Get/set the base serial number for this DAS.
///
[XmlSerializationTag("BaseSerialNumber")]
public string BaseSerialNumber
{
get => _BaseSerialNumber.Value;
set => _BaseSerialNumber.Value = value;
}
private readonly Property _BaseSerialNumber
= new Property(
typeof(DasTimestamp).Namespace + ".Test.DasTimestamp.BaseSerialNumber",
"",
true
);
///
/// Get/set the number of samples in this test das.
///
[XmlSerializationTag("NumberOfSamples")]
public UInt64 NumberOfSamples
{
get => _NumberOfSamples.Value;
set => _NumberOfSamples.Value = value;
}
private readonly Property _NumberOfSamples
= new Property(
typeof(DasTimestamp).Namespace + ".Test.DasTimestamp.NumberOfSamples",
0,
false
);
///
/// Get/set the number of bits per sample timestamp in this test.
///
[XmlSerializationTag("NumberOfBitsPerSample")]
public UInt32 NumberOfBitsPerSample
{
get => _NumberOfBitsPerSample.Value;
set => _NumberOfBitsPerSample.Value = value;
}
private readonly Property _NumberOfBitsPerSample
= new Property(
typeof(DasTimestamp).Namespace + ".Test.DasTimestamp.NumberOfBitsPerSample",
0,
false
);
///
/// The name of the .bin file in the Binary folder that corresponds to this set of timestamps.
///
[XmlSerializationTag("FileName")]
public string FileName
{
get => _fileName.Value;
set => _fileName.Value = value;
}
private readonly Property _fileName
= new Property(
typeof(DasTimestamp).Namespace + ".Test.DasTimestamp.FileName",
"",
false
);
///
/// 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 CultureInfo("");
var attributeExtractor = new AttributeExtractor();
//
// 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);
}
}
///
/// 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 CultureInfo("");
var attributeExtractor = new AttributeExtractor();
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);
}
}
///
/// 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
{
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() + "\"" : "<>"), ex);
}
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
}