mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-31 05:14:51 +00:00
This commit introduces significant updates to the device factory system, enhancing the way devices are created and managed within the PepperDash Essentials framework. The changes include: - New attributes for device configuration and description. - Refactoring of the device manager and essentials device classes to support new factory methods. - modified factory classes for essentials devices, plugin development devices, and processor extension devices. - The device factory interface has been updated to include a factory method for creating devices. - Added a wrapper for the device factory to streamline device creation. - Updated plugin loader to accommodate the new device factory structure. Fixes #1065 Fixed #1277
103 lines
3.0 KiB
C#
103 lines
3.0 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using PepperDash.Core;
|
|
using Serilog.Events;
|
|
|
|
namespace PepperDash.Essentials.Core
|
|
{
|
|
/// <summary>
|
|
/// Defines the basic needs for an EssentialsDevice to enable it to be build by an IDeviceFactory class
|
|
/// </summary>
|
|
[Description("The base Essentials Device Class")]
|
|
public abstract class EssentialsDevice : Device
|
|
{
|
|
/// <summary>
|
|
/// Event raised when the device is initialized.
|
|
/// </summary>
|
|
public event EventHandler Initialized;
|
|
|
|
private bool _isInitialized;
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether the device is initialized.
|
|
/// </summary>
|
|
public bool IsInitialized
|
|
{
|
|
get { return _isInitialized; }
|
|
private set
|
|
{
|
|
if (_isInitialized == value) return;
|
|
|
|
_isInitialized = value;
|
|
|
|
if (_isInitialized)
|
|
{
|
|
Initialized?.Invoke(this, new EventArgs());
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the EssentialsDevice class.
|
|
/// </summary>
|
|
/// <param name="key">The unique identifier for the device.</param>
|
|
protected EssentialsDevice(string key)
|
|
: base(key)
|
|
{
|
|
SubscribeToActivateComplete();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the EssentialsDevice class.
|
|
/// </summary>
|
|
/// <param name="key">The unique identifier for the device.</param>
|
|
/// <param name="name">The name of the device.</param>
|
|
protected EssentialsDevice(string key, string name)
|
|
: base(key, name)
|
|
{
|
|
SubscribeToActivateComplete();
|
|
}
|
|
|
|
private void SubscribeToActivateComplete()
|
|
{
|
|
DeviceManager.AllDevicesActivated += DeviceManagerOnAllDevicesActivated;
|
|
}
|
|
|
|
private void DeviceManagerOnAllDevicesActivated(object sender, EventArgs eventArgs)
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
try
|
|
{
|
|
Initialize();
|
|
|
|
IsInitialized = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.LogMessage(LogEventLevel.Error, this, "Exception initializing device: {0}", ex.Message);
|
|
Debug.LogMessage(LogEventLevel.Debug, this, "Stack Trace: {0}", ex.StackTrace);
|
|
}
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// CustomActivate method
|
|
/// </summary>
|
|
/// <inheritdoc />
|
|
public override bool CustomActivate()
|
|
{
|
|
CreateMobileControlMessengers();
|
|
|
|
return base.CustomActivate();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Override this method to build and create custom Mobile Control Messengers during the Activation phase
|
|
/// </summary>
|
|
protected virtual void CreateMobileControlMessengers()
|
|
{
|
|
|
|
}
|
|
}
|
|
} |