mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-13 11:44:54 +00:00
In order to solve some dependency issues that keep cropping up, MC should be moved back into the Essentials repo and loaded automatically on startup. This will allow for all plugins that use the MC Messengers library to use the same version without fear of overwriting a dll due to loading of plugin libraries.
94 lines
2.9 KiB
C#
94 lines
2.9 KiB
C#
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using PepperDash.Core;
|
|
using PepperDash.Essentials.Core;
|
|
|
|
namespace PepperDash.Essentials.AppServer.Messengers
|
|
{
|
|
public class IShutdownPromptTimerMessenger : MessengerBase
|
|
{
|
|
private readonly IShutdownPromptTimer _room;
|
|
|
|
public IShutdownPromptTimerMessenger(string key, string messagePath, IShutdownPromptTimer room)
|
|
: base(key, messagePath, room as Device)
|
|
{
|
|
_room = room;
|
|
}
|
|
|
|
protected override void RegisterActions()
|
|
{
|
|
AddAction("/status", (id, content) =>
|
|
{
|
|
SendFullStatus();
|
|
});
|
|
|
|
AddAction("/setShutdownPromptSeconds", (id, content) =>
|
|
{
|
|
var response = content.ToObject<int>();
|
|
|
|
_room.SetShutdownPromptSeconds(response);
|
|
|
|
SendFullStatus();
|
|
});
|
|
|
|
AddAction("/shutdownStart", (id, content) => _room.StartShutdown(eShutdownType.Manual));
|
|
|
|
AddAction("/shutdownEnd", (id, content) => _room.ShutdownPromptTimer.Finish());
|
|
|
|
AddAction("/shutdownCancel", (id, content) => _room.ShutdownPromptTimer.Cancel());
|
|
|
|
|
|
_room.ShutdownPromptTimer.HasStarted += (sender, args) =>
|
|
{
|
|
PostEventMessage("timerStarted");
|
|
};
|
|
|
|
_room.ShutdownPromptTimer.HasFinished += (sender, args) =>
|
|
{
|
|
PostEventMessage("timerFinished");
|
|
};
|
|
|
|
_room.ShutdownPromptTimer.WasCancelled += (sender, args) =>
|
|
{
|
|
PostEventMessage("timerCancelled");
|
|
};
|
|
|
|
_room.ShutdownPromptTimer.SecondsRemainingFeedback.OutputChange += (sender, args) =>
|
|
{
|
|
var status = new
|
|
{
|
|
secondsRemaining = _room.ShutdownPromptTimer.SecondsRemainingFeedback.IntValue,
|
|
percentageRemaining = _room.ShutdownPromptTimer.PercentFeedback.UShortValue
|
|
};
|
|
|
|
PostStatusMessage(JToken.FromObject(status));
|
|
};
|
|
}
|
|
|
|
private void SendFullStatus()
|
|
{
|
|
var status = new IShutdownPromptTimerStateMessage
|
|
{
|
|
ShutdownPromptSeconds = _room.ShutdownPromptTimer.SecondsToCount,
|
|
SecondsRemaining = _room.ShutdownPromptTimer.SecondsRemainingFeedback.IntValue,
|
|
PercentageRemaining = _room.ShutdownPromptTimer.PercentFeedback.UShortValue
|
|
};
|
|
|
|
PostStatusMessage(status);
|
|
}
|
|
}
|
|
|
|
|
|
public class IShutdownPromptTimerStateMessage : DeviceStateMessageBase
|
|
{
|
|
[JsonProperty("secondsRemaining")]
|
|
public int SecondsRemaining { get; set; }
|
|
|
|
[JsonProperty("percentageRemaining")]
|
|
public int PercentageRemaining { get; set; }
|
|
|
|
[JsonProperty("shutdownPromptSeconds")]
|
|
public int ShutdownPromptSeconds { get; set; }
|
|
}
|
|
}
|