mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-06 08:16:11 +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.
58 lines
2.0 KiB
C#
58 lines
2.0 KiB
C#
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using PepperDash.Core;
|
|
using PepperDash.Essentials.Core;
|
|
using PepperDash.Essentials.Core.Routing;
|
|
|
|
namespace PepperDash.Essentials.AppServer.Messengers
|
|
{
|
|
public class IHasCurrentSourceInfoMessenger : MessengerBase
|
|
{
|
|
private readonly IHasCurrentSourceInfoChange sourceDevice;
|
|
public IHasCurrentSourceInfoMessenger(string key, string messagePath, IHasCurrentSourceInfoChange device) : base(key, messagePath, device as IKeyName)
|
|
{
|
|
sourceDevice = device;
|
|
}
|
|
|
|
protected override void RegisterActions()
|
|
{
|
|
base.RegisterActions();
|
|
|
|
AddAction("/fullStatus", (id, content) =>
|
|
{
|
|
var message = new CurrentSourceStateMessage
|
|
{
|
|
CurrentSourceKey = sourceDevice.CurrentSourceInfoKey,
|
|
CurrentSource = sourceDevice.CurrentSourceInfo
|
|
};
|
|
|
|
PostStatusMessage(message);
|
|
});
|
|
|
|
sourceDevice.CurrentSourceChange += (sender, e) => {
|
|
switch (e)
|
|
{
|
|
case ChangeType.DidChange:
|
|
{
|
|
PostStatusMessage(JToken.FromObject(new
|
|
{
|
|
currentSourceKey = string.IsNullOrEmpty(sourceDevice.CurrentSourceInfoKey) ? string.Empty : sourceDevice.CurrentSourceInfoKey,
|
|
currentSource = sourceDevice.CurrentSourceInfo
|
|
}));
|
|
break;
|
|
}
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
public class CurrentSourceStateMessage: DeviceStateMessageBase
|
|
{
|
|
[JsonProperty("currentSourceKey", NullValueHandling = NullValueHandling.Ignore)]
|
|
public string CurrentSourceKey { get; set; }
|
|
|
|
[JsonProperty("currentSource")]
|
|
public SourceListItem CurrentSource { get; set; }
|
|
}
|
|
}
|