chore: fix issues related to remving crestron usings

This commit is contained in:
Andrew Welker
2025-07-04 12:46:08 -05:00
parent dc900f3f31
commit cc7e2ab675
3 changed files with 40 additions and 59 deletions

View File

@@ -2,7 +2,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
@@ -160,11 +159,7 @@ namespace PepperDash.Core.JsonToSimpl
/// <returns></returns> /// <returns></returns>
public static JObject ParseObject(string json) public static JObject ParseObject(string json)
{ {
#if NET6_0 using (var reader = new JsonTextReader(new StringReader(json)))
using (var reader = new JsonTextReader(new System.IO.StringReader(json)))
#else
using (var reader = new JsonTextReader(new Crestron.SimplSharp.CrestronIO.StringReader(json)))
#endif
{ {
var startDepth = reader.Depth; var startDepth = reader.Depth;
var obj = JObject.Load(reader); var obj = JObject.Load(reader);
@@ -181,11 +176,8 @@ namespace PepperDash.Core.JsonToSimpl
/// <returns></returns> /// <returns></returns>
public static JArray ParseArray(string json) public static JArray ParseArray(string json)
{ {
#if NET6_0
using (var reader = new JsonTextReader(new System.IO.StringReader(json))) using (var reader = new JsonTextReader(new StringReader(json)))
#else
using (var reader = new JsonTextReader(new Crestron.SimplSharp.CrestronIO.StringReader(json)))
#endif
{ {
var startDepth = reader.Depth; var startDepth = reader.Depth;
var obj = JArray.Load(reader); var obj = JArray.Load(reader);

View File

@@ -26,7 +26,7 @@ namespace PepperDash.Core
{ {
private HttpServer _httpsServer; private HttpServer _httpsServer;
private string _path = "/debug/join/"; private readonly string _path = "/debug/join/";
private const string _certificateName = "selfCres"; private const string _certificateName = "selfCres";
private const string _certificatePassword = "cres12345"; private const string _certificatePassword = "cres12345";
@@ -95,35 +95,25 @@ namespace PepperDash.Core
{ {
try try
{ {
//Debug.Console(0,"CreateCert Creating Utility");
CrestronConsole.PrintLine("CreateCert Creating Utility");
//var utility = new CertificateUtility();
var utility = new BouncyCertificate(); var utility = new BouncyCertificate();
//Debug.Console(0, "CreateCert Calling CreateCert");
CrestronConsole.PrintLine("CreateCert Calling CreateCert");
//utility.CreateCert();
var ipAddress = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0); var ipAddress = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0);
var hostName = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, 0); var hostName = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, 0);
var domainName = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DOMAIN_NAME, 0); var domainName = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DOMAIN_NAME, 0);
//Debug.Console(0, "DomainName: {0} | HostName: {1} | {1}.{0}@{2}", domainName, hostName, ipAddress);
CrestronConsole.PrintLine(string.Format("DomainName: {0} | HostName: {1} | {1}.{0}@{2}", domainName, hostName, ipAddress)); CrestronConsole.PrintLine(string.Format("DomainName: {0} | HostName: {1} | {1}.{0}@{2}", domainName, hostName, ipAddress));
var certificate = utility.CreateSelfSignedCertificate(string.Format("CN={0}.{1}", hostName, domainName), new[] { string.Format("{0}.{1}", hostName, domainName), ipAddress }, new[] { KeyPurposeID.id_kp_serverAuth, KeyPurposeID.id_kp_clientAuth }); var certificate = utility.CreateSelfSignedCertificate(string.Format("CN={0}.{1}", hostName, domainName), [string.Format("{0}.{1}", hostName, domainName), ipAddress], [KeyPurposeID.id_kp_serverAuth, KeyPurposeID.id_kp_clientAuth]);
//Crestron fails to let us do this...perhaps it should be done through their Dll's but haven't tested //Crestron fails to let us do this...perhaps it should be done through their Dll's but haven't tested
//Debug.Print($"CreateCert Storing Certificate To My.LocalMachine");
//utility.AddCertToStore(certificate, StoreName.My, StoreLocation.LocalMachine);
//Debug.Console(0, "CreateCert Saving Cert to \\user\\");
CrestronConsole.PrintLine("CreateCert Saving Cert to \\user\\");
utility.CertificatePassword = _certificatePassword; utility.CertificatePassword = _certificatePassword;
utility.WriteCertificate(certificate, @"\user\", _certificateName); utility.WriteCertificate(certificate, @"\user\", _certificateName);
//Debug.Console(0, "CreateCert Ending CreateCert");
CrestronConsole.PrintLine("CreateCert Ending CreateCert");
} }
catch (Exception ex) catch (Exception ex)
{ {
//Debug.Console(0, "WSS CreateCert Failed\r\n{0}\r\n{1}", ex.Message, ex.StackTrace); //Debug.Console(0, "WSS CreateCert Failed\r\n{0}\r\n{1}", ex.Message, ex.StackTrace);
CrestronConsole.PrintLine(string.Format("WSS CreateCert Failed\r\n{0}\r\n{1}", ex.Message, ex.StackTrace)); CrestronConsole.PrintLine("WSS CreateCert Failed\r\n{0}\r\n{1}", ex.Message, ex.StackTrace);
} }
} }

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Crestron.SimplSharp; using Crestron.SimplSharp;
// using Crestron.SimplSharp.CrestronIO;
using System.Reflection; using System.Reflection;
using System.IO; using System.IO;
using System.Reflection.PortableExecutable; using System.Reflection.PortableExecutable;
@@ -12,7 +11,7 @@ using PepperDash.Core;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
using Serilog.Events; using Serilog.Events;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.IO;
namespace PepperDash.Essentials namespace PepperDash.Essentials
{ {
@@ -86,7 +85,7 @@ namespace PepperDash.Essentials
{ {
Debug.LogMessage(LogEventLevel.Verbose, "Getting Assemblies loaded with Essentials"); Debug.LogMessage(LogEventLevel.Verbose, "Getting Assemblies loaded with Essentials");
// Get the loaded assembly filenames // Get the loaded assembly filenames
var appDi = new SystemIO.DirectoryInfo(Global.ApplicationDirectoryPathPrefix); var appDi = new DirectoryInfo(Global.ApplicationDirectoryPathPrefix);
var assemblyFiles = appDi.GetFiles("*.dll"); var assemblyFiles = appDi.GetFiles("*.dll");
Debug.LogMessage(LogEventLevel.Verbose, "Found {0} Assemblies", assemblyFiles.Length); Debug.LogMessage(LogEventLevel.Verbose, "Found {0} Assemblies", assemblyFiles.Length);
@@ -159,8 +158,8 @@ namespace PepperDash.Essentials
{ {
List<string> referencedAssemblies = new List<string>(); List<string> referencedAssemblies = new List<string>();
using (SystemIO.FileStream fs = new SystemIO.FileStream(filePath, SystemIO.FileMode.Open, using (FileStream fs = new FileStream(filePath, FileMode.Open,
SystemIO.FileAccess.Read, SystemIO.FileShare.ReadWrite)) FileAccess.Read, FileShare.ReadWrite))
using (PEReader peReader = new PEReader(fs)) using (PEReader peReader = new PEReader(fs))
{ {
if (!peReader.HasMetadata) if (!peReader.HasMetadata)
@@ -239,7 +238,7 @@ namespace PepperDash.Essentials
var (isCompatible, reason, references) = IsPluginCompatibleWithNet8(filePath); var (isCompatible, reason, references) = IsPluginCompatibleWithNet8(filePath);
if (!isCompatible) if (!isCompatible)
{ {
string fileName = CrestronIO.Path.GetFileName(filePath); string fileName = Path.GetFileName(filePath);
Debug.LogMessage(LogEventLevel.Warning, "Assembly '{0}' is not compatible with .NET 8: {1}", fileName, reason); Debug.LogMessage(LogEventLevel.Warning, "Assembly '{0}' is not compatible with .NET 8: {1}", fileName, reason);
var incompatiblePlugin = new IncompatiblePlugin(fileName, reason, requestedBy); var incompatiblePlugin = new IncompatiblePlugin(fileName, reason, requestedBy);
@@ -262,10 +261,10 @@ namespace PepperDash.Essentials
} }
return null; return null;
} }
catch(SystemIO.FileLoadException ex) when (ex.Message.Contains("Assembly with same name is already loaded")) catch(FileLoadException ex) when (ex.Message.Contains("Assembly with same name is already loaded"))
{ {
// Get the assembly name from the file path // Get the assembly name from the file path
string assemblyName = CrestronIO.Path.GetFileNameWithoutExtension(filePath); string assemblyName = Path.GetFileNameWithoutExtension(filePath);
// Try to find the already loaded assembly // Try to find the already loaded assembly
var existingAssembly = AppDomain.CurrentDomain.GetAssemblies() var existingAssembly = AppDomain.CurrentDomain.GetAssemblies()
@@ -285,7 +284,7 @@ namespace PepperDash.Essentials
} }
catch(Exception ex) catch(Exception ex)
{ {
string fileName = CrestronIO.Path.GetFileName(filePath); string fileName = Path.GetFileName(filePath);
// Check if this might be a .NET Framework compatibility issue // Check if this might be a .NET Framework compatibility issue
if (ex.Message.Contains("Could not load type") || if (ex.Message.Contains("Could not load type") ||
@@ -388,14 +387,14 @@ namespace PepperDash.Essentials
{ {
Debug.LogMessage(LogEventLevel.Information, "Looking for .dll assemblies from plugins folder..."); Debug.LogMessage(LogEventLevel.Information, "Looking for .dll assemblies from plugins folder...");
var pluginDi = new SystemIO.DirectoryInfo(_pluginDirectory); var pluginDi = new DirectoryInfo(_pluginDirectory);
var pluginFiles = pluginDi.GetFiles("*.dll"); var pluginFiles = pluginDi.GetFiles("*.dll");
if (pluginFiles.Length > 0) if (pluginFiles.Length > 0)
{ {
if (!SystemIO.Directory.Exists(_loadedPluginsDirectoryPath)) if (!Directory.Exists(_loadedPluginsDirectoryPath))
{ {
SystemIO.Directory.CreateDirectory(_loadedPluginsDirectoryPath); Directory.CreateDirectory(_loadedPluginsDirectoryPath);
} }
} }
@@ -412,14 +411,14 @@ namespace PepperDash.Essentials
filePath = _loadedPluginsDirectoryPath + Global.DirectorySeparator + pluginFile.Name; filePath = _loadedPluginsDirectoryPath + Global.DirectorySeparator + pluginFile.Name;
// Check if there is a previous file in the loadedPlugins directory and delete // Check if there is a previous file in the loadedPlugins directory and delete
if (SystemIO.File.Exists(filePath)) if (File.Exists(filePath))
{ {
Debug.LogMessage(LogEventLevel.Information, "Found existing file in loadedPlugins: {0} Deleting and moving new file to replace it", filePath); Debug.LogMessage(LogEventLevel.Information, "Found existing file in loadedPlugins: {0} Deleting and moving new file to replace it", filePath);
SystemIO.File.Delete(filePath); File.Delete(filePath);
} }
// Move the file // Move the file
SystemIO.File.Move(pluginFile.FullName, filePath); File.Move(pluginFile.FullName, filePath);
Debug.LogMessage(LogEventLevel.Verbose, "Moved {0} to {1}", pluginFile.FullName, filePath); Debug.LogMessage(LogEventLevel.Verbose, "Moved {0} to {1}", pluginFile.FullName, filePath);
} }
else else
@@ -443,7 +442,7 @@ namespace PepperDash.Essentials
static void UnzipAndMoveCplzArchives() static void UnzipAndMoveCplzArchives()
{ {
Debug.LogMessage(LogEventLevel.Information, "Looking for .cplz archives from plugins folder..."); Debug.LogMessage(LogEventLevel.Information, "Looking for .cplz archives from plugins folder...");
var di = new SystemIO.DirectoryInfo(_pluginDirectory); var di = new DirectoryInfo(_pluginDirectory);
var zFiles = di.GetFiles("*.cplz"); var zFiles = di.GetFiles("*.cplz");
//// Find cplz files at the root of the user folder. Makes development/testing easier for VC-4, and helps with mistakes by end users //// Find cplz files at the root of the user folder. Makes development/testing easier for VC-4, and helps with mistakes by end users
@@ -458,16 +457,16 @@ namespace PepperDash.Essentials
if (cplzFiles.Length > 0) if (cplzFiles.Length > 0)
{ {
if (!SystemIO.Directory.Exists(_loadedPluginsDirectoryPath)) if (!Directory.Exists(_loadedPluginsDirectoryPath))
{ {
SystemIO.Directory.CreateDirectory(_loadedPluginsDirectoryPath); Directory.CreateDirectory(_loadedPluginsDirectoryPath);
} }
} }
foreach (var zfi in cplzFiles) foreach (var zfi in cplzFiles)
{ {
SystemIO.Directory.CreateDirectory(_tempDirectory); Directory.CreateDirectory(_tempDirectory);
var tempDi = new SystemIO.DirectoryInfo(_tempDirectory); var tempDi = new DirectoryInfo(_tempDirectory);
Debug.LogMessage(LogEventLevel.Information, "Found cplz: {0}. Unzipping into temp plugins directory", zfi.FullName); Debug.LogMessage(LogEventLevel.Information, "Found cplz: {0}. Unzipping into temp plugins directory", zfi.FullName);
var result = CrestronZIP.Unzip(zfi.FullName, tempDi.FullName); var result = CrestronZIP.Unzip(zfi.FullName, tempDi.FullName);
@@ -485,14 +484,14 @@ namespace PepperDash.Essentials
filePath = _loadedPluginsDirectoryPath + Global.DirectorySeparator + tempFile.Name; filePath = _loadedPluginsDirectoryPath + Global.DirectorySeparator + tempFile.Name;
// Check if there is a previous file in the loadedPlugins directory and delete // Check if there is a previous file in the loadedPlugins directory and delete
if (SystemIO.File.Exists(filePath)) if (File.Exists(filePath))
{ {
Debug.LogMessage(LogEventLevel.Information, "Found existing file in loadedPlugins: {0} Deleting and moving new file to replace it", filePath); Debug.LogMessage(LogEventLevel.Information, "Found existing file in loadedPlugins: {0} Deleting and moving new file to replace it", filePath);
SystemIO.File.Delete(filePath); File.Delete(filePath);
} }
// Move the file // Move the file
SystemIO.File.Move(tempFile.FullName, filePath); File.Move(tempFile.FullName, filePath);
Debug.LogMessage(LogEventLevel.Verbose, "Moved {0} to {1}", tempFile.FullName, filePath); Debug.LogMessage(LogEventLevel.Verbose, "Moved {0} to {1}", tempFile.FullName, filePath);
} }
else else
@@ -508,7 +507,7 @@ namespace PepperDash.Essentials
} }
// Delete the .cplz and the temp directory // Delete the .cplz and the temp directory
SystemIO.Directory.Delete(_tempDirectory, true); Directory.Delete(_tempDirectory, true);
zfi.Delete(); zfi.Delete();
} }
@@ -521,7 +520,7 @@ namespace PepperDash.Essentials
static void LoadPluginAssemblies() static void LoadPluginAssemblies()
{ {
Debug.LogMessage(LogEventLevel.Information, "Loading assemblies from loadedPlugins folder..."); Debug.LogMessage(LogEventLevel.Information, "Loading assemblies from loadedPlugins folder...");
var pluginDi = new CrestronIO.DirectoryInfo(_loadedPluginsDirectoryPath); var pluginDi = new DirectoryInfo(_loadedPluginsDirectoryPath);
var pluginFiles = pluginDi.GetFiles("*.dll"); var pluginFiles = pluginDi.GetFiles("*.dll");
Debug.LogMessage(LogEventLevel.Verbose, "Found {0} plugin assemblies to load", pluginFiles.Length); Debug.LogMessage(LogEventLevel.Verbose, "Found {0} plugin assemblies to load", pluginFiles.Length);
@@ -591,7 +590,7 @@ namespace PepperDash.Essentials
// Check if any of the loader exceptions are due to missing assemblies // Check if any of the loader exceptions are due to missing assemblies
foreach (var loaderEx in e.LoaderExceptions) foreach (var loaderEx in e.LoaderExceptions)
{ {
if (loaderEx is SystemIO.FileNotFoundException fileNotFoundEx) if (loaderEx is FileNotFoundException fileNotFoundEx)
{ {
string missingAssembly = fileNotFoundEx.FileName; string missingAssembly = fileNotFoundEx.FileName;
if (!string.IsNullOrEmpty(missingAssembly)) if (!string.IsNullOrEmpty(missingAssembly))
@@ -601,7 +600,7 @@ namespace PepperDash.Essentials
// Add to incompatible plugins with dependency information // Add to incompatible plugins with dependency information
IncompatiblePlugins.Add(new IncompatiblePlugin( IncompatiblePlugins.Add(new IncompatiblePlugin(
CrestronIO.Path.GetFileName(missingAssembly), Path.GetFileName(missingAssembly),
$"Missing dependency required by {loadedAssembly.Name}", $"Missing dependency required by {loadedAssembly.Name}",
loadedAssembly.Name)); loadedAssembly.Name));
} }
@@ -795,7 +794,7 @@ namespace PepperDash.Essentials
{ {
Debug.LogMessage(LogEventLevel.Information, "Attempting to Load Plugins from {_pluginDirectory}", _pluginDirectory); Debug.LogMessage(LogEventLevel.Information, "Attempting to Load Plugins from {_pluginDirectory}", _pluginDirectory);
if (SystemIO.Directory.Exists(_pluginDirectory)) if (Directory.Exists(_pluginDirectory))
{ {
Debug.LogMessage(LogEventLevel.Information, "Plugins directory found, checking for plugins"); Debug.LogMessage(LogEventLevel.Information, "Plugins directory found, checking for plugins");
@@ -805,7 +804,7 @@ namespace PepperDash.Essentials
// Deal with any .cplz files // Deal with any .cplz files
UnzipAndMoveCplzArchives(); UnzipAndMoveCplzArchives();
if (SystemIO.Directory.Exists(_loadedPluginsDirectoryPath)) if (Directory.Exists(_loadedPluginsDirectoryPath))
{ {
// Load the assemblies from the loadedPlugins folder into the AppDomain // Load the assemblies from the loadedPlugins folder into the AppDomain
LoadPluginAssemblies(); LoadPluginAssemblies();