chore: miscellaeneous cleanup

This commit is contained in:
Andrew Welker
2025-03-25 22:46:41 -05:00
parent 789111cb9a
commit 277771d154
19 changed files with 289 additions and 496 deletions

View File

@@ -7,17 +7,19 @@ namespace PepperDash.Essentials.Core
[Obsolete("Please use the builtin HttpClient class instead: https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines")]
public class GenericHttpClient : Device, IBasicCommunication
{
public HttpClient Client;
private readonly HttpClient Client;
public event EventHandler<GenericHttpClientEventArgs> ResponseRecived;
public GenericHttpClient(string key, string name, string hostname)
: base(key, name)
{
Client = new HttpClient();
Client.HostName = hostname;
}
Client = new HttpClient
{
HostName = hostname
};
}
/// <summary>
///
@@ -54,9 +56,8 @@ namespace PepperDash.Essentials.Core
if (responseReceived.ContentString.Length > 0)
{
if (ResponseRecived != null)
ResponseRecived(this, new GenericHttpClientEventArgs(responseReceived.ContentString, (request as HttpClientRequest).Url.ToString(), error));
}
ResponseRecived?.Invoke(this, new GenericHttpClientEventArgs(responseReceived.ContentString, (request as HttpClientRequest).Url.ToString(), error));
}
}
}

View File

@@ -1,81 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Crestron.SimplSharpPro;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Config;
using PepperDash.Core;
using Serilog.Events;
namespace PepperDash.Essentials.Core.Devices
{
[Obsolete("Please use PepperDash.Essentials.Devices.Common, this will be removed in 2.1")]
public class Laptop : EssentialsDevice, IHasFeedback, IRoutingOutputs, IAttachVideoStatus, IUiDisplayInfo, IUsageTracking
{
public uint DisplayUiType { get { return DisplayUiConstants.TypeLaptop; } }
public string IconName { get; set; }
public BoolFeedback HasPowerOnFeedback { get; private set; }
public RoutingOutputPort AnyVideoOut { get; private set; }
#region IRoutingOutputs Members
/// <summary>
/// Options: hdmi
/// </summary>
public RoutingPortCollection<RoutingOutputPort> OutputPorts { get; private set; }
#endregion
public Laptop(string key, string name)
: base(key, name)
{
IconName = "Laptop";
HasPowerOnFeedback = new BoolFeedback("HasPowerFeedback",
() => this.GetVideoStatuses() != VideoStatusOutputs.NoStatus);
OutputPorts = new RoutingPortCollection<RoutingOutputPort>();
OutputPorts.Add(AnyVideoOut = new RoutingOutputPort(RoutingPortNames.AnyOut, eRoutingSignalType.Audio | eRoutingSignalType.Video,
eRoutingPortConnectionType.None, 0, this));
}
#region IHasFeedback Members
/// <summary>
/// Passes through the VideoStatuses list
/// </summary>
public FeedbackCollection<Feedback> Feedbacks
{
get
{
var newList = new FeedbackCollection<Feedback>();
newList.AddRange(this.GetVideoStatuses().ToList());
return newList;
}
}
#endregion
#region IUsageTracking Members
public UsageTracking UsageTracker { get; set; }
#endregion
}
[Obsolete("Please use PepperDash.Essentials.Devices.Common, this will be removed in 2.1")]
public class LaptopFactory : EssentialsDeviceFactory<Laptop>
{
public LaptopFactory()
{
TypeNames = new List<string>() { "deprecated" };
}
public override EssentialsDevice BuildDevice(DeviceConfig dc)
{
Debug.LogMessage(LogEventLevel.Debug, "Factory Attempting to create new Laptop Device");
return new Core.Devices.Laptop(dc.Key, dc.Name);
}
}
}

View File

