From 277771d15470623cdeda3285c9a65f0ff6c7ba19 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Tue, 25 Mar 2025 22:46:41 -0500 Subject: [PATCH] chore: miscellaeneous cleanup --- .../Comm and IR/GenericHttpClient.cs | 19 +- .../Devices/PC/Laptop.cs | 81 ----- ...lsHuddleSpaceFusionSystemControllerBase.cs | 90 ++---- .../Touchpanels/Mpc3Touchpanel.cs | 113 ++++--- .../SetDeviceStreamDebugRequestHandler.cs | 21 +- .../Cameras/CameraVisca.cs | 39 ++- .../Codec/iHasScheduleAwareness.cs | 20 +- .../VideoCodec/VideoCodecBase.cs | 288 ++++++++---------- .../DisplayBaseMessenger.cs | 3 +- .../Messengers/IDspPresetsMessenger.cs | 10 +- .../IEssentialsRoomCombinerMessenger.cs | 3 +- .../Messengers/IRunRouteActionMessenger.cs | 2 +- .../Messengers/LightingBaseMessenger.cs | 2 - .../Messengers/RoomEventScheduleMessenger.cs | 3 +- .../Messengers/SystemMonitorMessenger.cs | 6 +- .../Messengers/VideoCodecBaseMessenger.cs | 21 +- ...Essentials.MobileControl.Messengers.csproj | 12 +- .../MobileControlDeviceFactory.cs | 50 --- src/PepperDash.Essentials/ControlSystem.cs | 2 +- 19 files changed, 289 insertions(+), 496 deletions(-) delete mode 100644 src/PepperDash.Essentials.Core/Devices/PC/Laptop.cs diff --git a/src/PepperDash.Essentials.Core/Comm and IR/GenericHttpClient.cs b/src/PepperDash.Essentials.Core/Comm and IR/GenericHttpClient.cs index 47632c8d..d88e9728 100644 --- a/src/PepperDash.Essentials.Core/Comm and IR/GenericHttpClient.cs +++ b/src/PepperDash.Essentials.Core/Comm and IR/GenericHttpClient.cs @@ -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 ResponseRecived; public GenericHttpClient(string key, string name, string hostname) : base(key, name) { - Client = new HttpClient(); - Client.HostName = hostname; - - - } + Client = new HttpClient + { + HostName = hostname + }; + + + } /// /// @@ -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)); + } } } diff --git a/src/PepperDash.Essentials.Core/Devices/PC/Laptop.cs b/src/PepperDash.Essentials.Core/Devices/PC/Laptop.cs deleted file mode 100644 index 921d52c2..00000000 --- a/src/PepperDash.Essentials.Core/Devices/PC/Laptop.cs +++ /dev/null @@ -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 - - /// - /// Options: hdmi - /// - public RoutingPortCollection 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(); - OutputPorts.Add(AnyVideoOut = new RoutingOutputPort(RoutingPortNames.AnyOut, eRoutingSignalType.Audio | eRoutingSignalType.Video, - eRoutingPortConnectionType.None, 0, this)); - } - - #region IHasFeedback Members - - /// - /// Passes through the VideoStatuses list - /// - public FeedbackCollection Feedbacks - { - get - { - var newList = new FeedbackCollection(); - 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 - { - public LaptopFactory() - { - TypeNames = new List() { "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); - } - } -} \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/Fusion/EssentialsHuddleSpaceFusionSystemControllerBase.cs b/src/PepperDash.Essentials.Core/Fusion/EssentialsHuddleSpaceFusionSystemControllerBase.cs index ab04a0b0..9a2667f0 100644 --- a/src/PepperDash.Essentials.Core/Fusion/EssentialsHuddleSpaceFusionSystemControllerBase.cs +++ b/src/PepperDash.Essentials.Core/Fusion/EssentialsHuddleSpaceFusionSystemControllerBase.cs @@ -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 = "Local{0}"; 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 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 /// 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(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) @@ -1760,8 +1733,7 @@ namespace PepperDash.Essentials.Core.Fusion /// 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; diff --git a/src/PepperDash.Essentials.Core/Touchpanels/Mpc3Touchpanel.cs b/src/PepperDash.Essentials.Core/Touchpanels/Mpc3Touchpanel.cs index 8ea9772f..8649d292 100644 --- a/src/PepperDash.Essentials.Core/Touchpanels/Mpc3Touchpanel.cs +++ b/src/PepperDash.Essentials.Core/Touchpanels/Mpc3Touchpanel.cs @@ -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; + } + } + } /// /// 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 /// 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); } } diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs index 6378f1b2..fa20145c 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs @@ -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(); diff --git a/src/PepperDash.Essentials.Devices.Common/Cameras/CameraVisca.cs b/src/PepperDash.Essentials.Devices.Common/Cameras/CameraVisca.cs index fa82ba1f..384d60a3 100644 --- a/src/PepperDash.Essentials.Devices.Common/Cameras/CameraVisca.cs +++ b/src/PepperDash.Essentials.Devices.Common/Cameras/CameraVisca.cs @@ -21,7 +21,7 @@ namespace PepperDash.Essentials.Devices.Common.Cameras { public class CameraVisca : CameraBase, IHasCameraPtzControl, ICommunicationMonitor, IHasCameraPresets, IHasPowerControlWithFeedback, IBridgeAdvanced, IHasCameraFocusControl, IHasAutoFocusMode { - CameraViscaPropertiesConfig PropertiesConfig; + private readonly CameraViscaPropertiesConfig PropertiesConfig; public IBasicCommunication Communication { get; private set; } @@ -30,7 +30,7 @@ namespace PepperDash.Essentials.Devices.Common.Cameras /// /// Used to store the actions to parse inquiry responses as the inquiries are sent /// - private CrestronQueue> InquiryResponseQueue; + private readonly CrestronQueue> InquiryResponseQueue; /// /// Camera ID (Default 1) @@ -45,7 +45,7 @@ namespace PepperDash.Essentials.Devices.Common.Cameras public byte PanSpeedFast = 0x13; public byte TiltSpeedFast = 0x13; - private bool IsMoving; + // private bool IsMoving; private bool IsZooming; bool _powerIsOn; @@ -101,18 +101,17 @@ namespace PepperDash.Essentials.Devices.Common.Cameras Capabilities = eCameraCapabilities.Pan | eCameraCapabilities.Tilt | eCameraCapabilities.Zoom | eCameraCapabilities.Focus; Communication = comm; - var socket = comm as ISocketStatus; - if (socket != null) - { - // This instance uses IP control - socket.ConnectionChange += new EventHandler(socket_ConnectionChange); - } - else - { - // This instance uses RS-232 control - } + if (comm is ISocketStatus socket) + { + // This instance uses IP control + socket.ConnectionChange += new EventHandler(Socket_ConnectionChange); + } + else + { + // This instance uses RS-232 control + } - Communication.BytesReceived += new EventHandler(Communication_BytesReceived); + Communication.BytesReceived += new EventHandler(Communication_BytesReceived); PowerIsOnFeedback = new BoolFeedback(() => { return PowerIsOn; }); CameraIsOffFeedback = new BoolFeedback(() => { return !PowerIsOn; }); @@ -175,7 +174,7 @@ namespace PepperDash.Essentials.Devices.Common.Cameras LinkCameraToApi(this, trilist, joinStart, joinMapKey, bridge); } - void socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs e) + void Socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs e) { Debug.LogMessage(LogEventLevel.Verbose, this, "Socket Status Change: {0}", e.Client.ClientStatus.ToString()); @@ -449,12 +448,12 @@ namespace PepperDash.Essentials.Devices.Common.Cameras public void PanLeft() { SendPanTiltCommand(new byte[] {0x01, 0x03}, false); - IsMoving = true; + // IsMoving = true; } public void PanRight() { SendPanTiltCommand(new byte[] { 0x02, 0x03 }, false); - IsMoving = true; + // IsMoving = true; } public void PanStop() { @@ -463,12 +462,12 @@ namespace PepperDash.Essentials.Devices.Common.Cameras public void TiltDown() { SendPanTiltCommand(new byte[] { 0x03, 0x02 }, false); - IsMoving = true; + // IsMoving = true; } public void TiltUp() { SendPanTiltCommand(new byte[] { 0x03, 0x01 }, false); - IsMoving = true; + // IsMoving = true; } public void TiltStop() { @@ -507,7 +506,7 @@ namespace PepperDash.Essentials.Devices.Common.Cameras { StopSpeedTimer(); SendPanTiltCommand(new byte[] { 0x03, 0x03 }, false); - IsMoving = false; + // IsMoving = false; } } public void PositionHome() diff --git a/src/PepperDash.Essentials.Devices.Common/Codec/iHasScheduleAwareness.cs b/src/PepperDash.Essentials.Devices.Common/Codec/iHasScheduleAwareness.cs index 6d8d4a4a..602d65e3 100644 --- a/src/PepperDash.Essentials.Devices.Common/Codec/iHasScheduleAwareness.cs +++ b/src/PepperDash.Essentials.Devices.Common/Codec/iHasScheduleAwareness.cs @@ -40,9 +40,9 @@ namespace PepperDash.Essentials.Devices.Common.Codec private int _meetingWarningMinutes = 5; - private Meeting _previousChangedMeeting; + //private Meeting _previousChangedMeeting; - private eMeetingEventChangeType _previousChangeType = eMeetingEventChangeType.Unknown; + //private eMeetingEventChangeType _previousChangeType = eMeetingEventChangeType.Unknown; public int MeetingWarningMinutes { @@ -62,16 +62,11 @@ namespace PepperDash.Essentials.Devices.Common.Codec set { _meetings = value; - - var handler = MeetingsListHasChanged; - if (handler != null) - { - handler(this, new EventArgs()); - } + MeetingsListHasChanged?.Invoke(this, new EventArgs()); } } - private CTimer _scheduleChecker; + private readonly CTimer _scheduleChecker; public CodecScheduleAwareness() { @@ -99,12 +94,7 @@ namespace PepperDash.Essentials.Devices.Common.Codec { // Add this change type to the NotifiedChangeTypes meeting.NotifiedChangeTypes |= changeType; - - var handler = MeetingEventChange; - if (handler != null) - { - handler(this, new MeetingEventArgs() { ChangeType = changeType, Meeting = meeting }); - } + MeetingEventChange?.Invoke(this, new MeetingEventArgs() { ChangeType = changeType, Meeting = meeting }); } else { diff --git a/src/PepperDash.Essentials.Devices.Common/VideoCodec/VideoCodecBase.cs b/src/PepperDash.Essentials.Devices.Common/VideoCodec/VideoCodecBase.cs index be781486..236c7ad9 100644 --- a/src/PepperDash.Essentials.Devices.Common/VideoCodec/VideoCodecBase.cs +++ b/src/PepperDash.Essentials.Devices.Common/VideoCodec/VideoCodecBase.cs @@ -31,9 +31,9 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec protected const int MaxParticipants = 50; private readonly byte[] _clearBytes = XSigHelpers.ClearOutputs(); - private IHasDirectory _directoryCodec; - private BasicTriList _directoryTrilist; - private VideoCodecControllerJoinMap _directoryJoinmap; + private readonly IHasDirectory _directoryCodec; + private readonly BasicTriList _directoryTrilist; + private readonly VideoCodecControllerJoinMap _directoryJoinmap; protected string _timeFormatSpecifier; protected string _dateFormatSpecifier; @@ -216,11 +216,7 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec /// protected virtual void OnCallStatusChange(CodecActiveCallItem item) { - var handler = CallStatusChange; - if (handler != null) - { - handler(this, new CodecCallStatusItemChangeEventArgs(item)); - } + CallStatusChange?.Invoke(this, new CodecCallStatusItemChangeEventArgs(item)); PrivacyModeIsOnFeedback.FireUpdate(); @@ -252,12 +248,8 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec try { IsReady = true; - var h = IsReadyChange; - if (h != null) - { - h(this, new EventArgs()); - } - } + IsReadyChange?.Invoke(this, new EventArgs()); + } catch (Exception e) { Debug.LogMessage(LogEventLevel.Verbose, this, "Error in SetIsReady() : {0}", e); @@ -309,10 +301,7 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec joinMap.SetCustomJoinData(customJoins); } - if (bridge != null) - { - bridge.AddJoinMap(Key, joinMap); - } + bridge?.AddJoinMap(Key, joinMap); LinkVideoCodecToApi(codec, trilist, joinMap); @@ -530,11 +519,10 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec trilist.SetBool(joinMap.CameraModeOff.JoinNumber, false); - var autoCodec = codec as IHasCameraAutoMode; - if (autoCodec == null) return; + if (!(codec is IHasCameraAutoMode autoCodec)) return; - trilist.SetBool(joinMap.CameraModeAuto.JoinNumber, autoCodec.CameraAutoModeIsOnFeedback.BoolValue); + trilist.SetBool(joinMap.CameraModeAuto.JoinNumber, autoCodec.CameraAutoModeIsOnFeedback.BoolValue); trilist.SetBool(joinMap.CameraModeManual.JoinNumber, !autoCodec.CameraAutoModeIsOnFeedback.BoolValue); }; @@ -548,11 +536,10 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec trilist.SetBool(joinMap.CameraModeOff.JoinNumber, false); - var autoModeCodec = codec as IHasCameraAutoMode; - if (autoModeCodec == null) return; + if (!(codec is IHasCameraAutoMode autoModeCodec)) return; - trilist.SetBool(joinMap.CameraModeAuto.JoinNumber, autoModeCodec.CameraAutoModeIsOnFeedback.BoolValue); + trilist.SetBool(joinMap.CameraModeAuto.JoinNumber, autoModeCodec.CameraAutoModeIsOnFeedback.BoolValue); trilist.SetBool(joinMap.CameraModeManual.JoinNumber, !autoModeCodec.CameraAutoModeIsOnFeedback.BoolValue); } @@ -649,8 +636,7 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec var p = participant; if (index > MaxParticipants) break; - var audioMuteCodec = this as IHasParticipantAudioMute; - if (audioMuteCodec != null) + if (this is IHasParticipantAudioMute audioMuteCodec) { trilist.SetSigFalseAction(joinMap.ParticipantAudioMuteToggleStart.JoinNumber + index, () => audioMuteCodec.ToggleAudioForParticipant(p.UserId)); @@ -659,8 +645,7 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec () => audioMuteCodec.ToggleVideoForParticipant(p.UserId)); } - var pinCodec = this as IHasParticipantPinUnpin; - if (pinCodec != null) + if (this is IHasParticipantPinUnpin pinCodec) { trilist.SetSigFalseAction(joinMap.ParticipantPinToggleStart.JoinNumber + index, () => pinCodec.ToggleParticipantPinState(p.UserId, pinCodec.ScreenIndexToPinUserTo)); @@ -1089,29 +1074,25 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec // Allow auto dial of selected line. Always dials first contact method if (!trilist.GetBool(joinMap.DirectoryDisableAutoDialSelectedLine.JoinNumber)) { - var invitableEntry = _selectedDirectoryItem as IInvitableContact; - - if (invitableEntry != null) + if (_selectedDirectoryItem is IInvitableContact invitableEntry) { Dial(invitableEntry); return; } - var entryToDial = _selectedDirectoryItem as DirectoryContact; - trilist.SetString(joinMap.DirectoryEntrySelectedNumber.JoinNumber, + trilist.SetString(joinMap.DirectoryEntrySelectedNumber.JoinNumber, selectedContact != null ? selectedContact.ContactMethods[0].Number : string.Empty); - if (entryToDial == null) return; + if (!(_selectedDirectoryItem is DirectoryContact entryToDial)) return; Dial(entryToDial.ContactMethods[0].Number); } else { // If auto dial is disabled... - var entryToDial = _selectedDirectoryItem as DirectoryContact; - if (entryToDial == null) + if (!(_selectedDirectoryItem is DirectoryContact entryToDial)) { // Clear out values and actions from last selected item trilist.SetUshort(joinMap.SelectedContactMethodCount.JoinNumber, 0); @@ -1296,78 +1277,76 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec trilist.SetUshort(joinMap.ConnectedCallCount.JoinNumber, (ushort)ActiveCalls.Count); }; - var joinCodec = this as IJoinCalls; - if (joinCodec != null) - { - trilist.SetSigFalseAction(joinMap.JoinAllCalls.JoinNumber, () => joinCodec.JoinAllCalls()); + if (this is IJoinCalls joinCodec) + { + trilist.SetSigFalseAction(joinMap.JoinAllCalls.JoinNumber, () => joinCodec.JoinAllCalls()); - for (int i = 0; i < joinMap.JoinCallStart.JoinSpan; i++) - { - trilist.SetSigFalseAction((uint)(joinMap.JoinCallStart.JoinNumber + i), () => - { - var call = ActiveCalls[i]; - if (call != null) - { - joinCodec.JoinCall(call); - } - else - { - Debug.LogMessage(LogEventLevel.Information, this, "[Join Call] Unable to find call at index '{0}'", i); - } - }); - } - } + for (int i = 0; i < joinMap.JoinCallStart.JoinSpan; i++) + { + trilist.SetSigFalseAction((uint)(joinMap.JoinCallStart.JoinNumber + i), () => + { + var call = ActiveCalls[i]; + if (call != null) + { + joinCodec.JoinCall(call); + } + else + { + Debug.LogMessage(LogEventLevel.Information, this, "[Join Call] Unable to find call at index '{0}'", i); + } + }); + } + } - var holdCodec = this as IHasCallHold; - if (holdCodec != null) - { - trilist.SetSigFalseAction(joinMap.HoldAllCalls.JoinNumber, () => - { - foreach (var call in ActiveCalls) - { - holdCodec.HoldCall(call); - } - }); + if (this is IHasCallHold holdCodec) + { + trilist.SetSigFalseAction(joinMap.HoldAllCalls.JoinNumber, () => + { + foreach (var call in ActiveCalls) + { + holdCodec.HoldCall(call); + } + }); - for (int i = 0; i < joinMap.HoldCallsStart.JoinSpan; i++) - { - var index = i; + for (int i = 0; i < joinMap.HoldCallsStart.JoinSpan; i++) + { + var index = i; - trilist.SetSigFalseAction((uint)(joinMap.HoldCallsStart.JoinNumber + index), () => - { - if (index < 0 || index >= ActiveCalls.Count) return; + trilist.SetSigFalseAction((uint)(joinMap.HoldCallsStart.JoinNumber + index), () => + { + if (index < 0 || index >= ActiveCalls.Count) return; - var call = ActiveCalls[index]; - if (call != null) - { - holdCodec.HoldCall(call); - } - else - { - Debug.LogMessage(LogEventLevel.Information, this, "[Hold Call] Unable to find call at index '{0}'", i); - } - }); + var call = ActiveCalls[index]; + if (call != null) + { + holdCodec.HoldCall(call); + } + else + { + Debug.LogMessage(LogEventLevel.Information, this, "[Hold Call] Unable to find call at index '{0}'", i); + } + }); - trilist.SetSigFalseAction((uint)(joinMap.ResumeCallsStart.JoinNumber + index), () => - { - if (index < 0 || index >= ActiveCalls.Count) return; + trilist.SetSigFalseAction((uint)(joinMap.ResumeCallsStart.JoinNumber + index), () => + { + if (index < 0 || index >= ActiveCalls.Count) return; - var call = ActiveCalls[index]; - if (call != null) - { - holdCodec.ResumeCall(call); - } - else - { - Debug.LogMessage(LogEventLevel.Information, this, "[Resume Call] Unable to find call at index '{0}'", i); - } - }); - } - } + var call = ActiveCalls[index]; + if (call != null) + { + holdCodec.ResumeCall(call); + } + else + { + Debug.LogMessage(LogEventLevel.Information, this, "[Resume Call] Unable to find call at index '{0}'", i); + } + }); + } + } - trilist.OnlineStatusChange += (device, args) => + trilist.OnlineStatusChange += (device, args) => { if (!args.DeviceOnLine) return; @@ -1505,48 +1484,45 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec codec.CameraAutoModeIsOnFeedback.OutputChange += (o, a) => { - var offCodec = codec as IHasCameraOff; + if (codec is IHasCameraOff offCodec) + { + if (offCodec.CameraIsOffFeedback.BoolValue) + { + trilist.SetBool(joinMap.CameraModeAuto.JoinNumber, false); + trilist.SetBool(joinMap.CameraModeManual.JoinNumber, false); + trilist.SetBool(joinMap.CameraModeOff.JoinNumber, true); + return; + } - if (offCodec != null) - { - if (offCodec.CameraIsOffFeedback.BoolValue) - { - trilist.SetBool(joinMap.CameraModeAuto.JoinNumber, false); - trilist.SetBool(joinMap.CameraModeManual.JoinNumber, false); - trilist.SetBool(joinMap.CameraModeOff.JoinNumber, true); - return; - } + trilist.SetBool(joinMap.CameraModeAuto.JoinNumber, a.BoolValue); + trilist.SetBool(joinMap.CameraModeManual.JoinNumber, !a.BoolValue); + trilist.SetBool(joinMap.CameraModeOff.JoinNumber, false); + return; + } - trilist.SetBool(joinMap.CameraModeAuto.JoinNumber, a.BoolValue); - trilist.SetBool(joinMap.CameraModeManual.JoinNumber, !a.BoolValue); - trilist.SetBool(joinMap.CameraModeOff.JoinNumber, false); - return; - } - - trilist.SetBool(joinMap.CameraModeAuto.JoinNumber, a.BoolValue); + trilist.SetBool(joinMap.CameraModeAuto.JoinNumber, a.BoolValue); trilist.SetBool(joinMap.CameraModeManual.JoinNumber, !a.BoolValue); trilist.SetBool(joinMap.CameraModeOff.JoinNumber, false); }; - var offModeCodec = codec as IHasCameraOff; - if (offModeCodec != null) - { - if (offModeCodec.CameraIsOffFeedback.BoolValue) - { - trilist.SetBool(joinMap.CameraModeAuto.JoinNumber, false); - trilist.SetBool(joinMap.CameraModeManual.JoinNumber, false); - trilist.SetBool(joinMap.CameraModeOff.JoinNumber, true); - return; - } + if (codec is IHasCameraOff offModeCodec) + { + if (offModeCodec.CameraIsOffFeedback.BoolValue) + { + trilist.SetBool(joinMap.CameraModeAuto.JoinNumber, false); + trilist.SetBool(joinMap.CameraModeManual.JoinNumber, false); + trilist.SetBool(joinMap.CameraModeOff.JoinNumber, true); + return; + } - trilist.SetBool(joinMap.CameraModeAuto.JoinNumber, codec.CameraAutoModeIsOnFeedback.BoolValue); - trilist.SetBool(joinMap.CameraModeManual.JoinNumber, !codec.CameraAutoModeIsOnFeedback.BoolValue); - trilist.SetBool(joinMap.CameraModeOff.JoinNumber, false); - return; - } + trilist.SetBool(joinMap.CameraModeAuto.JoinNumber, codec.CameraAutoModeIsOnFeedback.BoolValue); + trilist.SetBool(joinMap.CameraModeManual.JoinNumber, !codec.CameraAutoModeIsOnFeedback.BoolValue); + trilist.SetBool(joinMap.CameraModeOff.JoinNumber, false); + return; + } - trilist.SetBool(joinMap.CameraModeAuto.JoinNumber, codec.CameraAutoModeIsOnFeedback.BoolValue); + trilist.SetBool(joinMap.CameraModeAuto.JoinNumber, codec.CameraAutoModeIsOnFeedback.BoolValue); trilist.SetBool(joinMap.CameraModeManual.JoinNumber, !codec.CameraAutoModeIsOnFeedback.BoolValue); trilist.SetBool(joinMap.CameraModeOff.JoinNumber, false); } @@ -1565,64 +1541,58 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec trilist.SetBoolSigAction(joinMap.CameraTiltUp.JoinNumber, (b) => { if (codec.SelectedCamera == null) return; - var camera = codec.SelectedCamera as IHasCameraPtzControl; - if (camera == null) return; + if (!(codec.SelectedCamera is IHasCameraPtzControl camera)) return; - if (b) camera.TiltUp(); + if (b) camera.TiltUp(); else camera.TiltStop(); }); trilist.SetBoolSigAction(joinMap.CameraTiltDown.JoinNumber, (b) => { if (codec.SelectedCamera == null) return; - var camera = codec.SelectedCamera as IHasCameraPtzControl; - if (camera == null) return; + if (!(codec.SelectedCamera is IHasCameraPtzControl camera)) return; - if (b) camera.TiltDown(); + if (b) camera.TiltDown(); else camera.TiltStop(); }); trilist.SetBoolSigAction(joinMap.CameraPanLeft.JoinNumber, (b) => { if (codec.SelectedCamera == null) return; - var camera = codec.SelectedCamera as IHasCameraPtzControl; - if (camera == null) return; + if (!(codec.SelectedCamera is IHasCameraPtzControl camera)) return; - if (b) camera.PanLeft(); + if (b) camera.PanLeft(); else camera.PanStop(); }); trilist.SetBoolSigAction(joinMap.CameraPanRight.JoinNumber, (b) => { if (codec.SelectedCamera == null) return; - var camera = codec.SelectedCamera as IHasCameraPtzControl; - if (camera == null) return; + if (!(codec.SelectedCamera is IHasCameraPtzControl camera)) return; - if (b) camera.PanRight(); + if (b) camera.PanRight(); else camera.PanStop(); }); trilist.SetBoolSigAction(joinMap.CameraZoomIn.JoinNumber, (b) => { if (codec.SelectedCamera == null) return; - var camera = codec.SelectedCamera as IHasCameraPtzControl; - if (camera == null) return; + if (!(codec.SelectedCamera is IHasCameraPtzControl camera)) return; - if (b) camera.ZoomIn(); + if (b) camera.ZoomIn(); else camera.ZoomStop(); }); trilist.SetBoolSigAction(joinMap.CameraZoomOut.JoinNumber, (b) => { if (codec.SelectedCamera == null) return; - var camera = codec.SelectedCamera as IHasCameraPtzControl; - if (camera == null) return; + if (!(codec.SelectedCamera is IHasCameraPtzControl camera)) return; - if (b) camera.ZoomOut(); + if (b) camera.ZoomOut(); else camera.ZoomStop(); }); @@ -1630,9 +1600,8 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec trilist.SetBoolSigAction(joinMap.CameraFocusNear.JoinNumber, (b) => { if (codec.SelectedCamera == null) return; - var camera = codec.SelectedCamera as IHasCameraFocusControl; - if (camera == null) return; + if (!(codec.SelectedCamera is IHasCameraFocusControl camera)) return; if (b) camera.FocusNear(); else camera.FocusStop(); @@ -1641,9 +1610,8 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec trilist.SetBoolSigAction(joinMap.CameraFocusFar.JoinNumber, (b) => { if (codec.SelectedCamera == null) return; - var camera = codec.SelectedCamera as IHasCameraFocusControl; - if (camera == null) return; + if (!(codec.SelectedCamera is IHasCameraFocusControl camera)) return; if (b) camera.FocusFar(); else camera.FocusStop(); @@ -1652,9 +1620,8 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec trilist.SetSigFalseAction(joinMap.CameraFocusAuto.JoinNumber, () => { if (codec.SelectedCamera == null) return; - var camera = codec.SelectedCamera as IHasCameraFocusControl; - if (camera == null) return; + if (!(codec.SelectedCamera is IHasCameraFocusControl camera)) return; camera.TriggerAutoFocus(); }); @@ -1773,7 +1740,6 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec // Following fields only used for Bridging private int _selectedRecentCallItemIndex; - private CodecCallHistory.CallHistoryEntry _selectedRecentCallItem; private DirectoryItem _selectedDirectoryItem; private void LinkVideoCodecCallHistoryToApi(IHasCallHistory codec, BasicTriList trilist, VideoCodecControllerJoinMap joinMap) @@ -1820,7 +1786,7 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec { // Clear out selected item _selectedRecentCallItemIndex = 0; - _selectedRecentCallItem = null; + trilist.SetUshort(joinMap.SelectRecentCallItem.JoinNumber, 0); trilist.SetString(joinMap.SelectedRecentCallName.JoinNumber, string.Empty); trilist.SetString(joinMap.SelectedRecentCallNumber.JoinNumber, string.Empty); @@ -1929,12 +1895,8 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec { if (value == true) { - var handler = InitialSyncCompleted; - if (handler != null) - { - handler(this, new EventArgs()); - } - } + InitialSyncCompleted?.Invoke(this, new EventArgs()); + } _InitialSyncComplete = value; } } diff --git a/src/PepperDash.Essentials.MobileControl.Messengers/DeviceTypeExtensions/DisplayBaseMessenger.cs b/src/PepperDash.Essentials.MobileControl.Messengers/DeviceTypeExtensions/DisplayBaseMessenger.cs index 3d15db76..cc09a637 100644 --- a/src/PepperDash.Essentials.MobileControl.Messengers/DeviceTypeExtensions/DisplayBaseMessenger.cs +++ b/src/PepperDash.Essentials.MobileControl.Messengers/DeviceTypeExtensions/DisplayBaseMessenger.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json.Linq; using PepperDash.Core; +using PepperDash.Core.Logging; using PepperDash.Essentials.AppServer; using PepperDash.Essentials.AppServer.Messengers; using System.Linq; @@ -32,7 +33,7 @@ namespace PepperDash.Essentials.Room.MobileControl if (inputPort == null) { - Debug.Console(1, "No input named {0} found for device {1}", s, display.Key); + this.LogWarning("No input named {inputName} found for {deviceKey}", s, display.Key); return; } diff --git a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IDspPresetsMessenger.cs b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IDspPresetsMessenger.cs index 31529566..e40cd8eb 100644 --- a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IDspPresetsMessenger.cs +++ b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IDspPresetsMessenger.cs @@ -7,12 +7,12 @@ namespace PepperDash.Essentials.AppServer.Messengers { public class IDspPresetsMessenger : MessengerBase { - private IDspPresets _device; + private readonly IDspPresets device; public IDspPresetsMessenger(string key, string messagePath, IDspPresets device) - : base(key, messagePath, device as Device) + : base(key, messagePath, device as IKeyName) { - _device = device; + this.device = device; } protected override void RegisterActions() @@ -23,7 +23,7 @@ namespace PepperDash.Essentials.AppServer.Messengers { var message = new IHasDspPresetsStateMessage { - Presets = _device.Presets + Presets = device.Presets }; PostStatusMessage(message); @@ -36,7 +36,7 @@ namespace PepperDash.Essentials.AppServer.Messengers if (!string.IsNullOrEmpty(presetKey)) { - _device.RecallPreset(presetKey); + device.RecallPreset(presetKey); } }); } diff --git a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IEssentialsRoomCombinerMessenger.cs b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IEssentialsRoomCombinerMessenger.cs index 2cedf5fa..9dc9eac7 100644 --- a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IEssentialsRoomCombinerMessenger.cs +++ b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IEssentialsRoomCombinerMessenger.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using PepperDash.Core; +using PepperDash.Core.Logging; using PepperDash.Essentials.Core; using System; using System.Collections.Generic; @@ -117,7 +118,7 @@ namespace PepperDash.Essentials.AppServer.Messengers } catch (Exception e) { - Debug.Console(0, this, "Error sending full status: {0}", e); + this.LogException(e, "Error sending full status"); } } diff --git a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IRunRouteActionMessenger.cs b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IRunRouteActionMessenger.cs index a5f2cf3a..98824530 100644 --- a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IRunRouteActionMessenger.cs +++ b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IRunRouteActionMessenger.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using PepperDash.Core; +using PepperDash.Core.Logging; using PepperDash.Essentials.Core; using System; @@ -43,7 +44,6 @@ namespace PepperDash.Essentials.AppServer.Messengers if (!string.IsNullOrEmpty(c.SourceListKey)) { // Check for source list in content of message - Debug.Console(1, this, "sourceListKey found in message"); sourceListKey = c.SourceListKey; } diff --git a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/LightingBaseMessenger.cs b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/LightingBaseMessenger.cs index 2fd02a25..5c04491b 100644 --- a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/LightingBaseMessenger.cs +++ b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/LightingBaseMessenger.cs @@ -45,8 +45,6 @@ namespace PepperDash.Essentials.AppServer.Messengers private void SendFullStatus() { - Debug.Console(2, "LightingBaseMessenger GetFullStatus"); - var state = new LightingBaseStateMessage { Scenes = Device.LightingScenes, diff --git a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/RoomEventScheduleMessenger.cs b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/RoomEventScheduleMessenger.cs index 8b3b5681..122dc883 100644 --- a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/RoomEventScheduleMessenger.cs +++ b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/RoomEventScheduleMessenger.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using PepperDash.Core; +using PepperDash.Core.Logging; using PepperDash.Essentials.Core; using PepperDash.Essentials.Room.Config; using System; @@ -51,7 +52,7 @@ namespace PepperDash.Essentials.AppServer.Messengers } catch (Exception ex) { - Debug.Console(0, this, "Exception saving event: {0}\r\n{1}", ex.Message, ex.StackTrace); + this.LogException(ex,"Exception saving event"); } } diff --git a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/SystemMonitorMessenger.cs b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/SystemMonitorMessenger.cs index 8b7750a2..2cb2ced0 100644 --- a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/SystemMonitorMessenger.cs +++ b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/SystemMonitorMessenger.cs @@ -59,16 +59,14 @@ namespace PepperDash.Essentials.AppServer.Messengers foreach (var p in systemMonitor.ProgramStatusFeedbackCollection) { - PostStatusMessage(JToken.FromObject(p.Value.ProgramInfo) - ); + PostStatusMessage(JToken.FromObject(p.Value.ProgramInfo)); } } private void SendSystemMonitorStatusMessage() { - Debug.Console(1, "Posting System Monitor Status Message."); - // This takes a while, launch a new thread + Task.Run(() => PostStatusMessage(JToken.FromObject(new SystemMonitorStateMessage { diff --git a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/VideoCodecBaseMessenger.cs b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/VideoCodecBaseMessenger.cs index fab0fe3b..a27e899b 100644 --- a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/VideoCodecBaseMessenger.cs +++ b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/VideoCodecBaseMessenger.cs @@ -2,6 +2,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using PepperDash.Core; +using PepperDash.Core.Logging; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.DeviceTypeInterfaces; using PepperDash.Essentials.Devices.Common.Cameras; @@ -111,7 +112,7 @@ namespace PepperDash.Essentials.AppServer.Messengers if (Codec is IHasDirectory dirCodec) { - Debug.Console(2, this, "Sending Directory. Directory Item Count: {0}", directory.CurrentDirectoryResults.Count); + this.LogVerbose("Sending Directory. Directory Item Count: {directoryItemCount}", directory.CurrentDirectoryResults.Count); //state.CurrentDirectory = PrefixDirectoryFolderItems(directory); state.CurrentDirectory = directory; @@ -238,7 +239,7 @@ namespace PepperDash.Essentials.AppServer.Messengers } if (Codec is IHasCodecCameras cameraCodec) { - Debug.Console(2, this, "Adding IHasCodecCameras Actions"); + this.LogVerbose("Adding IHasCodecCameras Actions"); cameraCodec.CameraSelected += CameraCodec_CameraSelected; @@ -254,7 +255,7 @@ namespace PepperDash.Essentials.AppServer.Messengers if (Codec is IHasCodecRoomPresets presetsCodec) { - Debug.Console(2, this, "Adding IHasCodecRoomPresets Actions"); + this.LogVerbose("Adding IHasCodecRoomPresets Actions"); presetsCodec.CodecRoomPresetsListHasChanged += PresetsCodec_CameraPresetsListHasChanged; @@ -275,7 +276,7 @@ namespace PepperDash.Essentials.AppServer.Messengers if (Codec is IHasCameraAutoMode speakerTrackCodec) { - Debug.Console(2, this, "Adding IHasCameraAutoMode Actions"); + this.LogVerbose("Adding IHasCameraAutoMode Actions"); speakerTrackCodec.CameraAutoModeIsOnFeedback.OutputChange += CameraAutoModeIsOnFeedback_OutputChange; @@ -286,7 +287,7 @@ namespace PepperDash.Essentials.AppServer.Messengers if (Codec is IHasCameraOff cameraOffCodec) { - Debug.Console(2, this, "Adding IHasCameraOff Actions"); + this.LogVerbose("Adding IHasCameraOff Actions"); cameraOffCodec.CameraIsOffFeedback.OutputChange += (CameraIsOffFeedback_OutputChange); @@ -298,7 +299,7 @@ namespace PepperDash.Essentials.AppServer.Messengers if (Codec is IHasCodecSelfView selfViewCodec) { - Debug.Console(2, this, "Adding IHasCodecSelfView Actions"); + this.LogVerbose("Adding IHasCodecSelfView Actions"); AddAction("/cameraSelfView", (id, content) => selfViewCodec.SelfViewModeToggle()); @@ -308,7 +309,7 @@ namespace PepperDash.Essentials.AppServer.Messengers if (Codec is IHasCodecLayouts layoutsCodec) { - Debug.Console(2, this, "Adding IHasCodecLayouts Actions"); + this.LogVerbose("Adding IHasCodecLayouts Actions"); AddAction("/cameraRemoteView", (id, content) => layoutsCodec.LocalLayoutToggle()); @@ -317,7 +318,7 @@ namespace PepperDash.Essentials.AppServer.Messengers if (Codec is IPasswordPrompt pwCodec) { - Debug.Console(2, this, "Adding IPasswordPrompt Actions"); + this.LogVerbose("Adding IPasswordPrompt Actions"); AddAction("/password", (id, content) => { @@ -334,7 +335,7 @@ namespace PepperDash.Essentials.AppServer.Messengers (sender, args) => PostReceivingContent(args.BoolValue); } - Debug.Console(2, this, "Adding Privacy & Standby Actions"); + this.LogVerbose("Adding Privacy & Standby Actions"); AddAction("/privacyModeOn", (id, content) => Codec.PrivacyModeOn()); AddAction("/privacyModeOff", (id, content) => Codec.PrivacyModeOff()); @@ -346,7 +347,7 @@ namespace PepperDash.Essentials.AppServer.Messengers } catch (Exception e) { - Debug.Console(2, this, "Error: {0}", e); + this.LogException(e, "Exception adding paths"); } } diff --git a/src/PepperDash.Essentials.MobileControl.Messengers/PepperDash.Essentials.MobileControl.Messengers.csproj b/src/PepperDash.Essentials.MobileControl.Messengers/PepperDash.Essentials.MobileControl.Messengers.csproj index 111d4c2c..0990c65d 100644 --- a/src/PepperDash.Essentials.MobileControl.Messengers/PepperDash.Essentials.MobileControl.Messengers.csproj +++ b/src/PepperDash.Essentials.MobileControl.Messengers/PepperDash.Essentials.MobileControl.Messengers.csproj @@ -26,16 +26,24 @@ pdbonly $(DefineConstants);SERIES4 + + + + + + + + - + false runtime - + false runtime diff --git a/src/PepperDash.Essentials.MobileControl/MobileControlDeviceFactory.cs b/src/PepperDash.Essentials.MobileControl/MobileControlDeviceFactory.cs index 0c1f1087..9fc8cc41 100644 --- a/src/PepperDash.Essentials.MobileControl/MobileControlDeviceFactory.cs +++ b/src/PepperDash.Essentials.MobileControl/MobileControlDeviceFactory.cs @@ -31,54 +31,4 @@ namespace PepperDash.Essentials } } } - - public class MobileControlSimplFactory : EssentialsDeviceFactory - { - public MobileControlSimplFactory() - { - TypeNames = new List { "mobilecontrolbridge-ddvc01", "mobilecontrolbridge-simpl" }; - } - - public override EssentialsDevice BuildDevice(DeviceConfig dc) - { - var comm = CommFactory.GetControlPropertiesConfig(dc); - - var bridge = new MobileControlSIMPLRoomBridge(dc.Key, dc.Name, comm.IpIdInt); - - bridge.AddPreActivationAction(() => - { - var parent = GetMobileControlDevice(); - - if (parent == null) - { - bridge.LogInformation("ERROR: Cannot connect bridge. System controller not present"); - return; - } - bridge.LogInformation("Linking to parent controller"); - - parent.AddDeviceMessenger(bridge); - }); - - return bridge; - } - - private static MobileControlSystemController GetMobileControlDevice() - { - var mobileControlList = DeviceManager.AllDevices.OfType().ToList(); - - if (mobileControlList.Count > 1) - { - Debug.LogMessage(LogEventLevel.Warning, "Multiple instances of Mobile Control Server found."); - return null; - } - - if (mobileControlList.Count > 0) - { - return mobileControlList[0]; - } - - Debug.LogMessage(LogEventLevel.Warning, "Mobile Control not enabled for this system"); - return null; - } - } } \ No newline at end of file diff --git a/src/PepperDash.Essentials/ControlSystem.cs b/src/PepperDash.Essentials/ControlSystem.cs index 5955faaa..7a32a459 100644 --- a/src/PepperDash.Essentials/ControlSystem.cs +++ b/src/PepperDash.Essentials/ControlSystem.cs @@ -261,7 +261,7 @@ namespace PepperDash.Essentials _ = new DeviceFactory(); _ = new ProcessorExtensionDeviceFactory(); - _ = new MobileControl.MobileControlFactory(); + _ = new MobileControlFactory(); Debug.LogMessage(LogEventLevel.Information, "Starting Essentials load from configuration");