style: run code cleanup & apply VS suggestions

This commit is contained in:
Andrew Welker
2025-03-25 22:14:15 -05:00
parent 4d98191fa7
commit 789111cb9a
64 changed files with 329 additions and 390 deletions

View File

@@ -1,6 +1,6 @@
using System;
namespace PepperDash.Essentials.Room.MobileControl
namespace PepperDash.Essentials
{
/// <summary>
/// Represents a room whose configuration is derived from runtime data,
@@ -10,7 +10,7 @@ namespace PepperDash.Essentials.Room.MobileControl
public interface IDelayedConfiguration
{
event EventHandler<EventArgs> ConfigurationIsReady;
}
}

View File

@@ -1,11 +1,6 @@
using Newtonsoft.Json.Linq;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
using PepperDash.Essentials.Core.Web.RequestHandlers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PepperDash.Essentials
{
@@ -13,9 +8,10 @@ namespace PepperDash.Essentials
{
public IMobileControlMessenger Messenger { get; private set; }
public Action<string, string, JToken> Action {get; private set; }
public Action<string, string, JToken> Action { get; private set; }
public MobileControlAction(IMobileControlMessenger messenger, Action<string,string, JToken> handler) {
public MobileControlAction(IMobileControlMessenger messenger, Action<string, string, JToken> handler)
{
Messenger = messenger;
Action = handler;
}

View File

@@ -1,6 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
namespace PepperDash.Essentials
@@ -57,7 +56,7 @@ namespace PepperDash.Essentials
[JsonProperty("port")]
public int Port { get; set; }
}

View File

@@ -2,7 +2,6 @@
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;
@@ -14,7 +13,7 @@ namespace PepperDash.Essentials
public class MobileControlDeviceFactory : EssentialsDeviceFactory<MobileControlSystemController>
{
public MobileControlDeviceFactory()
{
{
TypeNames = new List<string> { "appserver", "mobilecontrol", "webserver" };
}
@@ -36,7 +35,7 @@ namespace PepperDash.Essentials
public class MobileControlSimplFactory : EssentialsDeviceFactory<MobileControlSIMPLRoomBridge>
{
public MobileControlSimplFactory()
{
{
TypeNames = new List<string> { "mobilecontrolbridge-ddvc01", "mobilecontrolbridge-simpl" };
}
@@ -55,7 +54,7 @@ namespace PepperDash.Essentials
bridge.LogInformation("ERROR: Cannot connect bridge. System controller not present");
return;
}
bridge.LogInformation("Linking to parent controller");
bridge.LogInformation("Linking to parent controller");
parent.AddDeviceMessenger(bridge);
});

View File

@@ -1,24 +1,22 @@
using PepperDash.Core;
using PepperDash.Essentials.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace PepperDash.Essentials.MobileControl
namespace PepperDash.Essentials
{
public class MobileControlFactory
{
public MobileControlFactory() {
public MobileControlFactory()
{
var assembly = Assembly.GetExecutingAssembly();
PluginLoader.SetEssentialsAssembly(assembly.GetName().Name, assembly);
var types = assembly.GetTypes().Where(t => typeof(IDeviceFactory).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract);
if(types == null)
if (types == null)
{
return;
}

View File

@@ -1,16 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Crestron.SimplSharp;
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharp.Net.Http;
using Crestron.SimplSharp.WebScripting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Org.BouncyCastle.Crypto.Prng;
using PepperDash.Core;
using PepperDash.Core.Logging;
using PepperDash.Essentials.AppServer;
@@ -32,9 +25,16 @@ using PepperDash.Essentials.Devices.Common.Displays;
using PepperDash.Essentials.Devices.Common.SoftCodec;
using PepperDash.Essentials.Devices.Common.VideoCodec;
using PepperDash.Essentials.Room.MobileControl;
using PepperDash.Essentials.RoomBridges;
using PepperDash.Essentials.Services;
using PepperDash.Essentials.WebApiHandlers;
using Serilog.Events;
using PepperDash.Essentials.WebSocketServer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using WebSocketSharp;
namespace PepperDash.Essentials
@@ -160,7 +160,7 @@ namespace PepperDash.Essentials
: base(key, name)
{
Config = config;
// The queue that will collect the incoming messages in the order they are received
//_receiveQueue = new ReceiveQueue(key, ParseStreamRx);
_receiveQueue = new GenericQueue(
@@ -222,7 +222,7 @@ namespace PepperDash.Essentials
{
_roomCombiner = DeviceManager.AllDevices.OfType<IEssentialsRoomCombiner>().FirstOrDefault();
if(_roomCombiner == null)
if (_roomCombiner == null)
return;
_roomCombiner.RoomCombinationScenarioChanged += OnRoomCombinationScenarioChanged;
@@ -238,7 +238,7 @@ namespace PepperDash.Essentials
return _wsClient2.IsAlive && IsAuthorized;
});
}
}
private void SetupDefaultRoomMessengers()
{
@@ -247,7 +247,7 @@ namespace PepperDash.Essentials
foreach (var room in DeviceManager.AllDevices.OfType<IEssentialsRoom>())
{
this.LogVerbose(
"Setting up room messengers for room: {key}",
"Setting up room messengers for room: {key}",
room.Key
);
@@ -260,7 +260,7 @@ namespace PepperDash.Essentials
AddDefaultDeviceMessenger(messenger);
this.LogVerbose(
"Attempting to set up default room messengers for room: {0}",
"Attempting to set up default room messengers for room: {0}",
room.Key
);
@@ -328,7 +328,7 @@ namespace PepperDash.Essentials
var allDevices = DeviceManager.AllDevices.Where((d) => !(d is IEssentialsRoom));
this.LogInformation(
"All Devices that aren't rooms count: {0}",
"All Devices that aren't rooms count: {0}",
allDevices?.Count()
);
@@ -425,26 +425,26 @@ namespace PepperDash.Essentials
var presetsDevice = device as ITvPresetsProvider;
this.LogVerbose(
"Adding ITvPresetsProvider for {deviceKey}",
device.Key
);
this.LogVerbose(
"Adding ITvPresetsProvider for {deviceKey}",
device.Key
);
var presetsMessenger = new DevicePresetsModelMessenger(
$"{device.Key}-presets-{Key}",
$"/device/{device.Key}",
presetsDevice
);
var presetsMessenger = new DevicePresetsModelMessenger(
$"{device.Key}-presets-{Key}",
$"/device/{device.Key}",
presetsDevice
);
AddDefaultDeviceMessenger(presetsMessenger);
AddDefaultDeviceMessenger(presetsMessenger);
messengerAdded = true;
}
messengerAdded = true;
}
if (device is DisplayBase)
{
this.LogVerbose( "Adding actions for device: {0}", device.Key);
this.LogVerbose("Adding actions for device: {0}", device.Key);
var dbMessenger = new DisplayBaseMessenger(
$"{device.Key}-displayBase-{Key}",
@@ -458,7 +458,7 @@ namespace PepperDash.Essentials
}
if (device is TwoWayDisplayBase twoWayDisplay)
{
{
this.LogVerbose(
"Adding TwoWayDisplayBase for {deviceKey}",
device.Key
@@ -476,11 +476,11 @@ namespace PepperDash.Essentials
if (device is IBasicVolumeWithFeedback)
{
var deviceKey = device.Key;
this.LogVerbose(
"Adding IBasicVolumeControlWithFeedback for {deviceKey}",
deviceKey
);
this.LogVerbose(
"Adding IBasicVolumeControlWithFeedback for {deviceKey}",
deviceKey
);
var volControlDevice = device as IBasicVolumeWithFeedback;
var messenger = new DeviceVolumeMessenger(
$"{device.Key}-volume-{Key}",
@@ -500,7 +500,7 @@ namespace PepperDash.Essentials
"Adding LightingBaseMessenger for {deviceKey}",
deviceKey
);
var lightingDevice = device as ILightingScenes;
var messenger = new ILightingScenesMessenger(
$"{device.Key}-lighting-{Key}",
@@ -516,7 +516,7 @@ namespace PepperDash.Essentials
{
var deviceKey = device.Key;
var shadeDevice = device as IShadesOpenCloseStop;
this.LogVerbose(
"Adding ShadeBaseMessenger for {deviceKey}",
deviceKey
@@ -535,7 +535,7 @@ namespace PepperDash.Essentials
if (device is VideoCodecBase codec)
{
this.LogVerbose(
"Adding VideoCodecBaseMessenger for {deviceKey}", codec.Key );
"Adding VideoCodecBaseMessenger for {deviceKey}", codec.Key);
var messenger = new VideoCodecBaseMessenger(
$"{codec.Key}-videoCodec-{Key}",
@@ -571,7 +571,7 @@ namespace PepperDash.Essentials
"Adding ISetTopBoxControlMessenger for {deviceKey}"
);
var dev = device as Device;
var dev = device as Device;
var messenger = new ISetTopBoxControlsMessenger(
$"{device.Key}-stb-{Key}",
@@ -639,7 +639,7 @@ namespace PepperDash.Essentials
if (device is INumericKeypad)
{
this.LogVerbose("Adding INumericKeyapdMessenger for {deviceKey}", device.Key);
this.LogVerbose("Adding INumericKeyapdMessenger for {deviceKey}", device.Key);
var dev = device as PepperDash.Core.Device;
@@ -709,7 +709,7 @@ namespace PepperDash.Essentials
if (device is IHasCurrentSourceInfoChange)
{
this.LogVerbose("Adding IHasCurrentSourceInfoMessenger for {deviceKey}", device.Key );
this.LogVerbose("Adding IHasCurrentSourceInfoMessenger for {deviceKey}", device.Key);
var messenger = new IHasCurrentSourceInfoMessenger(
$"{device.Key}-currentSource-{Key}",
@@ -942,7 +942,7 @@ namespace PepperDash.Essentials
messengerAdded = true;
}
if (device is IDspPresets dspPresets)
if (device is IDspPresets dspPresets)
{
this.LogVerbose("Adding IDspPresetsMessenger for {deviceKey}", device.Key
);
@@ -958,13 +958,11 @@ namespace PepperDash.Essentials
messengerAdded = true;
}
this.LogVerbose("Trying to cast to generic device for device: {key}", 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)
if (!(device is EssentialsDevice genericDevice) || messengerAdded)
{
this.LogVerbose(
"Skipping GenericMessenger for {deviceKey}. Messenger(s) Added: {messengersAdded}.",
@@ -1100,7 +1098,7 @@ namespace PepperDash.Essentials
$"Connecting to MC API server"
);
ConnectWebsocketClient();
ConnectWebsocketClient();
},
"mobileconnect",
"Forces connect of websocket",
@@ -1111,7 +1109,7 @@ namespace PepperDash.Essentials
s =>
{
_disableReconnect = true;
CleanUpWebsocketClient();
CrestronConsole.ConsoleCommandResponse(
@@ -1334,7 +1332,7 @@ namespace PepperDash.Essentials
{
if (CrestronEnvironment.DevicePlatform != eDevicePlatform.Appliance)
{
this.LogWarning(
this.LogWarning(
"System Monitor does not exist for this platform. Skipping..."
);
return;
@@ -1394,7 +1392,7 @@ namespace PepperDash.Essentials
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"
);
}
}
@@ -1617,8 +1615,8 @@ namespace PepperDash.Essentials
if (Config.EnableApiServer)
{
CrestronConsole.ConsoleCommandResponse(
@"Mobile Control Edge Server API Information:
CrestronConsole.ConsoleCommandResponse(
@"Mobile Control Edge Server API Information:
Server address: {0}
System Name: {1}
@@ -1627,14 +1625,14 @@ namespace PepperDash.Essentials
System User code: {4}
Connected?: {5}
Seconds Since Last Ack: {6}",
url,
name,
ConfigReader.ConfigObject.SystemUrl,
SystemUuid,
code,
conn,
secSinceLastAck.Seconds
);
url,
name,
ConfigReader.ConfigObject.SystemUrl,
SystemUuid,
code,
conn,
secSinceLastAck.Seconds
);
}
else
{
@@ -1960,17 +1958,16 @@ Mobile Control Direct Server Infromation:
confObject.Info.RuntimeInfo.AssemblyVersion = essentialsVersion;
// // Set for local testing
// confObject.RuntimeInfo.PluginVersion = "4.0.0-localBuild";
// // Set for local testing
// confObject.RuntimeInfo.PluginVersion = "4.0.0-localBuild";
// Populate the plugin version
var pluginVersion = Assembly
.GetExecutingAssembly()
.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
var fullVersionAtt = pluginVersion[0] as AssemblyInformationalVersionAttribute;
if (fullVersionAtt != null)
if (pluginVersion[0] is AssemblyInformationalVersionAttribute fullVersionAtt)
{
var pluginInformationalVersion = fullVersionAtt.InformationalVersion;
@@ -2003,7 +2000,7 @@ Mobile Control Direct Server Infromation:
if (Config.EnableApiServer)
{
_transmitToServerQueue.Enqueue(new TransmitMessage(o, _wsClient2));
_transmitToServerQueue.Enqueue(new TransmitMessage(o, _wsClient2));
}
@@ -2074,7 +2071,7 @@ Mobile Control Direct Server Infromation:
private void PingTimerCallback(object o)
{
this.LogDebug(
"Ping timer expired. Closing websocket"
);
@@ -2142,7 +2139,6 @@ Mobile Control Direct Server Infromation:
{
var clientId = content["clientId"].Value<string>();
var roomKey = content["roomKey"].Value<string>();
var touchpanelKey = content.SelectToken("touchpanelKey"); //content["touchpanelKey"].Value<string>();
if (_roomCombiner == null)
{
@@ -2198,7 +2194,7 @@ Mobile Control Direct Server Infromation:
catch
{
qrChecksum = new JValue(string.Empty);
}
}
if (code == null)
{
@@ -2283,7 +2279,7 @@ Mobile Control Direct Server Infromation:
// Can't do direct comparison because it will match /room/roomA with /room/roomA/xxx instead of /room/roomAB/xxx
var handlersKv = _actionDictionary.FirstOrDefault(kv => message.Type.StartsWith(kv.Key + "/")); // adds trailing slash to ensure above case is handled
if (handlersKv.Key == null)
{

View File

@@ -30,6 +30,11 @@
<Compile Remove="bin\**" />
<EmbeddedResource Remove="bin\**" />
<None Remove="bin\**" />
</ItemGroup>
<ItemGroup>
<Compile Remove="MobileControlSimplDeviceBridge.cs" />
<Compile Remove="RoomBridges\MobileControlSIMPLRoomBridge.cs" />
<Compile Remove="RoomBridges\SourceDeviceMapDictionary.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Crestron.SimplSharp.SDK.ProgramLibrary" Version="2.21.90" />
@@ -48,15 +53,15 @@
<None Remove="C:\Users\awelker\source\Essentials\Essentials\src\PepperDash.Essentials.MobileControl\bin\Debug\net472\PepperDash.Essentials.MobileControl.4.0.0-local.net472.cplz" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PepperDash.Essentials.Core\PepperDash.Essentials.Core.csproj" >
<ProjectReference Include="..\PepperDash.Essentials.Core\PepperDash.Essentials.Core.csproj">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
<ProjectReference Include="..\PepperDash.Essentials.Devices.Common\PepperDash.Essentials.Devices.Common.csproj" >
<ProjectReference Include="..\PepperDash.Essentials.Devices.Common\PepperDash.Essentials.Devices.Common.csproj">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
<ProjectReference Include="..\PepperDash.Essentials.MobileControl.Messengers\PepperDash.Essentials.MobileControl.Messengers.csproj" >
<ProjectReference Include="..\PepperDash.Essentials.MobileControl.Messengers\PepperDash.Essentials.MobileControl.Messengers.csproj">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>

View File

@@ -1,10 +1,11 @@
using PepperDash.Core;
using PepperDash.Core.Logging;
using PepperDash.Essentials.AppServer.Messengers;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
using System;
namespace PepperDash.Essentials
namespace PepperDash.Essentials.RoomBridges
{
/// <summary>
///
@@ -102,12 +103,12 @@ namespace PepperDash.Essentials
/// </summary>
protected virtual void UserCodeChange()
{
Debug.Console(1, this, "Server user code changed: {0}", UserCode);
this.LogDebug("Server user code changed: {userCode}", UserCode);
var qrUrl = string.Format($"{Parent.Host}/api/rooms/{Parent.SystemUuid}/{RoomKey}/qr?x={new Random().Next()}");
QrCodeUrl = qrUrl;
Debug.Console(1, this, "Server user code changed: {0} - {1}", UserCode, qrUrl);
this.LogDebug("Server user code changed: {userCode} - {qrCodeUrl}", UserCode, qrUrl);
OnUserCodeChanged();
}

View File

@@ -16,14 +16,14 @@ using PepperDash.Essentials.Devices.Common.Cameras;
using PepperDash.Essentials.Devices.Common.Room;
using PepperDash.Essentials.Devices.Common.VideoCodec;
using PepperDash.Essentials.Room.Config;
using PepperDash.Essentials.WebSocketServer;
using System;
using System.Collections.Generic;
using System.Linq;
using IShades = PepperDash.Essentials.Core.Shades.IShades;
using ShadeBase = PepperDash.Essentials.Devices.Common.Shades.ShadeBase;
using Volume = PepperDash.Essentials.Room.MobileControl.Volume;
namespace PepperDash.Essentials
namespace PepperDash.Essentials.RoomBridges
{
public class MobileControlEssentialsRoomBridge : MobileControlBridgeBase
{
@@ -339,7 +339,7 @@ namespace PepperDash.Essentials
string shareText;
bool isSharing;
if (Room is IHasCurrentSourceInfoChange srcInfoRoom && (Room is IHasVideoCodec vcRoom && (vcRoom.VideoCodec.SharingContentIsOnFeedback.BoolValue && srcInfoRoom.CurrentSourceInfo != null)))
if (Room is IHasCurrentSourceInfoChange srcInfoRoom && Room is IHasVideoCodec vcRoom && vcRoom.VideoCodec.SharingContentIsOnFeedback.BoolValue && srcInfoRoom.CurrentSourceInfo != null)
{
shareText = srcInfoRoom.CurrentSourceInfo.PreferredName;
isSharing = true;
@@ -532,7 +532,8 @@ namespace PepperDash.Essentials
}
return state;
} catch (Exception ex)
}
catch (Exception ex)
{
Debug.LogMessage(ex, "Error getting full status", this);
return null;
@@ -560,7 +561,7 @@ namespace PepperDash.Essentials
{
var zrcTp = DeviceManager.AllDevices.OfType<IMobileControlTouchpanelController>().SingleOrDefault((tp) => tp.ZoomRoomController);
configuration.ZoomRoomControllerKey = zrcTp != null ? zrcTp.Key : null;
configuration.ZoomRoomControllerKey = zrcTp?.Key;
}
catch
{
@@ -578,7 +579,7 @@ namespace PepperDash.Essentials
// find the room combiner for this room by checking if the room is in the list of rooms for the room combiner
var roomCombiner = DeviceManager.AllDevices.OfType<IEssentialsRoomCombiner>().FirstOrDefault();
configuration.RoomCombinerKey = roomCombiner != null ? roomCombiner.Key : null;
configuration.RoomCombinerKey = roomCombiner?.Key;
if (room is IEssentialsRoomPropertiesConfig propertiesConfig)
@@ -620,7 +621,8 @@ namespace PepperDash.Essentials
configuration.VideoCodecKey = vcRoom.VideoCodec.Key;
configuration.VideoCodecIsZoomRoom = type.Name.Equals("ZoomRoom", StringComparison.InvariantCultureIgnoreCase);
}
};
}
;
if (room is IHasAudioCodec acRoom)
{
@@ -655,7 +657,7 @@ namespace PepperDash.Essentials
eEnvironmentalDeviceTypes type = eEnvironmentalDeviceTypes.None;
if (dev is ILightingScenes || dev is Devices.Common.Lighting.LightingBase)
if (dev is ILightingScenes)
{
type = eEnvironmentalDeviceTypes.Lighting;
}
@@ -871,7 +873,7 @@ namespace PepperDash.Essentials
public Dictionary<string, SourceListItem> SourceList { get; set; }
[JsonProperty("destinationList", NullValueHandling = NullValueHandling.Ignore)]
public Dictionary<string, DestinationListItem> DestinationList { get; set;}
public Dictionary<string, DestinationListItem> DestinationList { get; set; }
[JsonProperty("audioControlPointList", NullValueHandling = NullValueHandling.Ignore)]
public AudioControlPointListItem AudioControlPointList { get; set; }

View File

@@ -66,7 +66,8 @@ namespace PepperDash.Essentials.Services
}
return authResponse;
} catch(Exception ex)
}
catch (Exception ex)
{
Debug.LogMessage(ex, "Error authorizing with Mobile Control");
return new AuthorizationResponse { Authorized = false, Reason = ex.Message };

View File

@@ -1,15 +1,9 @@
using PepperDash.Core;
using PepperDash.Essentials.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PepperDash.Essentials.Touchpanel
{
public interface ITheme:IKeyed
{
public interface ITheme : IKeyed
{
string Theme { get; }
void UpdateTheme(string theme);

View File

@@ -3,7 +3,6 @@ using Newtonsoft.Json.Linq;
using PepperDash.Core;
using PepperDash.Core.Logging;
using PepperDash.Essentials.AppServer.Messengers;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
namespace PepperDash.Essentials.Touchpanel
{

View File

@@ -3,7 +3,6 @@ using Newtonsoft.Json.Linq;
using PepperDash.Core;
using PepperDash.Core.Logging;
using PepperDash.Essentials.AppServer.Messengers;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
namespace PepperDash.Essentials.Touchpanel
@@ -41,7 +40,7 @@ namespace PepperDash.Essentials.Touchpanel
_zoomControl.ZoomInCallFeedback.OutputChange += (s, a) =>
{
{
PostStatusMessage(JToken.FromObject(
new
{

View File

@@ -10,13 +10,12 @@ using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.DeviceInfo;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
using PepperDash.Essentials.Core.UI;
using PepperDash.Essentials.Touchpanel;
using System;
using System.Collections.Generic;
using System.Linq;
using Feedback = PepperDash.Essentials.Core.Feedback;
namespace PepperDash.Essentials.Devices.Common.TouchPanel
namespace PepperDash.Essentials.Touchpanel
{
//public interface IMobileControlTouchpanelController
//{
@@ -75,7 +74,7 @@ namespace PepperDash.Essentials.Devices.Common.TouchPanel
AddPostActivationAction(SubscribeForMobileControlUpdates);
ThemeFeedback = new StringFeedback($"{Key}-theme",() => Theme);
ThemeFeedback = new StringFeedback($"{Key}-theme", () => Theme);
AppUrlFeedback = new StringFeedback($"{Key}-appUrl", () => _appUrl);
QrCodeUrlFeedback = new StringFeedback($"{Key}-qrCodeUrl", () => _bridge?.QrCodeUrl);
McServerUrlFeedback = new StringFeedback($"{Key}-mcServerUrl", () => _bridge?.McServerUrl);
@@ -357,10 +356,11 @@ namespace PepperDash.Essentials.Devices.Common.TouchPanel
_bridge = bridge;
_bridge.UserCodeChanged += UpdateFeedbacks;
_bridge.AppUrlChanged += (s, a) => {
this.LogInformation("AppURL changed");
_bridge.AppUrlChanged += (s, a) =>
{
this.LogInformation("AppURL changed");
SetAppUrl(_bridge.AppUrl);
UpdateFeedbacks(s, a);
UpdateFeedbacks(s, a);
};
SetAppUrl(_bridge.AppUrl);

View File

@@ -1,7 +1,7 @@
using Newtonsoft.Json;
using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.Devices.Common.TouchPanel
namespace PepperDash.Essentials.Touchpanel
{
public class MobileControlTouchpanelProperties : CrestronTouchpanelPropertiesConfig
{

View File

@@ -27,14 +27,14 @@ namespace PepperDash.Essentials.Touchpanel
var theme = content.ToObject<MobileControlSimpleContent<string>>();
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "Setting theme to {theme}", this, theme.Value);
_tpDevice.UpdateTheme(theme.Value);
_tpDevice.UpdateTheme(theme.Value);
PostStatusMessage(JToken.FromObject(new {theme = theme.Value}));
PostStatusMessage(JToken.FromObject(new { theme = theme.Value }));
});
}
}
public class ThemeUpdateMessage:DeviceStateMessageBase
public class ThemeUpdateMessage : DeviceStateMessageBase
{
[JsonProperty("theme")]
public string Theme { get; set; }

View File

@@ -4,6 +4,7 @@ using PepperDash.Core;
using PepperDash.Core.Logging;
using PepperDash.Essentials.AppServer.Messengers;
using PepperDash.Essentials.Core.Queues;
using PepperDash.Essentials.WebSocketServer;
using Serilog.Events;
using System;
using System.Threading;
@@ -46,19 +47,19 @@ namespace PepperDash.Essentials
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.LogMessage(ex, "Caught an exception in the Transmit Processor");
Debug.LogMessage(ex, "Caught an exception in the Transmit Processor");
}
}
#endregion
@@ -89,7 +90,7 @@ namespace PepperDash.Essentials
{
try
{
if(_server == null)
if (_server == null)
{
Debug.LogMessage(LogEventLevel.Warning, "Cannot send message. Server is null");
return;
@@ -109,13 +110,13 @@ namespace PepperDash.Essentials
return;
}
_server.SendMessageToAllClients(message);
_server.LogVerbose("Message TX To all clients: {message}", null, message);
_server.SendMessageToAllClients(message);
_server.LogVerbose("Message TX To all clients: {message}", null, message);
}
catch (ThreadAbortException)
{
@@ -123,7 +124,7 @@ namespace PepperDash.Essentials
}
catch (Exception ex)
{
Debug.LogMessage(ex,"Caught an exception in the Transmit Processor");
Debug.LogMessage(ex, "Caught an exception in the Transmit Processor");
}

View File

@@ -1,6 +1,6 @@
using Newtonsoft.Json;
namespace PepperDash.Essentials.AppServer
namespace PepperDash.Essentials
{
public class UserCodeChangedContent
{

View File

@@ -1,7 +1,7 @@
using Newtonsoft.Json;
using System.Collections.Generic;
namespace PepperDash.Essentials.Room.MobileControl
namespace PepperDash.Essentials
{
public class Volumes
{

View File

@@ -1,7 +1,6 @@
using Crestron.SimplSharp.WebScripting;
using Newtonsoft.Json;
using PepperDash.Core.Web.RequestHandlers;
using PepperDash.Essentials.AppServer.Messengers;
using System.Collections.Generic;
using System.Linq;
@@ -33,7 +32,7 @@ namespace PepperDash.Essentials.WebApiHandlers
private readonly MobileControlSystemController mcController;
[JsonProperty("actionPaths")]
public List<ActionPath> ActionPaths => mcController.GetActionDictionaryPaths().Select((path) => new ActionPath { MessengerKey = path.Item1, Path = path.Item2}).ToList();
public List<ActionPath> ActionPaths => mcController.GetActionDictionaryPaths().Select((path) => new ActionPath { MessengerKey = path.Item1, Path = path.Item2 }).ToList();
public ActionPathsResponse(MobileControlSystemController mcController)
{

View File

@@ -3,6 +3,7 @@ using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Core.Web.RequestHandlers;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.WebSocketServer;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -30,8 +31,7 @@ namespace PepperDash.Essentials.WebApiHandlers
}
catch (Exception ex)
{
Debug.Console(1, $"exception showing mobile info: {ex.Message}");
Debug.Console(2, $"stack trace: {ex.StackTrace}");
Debug.LogMessage(ex, "exception showing mobile info");
context.Response.StatusCode = 500;
context.Response.End();
@@ -143,7 +143,7 @@ namespace PepperDash.Essentials.WebApiHandlers
public string Token => Key;
[JsonProperty("connected")]
public bool Connected => context.Client == null ? false : context.Client.Context.WebSocket.IsAlive;
public bool Connected => context.Client != null && context.Client.Context.WebSocket.IsAlive;
[JsonProperty("duration")]
public double Duration => context.Client == null ? 0 : context.Client.ConnectedDuration.TotalSeconds;

View File

@@ -3,6 +3,7 @@ using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Core.Web.RequestHandlers;
using PepperDash.Essentials.Core.Web;
using PepperDash.Essentials.WebSocketServer;
using Serilog.Events;
namespace PepperDash.Essentials.WebApiHandlers

View File

@@ -8,6 +8,7 @@ using PepperDash.Essentials.AppServer.Messengers;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
using PepperDash.Essentials.Core.Web;
using PepperDash.Essentials.RoomBridges;
using PepperDash.Essentials.WebApiHandlers;
using Serilog.Events;
using System;
@@ -23,7 +24,7 @@ using WebSocketSharp.Server;
using ErrorEventArgs = WebSocketSharp.ErrorEventArgs;
namespace PepperDash.Essentials
namespace PepperDash.Essentials.WebSocketServer
{
/// <summary>
/// Represents the behaviour to associate with a UiClient for WebSocket communication
@@ -255,14 +256,14 @@ namespace PepperDash.Essentials
Port = customPort;
}
if(parent.Config.DirectServer.AutomaticallyForwardPortToCSLAN == true)
if (parent.Config.DirectServer.AutomaticallyForwardPortToCSLAN == true)
{
try
{
CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetCSAdapter);
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "Automatically forwarding port {0} to CS LAN", Port);
Debug.LogMessage(LogEventLevel.Information, "Automatically forwarding port {0} to CS LAN", Port);
var csAdapterId = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetCSAdapter);
var csIp = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, csAdapterId);
@@ -271,12 +272,12 @@ namespace PepperDash.Essentials
if (result != CrestronEthernetHelper.PortForwardingUserPatRetCodes.NoErr)
{
Debug.LogMessage(Serilog.Events.LogEventLevel.Error, "Error adding port forwarding: {0}", result);
Debug.LogMessage(LogEventLevel.Error, "Error adding port forwarding: {0}", result);
}
}
catch (ArgumentException)
{
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "This processor does not have a CS LAN", this);
Debug.LogMessage(LogEventLevel.Information, "This processor does not have a CS LAN", this);
}
catch (Exception ex)
{
@@ -351,7 +352,7 @@ namespace PepperDash.Essentials
if (_server.IsListening)
{
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "Mobile Control WebSocket Server listening on port {port}", this, _server.Port);
Debug.LogMessage(LogEventLevel.Information, "Mobile Control WebSocket Server listening on port {port}", this, _server.Port);
}
CrestronEnvironment.ProgramStatusEventHandler += OnProgramStop;
@@ -537,7 +538,7 @@ namespace PepperDash.Essentials
{
Debug.LogMessage(ex, "Error getting application configuration", this);
Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Config Object: {config} from {parentConfig}", this, config, _parent.Config);
Debug.LogMessage(LogEventLevel.Verbose, "Config Object: {config} from {parentConfig}", this, config, _parent.Config);
}
return config;
@@ -558,9 +559,9 @@ namespace PepperDash.Essentials
if (secret != null)
{
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "Secret successfully retrieved", this);
Debug.LogMessage(LogEventLevel.Information, "Secret successfully retrieved", this);
Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, "Secret: {0}", this, secret.Value.ToString());
Debug.LogMessage(LogEventLevel.Debug, "Secret: {0}", this, secret.Value.ToString());
// populate the local secrets object
@@ -571,27 +572,27 @@ namespace PepperDash.Essentials
// populate the _uiClient collection
foreach (var token in _secret.Tokens)
{
if(token.Value == null)
if (token.Value == null)
{
Debug.LogMessage(Serilog.Events.LogEventLevel.Warning, "Token value is null", this);
Debug.LogMessage(LogEventLevel.Warning, "Token value is null", this);
continue;
}
}
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "Adding token: {0} for room: {1}", this, token.Key, token.Value.RoomKey);
if(UiClients == null)
Debug.LogMessage(LogEventLevel.Information, "Adding token: {0} for room: {1}", this, token.Key, token.Value.RoomKey);
if (UiClients == null)
{
Debug.LogMessage(Serilog.Events.LogEventLevel.Warning, "UiClients is null", this);
Debug.LogMessage(LogEventLevel.Warning, "UiClients is null", this);
UiClients = new Dictionary<string, UiClientContext>();
}
UiClients.Add(token.Key, new UiClientContext(token.Value));
}
}
if (UiClients.Count > 0)
{
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "Restored {uiClientCount} UiClients from secrets data", this, UiClients.Count);
Debug.LogMessage(LogEventLevel.Information, "Restored {uiClientCount} UiClients from secrets data", this, UiClients.Count);
foreach (var client in UiClients)
{
@@ -602,7 +603,7 @@ namespace PepperDash.Essentials
_server.AddWebSocketService(path, () =>
{
var c = new UiClient();
Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, "Constructing UiClient with id: {key}", this, key);
Debug.LogMessage(LogEventLevel.Debug, "Constructing UiClient with id: {key}", this, key);
c.Controller = _parent;
c.RoomKey = roomKey;
@@ -623,10 +624,10 @@ namespace PepperDash.Essentials
}
else
{
Debug.LogMessage(Serilog.Events.LogEventLevel.Warning, "No secret found");
Debug.LogMessage(LogEventLevel.Warning, "No secret found");
}
Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, "{uiClientCount} UiClients restored from secrets data", this, UiClients.Count);
Debug.LogMessage(LogEventLevel.Debug, "{uiClientCount} UiClients restored from secrets data", this, UiClients.Count);
}
catch (Exception ex)
{
@@ -643,7 +644,7 @@ namespace PepperDash.Essentials
{
if (_secret == null)
{
Debug.LogMessage(Serilog.Events.LogEventLevel.Error, "Secret is null", this);
Debug.LogMessage(LogEventLevel.Error, "Secret is null", this);
_secret = new ServerTokenSecrets(string.Empty);
}
@@ -748,17 +749,17 @@ namespace PepperDash.Essentials
_server.AddWebSocketService(path, () =>
{
var c = new UiClient();
Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Constructing UiClient with id: {0}", this, key);
Debug.LogMessage(LogEventLevel.Verbose, "Constructing UiClient with id: {0}", this, key);
c.Controller = _parent;
c.RoomKey = bridge.RoomKey;
UiClients[key].SetClient(c);
return c;
});
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "Added new WebSocket UiClient service at path: {path}", this, path);
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "Token: {@token}", this, token);
Debug.LogMessage(LogEventLevel.Information, "Added new WebSocket UiClient service at path: {path}", this, path);
Debug.LogMessage(LogEventLevel.Information, "Token: {@token}", this, token);
Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "{serviceCount} websocket services present", this, _server.WebSocketServices.Count);
Debug.LogMessage(LogEventLevel.Verbose, "{serviceCount} websocket services present", this, _server.WebSocketServices.Count);
UpdateSecret();
@@ -970,7 +971,7 @@ namespace PepperDash.Essentials
}
catch (Exception ex)
{
this.LogException(ex, "Caught an exception in the OnPost handler");
this.LogException(ex, "Caught an exception in the OnPost handler");
}
}
@@ -1048,7 +1049,7 @@ namespace PepperDash.Essentials
var body = Encoding.UTF8.GetBytes(message);
res.ContentLength64 = body.LongLength;
res.Close(body, true);
}
}
else
@@ -1101,23 +1102,23 @@ namespace PepperDash.Essentials
if (File.Exists(filePath))
{
if(filePath.EndsWith(".png"))
{
if (filePath.EndsWith(".png"))
{
res.ContentType = "image/png";
}
else if(filePath.EndsWith(".jpg"))
else if (filePath.EndsWith(".jpg"))
{
res.ContentType = "image/jpeg";
}
else if(filePath.EndsWith(".gif"))
else if (filePath.EndsWith(".gif"))
{
res.ContentType = "image/gif";
}
else if(filePath.EndsWith(".svg"))
else if (filePath.EndsWith(".svg"))
{
res.ContentType = "image/svg+xml";
}
byte[] contents = System.IO.File.ReadAllBytes(filePath);
byte[] contents = File.ReadAllBytes(filePath);
res.ContentLength64 = contents.LongLength;
res.Close(contents, true);
}
@@ -1126,7 +1127,7 @@ namespace PepperDash.Essentials
res.StatusCode = (int)HttpStatusCode.NotFound;
res.Close();
}
}
}
/// <summary>
/// Handles requests to serve files for the Angular single page app
@@ -1138,9 +1139,6 @@ namespace PepperDash.Essentials
{
this.LogVerbose("Requesting User app file");
var qp = req.QueryString;
var token = qp["token"];
string filePath = path.Split('?')[0];
// remove the token from the path if found
@@ -1202,10 +1200,10 @@ namespace PepperDash.Essentials
this.LogVerbose("Attempting to serve file: {filePath}", filePath);
byte[] contents;
if (System.IO.File.Exists(filePath))
if (File.Exists(filePath))
{
this.LogVerbose("File found: {filePath}", filePath);
contents = System.IO.File.ReadAllBytes(filePath);
contents = File.ReadAllBytes(filePath);
}
else
{

View File

@@ -1,7 +1,7 @@
using Newtonsoft.Json;
using PepperDash.Essentials.Core;
namespace PepperDash.Essentials
namespace PepperDash.Essentials.WebSocketServer
{
internal class WebSocketServerSecretProvider : CrestronLocalSecretsProvider
{