@@ -20,7 +20,7 @@ namespace PepperDash.Essentials.Core.Fusion
{
public class EssentialsHuddleSpaceFusionSystemControllerBase : Device, IOccupancyStatusProvider
{
protected EssentialsHuddleSpaceRoomFusionRoomJoinMap JoinMap;
private readonly EssentialsHuddleSpaceRoomFusionRoomJoinMap JoinMap;
private const string RemoteOccupancyXml = "<Occupancy><Type>Local</Type><State>{0}</State></Occupancy>";
private readonly bool _guidFileExists;
@@ -30,15 +30,15 @@ namespace PepperDash.Essentials.Core.Fusion
protected StringSigData CurrentRoomSourceNameSig;
public FusionCustomPropertiesBridge CustomPropertiesBridge = new FusionCustomPropertiesBridge();
private readonly FusionCustomPropertiesBridge CustomPropertiesBridge = new FusionCustomPropertiesBridge();
protected FusionOccupancySensorAsset FusionOccSensor;
protected FusionRemoteOccupancySensor FusionRemoteOccSensor;
private readonly FusionRemoteOccupancySensor FusionRemoteOccSensor;
protected FusionRoom FusionRoom;
protected Dictionary<int, FusionAsset> FusionStaticAssets;
public long PushNotificationTimeout = 5000;
protected IEssentialsRoom Room;
public long SchedulePollInterval = 300000;
private readonly long PushNotificationTimeout = 5000;
private readonly IEssentialsRoom Room;
private readonly long SchedulePollInterval = 300000;
private Event _currentMeeting;
private RoomSchedule _currentSchedule;
@@ -86,7 +86,7 @@ namespace PepperDash.Essentials.Core.Fusion
#region Default Display Source Sigs
private BooleanSigData[] _source = new BooleanSigData[10];
private readonly BooleanSigData[] _source = new BooleanSigData[10];
#endregion
@@ -152,9 +152,8 @@ namespace PepperDash.Essentials.Core.Fusion
ReadGuidFile(guidFilePath);
}
var occupancyRoom = Room as IRoomOccupancy;
if (occupancyRoom != null)
if (Room is IRoomOccupancy occupancyRoom)
{
if (occupancyRoom.RoomOccupancy != null)
{
@@ -368,8 +367,7 @@ namespace PepperDash.Essentials.Core.Fusion
CurrentRoomSourceNameSig = FusionRoom.CreateOffsetStringSig(JoinMap.Display1CurrentSourceName.JoinNumber, JoinMap.Display1CurrentSourceName.AttributeName,
eSigIoMask.InputSigOnly);
// Don't think we need to get current status of this as nothing should be alive yet.
var hasCurrentSourceInfoChange = Room as IHasCurrentSourceInfoChange;
if (hasCurrentSourceInfoChange != null)
if (Room is IHasCurrentSourceInfoChange hasCurrentSourceInfoChange)
{
hasCurrentSourceInfoChange.CurrentSourceChange += Room_CurrentSourceInfoChange;
}
@@ -378,8 +376,7 @@ namespace PepperDash.Essentials.Core.Fusion
FusionRoom.SystemPowerOn.OutputSig.SetSigFalseAction(Room.PowerOnToDefaultOrLastSource);
FusionRoom.SystemPowerOff.OutputSig.SetSigFalseAction(() =>
{
var runRouteAction = Room as IRunRouteAction;
if (runRouteAction != null)
if (Room is IRunRouteAction runRouteAction)
{
runRouteAction.RunRouteAction("roomOff", Room.SourceListKey);
}
@@ -661,7 +658,7 @@ namespace PepperDash.Essentials.Core.Fusion
var extendTime = _currentMeeting.dtEnd - DateTime.Now;
var extendMinutesRaw = extendTime.TotalMinutes;
extendMinutes = extendMinutes + (int) Math.Round(extendMinutesRaw);
extendMinutes += (int) Math.Round(extendMinutesRaw);
}
@@ -902,12 +899,7 @@ namespace PepperDash.Essentials.Core.Fusion
}
}
}
var handler = RoomInfoChange;
if (handler != null)
{
handler(this, new EventArgs());
}
RoomInfoChange?.Invoke(this, new EventArgs());
CustomPropertiesBridge.EvaluateRoomInfo(Room.Key, roomInformation);
}
@@ -1015,12 +1007,7 @@ namespace PepperDash.Essentials.Core.Fusion
}
// Fire Schedule Change Event
var handler = ScheduleChange;
if (handler != null)
{
handler(this, new ScheduleChangeEventArgs {Schedule = _currentSchedule});
}
ScheduleChange?.Invoke(this, new ScheduleChangeEventArgs { Schedule = _currentSchedule });
}
}
}
@@ -1092,7 +1079,7 @@ namespace PepperDash.Essentials.Core.Fusion
}
}
var laptops = dict.Where(d => d.Value.SourceDevice is Devices.Laptop);
var laptops = dict.Where(d => d.Value.SourceDevice is IRoutingSource);
i = 1;
foreach (var kvp in laptops)
{
@@ -1124,9 +1111,7 @@ namespace PepperDash.Essentials.Core.Fusion
/// <param name="e"></param>
protected void UsageTracker_DeviceUsageEnded(object sender, DeviceUsageEventArgs e)
{
var deviceTracker = sender as UsageTracking;
if (deviceTracker == null)
if (!(sender is UsageTracking deviceTracker))
{
return;
}
@@ -1169,8 +1154,7 @@ namespace PepperDash.Essentials.Core.Fusion
// And respond to selection in Fusion
sigD.OutputSig.SetSigFalseAction(() =>
{
var runRouteAction = Room as IRunRouteAction;
if (runRouteAction != null)
if (Room is IRunRouteAction runRouteAction)
{
runRouteAction.RunRouteAction(routeKey, Room.SourceListKey);
}
@@ -1214,12 +1198,11 @@ namespace PepperDash.Essentials.Core.Fusion
//uint attrNum = Convert.ToUInt32(keyNum);
// Check for UI devices
var uiDev = dev as IHasBasicTriListWithSmartObject;
if (uiDev != null)
if (dev is IHasBasicTriListWithSmartObject uiDev)
{
if (uiDev.Panel is Crestron.SimplSharpPro.UI.XpanelForSmartGraphics)
{
attrNum = attrNum + touchpanelNum;
attrNum += touchpanelNum;
if (attrNum > JoinMap.XpanelOnlineStart.JoinSpan)
{
@@ -1232,7 +1215,7 @@ namespace PepperDash.Essentials.Core.Fusion
}
else
{
attrNum = attrNum + xpanelNum;
attrNum += xpanelNum;
if (attrNum > JoinMap.TouchpanelOnlineStart.JoinSpan)
{
@@ -1248,7 +1231,7 @@ namespace PepperDash.Essentials.Core.Fusion
//else
if (dev is IDisplay)
{
attrNum = attrNum + displayNum;
attrNum += displayNum;
if (attrNum > JoinMap.DisplayOnlineStart.JoinSpan)
{
continue;
@@ -1300,13 +1283,11 @@ namespace PepperDash.Essentials.Core.Fusion
display.UsageTracker.DeviceUsageEnded += UsageTracker_DeviceUsageEnded;
}
var hasDefaultDisplay = Room as IHasDefaultDisplay;
if (hasDefaultDisplay == null)
if (!(Room is IHasDefaultDisplay hasDefaultDisplay))
{
return;
}
var defaultDisplay = hasDefaultDisplay.DefaultDisplay as IDisplay;
if (defaultDisplay == null)
if (!(hasDefaultDisplay.DefaultDisplay is IDisplay defaultDisplay))
{
Debug.LogMessage(LogEventLevel.Debug, this, "Cannot link null display to Fusion because default display is null");
return;
@@ -1358,8 +1339,7 @@ namespace PepperDash.Essentials.Core.Fusion
dispAsset.PowerOn.OutputSig.UserObject = dispPowerOnAction;
dispAsset.PowerOff.OutputSig.UserObject = dispPowerOffAction;
var defaultTwoWayDisplay = defaultDisplay as IHasPowerControlWithFeedback;
if (defaultTwoWayDisplay != null)
if (defaultDisplay is IHasPowerControlWithFeedback defaultTwoWayDisplay)
{
defaultTwoWayDisplay.PowerIsOnFeedback.LinkInputSig(FusionRoom.DisplayPowerOn.InputSig);
if (defaultDisplay is IDisplayUsage)
@@ -1392,8 +1372,7 @@ namespace PepperDash.Essentials.Core.Fusion
var displayName = string.Format("Display {0} - ", displayIndex);
var hasDefaultDisplay = Room as IHasDefaultDisplay;
if (hasDefaultDisplay == null || display != hasDefaultDisplay.DefaultDisplay)
if (!(Room is IHasDefaultDisplay hasDefaultDisplay) || display != hasDefaultDisplay.DefaultDisplay)
{
return;
}
@@ -1402,8 +1381,7 @@ namespace PepperDash.Essentials.Core.Fusion
eSigIoMask.InputOutputSig);
defaultDisplayVolume.OutputSig.UserObject = new Action<ushort>(b =>
{
var basicVolumeWithFeedback = display as IBasicVolumeWithFeedback;
if (basicVolumeWithFeedback == null)
if (!(display is IBasicVolumeWithFeedback basicVolumeWithFeedback))
{
return;
}
@@ -1436,8 +1414,7 @@ namespace PepperDash.Essentials.Core.Fusion
});
var defaultTwoWayDisplay = display as IHasPowerControlWithFeedback;
if (defaultTwoWayDisplay != null)
if (display is IHasPowerControlWithFeedback defaultTwoWayDisplay)
{
defaultTwoWayDisplay.PowerIsOnFeedback.LinkInputSig(defaultDisplayPowerOn.InputSig);
defaultTwoWayDisplay.PowerIsOnFeedback.LinkComplementInputSig(defaultDisplayPowerOff.InputSig);
@@ -1450,8 +1427,7 @@ namespace PepperDash.Essentials.Core.Fusion
{
if (!b)
{
var runRouteAction = Room as IRunRouteAction;
if (runRouteAction != null)
if (Room is IRunRouteAction runRouteAction)
{
runRouteAction.RunRouteAction("roomOff", Room.SourceListKey);
}
@@ -1465,8 +1441,7 @@ namespace PepperDash.Essentials.Core.Fusion
_errorMessageRollUp = new StatusMonitorCollection(this);
foreach (var dev in DeviceManager.GetDevices())
{
var md = dev as ICommunicationMonitor;
if (md != null)
if (dev is ICommunicationMonitor md)
{
_errorMessageRollUp.AddMonitor(md.CommunicationMonitor);
Debug.LogMessage(LogEventLevel.Verbose, this, "Adding '{0}' to room's overall error monitor",
@@ -1532,9 +1507,8 @@ namespace PepperDash.Essentials.Core.Fusion
// Tie to method on occupancy object
//occSensorShutdownMinutes.OutputSig.UserObject(new Action(ushort)(b => Room.OccupancyObj.SetShutdownMinutes(b));
var occRoom = Room as IRoomOccupancy;
if (occRoom != null)
if (Room is IRoomOccupancy occRoom)
{
occRoom.RoomOccupancy.RoomIsOccupiedFeedback.LinkInputSig(occSensorAsset.RoomOccupied.InputSig);
occRoom.RoomOccupancy.RoomIsOccupiedFeedback.OutputChange += RoomIsOccupiedFeedback_OutputChange;
@@ -1601,10 +1575,9 @@ namespace PepperDash.Essentials.Core.Fusion
// The sig/UO method: Need separate handlers for fixed and user sigs, all flavors,
// even though they all contain sigs.
var sigData = args.UserConfiguredSigDetail as BooleanSigDataFixedName;
BoolOutputSig outSig;
if (sigData != null)
if (args.UserConfiguredSigDetail is BooleanSigDataFixedName sigData)
{
outSig = sigData.OutputSig;
if (outSig.UserObject is Action<bool>)
@@ -1760,8 +1733,7 @@ namespace PepperDash.Essentials.Core.Fusion
/// </summary>
public static void TrySetMakeModel(this FusionStaticAsset asset, Device device)
{
var mm = device as IMakeModel;
if (mm != null)
if (device is IMakeModel mm)
{
asset.ParamMake.Value = mm.DeviceMake;
asset.ParamModel.Value = mm.DeviceModel;

View File

@@ -4,6 +4,7 @@ using System.Globalization;
using Crestron.SimplSharpPro;
using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Core.Logging;
using Serilog.Events;
namespace PepperDash.Essentials.Core.Touchpanels
@@ -34,9 +35,9 @@ namespace PepperDash.Essentials.Core.Touchpanels
Debug.LogMessage(LogEventLevel.Information, this, "touchpanel registration response: {0}", registrationResponse);
}
_touchpanel.BaseEvent += _touchpanel_BaseEvent;
_touchpanel.ButtonStateChange += _touchpanel_ButtonStateChange;
_touchpanel.PanelStateChange += _touchpanel_PanelStateChange;
_touchpanel.BaseEvent += Touchpanel_BaseEvent;
_touchpanel.ButtonStateChange += Touchpanel_ButtonStateChange;
_touchpanel.PanelStateChange += Touchpanel_PanelStateChange;
_buttons = buttons;
if (_buttons == null)
@@ -74,10 +75,9 @@ namespace PepperDash.Essentials.Core.Touchpanels
return;
}
int buttonNumber;
TryParseInt(key, out buttonNumber);
TryParseInt(key, out int buttonNumber);
var buttonEventTypes = config.EventTypes;
var buttonEventTypes = config.EventTypes;
BoolOutputSig enabledFb = null;
BoolOutputSig disabledFb = null;
@@ -161,11 +161,10 @@ namespace PepperDash.Essentials.Core.Touchpanels
return;
}
int buttonNumber;
TryParseInt(key, out buttonNumber);
TryParseInt(key, out int buttonNumber);
// Link up the button feedbacks to the specified device feedback
var buttonFeedback = config.Feedback;
// Link up the button feedbacks to the specified device feedback
var buttonFeedback = config.Feedback;
if (buttonFeedback == null || string.IsNullOrEmpty(buttonFeedback.DeviceKey))
{
Debug.LogMessage(LogEventLevel.Debug, this, "Button '{0}' feedback not configured, skipping.",
@@ -177,15 +176,14 @@ namespace PepperDash.Essentials.Core.Touchpanels
try
{
var device = DeviceManager.GetDeviceForKey(buttonFeedback.DeviceKey) as Device;
if (device == null)
{
Debug.LogMessage(LogEventLevel.Debug, this, "Button '{0}' feedback deviceKey '{1}' not found.",
key, buttonFeedback.DeviceKey);
return;
}
if (!(DeviceManager.GetDeviceForKey(buttonFeedback.DeviceKey) is Device device))
{
Debug.LogMessage(LogEventLevel.Debug, this, "Button '{0}' feedback deviceKey '{1}' not found.",
key, buttonFeedback.DeviceKey);
return;
}
deviceFeedback = device.GetFeedbackProperty(buttonFeedback.FeedbackName);
deviceFeedback = device.GetFeedbackProperty(buttonFeedback.FeedbackName);
if (deviceFeedback == null)
{
Debug.LogMessage(LogEventLevel.Debug, this, "Button '{0}' feedbackName property '{1}' not found.",
@@ -224,38 +222,37 @@ namespace PepperDash.Essentials.Core.Touchpanels
}
var boolFeedback = deviceFeedback as BoolFeedback;
var intFeedback = deviceFeedback as IntFeedback;
switch (key)
{
case ("power"):
{
if (boolFeedback != null) boolFeedback.LinkCrestronFeedback(_touchpanel.FeedbackPower);
break;
}
case ("volumeup"):
case ("volumedown"):
case ("volumefeedback"):
{
if (intFeedback != null)
{
var volumeFeedback = intFeedback;
volumeFeedback.LinkInputSig(_touchpanel.VolumeBargraph);
}
break;
}
case ("mute"):
{
if (boolFeedback != null) boolFeedback.LinkCrestronFeedback(_touchpanel.FeedbackMute);
break;
}
default:
{
if (boolFeedback != null) boolFeedback.LinkCrestronFeedback(_touchpanel.Feedbacks[(uint)buttonNumber]);
break;
}
}
}
switch (key)
{
case ("power"):
{
boolFeedback?.LinkCrestronFeedback(_touchpanel.FeedbackPower);
break;
}
case ("volumeup"):
case ("volumedown"):
case ("volumefeedback"):
{
if (deviceFeedback is IntFeedback intFeedback)
{
var volumeFeedback = intFeedback;
volumeFeedback.LinkInputSig(_touchpanel.VolumeBargraph);
}
break;
}
case ("mute"):
{
boolFeedback?.LinkCrestronFeedback(_touchpanel.FeedbackMute);
break;
}
default:
{
boolFeedback?.LinkCrestronFeedback(_touchpanel.Feedbacks[(uint)buttonNumber]);
break;
}
}
}
/// <summary>
/// Try parse int helper method
@@ -277,12 +274,12 @@ namespace PepperDash.Essentials.Core.Touchpanels
}
}
private void _touchpanel_BaseEvent(GenericBase device, BaseEventArgs args)
private void Touchpanel_BaseEvent(GenericBase device, BaseEventArgs args)
{
Debug.LogMessage(LogEventLevel.Debug, this, "BaseEvent: eventId-'{0}', index-'{1}'", args.EventId, args.Index);
}
private void _touchpanel_ButtonStateChange(GenericBase device, Crestron.SimplSharpPro.DeviceSupport.ButtonEventArgs args)
private void Touchpanel_ButtonStateChange(GenericBase device, Crestron.SimplSharpPro.DeviceSupport.ButtonEventArgs args)
{
Debug.LogMessage(LogEventLevel.Debug, this, "ButtonStateChange: buttonNumber-'{0}' buttonName-'{1}', buttonState-'{2}'", args.Button.Number, args.Button.Name, args.NewButtonState);
var type = args.NewButtonState.ToString();
@@ -297,7 +294,7 @@ namespace PepperDash.Essentials.Core.Touchpanels
}
}
private void _touchpanel_PanelStateChange(GenericBase device, BaseEventArgs args)
private void Touchpanel_PanelStateChange(GenericBase device, BaseEventArgs args)
{
Debug.LogMessage(LogEventLevel.Debug, this, "PanelStateChange: eventId-'{0}', index-'{1}'", args.EventId, args.Index);
}
@@ -310,7 +307,7 @@ namespace PepperDash.Essentials.Core.Touchpanels
/// <param name="type"></param>
public void Press(string buttonKey, string type)
{
Debug.LogMessage(LogEventLevel.Verbose, this, "Press: buttonKey-'{0}', type-'{1}'", buttonKey, type);
this.LogVerbose("Press: buttonKey-'{buttonKey}', type-'{type}'", buttonKey, type);
// TODO: In future, consider modifying this to generate actions at device activation time
// to prevent the need to dynamically call the method via reflection on each button press
@@ -325,18 +322,12 @@ namespace PepperDash.Essentials.Core.Touchpanels
public void ListButtons()
{
var line = new string('-', 35);
Debug.Console(0, this, line);
Debug.Console(0, this, "MPC3 Controller {0} - Available Butons", Key);
this.LogVerbose("MPC3 Controller {0} - Available Buttons", Key);
foreach (var button in _buttons)
{
Debug.Console(0, this, "Key: {0}", button.Key);
this.LogVerbose("Key: {key}", button.Key);
}
Debug.Console(0, this, line);
}
}

View File

@@ -119,23 +119,23 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
return;
}
var device = DeviceManager.GetDeviceForKey(body.DeviceKey) as IStreamDebugging;
if (device == null)
{
context.Response.StatusCode = 404;
context.Response.StatusDescription = "Not Found";
context.Response.End();
if (!(DeviceManager.GetDeviceForKey(body.DeviceKey) is IStreamDebugging device))
{
context.Response.StatusCode = 404;
context.Response.StatusDescription = "Not Found";
context.Response.End();
return;
}
eStreamDebuggingSetting debugSetting;
return;
}
eStreamDebuggingSetting debugSetting;
try
{
debugSetting = (eStreamDebuggingSetting) Enum.Parse(typeof (eStreamDebuggingSetting), body.Setting, true);
}
catch (Exception ex)
{
Debug.LogMessage(ex, "Exception handling set debug request");
context.Response.StatusCode = 500;
context.Response.StatusDescription = "Internal Server Error";
context.Response.End();
@@ -161,6 +161,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
}
catch (Exception ex)
{
Debug.LogMessage(ex, "Exception handling set debug request");
context.Response.StatusCode = 500;
context.Response.StatusDescription = "Internal Server Error";
context.Response.End();