init
This commit is contained in:
118
DataPRO/IService/Classes/TDAS/TDASConfig.cs
Normal file
118
DataPRO/IService/Classes/TDAS/TDASConfig.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
using System.Threading;
|
||||
using System.Xml;
|
||||
using System.Xml.Schema;
|
||||
using System.Xml.Serialization;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using DTS.DASLib.Command.SLICE;
|
||||
using DTS.Common.DAS.Concepts;
|
||||
using DTS.Common.Utilities.DotNetProgrammingConstructs;
|
||||
using DTS.Common.Utilities.Logging;
|
||||
|
||||
|
||||
namespace DTS.DASLib.Service
|
||||
{
|
||||
public class TDASConfig : IXmlSerializable
|
||||
{
|
||||
private Dictionary<string, TDASModuleConfig> _modules = new Dictionary<string, TDASModuleConfig>();
|
||||
public Dictionary<string, TDASModuleConfig> Modules { get { return _modules; } }
|
||||
private string _fileName;
|
||||
public string FileName { get { return _fileName; } }
|
||||
|
||||
public TDASConfig()
|
||||
{
|
||||
}
|
||||
|
||||
public TDASConfig(string fileName, bool deleteIfPresent)
|
||||
{
|
||||
const string dasConfigs = "DASConfigs";
|
||||
var location = Path.Combine(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), dasConfigs), fileName);
|
||||
|
||||
_fileName = location; //fileName;
|
||||
if (File.Exists(location))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (deleteIfPresent)
|
||||
{
|
||||
try { File.Delete(_fileName); }
|
||||
catch (Exception ex) { APILogger.Log("Problem deleting ", _fileName, ex); }
|
||||
}
|
||||
else { using (var sr = new StreamReader(_fileName)) { ReadXml(XmlReader.Create(sr)); } }
|
||||
}
|
||||
catch (Exception ex) { APILogger.Log("Problem reading ", _fileName, ex); }
|
||||
}
|
||||
}
|
||||
public void SetModule(TDASModuleConfig module)
|
||||
{
|
||||
if (_modules.ContainsKey(module.SerialNumber)) { _modules[module.SerialNumber] = module; }
|
||||
else { _modules.Add(module.SerialNumber, module); }
|
||||
}
|
||||
public TDASModuleConfig GetModule(TDASModuleConfig module)
|
||||
{
|
||||
if (_modules.ContainsKey(module.SerialNumber)) { return _modules[module.SerialNumber]; }
|
||||
else
|
||||
{
|
||||
_modules.Add(module.SerialNumber, module);
|
||||
return module;
|
||||
}
|
||||
}
|
||||
public XmlSchema GetSchema()
|
||||
{
|
||||
return (null);
|
||||
}
|
||||
//
|
||||
// Summary:
|
||||
// Generates an object from its XML representation.
|
||||
//
|
||||
// Parameters:
|
||||
// reader:
|
||||
// The System.Xml.XmlReader stream from which the object is deserialized.
|
||||
public void ReadXml(XmlReader reader)
|
||||
{
|
||||
reader.MoveToContent();
|
||||
reader.ReadStartElement("TDASConfig");
|
||||
|
||||
reader.ReadStartElement("Modules");
|
||||
|
||||
while (reader.MoveToContent() == XmlNodeType.Element)
|
||||
{
|
||||
TDASModuleConfig tConfig = new TDASModuleConfig();
|
||||
tConfig.ReadXml(reader);
|
||||
SetModule(tConfig);
|
||||
}
|
||||
|
||||
reader.ReadEndElement();
|
||||
reader.ReadEndElement();
|
||||
}
|
||||
//
|
||||
// Summary:
|
||||
// Converts an object into its XML representation.
|
||||
//
|
||||
// Parameters:
|
||||
// writer:
|
||||
// The System.Xml.XmlWriter stream to which the object is serialized.
|
||||
public void WriteXml(XmlWriter writer)
|
||||
{
|
||||
writer.WriteStartElement("TDASConfig");
|
||||
|
||||
writer.WriteStartElement("Modules");
|
||||
writer.Flush();
|
||||
|
||||
foreach (TDASModuleConfig module in _modules.Values)
|
||||
{
|
||||
module.WriteXml(writer);
|
||||
writer.Flush();
|
||||
}
|
||||
writer.WriteEndElement();
|
||||
writer.WriteEndElement();
|
||||
writer.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
326
DataPRO/IService/Classes/TDAS/TDASModuleConfig.cs
Normal file
326
DataPRO/IService/Classes/TDAS/TDASModuleConfig.cs
Normal file
@@ -0,0 +1,326 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
using System.Threading;
|
||||
using System.Xml;
|
||||
using System.Xml.Schema;
|
||||
using System.Xml.Serialization;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using DTS.DASLib.Command.SLICE;
|
||||
using DTS.Common.DAS.Concepts;
|
||||
using DTS.Common.Utilities.DotNetProgrammingConstructs;
|
||||
using DTS.Common.Utilities.Logging;
|
||||
using DTS.Common.Enums.DASFactory;
|
||||
|
||||
namespace DTS.DASLib.Service
|
||||
{
|
||||
public class TDASModuleConfig : IXmlSerializable
|
||||
{
|
||||
private string _serialNumber = "";
|
||||
public string SerialNumber { get { return _serialNumber; } set { _serialNumber = value; } }
|
||||
|
||||
private string _testId = "";
|
||||
public string TestId { get { return _testId; } set { _testId = value; } }
|
||||
|
||||
private string _testDescription = "";
|
||||
public string TestDescription { get { return _testDescription; } set { _testDescription = value; } }
|
||||
|
||||
public DFConstantsAndEnums.RecordingMode RecordingMode { get; set; } = DFConstantsAndEnums.RecordingMode.InvalidArmMode;
|
||||
|
||||
private float _aaFilterRateHz = 0;
|
||||
public float AAFilterRateHz { get { return _aaFilterRateHz; } set { _aaFilterRateHz = value; } }
|
||||
|
||||
private double _preTriggerSeconds = 0;
|
||||
public double PreTriggerSeconds { get { return _preTriggerSeconds; } set { _preTriggerSeconds = value; } }
|
||||
|
||||
private double _postTriggerSeconds = 0;
|
||||
public double PostTriggerSeconds { get { return _postTriggerSeconds; } set { _postTriggerSeconds = value; } }
|
||||
|
||||
private Dictionary<int, DASChannel> _channels = new Dictionary<int, DASChannel>();
|
||||
|
||||
private string _fileName;
|
||||
public string FileName { get { return _fileName; } }
|
||||
|
||||
private string _firmwareVersion = "";
|
||||
public string FirmwareVersion { get { return _firmwareVersion; } set { _firmwareVersion = value; } }
|
||||
|
||||
private UInt64? _maxEventStorageSpaceInBytes = 0;
|
||||
public UInt64? MaxEventStorageSpaceInBytes { get { return _maxEventStorageSpaceInBytes; } set { _maxEventStorageSpaceInBytes = value; } }
|
||||
|
||||
private int moduleArrayIndex = 0;
|
||||
public int ModuleArrayIndex { get { return moduleArrayIndex; } set { moduleArrayIndex = value; } }
|
||||
|
||||
public TDASModuleConfig()
|
||||
{
|
||||
}
|
||||
|
||||
public TDASModuleConfig(string fileName)
|
||||
{
|
||||
const string dasConfigs = "DASConfigs";
|
||||
var location = Path.Combine(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), dasConfigs), fileName);
|
||||
_fileName = location; //fileName;
|
||||
if (File.Exists(_fileName))
|
||||
{
|
||||
try
|
||||
{
|
||||
using (StreamReader sr = new StreamReader(_fileName))
|
||||
{
|
||||
ReadXml(System.Xml.XmlReader.Create(sr));
|
||||
}
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
APILogger.Log("Problem reading ", _fileName, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void SetChannel(OutputTOMDigitalChannel channel)
|
||||
{
|
||||
if (_channels.ContainsKey(channel.ModuleChannelNumber)) { _channels[channel.ModuleChannelNumber] = channel; }
|
||||
else { _channels.Add(channel.ModuleChannelNumber, channel); }
|
||||
}
|
||||
public void SetChannel(OutputSquibChannel channel)
|
||||
{
|
||||
if (_channels.ContainsKey(channel.ModuleChannelNumber)) { _channels[channel.ModuleChannelNumber] = channel; }
|
||||
else { _channels.Add(channel.ModuleChannelNumber, channel); }
|
||||
}
|
||||
public void SetChannel(AnalogInputDASChannel channel)
|
||||
{
|
||||
if (_channels.ContainsKey(channel.ModuleChannelNumber)) { _channels[channel.ModuleChannelNumber] = channel; }
|
||||
else { _channels.Add(channel.ModuleChannelNumber, channel); }
|
||||
}
|
||||
public AnalogInputDASChannel GetChannel(AnalogInputDASChannel channel)
|
||||
{
|
||||
if (_channels.ContainsKey(channel.ModuleChannelNumber)) { return _channels[channel.ModuleChannelNumber] as AnalogInputDASChannel; }
|
||||
else
|
||||
{
|
||||
_channels.Add(channel.ModuleChannelNumber, channel);
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
public OutputSquibChannel GetChannel(OutputSquibChannel channel)
|
||||
{
|
||||
if (_channels.ContainsKey(channel.ModuleChannelNumber)) { return _channels[channel.ModuleChannelNumber] as OutputSquibChannel; }
|
||||
else
|
||||
{
|
||||
_channels.Add(channel.ModuleChannelNumber, channel);
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
public OutputTOMDigitalChannel GetChannel(OutputTOMDigitalChannel channel)
|
||||
{
|
||||
if (_channels.ContainsKey(channel.ModuleChannelNumber)) { return _channels[channel.ModuleChannelNumber] as OutputTOMDigitalChannel; }
|
||||
else
|
||||
{
|
||||
_channels.Add(channel.ModuleChannelNumber, channel);
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
public XmlSchema GetSchema()
|
||||
{
|
||||
return (null);
|
||||
}
|
||||
//
|
||||
// Summary:
|
||||
// Generates an object from its XML representation.
|
||||
//
|
||||
// Parameters:
|
||||
// reader:
|
||||
// The System.Xml.XmlReader stream from which the object is deserialized.
|
||||
public void ReadXml(XmlReader reader)
|
||||
{
|
||||
reader.MoveToContent();
|
||||
reader.ReadStartElement("TDASModule");
|
||||
reader.ReadStartElement("SerialNumber");
|
||||
_serialNumber = reader.ReadString();
|
||||
reader.ReadEndElement();
|
||||
reader.ReadStartElement("TestId");
|
||||
_testId = reader.ReadString();
|
||||
reader.ReadEndElement();
|
||||
reader.ReadStartElement("TestDescription");
|
||||
_testDescription = reader.ReadString();
|
||||
reader.ReadEndElement();
|
||||
|
||||
reader.ReadStartElement("RecordingMode");
|
||||
string recordingMode = reader.ReadString();
|
||||
try
|
||||
{
|
||||
RecordingMode = (DFConstantsAndEnums.RecordingMode)Enum.Parse(typeof(DFConstantsAndEnums.RecordingMode), recordingMode);
|
||||
}
|
||||
catch (System.Exception ex) { APILogger.Log("Failed to load RecordingMode ", recordingMode, ex); }
|
||||
reader.ReadEndElement();
|
||||
|
||||
reader.ReadStartElement("AAFilterRateHz");
|
||||
string aaFilterRateHz = reader.ReadString();
|
||||
try
|
||||
{
|
||||
AAFilterRateHz = (float)Convert.ToDouble(aaFilterRateHz);
|
||||
}
|
||||
catch (System.Exception ex) { APILogger.Log("Failed to load AAFilterRateHz ", aaFilterRateHz, ex); }
|
||||
reader.ReadEndElement();
|
||||
|
||||
reader.ReadStartElement("PreTriggerSeconds");
|
||||
string preTriggerSeconds = reader.ReadString();
|
||||
try
|
||||
{
|
||||
PreTriggerSeconds = Convert.ToDouble(preTriggerSeconds);
|
||||
}
|
||||
catch (System.Exception ex) { APILogger.Log("Failed to load PreTriggerSeconds ", preTriggerSeconds, ex); }
|
||||
reader.ReadEndElement();
|
||||
|
||||
reader.ReadStartElement("PostTriggerSeconds");
|
||||
string postTriggerSeconds = reader.ReadString();
|
||||
try
|
||||
{
|
||||
PostTriggerSeconds = Convert.ToDouble(postTriggerSeconds);
|
||||
}
|
||||
catch (System.Exception ex) { APILogger.Log("Failed to load PostTriggerSeconds ", postTriggerSeconds, ex); }
|
||||
reader.ReadEndElement();
|
||||
|
||||
reader.ReadStartElement("FirmwareVersion");
|
||||
_firmwareVersion = reader.ReadString();
|
||||
reader.ReadEndElement();
|
||||
|
||||
reader.ReadStartElement("MaxEventStorageSpaceInBytes");
|
||||
string maxEventStorageSpaceInBytes = reader.ReadString();
|
||||
|
||||
{
|
||||
double d;
|
||||
if (double.TryParse(maxEventStorageSpaceInBytes, out d))
|
||||
{
|
||||
if (d >= 0 && d < ulong.MaxValue) { MaxEventStorageSpaceInBytes = Convert.ToUInt64(d); }
|
||||
else { APILogger.Log("Failed to load MaxEventStorageSpaceInBytes ", maxEventStorageSpaceInBytes); }
|
||||
}
|
||||
else { APILogger.Log("Failed to load MaxEventStorageSpaceInBytes ", maxEventStorageSpaceInBytes); }
|
||||
}
|
||||
reader.ReadEndElement();
|
||||
|
||||
try
|
||||
{
|
||||
reader.ReadStartElement("ModuleArrayIndex");
|
||||
string moduleArrayIndex = reader.ReadString();
|
||||
|
||||
{
|
||||
int m;
|
||||
if (int.TryParse(moduleArrayIndex, out m))
|
||||
{
|
||||
if (m >= 0 && m < int.MaxValue) { ModuleArrayIndex = Convert.ToInt32(m); }
|
||||
else { APILogger.Log("Failed to load ModuleArrayIndex ", moduleArrayIndex); }
|
||||
}
|
||||
else { APILogger.Log("Failed to load ModuleArrayIndex ", moduleArrayIndex); }
|
||||
}
|
||||
reader.ReadEndElement();
|
||||
}
|
||||
catch
|
||||
{
|
||||
//This must be an old config file
|
||||
}
|
||||
|
||||
reader.ReadStartElement("Channels");
|
||||
|
||||
while (reader.MoveToContent() == XmlNodeType.Element)
|
||||
{
|
||||
string sType = reader.GetAttribute("type");
|
||||
switch (sType)
|
||||
{
|
||||
case "OutputSquibChannel":
|
||||
OutputSquibChannel osc = new OutputSquibChannel();
|
||||
osc.ReadXml(reader);
|
||||
SetChannel(osc);
|
||||
break;
|
||||
case "OutputTOMDigitalChannel":
|
||||
OutputTOMDigitalChannel tom = new OutputTOMDigitalChannel();
|
||||
tom.ReadXml(reader);
|
||||
SetChannel(tom);
|
||||
break;
|
||||
default:
|
||||
AnalogInputDASChannel aic = new AnalogInputDASChannel();
|
||||
aic.ReadXml(reader);
|
||||
SetChannel(aic);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
reader.ReadEndElement();
|
||||
reader.ReadEndElement();
|
||||
}
|
||||
//
|
||||
// Summary:
|
||||
// Converts an object into its XML representation.
|
||||
//
|
||||
// Parameters:
|
||||
// writer:
|
||||
// The System.Xml.XmlWriter stream to which the object is serialized.
|
||||
public void WriteXml(XmlWriter writer)
|
||||
{
|
||||
//writer.WriteStartElement ( attributeExtractor.ExtractAttachedAttributeFromObject ( this
|
||||
writer.WriteStartElement("TDASModule");
|
||||
writer.WriteStartElement("SerialNumber");
|
||||
writer.WriteString(SerialNumber);
|
||||
writer.WriteEndElement();
|
||||
writer.WriteStartElement("TestId");
|
||||
writer.WriteString(TestId);
|
||||
writer.WriteEndElement();
|
||||
writer.WriteStartElement("TestDescription");
|
||||
writer.WriteString(TestDescription);
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("RecordingMode");
|
||||
writer.WriteString(RecordingMode.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("AAFilterRateHz");
|
||||
writer.WriteString(AAFilterRateHz.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("PreTriggerSeconds");
|
||||
writer.WriteString(PreTriggerSeconds.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("PostTriggerSeconds");
|
||||
writer.WriteString(PostTriggerSeconds.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("FirmwareVersion");
|
||||
writer.WriteString(FirmwareVersion);
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("MaxEventStorageSpaceInBytes");
|
||||
writer.WriteString(MaxEventStorageSpaceInBytes.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("ModuleArrayIndex");
|
||||
writer.WriteString(ModuleArrayIndex.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("Channels");
|
||||
writer.Flush();
|
||||
|
||||
foreach (DASChannel channel in _channels.Values)
|
||||
{
|
||||
channel.WriteElementStart(writer);
|
||||
channel.WriteXml(writer);
|
||||
channel.WriteElementEnd(writer);
|
||||
writer.Flush();
|
||||
}
|
||||
writer.WriteEndElement();
|
||||
writer.WriteEndElement();
|
||||
writer.Flush();
|
||||
}
|
||||
public virtual void WriteElementStart(XmlWriter writer)
|
||||
{
|
||||
writer.WriteStartElement("TDASModule");
|
||||
var tgt = GetType();
|
||||
writer.WriteAttributeString("xsi", "type", null, tgt.Name);
|
||||
}
|
||||
|
||||
public virtual void WriteElementEnd(XmlWriter writer)
|
||||
{
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
23
DataPRO/IService/Classes/TDAS/TDASServiceSetupInfo.cs
Normal file
23
DataPRO/IService/Classes/TDAS/TDASServiceSetupInfo.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using DTS.Common.DAS.Concepts;
|
||||
using DTS.Common.Enums.DASFactory;
|
||||
|
||||
namespace DTS.DASLib.Service
|
||||
{
|
||||
public class TDASServiceSetupInfo
|
||||
{
|
||||
public string SetupDescription { get; set; }
|
||||
public double? SamplesPerSecond { get; set; }
|
||||
public float HardwareFilterRateHz { get; set; }
|
||||
public DFConstantsAndEnums.RecordingMode RecordingMode { get; set; }
|
||||
public bool? CheckoutMode { get; set; }
|
||||
|
||||
public TDASServiceSetupInfo(string setupDescription, double? samplesPerSecond, float hardwareFilterRateHz, DFConstantsAndEnums.RecordingMode recordingMode, bool? checkoutMode)
|
||||
{
|
||||
SetupDescription = setupDescription;
|
||||
SamplesPerSecond = samplesPerSecond;
|
||||
HardwareFilterRateHz = hardwareFilterRateHz;
|
||||
RecordingMode = recordingMode;
|
||||
CheckoutMode = checkoutMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
DataPRO/IService/Classes/TDAS/TDASServiceSetupInfoLookup.cs
Normal file
28
DataPRO/IService/Classes/TDAS/TDASServiceSetupInfoLookup.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using DTS.Common.DAS.Concepts;
|
||||
using DTS.Common.Enums.DASFactory;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DTS.DASLib.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// This is identical to TDASServiceSetupInfo except that the SamplesPerSecond and HardwareFilterRateHz
|
||||
/// are Dictionaries so that they can differ based on the DAS being used.
|
||||
/// </summary>
|
||||
public class TDASServiceSetupInfoLookup
|
||||
{
|
||||
public string SetupDescription { get; set; }
|
||||
public Dictionary<string, double> SamplesPerSecondLookup { get; set; }
|
||||
public Dictionary<string, float> HardwareFilterRateHzLookup { get; set; }
|
||||
public DFConstantsAndEnums.RecordingMode RecordingMode { get; set; }
|
||||
public bool? CheckoutMode { get; set; }
|
||||
|
||||
public TDASServiceSetupInfoLookup(string setupDescription, Dictionary<string, double> sampleRateLookup, Dictionary<string, float> aafLookup, DFConstantsAndEnums.RecordingMode recordingMode, bool? checkoutMode)
|
||||
{
|
||||
SetupDescription = setupDescription;
|
||||
SamplesPerSecondLookup = sampleRateLookup;
|
||||
HardwareFilterRateHzLookup = aafLookup;
|
||||
RecordingMode = recordingMode;
|
||||
CheckoutMode = checkoutMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user