Files
WMS/HHWMS.Web/Services/MqttRuntimeState.cs

28 lines
714 B
C#

using System;
using System.Threading;
namespace HHWMS.Web.Services
{
public class MqttRuntimeState
{
private int _enabled;
public bool Enabled => Volatile.Read(ref _enabled) == 1;
public DateTime? LastChangedAt { get; private set; }
public string LastChangedBy { get; private set; }
public void Update(bool enabled, string changedBy = null)
{
var oldEnabled = Enabled;
Volatile.Write(ref _enabled, enabled ? 1 : 0);
if (oldEnabled != enabled || string.IsNullOrEmpty(LastChangedBy))
{
LastChangedAt = DateTime.Now;
LastChangedBy = changedBy;
}
}
}
}