diff --git a/src/PepperDash.Core/JsonToSimpl/JsonToSimplMaster.cs b/src/PepperDash.Core/JsonToSimpl/JsonToSimplMaster.cs index bc965e92..fcf6e0f8 100644 --- a/src/PepperDash.Core/JsonToSimpl/JsonToSimplMaster.cs +++ b/src/PepperDash.Core/JsonToSimpl/JsonToSimplMaster.cs @@ -167,11 +167,7 @@ namespace PepperDash.Core.JsonToSimpl /// public static JObject ParseObject(string json) { - #if NET6_0 using (var reader = new JsonTextReader(new System.IO.StringReader(json))) -#else - using (var reader = new JsonTextReader(new System.IO.StringReader(json))) -#endif { var startDepth = reader.Depth; var obj = JObject.Load(reader); @@ -191,11 +187,8 @@ namespace PepperDash.Core.JsonToSimpl /// public static JArray ParseArray(string json) { - #if NET6_0 + using (var reader = new JsonTextReader(new System.IO.StringReader(json))) -#else - using (var reader = new JsonTextReader(new System.IO.StringReader(json))) -#endif { var startDepth = reader.Depth; var obj = JArray.Load(reader); diff --git a/src/PepperDash.Core/Logging/DebugWebsocketSink.cs b/src/PepperDash.Core/Logging/DebugWebsocketSink.cs index 5f4f1de2..81d981ec 100644 --- a/src/PepperDash.Core/Logging/DebugWebsocketSink.cs +++ b/src/PepperDash.Core/Logging/DebugWebsocketSink.cs @@ -1,4 +1,4 @@ -extern alias NewtonsoftJson; +extern alias NewtonsoftJson; using System; using System.Collections.Generic; @@ -34,7 +34,7 @@ namespace PepperDash.Core { private WebSocketServer _wsServer; - private string _path = "/debug/join/"; + private readonly string _path = "/debug/join/"; private const string _certificateName = "selfCres"; private const string _certificatePassword = "cres12345"; @@ -102,31 +102,21 @@ namespace PepperDash.Core private static void CreateCert() { try - { - //Debug.Console(0,"CreateCert Creating Utility"); - CrestronConsole.PrintLine("CreateCert Creating Utility"); - //var utility = new CertificateUtility(); + { 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 hostName = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, 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)); - 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 }); - //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\\"); + 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 + utility.CertificatePassword = _certificatePassword; - utility.WriteCertificate(certificate, @"\user\", _certificateName); - //Debug.Console(0, "CreateCert Ending CreateCert"); - CrestronConsole.PrintLine("CreateCert Ending CreateCert"); + utility.WriteCertificate(certificate, @"\user\", _certificateName); } catch (Exception ex) { diff --git a/src/PepperDash.Essentials.Core/Plugins/PluginLoader.cs b/src/PepperDash.Essentials.Core/Plugins/PluginLoader.cs index 17619b2f..0f76b528 100644 --- a/src/PepperDash.Essentials.Core/Plugins/PluginLoader.cs +++ b/src/PepperDash.Essentials.Core/Plugins/PluginLoader.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Reflection; using Crestron.SimplSharp; +using System.Reflection; +using System.IO; using Newtonsoft.Json; using System.Reflection.PortableExecutable; using System.Reflection.Metadata; @@ -95,7 +95,7 @@ namespace PepperDash.Essentials { Debug.LogMessage(LogEventLevel.Verbose, "Getting Assemblies loaded with Essentials"); // Get the loaded assembly filenames - var appDi = new SystemIO.DirectoryInfo(Global.ApplicationDirectoryPathPrefix); + var appDi = new DirectoryInfo(Global.ApplicationDirectoryPathPrefix); var assemblyFiles = appDi.GetFiles("*.dll"); Debug.LogMessage(LogEventLevel.Verbose, "Found {0} Assemblies", assemblyFiles.Length); @@ -172,8 +172,8 @@ namespace PepperDash.Essentials { List referencedAssemblies = new List(); - using (SystemIO.FileStream fs = new SystemIO.FileStream(filePath, SystemIO.FileMode.Open, - SystemIO.FileAccess.Read, SystemIO.FileShare.ReadWrite)) + using (FileStream fs = new FileStream(filePath, FileMode.Open, + FileAccess.Read, FileShare.ReadWrite)) using (PEReader peReader = new PEReader(fs)) { if (!peReader.HasMetadata) @@ -252,7 +252,7 @@ namespace PepperDash.Essentials var (isCompatible, reason, references) = IsPluginCompatibleWithNet8(filePath); 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); var incompatiblePlugin = new IncompatiblePlugin(fileName, reason, requestedBy); @@ -275,10 +275,10 @@ namespace PepperDash.Essentials } 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 - string assemblyName = CrestronIO.Path.GetFileNameWithoutExtension(filePath); + string assemblyName = Path.GetFileNameWithoutExtension(filePath); // Try to find the already loaded assembly var existingAssembly = AppDomain.CurrentDomain.GetAssemblies() @@ -298,7 +298,7 @@ namespace PepperDash.Essentials } catch(Exception ex) { - string fileName = CrestronIO.Path.GetFileName(filePath); + string fileName = Path.GetFileName(filePath); // Check if this might be a .NET Framework compatibility issue if (ex.Message.Contains("Could not load type") || @@ -415,14 +415,14 @@ namespace PepperDash.Essentials { 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"); if (pluginFiles.Length > 0) { - if (!SystemIO.Directory.Exists(_loadedPluginsDirectoryPath)) + if (!Directory.Exists(_loadedPluginsDirectoryPath)) { - SystemIO.Directory.CreateDirectory(_loadedPluginsDirectoryPath); + Directory.CreateDirectory(_loadedPluginsDirectoryPath); } } @@ -439,14 +439,14 @@ namespace PepperDash.Essentials filePath = _loadedPluginsDirectoryPath + Global.DirectorySeparator + pluginFile.Name; // 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); - SystemIO.File.Delete(filePath); + File.Delete(filePath); } // 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); } else @@ -470,7 +470,7 @@ namespace PepperDash.Essentials static void UnzipAndMoveCplzArchives() { 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"); //// Find cplz files at the root of the user folder. Makes development/testing easier for VC-4, and helps with mistakes by end users @@ -485,16 +485,16 @@ namespace PepperDash.Essentials 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) { - SystemIO.Directory.CreateDirectory(_tempDirectory); - var tempDi = new SystemIO.DirectoryInfo(_tempDirectory); + Directory.CreateDirectory(_tempDirectory); + var tempDi = new DirectoryInfo(_tempDirectory); Debug.LogMessage(LogEventLevel.Information, "Found cplz: {0}. Unzipping into temp plugins directory", zfi.FullName); var result = CrestronZIP.Unzip(zfi.FullName, tempDi.FullName); @@ -512,14 +512,14 @@ namespace PepperDash.Essentials filePath = _loadedPluginsDirectoryPath + Global.DirectorySeparator + tempFile.Name; // 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); - SystemIO.File.Delete(filePath); + File.Delete(filePath); } // 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); } else @@ -535,7 +535,7 @@ namespace PepperDash.Essentials } // Delete the .cplz and the temp directory - SystemIO.Directory.Delete(_tempDirectory, true); + Directory.Delete(_tempDirectory, true); zfi.Delete(); } @@ -548,7 +548,7 @@ namespace PepperDash.Essentials static void LoadPluginAssemblies() { 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"); Debug.LogMessage(LogEventLevel.Verbose, "Found {0} plugin assemblies to load", pluginFiles.Length); @@ -618,7 +618,7 @@ namespace PepperDash.Essentials // Check if any of the loader exceptions are due to missing assemblies foreach (var loaderEx in e.LoaderExceptions) { - if (loaderEx is SystemIO.FileNotFoundException fileNotFoundEx) + if (loaderEx is FileNotFoundException fileNotFoundEx) { string missingAssembly = fileNotFoundEx.FileName; if (!string.IsNullOrEmpty(missingAssembly)) @@ -628,7 +628,7 @@ namespace PepperDash.Essentials // Add to incompatible plugins with dependency information IncompatiblePlugins.Add(new IncompatiblePlugin( - CrestronIO.Path.GetFileName(missingAssembly), + Path.GetFileName(missingAssembly), $"Missing dependency required by {loadedAssembly.Name}", loadedAssembly.Name)); } @@ -797,7 +797,7 @@ namespace PepperDash.Essentials { 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"); @@ -807,7 +807,7 @@ namespace PepperDash.Essentials // Deal with any .cplz files UnzipAndMoveCplzArchives(); - if (SystemIO.Directory.Exists(_loadedPluginsDirectoryPath)) + if (Directory.Exists(_loadedPluginsDirectoryPath)) { // Load the assemblies from the loadedPlugins folder into the AppDomain LoadPluginAssemblies();