mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-06 16:25:01 +00:00
chore: move all files to file-scoped namespace
This commit is contained in:
@@ -11,8 +11,8 @@ using System.ComponentModel;
|
||||
using PepperDash.Core;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
namespace PepperDash.Essentials.Core;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
@@ -53,5 +53,4 @@ namespace PepperDash.Essentials.Core
|
||||
else
|
||||
StartErrorTimers();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,48 +3,48 @@ using PepperDash.Core;
|
||||
using System.Threading;
|
||||
using PepperDash.Core.Logging;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
namespace PepperDash.Essentials.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Used for monitoring comms that are IBasicCommunication. Will send a poll string and provide an event when
|
||||
/// statuses change.
|
||||
/// Default monitoring uses TextReceived event on Client.
|
||||
/// Default monitoring uses TextReceived event on Client.
|
||||
/// </summary>
|
||||
public class GenericCommunicationMonitor : StatusMonitorBase
|
||||
{
|
||||
public IBasicCommunication Client { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Will monitor Client.BytesReceived if set to true. Otherwise the default is to monitor Client.TextReceived
|
||||
/// </summary>
|
||||
public bool MonitorBytesReceived { get; private set; }
|
||||
/// <summary>
|
||||
/// Will monitor Client.BytesReceived if set to true. Otherwise the default is to monitor Client.TextReceived
|
||||
/// </summary>
|
||||
public bool MonitorBytesReceived { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Return true if the Client is ISocketStatus
|
||||
/// </summary>
|
||||
public bool IsSocket => Client is ISocketStatus;
|
||||
/// <summary>
|
||||
/// Return true if the Client is ISocketStatus
|
||||
/// </summary>
|
||||
public bool IsSocket => Client is ISocketStatus;
|
||||
|
||||
private readonly string PollString;
|
||||
private readonly Action PollAction;
|
||||
private readonly long PollTime;
|
||||
private readonly string PollString;
|
||||
private readonly Action PollAction;
|
||||
private readonly long PollTime;
|
||||
|
||||
private Timer PollTimer;
|
||||
|
||||
private SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
|
||||
private SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
|
||||
|
||||
/// <summary>
|
||||
/// GenericCommunicationMonitor constructor
|
||||
///
|
||||
/// Note: If the client is a socket, the connection status will be monitored and the PollTimer will be started automatically when the client is connected
|
||||
/// </summary>
|
||||
/// <param name="parent">Parent device</param>
|
||||
/// <param name="client">Communications Client</param>
|
||||
/// <param name="pollTime">Time in MS for polling</param>
|
||||
/// <param name="warningTime">Warning time in MS. If a message is not received before this elapsed time the status will be Warning</param>
|
||||
/// <param name="errorTime">Error time in MS. If a message is not received before this elapsed time the status will be Error</param>
|
||||
/// <param name="pollString">string to send for polling</param>
|
||||
/// <exception cref="ArgumentException">Poll time must be less than warning and error time</exception>
|
||||
public GenericCommunicationMonitor(IKeyed parent, IBasicCommunication client, long pollTime,
|
||||
/// <summary>
|
||||
/// GenericCommunicationMonitor constructor
|
||||
///
|
||||
/// Note: If the client is a socket, the connection status will be monitored and the PollTimer will be started automatically when the client is connected
|
||||
/// </summary>
|
||||
/// <param name="parent">Parent device</param>
|
||||
/// <param name="client">Communications Client</param>
|
||||
/// <param name="pollTime">Time in MS for polling</param>
|
||||
/// <param name="warningTime">Warning time in MS. If a message is not received before this elapsed time the status will be Warning</param>
|
||||
/// <param name="errorTime">Error time in MS. If a message is not received before this elapsed time the status will be Error</param>
|
||||
/// <param name="pollString">string to send for polling</param>
|
||||
/// <exception cref="ArgumentException">Poll time must be less than warning and error time</exception>
|
||||
public GenericCommunicationMonitor(IKeyed parent, IBasicCommunication client, long pollTime,
|
||||
long warningTime, long errorTime, string pollString) :
|
||||
base(parent, warningTime, errorTime)
|
||||
{
|
||||
@@ -55,212 +55,212 @@ namespace PepperDash.Essentials.Core
|
||||
PollTime = pollTime;
|
||||
PollString = pollString;
|
||||
|
||||
if (IsSocket)
|
||||
{
|
||||
(Client as ISocketStatus).ConnectionChange += Socket_ConnectionChange;
|
||||
}
|
||||
if (IsSocket)
|
||||
{
|
||||
(Client as ISocketStatus).ConnectionChange += Socket_ConnectionChange;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GenericCommunicationMonitor constructor with a bool to specify whether to monitor BytesReceived
|
||||
///
|
||||
/// Note: If the client is a socket, the connection status will be monitored and the PollTimer will be started automatically when the client is connected
|
||||
/// </summary>
|
||||
/// <param name="parent">Parent device</param>
|
||||
/// <param name="client">Communications Client</param>
|
||||
/// <param name="pollTime">Time in MS for polling</param>
|
||||
/// <param name="warningTime">Warning time in MS. If a message is not received before this elapsed time the status will be Warning</param>
|
||||
/// <param name="errorTime">Error time in MS. If a message is not received before this elapsed time the status will be Error</param>
|
||||
/// <param name="pollString">string to send for polling</param>
|
||||
/// <param name="monitorBytesReceived">Use bytesReceived event instead of textReceived when true</param>
|
||||
public GenericCommunicationMonitor(IKeyed parent, IBasicCommunication client, long pollTime,
|
||||
long warningTime, long errorTime, string pollString, bool monitorBytesReceived) :
|
||||
this(parent, client, pollTime, warningTime, errorTime, pollString)
|
||||
/// <summary>
|
||||
/// GenericCommunicationMonitor constructor with a bool to specify whether to monitor BytesReceived
|
||||
///
|
||||
/// Note: If the client is a socket, the connection status will be monitored and the PollTimer will be started automatically when the client is connected
|
||||
/// </summary>
|
||||
/// <param name="parent">Parent device</param>
|
||||
/// <param name="client">Communications Client</param>
|
||||
/// <param name="pollTime">Time in MS for polling</param>
|
||||
/// <param name="warningTime">Warning time in MS. If a message is not received before this elapsed time the status will be Warning</param>
|
||||
/// <param name="errorTime">Error time in MS. If a message is not received before this elapsed time the status will be Error</param>
|
||||
/// <param name="pollString">string to send for polling</param>
|
||||
/// <param name="monitorBytesReceived">Use bytesReceived event instead of textReceived when true</param>
|
||||
public GenericCommunicationMonitor(IKeyed parent, IBasicCommunication client, long pollTime,
|
||||
long warningTime, long errorTime, string pollString, bool monitorBytesReceived) :
|
||||
this(parent, client, pollTime, warningTime, errorTime, pollString)
|
||||
{
|
||||
MonitorBytesReceived = monitorBytesReceived;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GenericCommunicationMonitor constructor with a poll action instead of a poll string
|
||||
///
|
||||
/// Note: If the client is a socket, the connection status will be monitored and the PollTimer will be started automatically when the client is connected
|
||||
/// </summary>
|
||||
/// <param name="parent">Parent device</param>
|
||||
/// <param name="client">Communications Client</param>
|
||||
/// <param name="pollTime">Time in MS for polling</param>
|
||||
/// <param name="warningTime">Warning time in MS. If a message is not received before this elapsed time the status will be Warning</param>
|
||||
/// <param name="errorTime">Error time in MS. If a message is not received before this elapsed time the status will be Error</param>
|
||||
/// <param name="pollAction">Action to execute for polling</param>
|
||||
/// <exception cref="ArgumentException">Poll time must be less than warning and error time</exception>
|
||||
public GenericCommunicationMonitor(IKeyed parent, IBasicCommunication client, long pollTime,
|
||||
long warningTime, long errorTime, Action pollAction) :
|
||||
base(parent, warningTime, errorTime)
|
||||
{
|
||||
if (pollTime > warningTime || pollTime > errorTime)
|
||||
throw new ArgumentException("pollTime must be less than warning or errorTime");
|
||||
//if (pollTime < 5000)
|
||||
// throw new ArgumentException("pollTime cannot be less than 5000 ms");
|
||||
|
||||
Client = client;
|
||||
PollTime = pollTime;
|
||||
PollAction = pollAction;
|
||||
|
||||
if (IsSocket)
|
||||
{
|
||||
MonitorBytesReceived = monitorBytesReceived;
|
||||
(Client as ISocketStatus).ConnectionChange += Socket_ConnectionChange;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GenericCommunicationMonitor constructor with a poll action instead of a poll string
|
||||
///
|
||||
/// Note: If the client is a socket, the connection status will be monitored and the PollTimer will be started automatically when the client is connected
|
||||
/// </summary>
|
||||
/// <param name="parent">Parent device</param>
|
||||
/// <param name="client">Communications Client</param>
|
||||
/// <param name="pollTime">Time in MS for polling</param>
|
||||
/// <param name="warningTime">Warning time in MS. If a message is not received before this elapsed time the status will be Warning</param>
|
||||
/// <param name="errorTime">Error time in MS. If a message is not received before this elapsed time the status will be Error</param>
|
||||
/// <param name="pollAction">Action to execute for polling</param>
|
||||
/// <exception cref="ArgumentException">Poll time must be less than warning and error time</exception>
|
||||
public GenericCommunicationMonitor(IKeyed parent, IBasicCommunication client, long pollTime,
|
||||
long warningTime, long errorTime, Action pollAction) :
|
||||
base(parent, warningTime, errorTime)
|
||||
{
|
||||
if (pollTime > warningTime || pollTime > errorTime)
|
||||
throw new ArgumentException("pollTime must be less than warning or errorTime");
|
||||
//if (pollTime < 5000)
|
||||
// throw new ArgumentException("pollTime cannot be less than 5000 ms");
|
||||
}
|
||||
|
||||
Client = client;
|
||||
PollTime = pollTime;
|
||||
PollAction = pollAction;
|
||||
|
||||
if (IsSocket)
|
||||
{
|
||||
(Client as ISocketStatus).ConnectionChange += Socket_ConnectionChange;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GenericCommunicationMonitor constructor with a poll action instead of a poll string and a bool to specify whether to monitor BytesReceived
|
||||
///
|
||||
/// Note: If the client is a socket, the connection status will be monitored and the PollTimer will be started automatically when the client is connected
|
||||
/// </summary>
|
||||
/// <param name="parent">Parent device</param>
|
||||
/// <param name="client">Communications Client</param>
|
||||
/// <param name="pollTime">Time in MS for polling</param>
|
||||
/// <param name="warningTime">Warning time in MS. If a message is not received before this elapsed time the status will be Warning</param>
|
||||
/// <param name="errorTime">Error time in MS. If a message is not received before this elapsed time the status will be Error</param>
|
||||
/// <param name="pollAction">Action to execute for polling</param>
|
||||
/// <param name="monitorBytesReceived">Use bytesReceived event instead of textReceived when true</param>
|
||||
public GenericCommunicationMonitor(IKeyed parent, IBasicCommunication client, long pollTime,
|
||||
long warningTime, long errorTime, Action pollAction, bool monitorBytesReceived) :
|
||||
this(parent, client, pollTime, warningTime, errorTime, pollAction)
|
||||
{
|
||||
MonitorBytesReceived = monitorBytesReceived;
|
||||
}
|
||||
/// <summary>
|
||||
/// GenericCommunicationMonitor constructor with a poll action instead of a poll string and a bool to specify whether to monitor BytesReceived
|
||||
///
|
||||
/// Note: If the client is a socket, the connection status will be monitored and the PollTimer will be started automatically when the client is connected
|
||||
/// </summary>
|
||||
/// <param name="parent">Parent device</param>
|
||||
/// <param name="client">Communications Client</param>
|
||||
/// <param name="pollTime">Time in MS for polling</param>
|
||||
/// <param name="warningTime">Warning time in MS. If a message is not received before this elapsed time the status will be Warning</param>
|
||||
/// <param name="errorTime">Error time in MS. If a message is not received before this elapsed time the status will be Error</param>
|
||||
/// <param name="pollAction">Action to execute for polling</param>
|
||||
/// <param name="monitorBytesReceived">Use bytesReceived event instead of textReceived when true</param>
|
||||
public GenericCommunicationMonitor(IKeyed parent, IBasicCommunication client, long pollTime,
|
||||
long warningTime, long errorTime, Action pollAction, bool monitorBytesReceived) :
|
||||
this(parent, client, pollTime, warningTime, errorTime, pollAction)
|
||||
{
|
||||
MonitorBytesReceived = monitorBytesReceived;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// GenericCommunicationMonitor constructor with a config object
|
||||
///
|
||||
/// Note: If the client is a socket, the connection status will be monitored and the PollTimer will be started automatically when the client is connected
|
||||
/// </summary>
|
||||
/// <param name="parent">Parent Device</param>
|
||||
/// <param name="client">Communications Client</param>
|
||||
/// <param name="props"><see cref="CommunicationMonitorConfig">Communication Monitor Config</see> object</param>
|
||||
public GenericCommunicationMonitor(IKeyed parent, IBasicCommunication client,
|
||||
/// <summary>
|
||||
/// GenericCommunicationMonitor constructor with a config object
|
||||
///
|
||||
/// Note: If the client is a socket, the connection status will be monitored and the PollTimer will be started automatically when the client is connected
|
||||
/// </summary>
|
||||
/// <param name="parent">Parent Device</param>
|
||||
/// <param name="client">Communications Client</param>
|
||||
/// <param name="props"><see cref="CommunicationMonitorConfig">Communication Monitor Config</see> object</param>
|
||||
public GenericCommunicationMonitor(IKeyed parent, IBasicCommunication client,
|
||||
CommunicationMonitorConfig props) :
|
||||
this(parent, client, props.PollInterval, props.TimeToWarning, props.TimeToError, props.PollString)
|
||||
{
|
||||
if (IsSocket)
|
||||
{
|
||||
(Client as ISocketStatus).ConnectionChange += Socket_ConnectionChange;
|
||||
}
|
||||
if (IsSocket)
|
||||
{
|
||||
(Client as ISocketStatus).ConnectionChange += Socket_ConnectionChange;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GenericCommunicationMonitor constructor with a config object and a bool to specify whether to monitor BytesReceived
|
||||
///
|
||||
/// Note: If the client is a socket, the connection status will be monitored and the PollTimer will be started automatically when the client is connected
|
||||
/// </summary>
|
||||
/// <param name="parent">Parent Device</param>
|
||||
/// <param name="client">Communications Client</param>
|
||||
/// <param name="props"><see cref="CommunicationMonitorConfig">Communication Monitor Config</see> object</param>
|
||||
/// <param name="monitorBytesReceived">Use bytesReceived event instead of textReceived when true</param>
|
||||
public GenericCommunicationMonitor(IKeyed parent, IBasicCommunication client, CommunicationMonitorConfig props, bool monitorBytesReceived) :
|
||||
this(parent, client, props.PollInterval, props.TimeToWarning, props.TimeToError, props.PollString)
|
||||
{
|
||||
MonitorBytesReceived = monitorBytesReceived;
|
||||
}
|
||||
/// <summary>
|
||||
/// GenericCommunicationMonitor constructor with a config object and a bool to specify whether to monitor BytesReceived
|
||||
///
|
||||
/// Note: If the client is a socket, the connection status will be monitored and the PollTimer will be started automatically when the client is connected
|
||||
/// </summary>
|
||||
/// <param name="parent">Parent Device</param>
|
||||
/// <param name="client">Communications Client</param>
|
||||
/// <param name="props"><see cref="CommunicationMonitorConfig">Communication Monitor Config</see> object</param>
|
||||
/// <param name="monitorBytesReceived">Use bytesReceived event instead of textReceived when true</param>
|
||||
public GenericCommunicationMonitor(IKeyed parent, IBasicCommunication client, CommunicationMonitorConfig props, bool monitorBytesReceived) :
|
||||
this(parent, client, props.PollInterval, props.TimeToWarning, props.TimeToError, props.PollString)
|
||||
{
|
||||
MonitorBytesReceived = monitorBytesReceived;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start the poll cycle
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Start the poll cycle
|
||||
/// </summary>
|
||||
public override void Start()
|
||||
{
|
||||
if (MonitorBytesReceived)
|
||||
{
|
||||
if (MonitorBytesReceived)
|
||||
{
|
||||
Client.BytesReceived -= Client_BytesReceived;
|
||||
Client.BytesReceived += Client_BytesReceived;
|
||||
}
|
||||
else
|
||||
{
|
||||
Client.TextReceived -= Client_TextReceived;
|
||||
Client.TextReceived += Client_TextReceived;
|
||||
}
|
||||
Client.BytesReceived += Client_BytesReceived;
|
||||
}
|
||||
else
|
||||
{
|
||||
Client.TextReceived -= Client_TextReceived;
|
||||
Client.TextReceived += Client_TextReceived;
|
||||
}
|
||||
|
||||
BeginPolling();
|
||||
BeginPolling();
|
||||
}
|
||||
|
||||
private void Socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs e)
|
||||
private void Socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs e)
|
||||
{
|
||||
if (!e.Client.IsConnected)
|
||||
{
|
||||
if (!e.Client.IsConnected)
|
||||
{
|
||||
// Immediately stop polling and notify that device is offline
|
||||
Stop();
|
||||
Status = MonitorStatus.InError;
|
||||
ResetErrorTimers();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Start polling and set status to unknow and let poll result update the status to IsOk when a response is received
|
||||
Status = MonitorStatus.StatusUnknown;
|
||||
Start();
|
||||
}
|
||||
// Immediately stop polling and notify that device is offline
|
||||
Stop();
|
||||
Status = MonitorStatus.InError;
|
||||
ResetErrorTimers();
|
||||
}
|
||||
|
||||
private void BeginPolling()
|
||||
else
|
||||
{
|
||||
try
|
||||
// Start polling and set status to unknow and let poll result update the status to IsOk when a response is received
|
||||
Status = MonitorStatus.StatusUnknown;
|
||||
Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void BeginPolling()
|
||||
{
|
||||
try
|
||||
{
|
||||
semaphore.Wait();
|
||||
{
|
||||
semaphore.Wait();
|
||||
if (PollTimer != null)
|
||||
{
|
||||
if (PollTimer != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PollTimer = new Timer(o => Poll(), null, 0, PollTime);
|
||||
return;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
semaphore.Release();
|
||||
|
||||
PollTimer = new Timer(o => Poll(), null, 0, PollTime);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
semaphore.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop the poll cycle
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Stop the poll cycle
|
||||
/// </summary>
|
||||
public override void Stop()
|
||||
{
|
||||
if(MonitorBytesReceived)
|
||||
{
|
||||
if(MonitorBytesReceived)
|
||||
{
|
||||
Client.BytesReceived -= Client_BytesReceived;
|
||||
}
|
||||
else
|
||||
{
|
||||
Client.TextReceived -= Client_TextReceived;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Client.TextReceived -= Client_TextReceived;
|
||||
}
|
||||
|
||||
StopErrorTimers();
|
||||
StopErrorTimers();
|
||||
|
||||
if (PollTimer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PollTimer.Dispose();
|
||||
PollTimer = null;
|
||||
if (PollTimer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PollTimer.Dispose();
|
||||
PollTimer = null;
|
||||
}
|
||||
|
||||
private void Client_TextReceived(object sender, GenericCommMethodReceiveTextArgs e)
|
||||
{
|
||||
DataReceived();
|
||||
}
|
||||
private void Client_TextReceived(object sender, GenericCommMethodReceiveTextArgs e)
|
||||
{
|
||||
DataReceived();
|
||||
}
|
||||
|
||||
private void Client_BytesReceived(object sender, GenericCommMethodReceiveBytesArgs e)
|
||||
{
|
||||
DataReceived();
|
||||
}
|
||||
DataReceived();
|
||||
}
|
||||
|
||||
private void DataReceived()
|
||||
{
|
||||
Status = MonitorStatus.IsOk;
|
||||
ResetErrorTimers();
|
||||
}
|
||||
private void DataReceived()
|
||||
{
|
||||
Status = MonitorStatus.IsOk;
|
||||
ResetErrorTimers();
|
||||
}
|
||||
|
||||
private void Poll()
|
||||
{
|
||||
@@ -268,10 +268,10 @@ namespace PepperDash.Essentials.Core
|
||||
if (Client.IsConnected)
|
||||
{
|
||||
//Debug.LogMessage(LogEventLevel.Verbose, this, "Polling");
|
||||
if(PollAction != null)
|
||||
PollAction.Invoke();
|
||||
else
|
||||
Client.SendText(PollString);
|
||||
if(PollAction != null)
|
||||
PollAction.Invoke();
|
||||
else
|
||||
Client.SendText(PollString);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -280,9 +280,9 @@ namespace PepperDash.Essentials.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Communication Monitor Configuration from Essentials Configuration
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Communication Monitor Configuration from Essentials Configuration
|
||||
/// </summary>
|
||||
public class CommunicationMonitorConfig
|
||||
{
|
||||
public int PollInterval { get; set; }
|
||||
@@ -290,9 +290,9 @@ namespace PepperDash.Essentials.Core
|
||||
public int TimeToError { get; set; }
|
||||
public string PollString { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor. Sets pollInterval to 30s, TimeToWarning to 120s, and TimeToError to 300s
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Default constructor. Sets pollInterval to 30s, TimeToWarning to 120s, and TimeToError to 300s
|
||||
/// </summary>
|
||||
public CommunicationMonitorConfig()
|
||||
{
|
||||
PollInterval = 30000;
|
||||
@@ -300,5 +300,4 @@ namespace PepperDash.Essentials.Core
|
||||
TimeToError = 300000;
|
||||
PollString = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@ using System;
|
||||
using PepperDash.Core;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
namespace PepperDash.Essentials.Core;
|
||||
|
||||
public interface IStatusMonitor
|
||||
{
|
||||
IKeyed Parent { get; }
|
||||
@@ -31,10 +31,10 @@ namespace PepperDash.Essentials.Core
|
||||
/// </summary>
|
||||
public enum MonitorStatus
|
||||
{
|
||||
StatusUnknown = 0,
|
||||
StatusUnknown = 0,
|
||||
IsOk = 1,
|
||||
InWarning = 2,
|
||||
InError = 3
|
||||
InWarning = 2,
|
||||
InError = 3
|
||||
}
|
||||
|
||||
public class MonitorStatusChangeEventArgs : EventArgs
|
||||
@@ -53,5 +53,4 @@ namespace PepperDash.Essentials.Core
|
||||
Status = status;
|
||||
Message = message;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,18 +11,18 @@ using System.ComponentModel;
|
||||
using PepperDash.Core;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
namespace PepperDash.Essentials.Core;
|
||||
|
||||
public abstract class StatusMonitorBase : IStatusMonitor, IKeyName
|
||||
{
|
||||
public event EventHandler<MonitorStatusChangeEventArgs> StatusChange;
|
||||
|
||||
/// <summary>
|
||||
/// Format returned: "parentdevkey-comMonitor"
|
||||
/// </summary>
|
||||
public string Key { get { return Parent.Key + "-comMonitor"; } }
|
||||
/// <summary>
|
||||
/// Format returned: "parentdevkey-comMonitor"
|
||||
/// </summary>
|
||||
public string Key { get { return Parent.Key + "-comMonitor"; } }
|
||||
|
||||
public string Name { get { return "Comm. monitor"; } }
|
||||
public string Name { get { return "Comm. monitor"; } }
|
||||
|
||||
public IKeyed Parent { get; private set; }
|
||||
|
||||
@@ -118,13 +118,12 @@ namespace PepperDash.Essentials.Core
|
||||
ErrorTimer = null;
|
||||
}
|
||||
|
||||
protected void ResetErrorTimers()
|
||||
{
|
||||
if(WarningTimer != null)
|
||||
WarningTimer.Reset(WarningTime, WarningTime);
|
||||
if(ErrorTimer != null)
|
||||
ErrorTimer.Reset(ErrorTime, ErrorTime);
|
||||
protected void ResetErrorTimers()
|
||||
{
|
||||
if(WarningTimer != null)
|
||||
WarningTimer.Reset(WarningTime, WarningTime);
|
||||
if(ErrorTimer != null)
|
||||
ErrorTimer.Reset(ErrorTime, ErrorTime);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,8 @@ using System.ComponentModel;
|
||||
using PepperDash.Core;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
namespace PepperDash.Essentials.Core;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
@@ -70,28 +70,28 @@ namespace PepperDash.Essentials.Core
|
||||
initialStatus = MonitorStatus.StatusUnknown;
|
||||
|
||||
// Build the error message string
|
||||
if (InError.Count() > 0 || InWarning.Count() > 0)
|
||||
if (InError.Count() > 0 || InWarning.Count() > 0)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(prefix);
|
||||
if (InError.Count() > 0)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(prefix);
|
||||
if (InError.Count() > 0)
|
||||
{
|
||||
// Do string splits and joins
|
||||
sb.Append(string.Format("{0} Errors:", InError.Count()));
|
||||
foreach (var mon in InError)
|
||||
sb.Append(string.Format("{0}, ", mon.Parent.Key));
|
||||
}
|
||||
if (InWarning.Count() > 0)
|
||||
{
|
||||
sb.Append(string.Format("{0} Warnings:", InWarning.Count()));
|
||||
foreach (var mon in InWarning)
|
||||
sb.Append(string.Format("{0}, ", mon.Parent.Key));
|
||||
}
|
||||
Message = sb.ToString();
|
||||
// Do string splits and joins
|
||||
sb.Append(string.Format("{0} Errors:", InError.Count()));
|
||||
foreach (var mon in InError)
|
||||
sb.Append(string.Format("{0}, ", mon.Parent.Key));
|
||||
}
|
||||
else
|
||||
if (InWarning.Count() > 0)
|
||||
{
|
||||
Message = "Room Ok.";
|
||||
sb.Append(string.Format("{0} Warnings:", InWarning.Count()));
|
||||
foreach (var mon in InWarning)
|
||||
sb.Append(string.Format("{0}, ", mon.Parent.Key));
|
||||
}
|
||||
Message = sb.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
Message = "Room Ok.";
|
||||
}
|
||||
|
||||
// Want to fire even if status doesn't change because the message may.
|
||||
Status = initialStatus;
|
||||
@@ -124,5 +124,4 @@ namespace PepperDash.Essentials.Core
|
||||
if (handler != null)
|
||||
handler(this, new MonitorStatusChangeEventArgs(status, message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user