From 4d98191fa70430dad14fd0d460b4c9bf9cbfba26 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Tue, 25 Mar 2025 21:53:41 -0500 Subject: [PATCH] chore: remove obsolete log methods --- .../MobileControlDeviceFactory.cs | 14 +- .../MobileControlSystemController.cs | 662 ++++++------------ .../MobileControlSIMPLRoomBridge.cs | 3 +- .../Touchpanel/ITswAppControlMessenger.cs | 3 +- .../Touchpanel/ITswZoomControlMessenger.cs | 3 +- .../TransmitMessage.cs | 103 ++- .../WebApiHandlers/UiClientHandler.cs | 3 +- .../MobileControlWebsocketServer.cs | 99 +-- 8 files changed, 309 insertions(+), 581 deletions(-) diff --git a/src/PepperDash.Essentials.MobileControl/MobileControlDeviceFactory.cs b/src/PepperDash.Essentials.MobileControl/MobileControlDeviceFactory.cs index 0d589c9f..6ccbb382 100644 --- a/src/PepperDash.Essentials.MobileControl/MobileControlDeviceFactory.cs +++ b/src/PepperDash.Essentials.MobileControl/MobileControlDeviceFactory.cs @@ -1,7 +1,9 @@ using PepperDash.Core; +using PepperDash.Core.Logging; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Room.MobileControl; +using Serilog.Events; using System; using System.Collections.Generic; using System.Linq; @@ -50,13 +52,10 @@ namespace PepperDash.Essentials if (parent == null) { - Debug.Console(0, bridge, "ERROR: Cannot connect bridge. System controller not present"); + bridge.LogInformation("ERROR: Cannot connect bridge. System controller not present"); return; } - Debug.Console(0, bridge, "Linking to parent controller"); - - /*bridge.AddParent(parent); - parent.AddBridge(bridge);*/ + bridge.LogInformation("Linking to parent controller"); parent.AddDeviceMessenger(bridge); }); @@ -70,8 +69,7 @@ namespace PepperDash.Essentials if (mobileControlList.Count > 1) { - Debug.Console(0, Debug.ErrorLogLevel.Warning, - "Multiple instances of Mobile Control Server found."); + Debug.LogMessage(LogEventLevel.Warning, "Multiple instances of Mobile Control Server found."); return null; } @@ -80,7 +78,7 @@ namespace PepperDash.Essentials return mobileControlList[0]; } - Debug.Console(0, Debug.ErrorLogLevel.Notice, "Mobile Control not enabled for this system"); + Debug.LogMessage(LogEventLevel.Warning, "Mobile Control not enabled for this system"); return null; } } diff --git a/src/PepperDash.Essentials.MobileControl/MobileControlSystemController.cs b/src/PepperDash.Essentials.MobileControl/MobileControlSystemController.cs index f7356f10..898fd10b 100644 --- a/src/PepperDash.Essentials.MobileControl/MobileControlSystemController.cs +++ b/src/PepperDash.Essentials.MobileControl/MobileControlSystemController.cs @@ -98,19 +98,13 @@ namespace PepperDash.Essentials return ConfigReader.ConfigObject.SystemUuid; } - Debug.Console( - 0, - this, - Debug.ErrorLogLevel.Notice, + this.LogWarning( "No system_url value defined in config. Checking for value from SIMPL Bridge." ); if (!string.IsNullOrEmpty(SystemUrl)) { - Debug.Console( - 0, - this, - Debug.ErrorLogLevel.Error, + this.LogError( "No system_url value defined in config or SIMPL Bridge. Unable to connect to Mobile Control." ); return string.Empty; @@ -206,9 +200,7 @@ namespace PepperDash.Essentials ApiService = new MobileControlApiService(Host); - Debug.Console( - 0, - this, + this.LogInformation( "Mobile UI controller initializing for server:{0}", config.ServerUrl ); @@ -250,15 +242,15 @@ namespace PepperDash.Essentials private void SetupDefaultRoomMessengers() { - Debug.LogMessage(LogEventLevel.Verbose, "Setting up room messengers", this); + this.LogVerbose("Setting up room messengers"); + foreach (var room in DeviceManager.AllDevices.OfType()) { - Debug.LogMessage( - LogEventLevel.Verbose, - "Setting up room messengers for room: {key}", - this, + this.LogVerbose( + "Setting up room messengers for room: {key}", room.Key ); + var messenger = new MobileControlEssentialsRoomBridge(room); messenger.AddParent(this); @@ -267,16 +259,14 @@ namespace PepperDash.Essentials AddDefaultDeviceMessenger(messenger); - Debug.LogMessage( - LogEventLevel.Verbose, - "Attempting to set up default room messengers for room: {0}", - this, + this.LogVerbose( + "Attempting to set up default room messengers for room: {0}", room.Key ); if (room is IRoomEventSchedule) { - Debug.LogMessage(LogEventLevel.Information, "Setting up event schedule messenger for room: {key}", this, room.Key); + this.LogInformation("Setting up event schedule messenger for room: {key}", room.Key); var scheduleMessenger = new RoomEventScheduleMessenger( $"{room.Key}-schedule-{Key}", @@ -289,7 +279,7 @@ namespace PepperDash.Essentials if (room is ITechPassword) { - Debug.LogMessage(LogEventLevel.Information, "Setting up tech password messenger for room: {key}", this, room.Key); + this.LogInformation("Setting up tech password messenger for room: {key}", room.Key); var techPasswordMessenger = new ITechPasswordMessenger( $"{room.Key}-techPassword-{Key}", @@ -302,7 +292,7 @@ namespace PepperDash.Essentials if (room is IShutdownPromptTimer) { - Debug.LogMessage(LogEventLevel.Information, "Setting up shutdown prompt timer messenger for room: {key}", this, room.Key); + this.LogInformation("Setting up shutdown prompt timer messenger for room: {key}", this, room.Key); var shutdownPromptTimerMessenger = new IShutdownPromptTimerMessenger( $"{room.Key}-shutdownPromptTimer-{Key}", @@ -315,7 +305,7 @@ namespace PepperDash.Essentials if (room is ILevelControls levelControls) { - Debug.LogMessage(LogEventLevel.Information, "Setting up level controls messenger for room: {key}", this, room.Key); + this.LogInformation("Setting up level controls messenger for room: {key}", this, room.Key); var levelControlsMessenger = new ILevelControlsMessenger( $"{room.Key}-levelControls-{Key}", @@ -334,77 +324,71 @@ namespace PepperDash.Essentials private void SetupDefaultDeviceMessengers() { bool messengerAdded = false; + var allDevices = DeviceManager.AllDevices.Where((d) => !(d is IEssentialsRoom)); - Debug.LogMessage( - LogEventLevel.Verbose, - "All Devices that aren't rooms count: {0}", - this, + + this.LogInformation( + "All Devices that aren't rooms count: {0}", allDevices?.Count() ); + var count = allDevices.Count(); + foreach (var device in allDevices) { try { - Debug.LogMessage( - LogEventLevel.Verbose, - "Attempting to set up device messengers for device: {0}", - this, + this.LogVerbose( + "Attempting to set up device messengers for {deviceKey}", device.Key ); + // StatusMonitorBase which is prop of ICommunicationMonitor is not a PepperDash.Core.Device, but is in the device array if (device is ICommunicationMonitor) { - Debug.LogMessage( - LogEventLevel.Verbose, - "Trying to cast to ICommunicationMonitor for device: {0}", - this, + this.LogVerbose( + "Checking if {deviceKey} implements ICommunicationMonitor", device.Key ); - var commMonitor = device as ICommunicationMonitor; - if (commMonitor == null) + + if (!(device is ICommunicationMonitor commMonitor)) { - Debug.LogMessage( - LogEventLevel.Debug, - "[Error] CommunicationMonitor cast is null for device: {0}. Skipping CommunicationMonitorMessenger", - this, + this.LogDebug( + "{deviceKey} does not implement ICommunicationMonitor. Skipping CommunicationMonitorMessenger", device.Key ); - Debug.LogMessage( - LogEventLevel.Debug, - "AllDevices Completed a device. Devices Left: {0}", - this, - --count - ); + + this.LogDebug("Created all messengers for {deviceKey}. Devices Left: {deviceCount}", device.Key, --count); + continue; } - Debug.LogMessage( - LogEventLevel.Debug, - "Adding CommunicationMonitorMessenger for device: {0}", - this, + + this.LogDebug( + "Adding CommunicationMonitorMessenger for {deviceKey}", device.Key ); + var commMessenger = new ICommunicationMonitorMessenger( $"{device.Key}-commMonitor-{Key}", string.Format("/device/{0}", device.Key), commMonitor ); + AddDefaultDeviceMessenger(commMessenger); + messengerAdded = true; } - if (device is CameraBase) + if (device is CameraBase cameraDevice) { - Debug.Console( - 2, - this, - "Adding CameraBaseMessenger for device: {0}", + this.LogVerbose( + "Adding CameraBaseMessenger for {deviceKey}", device.Key ); var cameraMessenger = new CameraBaseMessenger( $"{device.Key}-cameraBase-{Key}", - device as CameraBase, + cameraDevice, $"/device/{device.Key}" ); @@ -415,10 +399,8 @@ namespace PepperDash.Essentials if (device is BlueJeansPc) { - Debug.Console( - 2, - this, - "Adding IRunRouteActionMessnger for device: {0}", + this.LogVerbose( + "Adding IRunRouteActionMessnger for {deviceKey}", device.Key ); @@ -435,30 +417,16 @@ namespace PepperDash.Essentials if (device is ITvPresetsProvider) { - Debug.LogMessage( - LogEventLevel.Verbose, - "Trying to cast to ITvPresetsProvider for device: {0}", - this, + this.LogVerbose( + "Trying to cast to ITvPresetsProvider for {deviceKey}", device.Key ); var presetsDevice = device as ITvPresetsProvider; - if (presetsDevice.TvPresets == null) - { - Debug.Console( - 2, - this, - "TvPresets is null for device: '{0}'. Skipping DevicePresetsModelMessenger", - device.Key - ); - } - else - { - Debug.Console( - 2, - this, - "Adding ITvPresetsProvider for device: {0}", + + this.LogVerbose( + "Adding ITvPresetsProvider for {deviceKey}", device.Key ); @@ -472,11 +440,11 @@ namespace PepperDash.Essentials messengerAdded = true; } - } + if (device is DisplayBase) { - Debug.Console(2, this, "Adding actions for device: {0}", device.Key); + this.LogVerbose( "Adding actions for device: {0}", device.Key); var dbMessenger = new DisplayBaseMessenger( $"{device.Key}-displayBase-{Key}", @@ -489,26 +457,10 @@ namespace PepperDash.Essentials messengerAdded = true; } - //if (device is Core.DisplayBase) - //{ - // Debug.Console(2, this, "Adding actions for device: {0}", device.Key); - - // var dbMessenger = new CoreDisplayBaseMessenger( - // $"{device.Key}-displayBase-{Key}", - // $"/device/{device.Key}", - // device as Core.DisplayBase - // ); - // AddDefaultDeviceMessenger(dbMessenger); - - // messengerAdded = true; - //} - if (device is TwoWayDisplayBase twoWayDisplay) { - Debug.Console( - 2, - this, - "Adding TwoWayDisplayBase for device: {0}", + this.LogVerbose( + "Adding TwoWayDisplayBase for {deviceKey}", device.Key ); var twoWayDisplayMessenger = new TwoWayDisplayBaseMessenger( @@ -524,12 +476,11 @@ namespace PepperDash.Essentials if (device is IBasicVolumeWithFeedback) { var deviceKey = device.Key; - Debug.Console( - 2, - this, - "Adding IBasicVolumeControlWithFeedback for device: {0}", - deviceKey - ); + this.LogVerbose( + "Adding IBasicVolumeControlWithFeedback for {deviceKey}", + deviceKey + ); + var volControlDevice = device as IBasicVolumeWithFeedback; var messenger = new DeviceVolumeMessenger( $"{device.Key}-volume-{Key}", @@ -544,12 +495,12 @@ namespace PepperDash.Essentials if (device is ILightingScenes) { var deviceKey = device.Key; - Debug.Console( - 2, - this, - "Adding LightingBaseMessenger for device: {0}", + + this.LogVerbose( + "Adding LightingBaseMessenger for {deviceKey}", deviceKey ); + var lightingDevice = device as ILightingScenes; var messenger = new ILightingScenesMessenger( $"{device.Key}-lighting-{Key}", @@ -565,12 +516,12 @@ namespace PepperDash.Essentials { var deviceKey = device.Key; var shadeDevice = device as IShadesOpenCloseStop; - Debug.Console( - 2, - this, - "Adding ShadeBaseMessenger for device: {0}", + + this.LogVerbose( + "Adding ShadeBaseMessenger for {deviceKey}", deviceKey ); + var messenger = new IShadesOpenCloseStopMessenger( $"{device.Key}-shades-{Key}", shadeDevice, @@ -583,11 +534,8 @@ namespace PepperDash.Essentials if (device is VideoCodecBase codec) { - Debug.Console( - 2, - this, - $"Adding VideoCodecBaseMessenger for device: {codec.Key}" - ); + this.LogVerbose( + "Adding VideoCodecBaseMessenger for {deviceKey}", codec.Key ); var messenger = new VideoCodecBaseMessenger( $"{codec.Key}-videoCodec-{Key}", @@ -602,10 +550,8 @@ namespace PepperDash.Essentials if (device is AudioCodecBase audioCodec) { - Debug.Console( - 2, - this, - $"Adding AudioCodecBaseMessenger for device: {audioCodec.Key}" + this.LogVerbose( + "Adding AudioCodecBaseMessenger for {deviceKey}", audioCodec.Key ); var messenger = new AudioCodecBaseMessenger( @@ -621,13 +567,11 @@ namespace PepperDash.Essentials if (device is ISetTopBoxControls) { - Debug.Console( - 2, - this, - $"Adding ISetTopBoxControlMessenger for device: {device.Key}" + this.LogVerbose( + "Adding ISetTopBoxControlMessenger for {deviceKey}" ); - var dev = device as PepperDash.Core.Device; + var dev = device as Device; var messenger = new ISetTopBoxControlsMessenger( $"{device.Key}-stb-{Key}", @@ -642,10 +586,8 @@ namespace PepperDash.Essentials if (device is IChannel) { - Debug.Console( - 2, - this, - $"Adding IChannelMessenger for device: {device.Key}" + this.LogVerbose( + "Adding IChannelMessenger for {deviceKey}", device.Key ); var dev = device as PepperDash.Core.Device; @@ -663,7 +605,7 @@ namespace PepperDash.Essentials if (device is IColor) { - Debug.Console(2, this, $"Adding IColorMessenger for device: {device.Key}"); + this.LogVerbose("Adding IColorMessenger for {deviceKey}", device.Key); var dev = device as PepperDash.Core.Device; @@ -680,7 +622,7 @@ namespace PepperDash.Essentials if (device is IDPad) { - Debug.Console(2, this, $"Adding IDPadMessenger for device: {device.Key}"); + this.LogVerbose("Adding IDPadMessenger for {deviceKey}", device.Key); var dev = device as PepperDash.Core.Device; @@ -697,11 +639,7 @@ namespace PepperDash.Essentials if (device is INumericKeypad) { - Debug.Console( - 2, - this, - $"Adding INumericKeyapdMessenger for device: {device.Key}" - ); + this.LogVerbose("Adding INumericKeyapdMessenger for {deviceKey}", device.Key); var dev = device as PepperDash.Core.Device; @@ -718,11 +656,7 @@ namespace PepperDash.Essentials if (device is IHasPowerControl) { - Debug.Console( - 2, - this, - $"Adding IHasPowerControlMessenger for device: {device.Key}" - ); + this.LogVerbose("Adding IHasPowerControlMessenger for {deviceKey}", device.Key); var dev = device as PepperDash.Core.Device; @@ -740,10 +674,8 @@ namespace PepperDash.Essentials if (device is IHasPowerControlWithFeedback powerControl) { var deviceKey = device.Key; - Debug.Console( - 2, - this, - "Adding IHasPowerControlWithFeedbackMessenger for device: {0}", + this.LogVerbose( + "Adding IHasPowerControlWithFeedbackMessenger for {deviceKey}", deviceKey ); @@ -758,10 +690,8 @@ namespace PepperDash.Essentials if (device is ITransport) { - Debug.Console( - 2, - this, - $"Adding ITransportMessenger for device: {device.Key}" + this.LogVerbose( + "Adding ITransportMessenger for {deviceKey}", device.Key ); var dev = device as PepperDash.Core.Device; @@ -779,11 +709,7 @@ namespace PepperDash.Essentials if (device is IHasCurrentSourceInfoChange) { - Debug.Console( - 2, - this, - $"Adding IHasCurrentSourceInfoMessenger for device: {device.Key}" - ); + this.LogVerbose("Adding IHasCurrentSourceInfoMessenger for {deviceKey}", device.Key ); var messenger = new IHasCurrentSourceInfoMessenger( $"{device.Key}-currentSource-{Key}", @@ -798,10 +724,8 @@ namespace PepperDash.Essentials if (device is ISwitchedOutput) { - Debug.Console( - 2, - this, - $"Adding ISwitchedOutputMessenger for device: {device.Key}" + this.LogVerbose( + "Adding ISwitchedOutputMessenger for {deviceKey}", device.Key ); var messenger = new ISwitchedOutputMessenger( @@ -817,10 +741,7 @@ namespace PepperDash.Essentials if (device is IDeviceInfoProvider provider) { - Debug.Console( - 2, - this, - $"Adding IHasDeviceInfoMessenger for device: {device.Key}" + this.LogVerbose("Adding IHasDeviceInfoMessenger for {deviceKey}", device.Key ); var messenger = new DeviceInfoMessenger( @@ -836,10 +757,8 @@ namespace PepperDash.Essentials if (device is ILevelControls levelControls) { - Debug.Console( - 2, - this, - $"Adding LevelControlsMessenger for device: {device.Key}" + this.LogVerbose( + "Adding LevelControlsMessenger for {deviceKey}", device.Key ); var messenger = new ILevelControlsMessenger( @@ -855,41 +774,41 @@ namespace PepperDash.Essentials // This will work if TKey and TSelector are both string types. // Otherwise plugin device needs to instantiate ISelectableItemsMessenger and add it to the controller. - if (device is IHasInputs inputs) - { - Debug.Console(2, this, $"Adding InputsMessenger for device: {device.Key}"); + //if (device is IHasInputs inputs) + //{ + // this.LogVerbose("Adding InputsMessenger for {deviceKey}", device.Key); - var messenger = new ISelectableItemsMessenger( - $"{device.Key}-inputs-{Key}", - $"/device/{device.Key}", - inputs.Inputs, - "inputs" - ); + // var messenger = new ISelectableItemsMessenger( + // $"{device.Key}-inputs-{Key}", + // $"/device/{device.Key}", + // inputs.Inputs, + // "inputs" + // ); - AddDefaultDeviceMessenger(messenger); + // AddDefaultDeviceMessenger(messenger); - messengerAdded = true; - } + // messengerAdded = true; + //} - if (device is IHasInputs byteIntInputs) - { - Debug.Console(2, this, $"Adding InputsMessenger for device: {device.Key}"); + //if (device is IHasInputs byteIntInputs) + //{ + // this.LogVerbose("Adding InputsMessenger for {deviceKey}", device.Key); - var messenger = new ISelectableItemsMessenger( - $"{device.Key}-inputs-{Key}", - $"/device/{device.Key}", - byteIntInputs.Inputs, - "inputs" - ); + // var messenger = new ISelectableItemsMessenger( + // $"{device.Key}-inputs-{Key}", + // $"/device/{device.Key}", + // byteIntInputs.Inputs, + // "inputs" + // ); - AddDefaultDeviceMessenger(messenger); + // AddDefaultDeviceMessenger(messenger); - messengerAdded = true; - } + // messengerAdded = true; + //} if (device is IHasInputs stringInputs) { - Debug.Console(2, this, $"Adding InputsMessenger for device: {device.Key}"); + this.LogVerbose("Adding InputsMessenger for {deviceKey}", device.Key); var messenger = new ISelectableItemsMessenger( $"{device.Key}-inputs-{Key}", @@ -905,7 +824,7 @@ namespace PepperDash.Essentials if (device is IHasInputs byteInputs) { - Debug.Console(2, this, $"Adding InputsMessenger for device: {device.Key}"); + this.LogVerbose("Adding InputsMessenger for {deviceKey}", device.Key); var messenger = new ISelectableItemsMessenger( $"{device.Key}-inputs-{Key}", @@ -921,7 +840,7 @@ namespace PepperDash.Essentials if (device is IHasInputs intInputs) { - Debug.Console(2, this, $"Adding InputsMessenger for device: {device.Key}"); + this.LogVerbose("Adding InputsMessenger for {deviceKey}", device.Key); var messenger = new ISelectableItemsMessenger( $"{device.Key}-inputs-{Key}", @@ -938,10 +857,8 @@ namespace PepperDash.Essentials if (device is IMatrixRouting matrix) { - Debug.LogMessage( - Serilog.Events.LogEventLevel.Verbose, - "Adding IMatrixRoutingMessenger for device: {key}", - this, + this.LogVerbose( + "Adding IMatrixRoutingMessenger for {deviceKey}", device.Key ); @@ -958,10 +875,8 @@ namespace PepperDash.Essentials if (device is ITemperatureSensor tempSensor) { - Debug.LogMessage( - Serilog.Events.LogEventLevel.Verbose, - "Adding ITemperatureSensor for device: {key}", - this, + this.LogVerbose( + "Adding ITemperatureSensor for {deviceKey}", device.Key ); @@ -978,10 +893,8 @@ namespace PepperDash.Essentials if (device is IHumiditySensor humSensor) { - Debug.LogMessage( - Serilog.Events.LogEventLevel.Verbose, - "Adding IHumiditySensor for device: {key}", - this, + this.LogVerbose( + "Adding IHumiditySensor for {deviceKey}", device.Key ); @@ -998,10 +911,8 @@ namespace PepperDash.Essentials if (device is IEssentialsRoomCombiner roomCombiner) { - Debug.Console( - 2, - this, - $"Adding IEssentialsRoomCombinerMessenger for device: {device.Key}" + this.LogVerbose( + "Adding IEssentialsRoomCombinerMessenger for {deviceKey}", device.Key ); var messenger = new IEssentialsRoomCombinerMessenger( @@ -1014,12 +925,10 @@ namespace PepperDash.Essentials messengerAdded = true; } + if (device is IProjectorScreenLiftControl screenLiftControl) { - Debug.Console( - 2, - this, - $"Adding IProjectorScreenLiftControlMessenger for device: {device.Key}" + this.LogVerbose("Adding IProjectorScreenLiftControlMessenger for {deviceKey}", device.Key ); var messenger = new IProjectorScreenLiftControlMessenger( @@ -1035,10 +944,7 @@ namespace PepperDash.Essentials if (device is IDspPresets dspPresets) { - Debug.Console( - 2, - this, - $"Adding IDspPresetsMessenger for device: {device.Key}" + this.LogVerbose("Adding IDspPresetsMessenger for {deviceKey}", device.Key ); var messenger = new IDspPresetsMessenger( @@ -1052,39 +958,32 @@ namespace PepperDash.Essentials messengerAdded = true; } - Debug.LogMessage( - LogEventLevel.Verbose, - "Trying to cast to generic device for device: {key}", - this, - device.Key - ); + this.LogVerbose("Trying to cast to generic device for device: {key}", device.Key ); + if (device is EssentialsDevice) { var genericDevice = device as EssentialsDevice; + if (genericDevice == null || messengerAdded) { - Debug.LogMessage( - LogEventLevel.Verbose, - "Skipping GenericMessenger for device: {0}. Messenger Added: {1}. GenericDevice null: {2}", - this, + this.LogVerbose( + "Skipping GenericMessenger for {deviceKey}. Messenger(s) Added: {messengersAdded}.", device.Key, - messengerAdded, - genericDevice == null + messengerAdded ); - Debug.LogMessage( - LogEventLevel.Debug, - "AllDevices Completed a device. Devices Left: {0}", - this, + this.LogDebug( + "AllDevices Completed a device. Devices Left: {count}", --count ); continue; } - Debug.LogMessage( - LogEventLevel.Debug, - "Adding GenericMessenger for device: {0}", + + this.LogDebug( + "Adding GenericMessenger for {deviceKey}", this, genericDevice?.Key ); + AddDefaultDeviceMessenger( new GenericMessenger( genericDevice.Key + "-" + Key + "-generic", @@ -1095,29 +994,20 @@ namespace PepperDash.Essentials } else { - Debug.LogMessage( - LogEventLevel.Verbose, - "Not Essentials Device. Skipping GenericMessenger for device: {0}", - this, + this.LogVerbose( + "Not Essentials Device. Skipping GenericMessenger for {deviceKey}", device.Key ); } - Debug.LogMessage( - LogEventLevel.Debug, - "AllDevices Completed a device. Devices Left: {0}", - this, + this.LogDebug( + "AllDevices Completed a device. Devices Left: {count}", --count ); } + catch (Exception ex) { - Debug.LogMessage( - LogEventLevel.Verbose, - "[ERROR] setting up default device messengers: {0}", - this, - ex.Message - ); - Debug.LogMessage(ex, "[ERROR] setting up default device messengers", this); + this.LogException(ex, "Exception setting up default device messengers"); } } } @@ -1130,10 +1020,11 @@ namespace PepperDash.Essentials if (apiServer == null) { - Debug.Console(0, this, "No API Server available"); + this.LogWarning("No API Server available"); return; } + // TODO: Add routes for the rest of the MC console commands var routes = new List { new HttpCwsRoute($"device/{Key}/authorize") @@ -1204,31 +1095,28 @@ namespace PepperDash.Essentials s => { _disableReconnect = false; - Debug.Console( - 1, - this, - Debug.ErrorLogLevel.Notice, - "User command: {0}", - "mobileConnect" + + CrestronConsole.ConsoleCommandResponse( + $"Connecting to MC API server" ); - ConnectWebsocketClient(); + + ConnectWebsocketClient(); }, "mobileconnect", "Forces connect of websocket", ConsoleAccessLevelEnum.AccessOperator ); + CrestronConsole.AddNewConsoleCommand( s => { _disableReconnect = true; - Debug.Console( - 1, - this, - Debug.ErrorLogLevel.Notice, - "User command: {0}", - "mobileDisco" - ); + CleanUpWebsocketClient(); + + CrestronConsole.ConsoleCommandResponse( + $"Disonnected from MC API server" + ); }, "mobiledisco", "Disconnects websocket", @@ -1273,7 +1161,7 @@ namespace PepperDash.Essentials { if (_messengers.ContainsKey(messenger.Key)) { - Debug.Console(1, this, "Messenger with key {0} already added", messenger.Key); + this.LogWarning("Messenger with key {messengerKey) already added", messenger.Key); return; } @@ -1287,10 +1175,8 @@ namespace PepperDash.Essentials _roomBridges.Add(roomBridge); } - Debug.Console( - 2, - this, - "Adding messenger with key {0} for path {1}", + this.LogVerbose( + "Adding messenger with key {messengerKey} for path {messengerPath}", messenger.Key, messenger.MessagePath ); @@ -1304,10 +1190,8 @@ namespace PepperDash.Essentials { if (_defaultMessengers.ContainsKey(messenger.Key)) { - Debug.Console( - 1, - this, - "Default messenger with key {0} already added", + this.LogWarning( + "Default messenger with key {messengerKey} already added", messenger.Key ); return; @@ -1317,10 +1201,8 @@ namespace PepperDash.Essentials { simplMessenger.ConfigurationIsReady += Bridge_ConfigurationIsReady; } - Debug.Console( - 2, - this, - "Adding default messenger with key {0} for path {1}", + this.LogVerbose( + "Adding default messenger with key {messengerKey} for path {messengerPath}", messenger.Key, messenger.MessagePath ); @@ -1335,10 +1217,8 @@ namespace PepperDash.Essentials private void RegisterMessengerWithServer(IMobileControlMessenger messenger) { - Debug.Console( - 2, - this, - "Registering messenger with key {0} for path {1}", + this.LogVerbose( + "Registering messenger with key {messengerKey} for path {messengerPath}", messenger.Key, messenger.MessagePath ); @@ -1356,16 +1236,7 @@ namespace PepperDash.Essentials } catch (Exception ex) { - Debug.Console( - 0, - this, - $"Exception registering paths for {messenger.Key}: {ex.Message}" - ); - Debug.Console( - 2, - this, - $"Exception registering paths for {messenger.Key}: {ex.StackTrace}" - ); + this.LogException(ex, "Exception registering custom messenger {messengerKey}", messenger.Key); continue; } } @@ -1378,16 +1249,7 @@ namespace PepperDash.Essentials } catch (Exception ex) { - Debug.Console( - 0, - this, - $"Exception registering paths for {messenger.Key}: {ex.Message}" - ); - Debug.Console( - 2, - this, - $"Exception registering paths for {messenger.Key}: {ex.StackTrace}" - ); + this.LogException(ex, "Exception registering default messenger {messengerKey}", messenger.Key); continue; } } @@ -1417,7 +1279,7 @@ namespace PepperDash.Essentials } catch (Exception e) { - Debug.Console(0, "Unable to find MobileControlSystemController in Devices: {0}", e); + Debug.LogMessage(e, "Unable to find MobileControlSystemController in Devices"); return null; } } @@ -1435,10 +1297,7 @@ namespace PepperDash.Essentials if (string.IsNullOrEmpty(SystemUuid)) { - Debug.Console( - 0, - this, - Debug.ErrorLogLevel.Error, + this.LogError( "System UUID not defined. Unable to connect to Mobile Control" ); return false; @@ -1452,10 +1311,8 @@ namespace PepperDash.Essentials Log = { Output = (data, s) => - Debug.Console( - 1, - Debug.ErrorLogLevel.Notice, - "Message from websocket: {0}", + this.LogDebug( + "Message from websocket: {message}", data ) } @@ -1477,10 +1334,7 @@ namespace PepperDash.Essentials { if (CrestronEnvironment.DevicePlatform != eDevicePlatform.Appliance) { - Debug.Console( - 0, - this, - Debug.ErrorLogLevel.Notice, + this.LogWarning( "System Monitor does not exist for this platform. Skipping..." ); return; @@ -1497,22 +1351,13 @@ namespace PepperDash.Essentials AddDeviceMessenger(messenger); } - /* public void CreateMobileControlRoomBridge(IEssentialsRoom room, IMobileControl parent) - { - var bridge = new MobileControlEssentialsRoomBridge(room); - AddBridgePostActivationAction(bridge); - DeviceManager.AddDevice(bridge); - } */ - #endregion private void SetWebsocketDebugLevel(string cmdparameters) { if (CrestronEnvironment.ProgramCompatibility == eCrestronSeries.Series4) { - Debug.Console( - 0, - this, + this.LogInformation( "Setting websocket log level not currently allowed on 4 series." ); return; // Web socket log level not currently allowed in series4 @@ -1520,22 +1365,14 @@ namespace PepperDash.Essentials if (string.IsNullOrEmpty(cmdparameters)) { - Debug.Console(0, this, "Current Websocket debug level: {0}", _wsLogLevel); + this.LogInformation("Current Websocket debug level: {webSocketDebugLevel}", _wsLogLevel); return; } if (cmdparameters.ToLower().Contains("help") || cmdparameters.ToLower().Contains("?")) { - Debug.Console( - 0, - this, - "valid options are:\r\n{0}\r\n{1}\r\n{2}\r\n{3}\r\n{4}\r\n{5}\r\n", - LogLevel.Trace, - LogLevel.Debug, - LogLevel.Info, - LogLevel.Warn, - LogLevel.Error, - LogLevel.Fatal + CrestronConsole.ConsoleCommandResponse( + $"valid options are:\r\n{LogLevel.Trace}\r\n{LogLevel.Debug}\r\n{LogLevel.Info}\r\n{LogLevel.Warn}\r\n{LogLevel.Error}\r\n{LogLevel.Fatal}\r\n" ); } @@ -1550,35 +1387,17 @@ namespace PepperDash.Essentials _wsClient2.Log.Level = _wsLogLevel; } - Debug.Console(0, this, "Websocket log level set to {0}", debugLevel); + CrestronConsole.ConsoleCommandResponse($"Websocket log level set to {debugLevel}"); } catch { - Debug.Console( - 0, - this, - "{0} is not a valid debug level. Valid options are: {1}, {2}, {3}, {4}, {5}, {6}", - cmdparameters, - LogLevel.Trace, - LogLevel.Debug, - LogLevel.Info, - LogLevel.Warn, - LogLevel.Error, - LogLevel.Fatal + CrestronConsole.ConsoleCommandResponse( + $"{cmdparameters} is not a valid debug level. Valid options are:\r\n{LogLevel.Trace}\r\n{LogLevel.Debug}\r\n{LogLevel.Info}\r\n{LogLevel.Warn}\r\n{LogLevel.Error}\r\n{LogLevel.Fatal}\r\n" ); + } } - /* private void AddBridgePostActivationAction(MobileControlBridgeBase bridge) - { - bridge.AddPostActivationAction(() => - { - Debug.Console(0, bridge, "Linking to parent controller"); - bridge.AddParent(this); - AddBridge(bridge); - }); - }*/ - /// /// Sends message to server to indicate the system is shutting down /// @@ -1653,11 +1472,7 @@ namespace PepperDash.Essentials ) ) { - Debug.Console( - 0, - this, - $"Messenger of type {messenger.GetType().Name} already exists. Skipping actions for {messenger.Key}" - ); + this.LogWarning("Messenger of type {messengerType} already exists. Skipping actions for {messengerKey}", messenger.GetType().Name, messenger.Key); return; } @@ -1702,7 +1517,7 @@ namespace PepperDash.Essentials /// private void Bridge_ConfigurationIsReady(object sender, EventArgs e) { - Debug.Console(1, this, "Bridge ready. Registering"); + this.LogDebug("Bridge ready. Registering"); // send the configuration object to the server @@ -1726,7 +1541,7 @@ namespace PepperDash.Essentials /// private void ReconnectToServerTimerCallback(object o) { - Debug.Console(1, this, "Attempting to reconnect to server..."); + this.LogDebug("Attempting to reconnect to server..."); ConnectWebsocketClient(); } @@ -1769,12 +1584,12 @@ namespace PepperDash.Essentials if (response.Authorized) { - Debug.Console(0, this, "System authorized, sending config."); + this.LogDebug("System authorized, sending config."); RegisterSystemToServer(); return; } - Debug.Console(0, this, response.Reason); + this.LogInformation(response.Reason); }); } @@ -1908,9 +1723,7 @@ Mobile Control Direct Server Infromation: if (!Config.EnableApiServer) { - Debug.Console( - 0, - this, + this.LogInformation( "ApiServer disabled via config. Cancelling attempt to register to server." ); return; @@ -1920,7 +1733,7 @@ Mobile Control Direct Server Infromation: if (!result) { - Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Unable to create websocket."); + this.LogFatal("Unable to create websocket."); return; } @@ -1957,11 +1770,8 @@ Mobile Control Direct Server Infromation: //Fires OnMessage event when PING is received. _wsClient2.EmitOnPing = true; - Debug.Console( - 1, - this, - Debug.ErrorLogLevel.Notice, - "Connecting mobile control client to {0}", + this.LogDebug( + "Connecting mobile control client to {mobileControlUrl}", _wsClient2.Url ); @@ -1985,26 +1795,21 @@ Mobile Control Direct Server Infromation: } catch (InvalidOperationException) { - Debug.Console( - 0, - Debug.ErrorLogLevel.Error, + this.LogError( "Maximum retries exceeded. Restarting websocket" ); HandleConnectFailure(); } catch (IOException ex) { - Debug.Console(0, this, Debug.ErrorLogLevel.Error, "IO Exception\r\n{0}", ex); + this.LogException(ex, "IO Exception on connect"); HandleConnectFailure(); } catch (Exception ex) { - Debug.Console( - 0, - Debug.ErrorLogLevel.Error, - "Error on Websocket Connect: {0}\r\nStack Trace: {1}", - ex.Message, - ex.StackTrace + this.LogException( + ex, + "Error on Websocket Connect" ); HandleConnectFailure(); } @@ -2024,10 +1829,8 @@ Mobile Control Direct Server Infromation: Log = { Output = (data, s) => - Debug.Console( - 1, - Debug.ErrorLogLevel.Notice, - "Message from websocket: {0}", + this.LogDebug( + "Message from websocket: {message}", data ) } @@ -2055,7 +1858,7 @@ Mobile Control Direct Server Infromation: { StopServerReconnectTimer(); StartPingTimer(); - Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Mobile Control API connected"); + this.LogInformation("Mobile Control API connected"); SendMessageObject(new MobileControlMessage { Type = "hello" }); } @@ -2087,7 +1890,8 @@ Mobile Control Direct Server Infromation: /// private void HandleError(object sender, ErrorEventArgs e) { - Debug.Console(1, this, "Websocket error {0}", e.Message); + this.LogError("Websocket error {0}", e.Message); + IsAuthorized = false; StartServerReconnectTimer(); } @@ -2099,11 +1903,8 @@ Mobile Control Direct Server Infromation: /// private void HandleClose(object sender, CloseEventArgs e) { - Debug.Console( - 1, - this, - Debug.ErrorLogLevel.Notice, - "Websocket close {0} {1}, clean={2}", + this.LogDebug( + "Websocket close {code} {reason}, clean={wasClean}", e.Code, e.Reason, e.WasClean @@ -2125,7 +1926,7 @@ Mobile Control Direct Server Infromation: /// private void SendInitialMessage() { - Debug.Console(1, this, "Sending initial join message"); + this.LogInformation("Sending initial join message"); var touchPanels = DeviceManager .AllDevices.OfType() @@ -2241,7 +2042,7 @@ Mobile Control Direct Server Infromation: return; } - Debug.Console(1, this, "Disconnecting websocket"); + this.LogDebug("Disconnecting websocket"); _wsClient2.Close(); } @@ -2272,10 +2073,8 @@ Mobile Control Direct Server Infromation: private void PingTimerCallback(object o) { - Debug.Console( - 1, - this, - Debug.ErrorLogLevel.Notice, + this.LogDebug( + "Ping timer expired. Closing websocket" ); @@ -2285,12 +2084,8 @@ Mobile Control Direct Server Infromation: } catch (Exception ex) { - Debug.Console( - 0, - Debug.ErrorLogLevel.Error, - "Exception closing websocket: {0}\r\nStack Trace: {1}", - ex.Message, - ex.StackTrace + this.LogException(ex, + "Exception closing websocket" ); HandleConnectFailure(); @@ -2307,7 +2102,7 @@ Mobile Control Direct Server Infromation: ReconnectToServerTimerCallback, ServerReconnectInterval ); - Debug.Console(1, this, "Reconnect Timer Started."); + this.LogDebug("Reconnect Timer Started."); } /// @@ -2343,21 +2138,6 @@ Mobile Control Direct Server Infromation: } } - //private void HandleClientJoined(JToken content) - //{ - // var clientId = content["clientId"].Value(); - // var roomKey = content["roomKey"].Value(); - - // SendMessageObject( - // new MobileControlMessage - // { - // Type = "/system/roomKey", - // ClientId = clientId, - // Content = roomKey - // } - // ); - //} - private void HandleClientJoined(JToken content) { var clientId = content["clientId"].Value(); @@ -2379,8 +2159,8 @@ Mobile Control Direct Server Infromation: if (!_roomCombiner.CurrentScenario.UiMap.ContainsKey(roomKey)) { - Debug.Console(0, this, - "Unable to find correct roomKey for {0} in current scenario. Returning {0} as roomKey", roomKey); + this.LogWarning( + "Unable to find correct roomKey for {roomKey} in current scenario. Returning {roomKey} as roomKey", roomKey); var message = new MobileControlMessage { @@ -2418,14 +2198,7 @@ Mobile Control Direct Server Infromation: catch { qrChecksum = new JValue(string.Empty); - } - - Debug.Console( - 1, - this, - "QR checksum: {0}", - qrChecksum == null ? string.Empty : qrChecksum.Value() - ); + } if (code == null) { @@ -2462,10 +2235,8 @@ Mobile Control Direct Server Infromation: if (!messageText.Contains("/system/heartbeat")) { - Debug.LogMessage( - LogEventLevel.Debug, + this.LogDebug( "Message RX: {messageText}", - this, messageText ); } @@ -2499,7 +2270,7 @@ Mobile Control Direct Server Infromation: DeviceJsonApi.DoDeviceAction(wrapper); break; case "close": - Debug.Console(1, this, "Received close message from server."); + this.LogDebug("Received close message from server"); break; default: // Incoming message example @@ -2535,10 +2306,9 @@ Mobile Control Direct Server Infromation: } catch (Exception err) { - Debug.LogMessage( + this.LogException( err, "Unable to parse {message}", - this, messageText ); } diff --git a/src/PepperDash.Essentials.MobileControl/RoomBridges/MobileControlSIMPLRoomBridge.cs b/src/PepperDash.Essentials.MobileControl/RoomBridges/MobileControlSIMPLRoomBridge.cs index 8febf414..ce1864b6 100644 --- a/src/PepperDash.Essentials.MobileControl/RoomBridges/MobileControlSIMPLRoomBridge.cs +++ b/src/PepperDash.Essentials.MobileControl/RoomBridges/MobileControlSIMPLRoomBridge.cs @@ -5,6 +5,7 @@ using Crestron.SimplSharpPro.EthernetCommunication; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using PepperDash.Core; +using PepperDash.Core.Logging; using PepperDash.Essentials.AppServer; using PepperDash.Essentials.AppServer.Messengers; using PepperDash.Essentials.Core; @@ -592,7 +593,7 @@ namespace PepperDash.Essentials.Room.MobileControl if (!Eisc.BooleanOutput[JoinMap.UseSourceEnabled.JoinNumber].BoolValue && string.IsNullOrEmpty(name)) { - Debug.Console(1, "Source at join {0} does not have a name", JoinMap.SourceNameJoinStart.JoinNumber + i); + this.LogDebug("Source at join {join} does not have a name", JoinMap.SourceNameJoinStart.JoinNumber + i); break; } diff --git a/src/PepperDash.Essentials.MobileControl/Touchpanel/ITswAppControlMessenger.cs b/src/PepperDash.Essentials.MobileControl/Touchpanel/ITswAppControlMessenger.cs index 52fa693b..dd69d2da 100644 --- a/src/PepperDash.Essentials.MobileControl/Touchpanel/ITswAppControlMessenger.cs +++ b/src/PepperDash.Essentials.MobileControl/Touchpanel/ITswAppControlMessenger.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using PepperDash.Core; +using PepperDash.Core.Logging; using PepperDash.Essentials.AppServer.Messengers; using PepperDash.Essentials.Core.DeviceTypeInterfaces; @@ -19,7 +20,7 @@ namespace PepperDash.Essentials.Touchpanel { if (_appControl == null) { - Debug.Console(0, this, $"{_device.Key} does not implement ITswAppControl"); + this.LogInformation("{deviceKey} does not implement ITswAppControl", _device.Key); return; } diff --git a/src/PepperDash.Essentials.MobileControl/Touchpanel/ITswZoomControlMessenger.cs b/src/PepperDash.Essentials.MobileControl/Touchpanel/ITswZoomControlMessenger.cs index da59d93c..66ed4c1f 100644 --- a/src/PepperDash.Essentials.MobileControl/Touchpanel/ITswZoomControlMessenger.cs +++ b/src/PepperDash.Essentials.MobileControl/Touchpanel/ITswZoomControlMessenger.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using PepperDash.Core; +using PepperDash.Core.Logging; using PepperDash.Essentials.AppServer.Messengers; using PepperDash.Essentials.Core.DeviceTypeInterfaces; @@ -20,7 +21,7 @@ namespace PepperDash.Essentials.Touchpanel { if (_zoomControl == null) { - Debug.Console(0, this, $"{_device.Key} does not implement ITswZoomControl"); + this.LogInformation("{deviceKey} does not implement ITswZoomControl", _device.Key); return; } diff --git a/src/PepperDash.Essentials.MobileControl/TransmitMessage.cs b/src/PepperDash.Essentials.MobileControl/TransmitMessage.cs index 76c5f1b3..6e536f4a 100644 --- a/src/PepperDash.Essentials.MobileControl/TransmitMessage.cs +++ b/src/PepperDash.Essentials.MobileControl/TransmitMessage.cs @@ -1,8 +1,10 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; using PepperDash.Core; +using PepperDash.Core.Logging; using PepperDash.Essentials.AppServer.Messengers; using PepperDash.Essentials.Core.Queues; +using Serilog.Events; using System; using System.Threading; using WebSocketSharp; @@ -32,40 +34,32 @@ namespace PepperDash.Essentials { try { - - //Debug.Console(2, "Dispatching message type: {0}", msgToSend.GetType()); - - //Debug.Console(2, "Message: {0}", msgToSend.ToString()); - - //var messageToSend = JObject.FromObject(msgToSend); - - if (_ws != null && _ws.IsAlive) + if (_ws == null) { - var message = JsonConvert.SerializeObject(msgToSend, Formatting.None, - new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, Converters = { new IsoDateTimeConverter() } }); - - Debug.Console(2, "Message TX: {0}", message); - - _ws.Send(message); + Debug.LogMessage(LogEventLevel.Warning, "Cannot send message. Websocket client is null"); + return; } - else if (_ws == null) + + if (!_ws.IsAlive) { - Debug.Console(1, "Cannot send. No client."); + Debug.LogMessage(LogEventLevel.Warning, "Cannot send message. Websocket client is not connected"); + return; } + + + var message = JsonConvert.SerializeObject(msgToSend, Formatting.None, + new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, Converters = { new IsoDateTimeConverter() } }); + + Debug.LogMessage(LogEventLevel.Verbose, "Message TX: {0}", null, message); + + _ws.Send(message); + + } catch (Exception ex) { - Debug.Console(0, Debug.ErrorLogLevel.Error, "Caught an exception in the Transmit Processor {0}\r{1}\r{2}", ex.Message, ex.InnerException, ex.StackTrace); - Debug.Console(2, Debug.ErrorLogLevel.Error, "Stack Trace: {0}", ex.StackTrace); - - if (ex.InnerException != null) - { - Debug.Console(0, Debug.ErrorLogLevel.Error, "Inner Exception: {0}", ex.InnerException.Message); - Debug.Console(2, Debug.ErrorLogLevel.Error, "Stack Trace: {0}", ex.InnerException.StackTrace); - } + Debug.LogMessage(ex, "Caught an exception in the Transmit Processor"); } - - } #endregion } @@ -95,35 +89,33 @@ namespace PepperDash.Essentials { try { - //Debug.Console(2, "Message: {0}", msgToSend.ToString()); - - if (_server != null) + if(_server == null) { - Debug.Console(2, _server, Debug.ErrorLogLevel.Notice, "Dispatching message type: {0}", msgToSend.GetType()); - - var message = JsonConvert.SerializeObject(msgToSend, Formatting.None, - new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, Converters = { new IsoDateTimeConverter() } }); - - var clientSpecificMessage = msgToSend as MobileControlMessage; - if (clientSpecificMessage.ClientId != null) - { - var clientId = clientSpecificMessage.ClientId; - - Debug.Console(2, _server, "Message TX To Client ID: {0} Message: {1}", clientId, message); - - _server.SendMessageToClient(clientId, message); - } - else - { - _server.SendMessageToAllClients(message); - - Debug.Console(2, "Message TX To Clients: {0}", message); - } + Debug.LogMessage(LogEventLevel.Warning, "Cannot send message. Server is null"); + return; } - else if (_server == null) + + var message = JsonConvert.SerializeObject(msgToSend, Formatting.None, + new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, Converters = { new IsoDateTimeConverter() } }); + + var clientSpecificMessage = msgToSend as MobileControlMessage; + if (clientSpecificMessage.ClientId != null) { - Debug.Console(1, "Cannot send. No server."); + var clientId = clientSpecificMessage.ClientId; + + _server.LogVerbose("Message TX To client {clientId} Message: {message}", clientId, message); + + _server.SendMessageToClient(clientId, message); + + return; } + + _server.SendMessageToAllClients(message); + + _server.LogVerbose("Message TX To all clients: {message}", null, message); + + + } catch (ThreadAbortException) { @@ -131,14 +123,7 @@ namespace PepperDash.Essentials } catch (Exception ex) { - Debug.Console(0, Debug.ErrorLogLevel.Error, "Caught an exception in the Transmit Processor {0}", ex.Message); - Debug.Console(2, Debug.ErrorLogLevel.Error, "Stack Trace: {0}", ex.StackTrace); - - if (ex.InnerException != null) - { - Debug.Console(0, Debug.ErrorLogLevel.Error, "----\r\n{0}", ex.InnerException.Message); - Debug.Console(2, Debug.ErrorLogLevel.Error, "Stack Trace: {0}", ex.InnerException.StackTrace); - } + Debug.LogMessage(ex,"Caught an exception in the Transmit Processor"); } diff --git a/src/PepperDash.Essentials.MobileControl/WebApiHandlers/UiClientHandler.cs b/src/PepperDash.Essentials.MobileControl/WebApiHandlers/UiClientHandler.cs index 537dafb9..56d61347 100644 --- a/src/PepperDash.Essentials.MobileControl/WebApiHandlers/UiClientHandler.cs +++ b/src/PepperDash.Essentials.MobileControl/WebApiHandlers/UiClientHandler.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; using PepperDash.Essentials.Core.Web; +using Serilog.Events; namespace PepperDash.Essentials.WebApiHandlers { @@ -113,7 +114,7 @@ namespace PepperDash.Essentials.WebApiHandlers if (!server.Server.RemoveWebSocketService(path)) { - Debug.Console(0, $"Unable to remove client with token {request.Token}"); + Debug.LogMessage(LogEventLevel.Warning, "Unable to remove client with token {token}", request.Token); var response = new ClientResponse { diff --git a/src/PepperDash.Essentials.MobileControl/WebSocketServer/MobileControlWebsocketServer.cs b/src/PepperDash.Essentials.MobileControl/WebSocketServer/MobileControlWebsocketServer.cs index b1aa483e..ee9ff1f3 100644 --- a/src/PepperDash.Essentials.MobileControl/WebSocketServer/MobileControlWebsocketServer.cs +++ b/src/PepperDash.Essentials.MobileControl/WebSocketServer/MobileControlWebsocketServer.cs @@ -3,11 +3,13 @@ using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using PepperDash.Core; +using PepperDash.Core.Logging; using PepperDash.Essentials.AppServer.Messengers; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.DeviceTypeInterfaces; using PepperDash.Essentials.Core.Web; using PepperDash.Essentials.WebApiHandlers; +using Serilog.Events; using System; using System.Collections.Generic; using System.IO; @@ -61,7 +63,7 @@ namespace PepperDash.Essentials base.OnOpen(); var url = Context.WebSocket.Url; - Debug.Console(2, Debug.ErrorLogLevel.Notice, "New WebSocket Connection from: {0}", url); + Debug.LogMessage(LogEventLevel.Verbose, "New WebSocket Connection from: {0}", null, url); var match = Regex.Match(url.AbsoluteUri, "(?:ws|wss):\\/\\/.*(?:\\/mc\\/api\\/ui\\/join\\/)(.*)"); @@ -76,7 +78,7 @@ namespace PepperDash.Essentials if (Controller == null) { - Debug.Console(2, "WebSocket UiClient Controller is null"); + Debug.LogMessage(LogEventLevel.Verbose, "WebSocket UiClient Controller is null"); _connectionTime = DateTime.Now; } @@ -91,37 +93,6 @@ namespace PepperDash.Essentials }; Controller.HandleClientMessage(JsonConvert.SerializeObject(clientJoinedMessage)); - // Inform controller of client joining - /* - var clientJoined = new MobileControlMessage - { - Type = "/system/roomKey", - ClientId = clientId, - Content = RoomKey, - }; - - Controller.SendMessageObjectToDirectClient(clientJoined); - - if (Controller.Config.EnableUiMirroring) - { - var uiMirrorEnabled = new MobileControlMessage - { - Type = "/system/uiMirrorEnabled", - ClientId = clientId, - Content = JToken.FromObject(new MobileControlSimpleContent { Value = Controller.Config.EnableUiMirroring }), - }; - - var uiState = new MobileControlMessage - { - Type = "/system/uiMirrorState", - ClientId = clientId, - Content = Controller.LastUiState, - }; - - Controller.SendMessageObjectToDirectClient(uiMirrorEnabled); - - Controller.SendMessageObjectToDirectClient(uiState); - }*/ var bridge = Controller.GetRoomBridge(RoomKey); @@ -173,15 +144,14 @@ namespace PepperDash.Essentials { base.OnClose(e); - Debug.Console(2, Debug.ErrorLogLevel.Notice, "WebSocket UiClient Closing: {0} reason: {1}", e.Code, e.Reason); - + Debug.LogMessage(LogEventLevel.Verbose, "WebSocket UiClient Closing: {0} reason: {1}", null, e.Code, e.Reason); } protected override void OnError(ErrorEventArgs e) { base.OnError(e); - Debug.Console(2, Debug.ErrorLogLevel.Notice, "WebSocket UiClient Error: {0} message: {1}", e.Exception, e.Message); + Debug.LogMessage(LogEventLevel.Verbose, "WebSocket UiClient Error: {exception} message: {message}", e.Exception, e.Message); } } @@ -333,7 +303,7 @@ namespace PepperDash.Essentials if (apiServer == null) { - Debug.Console(0, this, "No API Server available"); + this.LogInformation("No API Server available"); return; } @@ -423,7 +393,7 @@ namespace PepperDash.Essentials if (bridge == null) { - Debug.Console(0, this, $"Unable to find room with key: {client.DefaultRoomKey}"); + this.LogWarning("Unable to find room with key: {defaultRoomKey}", client.DefaultRoomKey); return; } @@ -431,7 +401,7 @@ namespace PepperDash.Essentials if (key == null) { - Debug.Console(0, this, $"Unable to generate a client for {client.Key}"); + this.LogWarning("Unable to generate a client for {clientKey}", client.Key); continue; } } @@ -440,7 +410,7 @@ namespace PepperDash.Essentials var processorIp = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, lanAdapterId); - Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, $"Processor IP: {processorIp}", this); + this.LogVerbose("Processor IP: {processorIp}", processorIp); foreach (var touchpanel in touchpanels.Select(tp => { @@ -453,19 +423,19 @@ namespace PepperDash.Essentials { if (touchpanel.Key == null) { - Debug.Console(0, this, $"Token for touchpanel {touchpanel.Touchpanel.Key} not found"); + this.LogWarning("Token for touchpanel {touchpanelKey} not found", touchpanel.Touchpanel.Key); continue; } if (touchpanel.Messenger == null) { - Debug.Console(2, this, $"Unable to find room messenger for {touchpanel.Touchpanel.DefaultRoomKey}"); + this.LogWarning("Unable to find room messenger for {defaultRoomKey}", touchpanel.Touchpanel.DefaultRoomKey); continue; } var appUrl = $"http://{processorIp}:{_parent.Config.DirectServer.Port}/mc/app?token={touchpanel.Key}"; - Debug.Console(2, this, $"Sending URL {appUrl}"); + this.LogVerbose("Sending URL {appUrl}", appUrl); touchpanel.Messenger.UpdateAppUrl($"http://{processorIp}:{_parent.Config.DirectServer.Port}/mc/app?token={touchpanel.Key}"); } @@ -737,7 +707,7 @@ namespace PepperDash.Essentials if (bridge == null) { - Debug.Console(0, this, $"Unable to find room with key: {roomKey}"); + this.LogWarning("Unable to find room with key: {roomKey}", roomKey); return (null, null); } @@ -926,7 +896,7 @@ namespace PepperDash.Essentials var path = req.RawUrl; - Debug.Console(2, this, "GET Request received at path: {0}", path); + this.LogVerbose("GET Request received at path: {path}", path); // Call for user app to join the room with a token if (path.StartsWith("/mc/api/ui/joinroom")) @@ -972,9 +942,9 @@ namespace PepperDash.Essentials var path = req.RawUrl; var ip = req.RemoteEndPoint.Address.ToString(); - Debug.Console(2, this, "POST Request received at path: {0} from host {1}", path, ip); + this.LogVerbose("POST Request received at path: {path} from host {host}", path, ip); - var body = new System.IO.StreamReader(req.InputStream).ReadToEnd(); + var body = new StreamReader(req.InputStream).ReadToEnd(); if (path.StartsWith("/mc/api/log")) { @@ -990,7 +960,7 @@ namespace PepperDash.Essentials await LogClient.SendAsync(logRequest); - Debug.Console(2, this, "Log data sent to {0}:{1}", _parent.Config.DirectServer.Logging.Host, _parent.Config.DirectServer.Logging.Port); + this.LogVerbose("Log data sent to {host}:{port}", _parent.Config.DirectServer.Logging.Host, _parent.Config.DirectServer.Logging.Port); } else { @@ -1000,7 +970,7 @@ namespace PepperDash.Essentials } catch (Exception ex) { - Debug.LogMessage(ex, "Caught an exception in the OnPost handler", this); + this.LogException(ex, "Caught an exception in the OnPost handler"); } } @@ -1033,7 +1003,7 @@ namespace PepperDash.Essentials var qp = req.QueryString; var token = qp["token"]; - Debug.Console(2, this, "Join Room Request with token: {0}", token); + this.LogVerbose("Join Room Request with token: {token}", token); if (UiClients.TryGetValue(token, out UiClientContext clientContext)) @@ -1074,10 +1044,11 @@ namespace PepperDash.Essentials var message = string.Format("Unable to find bridge with key: {0}", clientContext.Token.RoomKey); res.StatusCode = 404; res.ContentType = "application/json"; + this.LogVerbose("{message}", message); var body = Encoding.UTF8.GetBytes(message); res.ContentLength64 = body.LongLength; res.Close(body, true); - Debug.Console(2, this, "{0}", message); + } } else @@ -1085,7 +1056,7 @@ namespace PepperDash.Essentials var message = "Token invalid or has expired"; res.StatusCode = 401; res.ContentType = "application/json"; - Debug.Console(2, this, "{0}", message); + this.LogVerbose("{message}", message); var body = Encoding.UTF8.GetBytes(message); res.ContentLength64 = body.LongLength; res.Close(body, true); @@ -1102,7 +1073,7 @@ namespace PepperDash.Essentials res.ContentType = "application/json"; var version = new Version() { ServerVersion = _parent.GetConfigWithPluginVersion().RuntimeInfo.PluginVersion }; var message = JsonConvert.SerializeObject(version); - Debug.Console(2, this, "{0}", message); + this.LogVerbose("{message}", message); var body = Encoding.UTF8.GetBytes(message); res.ContentLength64 = body.LongLength; @@ -1118,7 +1089,7 @@ namespace PepperDash.Essentials { var path = req.RawUrl; - Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Requesting Image: {0}", this, path); + Debug.LogMessage(LogEventLevel.Verbose, "Requesting Image: {0}", this, path); var imageBasePath = Global.DirectorySeparator + "html" + Global.DirectorySeparator + "logo" + Global.DirectorySeparator; @@ -1126,9 +1097,9 @@ namespace PepperDash.Essentials var filePath = imageBasePath + image; - Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Retrieving Image: {0}", this, filePath); + Debug.LogMessage(LogEventLevel.Verbose, "Retrieving Image: {0}", this, filePath); - if (System.IO.File.Exists(filePath)) + if (File.Exists(filePath)) { if(filePath.EndsWith(".png")) { @@ -1165,7 +1136,7 @@ namespace PepperDash.Essentials /// private void HandleUserAppRequest(HttpListenerRequest req, HttpListenerResponse res, string path) { - Debug.Console(2, this, "Requesting User app file..."); + this.LogVerbose("Requesting User app file"); var qp = req.QueryString; var token = qp["token"]; @@ -1189,7 +1160,7 @@ namespace PepperDash.Essentials // swap the base href prefix for the file path prefix filePath = filePath.Replace(_userAppBaseHref, _appPath); - Debug.Console(2, this, "filepath: {0}", filePath); + this.LogVerbose("filepath: {filePath}", filePath); // append index.html if no specific file is specified @@ -1208,7 +1179,7 @@ namespace PepperDash.Essentials // Set ContentType based on file type if (filePath.EndsWith(".html")) { - Debug.Console(2, this, "Client requesting User App..."); + this.LogVerbose("Client requesting User App"); res.ContentType = "text/html"; } @@ -1228,17 +1199,17 @@ namespace PepperDash.Essentials } } - Debug.Console(2, this, "Attempting to serve file: {0}", filePath); + this.LogVerbose("Attempting to serve file: {filePath}", filePath); byte[] contents; if (System.IO.File.Exists(filePath)) { - Debug.Console(2, this, "File found"); + this.LogVerbose("File found: {filePath}", filePath); contents = System.IO.File.ReadAllBytes(filePath); } else { - Debug.Console(2, this, "File not found: {0}", filePath); + this.LogVerbose("File not found: {filePath}", filePath); res.StatusCode = (int)HttpStatusCode.NotFound; res.Close(); return; @@ -1250,7 +1221,7 @@ namespace PepperDash.Essentials public void StopServer() { - Debug.Console(2, this, "Stopping WebSocket Server"); + this.LogVerbose("Stopping WebSocket Server"); _server.Stop(CloseStatusCode.Normal, "Server Shutting Down"); } @@ -1295,7 +1266,7 @@ namespace PepperDash.Essentials } else { - Debug.Console(0, this, "Unable to find client with ID: {0}", clientId); + this.LogWarning("Unable to find client with ID: {clientId}", clientId); } } }