This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,109 @@
using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.IO;
using DTS.Common.Utilities.Logging;
namespace DTS.DASLib.Service
{
public class CANConfig : IXmlSerializable
{
private readonly Dictionary<string, CANModuleConfig> _modules = new Dictionary<string, CANModuleConfig>();
public Dictionary<string, CANModuleConfig> Modules { get { return _modules; } }
private readonly string _fileName;
public string FileName { get { return _fileName; } }
public CANConfig()
{
}
public CANConfig(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;
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(CANModuleConfig module)
{
if (_modules.ContainsKey(module.SerialNumber)) { _modules[module.SerialNumber] = module; }
else { _modules.Add(module.SerialNumber, module); }
}
public CANModuleConfig GetModule(CANModuleConfig 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("CANConfig");
reader.ReadStartElement("Modules");
while (reader.MoveToContent() == XmlNodeType.Element)
{
CANModuleConfig tConfig = new CANModuleConfig();
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("CANConfig");
writer.WriteStartElement("Modules");
writer.Flush();
foreach (CANModuleConfig module in _modules.Values)
{
module.WriteXml(writer);
writer.Flush();
}
writer.WriteEndElement();
writer.WriteEndElement();
writer.Flush();
}
}
}