Skip to content

Commit

Permalink
Added overridable method to device base for interacting with online /…
Browse files Browse the repository at this point in the history
… offline events
  • Loading branch information
mikejobson committed May 14, 2024
1 parent 5a8a506 commit e8f87d8
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions UXAV.AVnet.Core/DeviceSupport/DeviceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,35 @@ protected set
{
if (_deviceCommunicating == value) return;
_deviceCommunicating = value;
if (_deviceCommunicating)
Logger.Success($"{Name} is now online.", GetType().Name, true);
else
Logger.Warn($"{Name} is offline!", GetType().Name, false);

try
{
DeviceCommunicatingChange?.Invoke(this, _deviceCommunicating);
}
catch (Exception e)
{
OnDeviceCommunicatingChange(value);
}
}

protected virtual void OnDeviceCommunicatingChange(bool communicating, bool log = true, bool notify = true)
{
if (_deviceCommunicating && log)
Logger.Success($"{Name} is now online.", GetType().Name, true);
else if (!_deviceCommunicating && log)
Logger.Warn($"{Name} is offline!", GetType().Name, false);

try
{
DeviceCommunicatingChange?.Invoke(this, _deviceCommunicating);
}
catch (Exception e)
{
if (log)
Logger.Error(e);
}

if (System.BootStatus != SystemBase.EBootStatus.Running) return;
EventService.Notify(EventMessageType.DeviceConnectionChange, new
{
Device = Name,
Description = AllocatedRoom?.Name,
ConnectionInfo,
Online = value
});
}

if (System.BootStatus != SystemBase.EBootStatus.Running || !notify) return;
EventService.Notify(EventMessageType.DeviceConnectionChange, new
{
Device = Name,
Description = AllocatedRoom?.Name,
ConnectionInfo,
Online = communicating
});
}

public virtual bool DebugEnabled { get; set; }
Expand Down

0 comments on commit e8f87d8

Please sign in to comment.