Major upgrade

This commit is contained in:
Duc
2025-10-24 15:18:11 -07:00
parent fd85735c93
commit ce583d1664
478 changed files with 237518 additions and 47610 deletions

View File

@@ -22,329 +22,287 @@ using Raytheon.Common;
namespace Raytheon.Instruments
{
/// <summary>
/// A simulated implementation of the ISwitch interface.
/// </summary>
public class SwitchSim : ISwitch
{
#region PrivateMemberVariables
/// <summary>
/// A simulated implementation of the ISwitch interface.
/// </summary>
public class SwitchSim : ISwitch
{
#region PrivateMemberVariables
private Dictionary<String, bool> _relayStates;
private string _name;
private State _state;
private SelfTestResult _selfTestResult;
private Dictionary<String, bool> _relayStates;
private string _name;
private State _state;
private SelfTestResult _selfTestResult;
/// <summary>
/// NLog logger
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Raytheon configuration
/// </summary>
private readonly IConfigurationManager _configurationManager;
private readonly IConfiguration _configuration;
private readonly ILogger _logger;
#endregion
private readonly IConfigurationManager _configurationManager;
private readonly IConfiguration _configuration;
#region PrivateFunctions
#endregion
/// <summary>
/// The Finalizer
/// </summary>
~SwitchSim()
{
Dispose(false);
}
#region PrivateFunctions
/// <summary>
/// Dispose of this object's resources.
/// </summary>
/// <param name="disposing">True = currently disposing, False = not disposing.</param>
protected virtual void Dispose(bool disposing)
{
try
{
if (disposing)
{
if (_state == State.Ready)
{
_state = State.Uninitialized;
}
}
}
catch (Exception)
{
try
{
//ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
}
catch (Exception)
{
//Do not rethrow. Exception from error logger that has already been garbage collected
}
}
}
/// <summary>
/// The Finalizer
/// </summary>
~SwitchSim()
{
Dispose(false);
}
/// <summary>
/// Close a relay (simulated).
/// </summary>
/// <param name="relay">The relay to close.</param>
private void RelayClose(string relay)
{
_relayStates[relay] = true;
}
/// <summary>
/// Dispose of this object's resources.
/// </summary>
/// <param name="disposing">True = currently disposing, False = not disposing.</param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (_state == State.Ready)
{
_state = State.Uninitialized;
}
}
}
/// <summary>
/// Open a relay (simulated).
/// </summary>
/// <param name="relay">The relay to open.</param>
private void RelayOpen(string relay)
{
_relayStates[relay] = false;
}
/// <summary>
/// Close a relay (simulated).
/// </summary>
/// <param name="relay">The relay to close.</param>
private void OperateRelays(string path, bool state)
{
_relayStates[path] = state;
}
/// <summary>
///
/// </summary>
private void RelayOpenAll()
{
List<string> keys = new List<string>(_relayStates.Keys);
/// <summary>
///
/// </summary>
private void RelayOpenAll()
{
List<string> keys = new List<string>(_relayStates.Keys);
foreach (string key in keys)
{
_relayStates[key] = false;
}
}
foreach (string key in keys)
{
_relayStates[key] = false;
}
}
#endregion
#endregion
#region PublicFunctions
#region PublicFunctions
/// <summary>
/// SwitchSim factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public SwitchSim(string deviceName, IConfigurationManager configurationManager, ILogger logger)
{
Name = deviceName;
/// <summary>
/// SwitchSim factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public SwitchSim(string deviceName, IConfigurationManager configurationManager)
{
Name = deviceName;
_logger = logger;
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_relayStates = new Dictionary<String, bool>();
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
_relayStates = new Dictionary<String, bool>();
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
/// Constructor for RelaySwitch card (simulated).
/// </summary>
public SwitchSim(string name)
{
_name = name;
_logger = LogManager.GetCurrentClassLogger();
_relayStates = new Dictionary<String, bool>();
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
/// Constructor for RelaySwitch card (simulated).
/// </summary>
public SwitchSim(string deviceName)
{
_name = deviceName;
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
_relayStates = new Dictionary<String, bool>();
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Connect(string path)
{
RelayClose(path);
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Connect(string path)
{
OperateRelays(path, true);
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Disconnect(string path)
{
RelayOpen(path);
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Disconnect(string path)
{
OperateRelays(path, false);
}
/// <summary>
///
/// </summary>
public void DisconnectAll()
{
RelayOpenAll();
}
/// <summary>
///
/// </summary>
public void DisconnectAll()
{
RelayOpenAll();
}
/// <summary>
/// Dispose of this object.
/// </summary>
public void Dispose()
{
try
{
Dispose(true);
/// <summary>
/// Dispose of this object.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
catch (Exception)
{
try
{
//ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
}
catch (Exception)
{
//Do not rethrow. Exception from error logger that has already been garbage collected
}
}
}
GC.SuppressFinalize(this);
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a Sim Switch";
}
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a Sim Switch";
}
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public bool FrontPanelEnabled
{
get
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public bool FrontPanelEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public bool IsDebounced
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public bool IsDebounced
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public void Initialize()
{
if (_state == State.Uninitialized)
{
_state = State.Ready;
}
else
{
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
}
}
/// <summary>
///
/// </summary>
public void Initialize()
{
if (_state == State.Uninitialized)
{
_state = State.Ready;
}
else
{
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
}
}
/// <summary>
///
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
/// <summary>
///
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public void Reset()
{
}
/// <summary>
///
/// </summary>
public void Reset()
{
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
/// <summary>
///
/// </summary>
public void Shutdown()
{
_state = State.Uninitialized;
}
/// <summary>
///
/// </summary>
public void Shutdown()
{
_state = State.Uninitialized;
}
#endregion
}
#endregion
}
}