From 955d68b3f3632835c6249ecb107db887fdee0cc1 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Tue, 30 Mar 2021 15:56:05 -0600 Subject: [PATCH 1/8] #671 switches to private Dispose() on program stop --- .../PepperDashEssentialsBase/Queues/GenericQueue.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs index 693c39e5..36f69e0f 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs @@ -155,7 +155,7 @@ namespace PepperDash.Essentials.Core.Queues if (programEvent != eProgramStatusEventType.Stopping) return; - Dispose(); + Dispose(true); }; } @@ -407,7 +407,7 @@ namespace PepperDash_Essentials_Core.Queues if (programEvent != eProgramStatusEventType.Stopping) return; - Dispose(); + Dispose(true); }; } From 2feec6205285d82a961eb9c64ec908b4255cd8d5 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Wed, 31 Mar 2021 16:35:33 -0600 Subject: [PATCH 2/8] Removes explicit call to dispose when program stops. Clears queue in dispose --- .../Queues/GenericQueue.cs | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs index 36f69e0f..f2e8000d 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs @@ -150,13 +150,13 @@ namespace PepperDash.Essentials.Core.Queues _delayEnabled = pacing > 0; _delayTime = pacing; - CrestronEnvironment.ProgramStatusEventHandler += programEvent => - { - if (programEvent != eProgramStatusEventType.Stopping) - return; + //CrestronEnvironment.ProgramStatusEventHandler += programEvent => + //{ + // if (programEvent != eProgramStatusEventType.Stopping) + // return; - Dispose(true); - }; + // Dispose(true); + //}; } /// @@ -231,6 +231,8 @@ namespace PepperDash.Essentials.Core.Queues if (disposing) { + Debug.Console(2, this, "Disposing..."); + _queue.Clear(); Enqueue(null); _worker.Join(); _waitHandle.Close(); @@ -402,13 +404,13 @@ namespace PepperDash_Essentials_Core.Queues _delayEnabled = pacing > 0; _delayTime = pacing; - CrestronEnvironment.ProgramStatusEventHandler += programEvent => - { - if (programEvent != eProgramStatusEventType.Stopping) - return; + //CrestronEnvironment.ProgramStatusEventHandler += programEvent => + //{ + // if (programEvent != eProgramStatusEventType.Stopping) + // return; - Dispose(true); - }; + // Dispose(true); + //}; } /// @@ -477,6 +479,8 @@ namespace PepperDash_Essentials_Core.Queues if (disposing) { + Debug.Console(2, this, "Disposing..."); + _queue.Clear(); Enqueue(null); _worker.Join(); _waitHandle.Close(); From dd0f7a586e8f04806643db079637b2bdbdb0d143 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Fri, 2 Apr 2021 09:03:39 -0600 Subject: [PATCH 3/8] fix Console statement and add help --- .../PepperDashEssentialsBase/Devices/DeviceManager.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceManager.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceManager.cs index 55bc523a..cb8c89db 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceManager.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceManager.cs @@ -387,6 +387,15 @@ namespace PepperDash.Essentials.Core /// public static void SetDeviceStreamDebugging(string s) { + if (String.IsNullOrEmpty(s) || s.Contains("?")) + { + Debug.Console(0, + @"SETDEVICESTREAMDEBUG [{deviceKey}] [OFF |TX | RX | BOTH] [timeOutInMinutes] + {deviceKey} [OFF | TX | RX | BOTH] - Device to set stream debugging on, and which setting to use + timeOutInMinutes - Set timeout for stream debugging. Default is 30 minutes"); + return; + } + var args = s.Split(' '); var deviceKey = args[0]; @@ -437,7 +446,7 @@ namespace PepperDash.Essentials.Core else { device.StreamDebugging.SetDebuggingWithDefaultTimeout(debugSetting); - Debug.Console(0, "Device: '{0}' debug level set to {1) for default time (30 minutes)", deviceKey, debugSetting); + Debug.Console(0, "Device: '{0}' debug level set to {1} for default time (30 minutes)", deviceKey, debugSetting); } } From 252d0373802814c663c9ae1125d5bac53a6571f5 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Fri, 2 Apr 2021 09:09:13 -0600 Subject: [PATCH 4/8] change to method signature instead of lambda --- .../PepperDashEssentialsBase/Devices/DeviceManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceManager.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceManager.cs index cb8c89db..b8e20e9b 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceManager.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceManager.cs @@ -46,7 +46,7 @@ namespace PepperDash.Essentials.Core CrestronConsole.AddNewConsoleCommand(SimulateComReceiveOnDevice, "devsimreceive", "Simulates incoming data on a com device", ConsoleAccessLevelEnum.AccessOperator); - CrestronConsole.AddNewConsoleCommand(s => SetDeviceStreamDebugging(s), "setdevicestreamdebug", "set comm debug [deviceKey] [off/rx/tx/both] ([minutes])", ConsoleAccessLevelEnum.AccessOperator); + CrestronConsole.AddNewConsoleCommand(SetDeviceStreamDebugging, "setdevicestreamdebug", "set comm debug [deviceKey] [off/rx/tx/both] ([minutes])", ConsoleAccessLevelEnum.AccessOperator); CrestronConsole.AddNewConsoleCommand(s => DisableAllDeviceStreamDebugging(), "disableallstreamdebug", "disables stream debugging on all devices", ConsoleAccessLevelEnum.AccessOperator); } From e832566168aa59a7bfcf5051b42c4319cef5638b Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Fri, 2 Apr 2021 09:44:02 -0600 Subject: [PATCH 5/8] change to CrestronConsole.ConsoleCommandResponse for help text --- .../PepperDashEssentialsBase/Devices/DeviceManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceManager.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceManager.cs index b8e20e9b..cca16ec7 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceManager.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceManager.cs @@ -389,7 +389,7 @@ namespace PepperDash.Essentials.Core { if (String.IsNullOrEmpty(s) || s.Contains("?")) { - Debug.Console(0, + CrestronConsole.ConsoleCommandResponse( @"SETDEVICESTREAMDEBUG [{deviceKey}] [OFF |TX | RX | BOTH] [timeOutInMinutes] {deviceKey} [OFF | TX | RX | BOTH] - Device to set stream debugging on, and which setting to use timeOutInMinutes - Set timeout for stream debugging. Default is 30 minutes"); From 200080247a4e23b42cacc28def902752ca48572f Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Tue, 6 Apr 2021 10:38:39 -0600 Subject: [PATCH 6/8] closes #671 and changes to aborting thread in Dispose instead of attempting to join --- .../Queues/GenericQueue.cs | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs index f2e8000d..a5def83d 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs @@ -14,7 +14,7 @@ namespace PepperDash.Essentials.Core.Queues protected readonly CrestronQueue _queue; protected readonly Thread _worker; protected readonly CEvent _waitHandle = new CEvent(); - + private bool _delayEnabled; private int _delayTime; @@ -150,15 +150,15 @@ namespace PepperDash.Essentials.Core.Queues _delayEnabled = pacing > 0; _delayTime = pacing; - //CrestronEnvironment.ProgramStatusEventHandler += programEvent => - //{ - // if (programEvent != eProgramStatusEventType.Stopping) - // return; + CrestronEnvironment.ProgramStatusEventHandler += programEvent => + { + if (programEvent != eProgramStatusEventType.Stopping) + return; - // Dispose(true); - //}; + Dispose(true); + }; } - + /// /// Thread callback /// @@ -231,10 +231,13 @@ namespace PepperDash.Essentials.Core.Queues if (disposing) { - Debug.Console(2, this, "Disposing..."); - _queue.Clear(); - Enqueue(null); - _worker.Join(); + Debug.Console(2, this, "Disposing..."); + if (_queue != null && !_queue.Disposed) + { + _queue.Clear(); + Enqueue(null); + } + _worker.Abort(); _waitHandle.Close(); } @@ -243,7 +246,7 @@ namespace PepperDash.Essentials.Core.Queues ~GenericQueue() { - Dispose(false); + Dispose(true); } /// @@ -404,13 +407,13 @@ namespace PepperDash_Essentials_Core.Queues _delayEnabled = pacing > 0; _delayTime = pacing; - //CrestronEnvironment.ProgramStatusEventHandler += programEvent => - //{ - // if (programEvent != eProgramStatusEventType.Stopping) - // return; + CrestronEnvironment.ProgramStatusEventHandler += programEvent => + { + if (programEvent != eProgramStatusEventType.Stopping) + return; - // Dispose(true); - //}; + Dispose(true); + }; } /// @@ -479,10 +482,13 @@ namespace PepperDash_Essentials_Core.Queues if (disposing) { - Debug.Console(2, this, "Disposing..."); - _queue.Clear(); - Enqueue(null); - _worker.Join(); + Debug.Console(2, this, "Disposing..."); + if (_queue != null && !_queue.Disposed) + { + _queue.Clear(); + Enqueue(null); + } + _worker.Abort(); _waitHandle.Close(); } @@ -491,7 +497,7 @@ namespace PepperDash_Essentials_Core.Queues ~GenericQueue() { - Dispose(false); + Dispose(true); } /// From 6ddfdc4b38c280995637bb42802db03198e7c6ce Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Thu, 8 Apr 2021 13:54:06 -0600 Subject: [PATCH 7/8] Updating plugin loading mechanism to provide better feedback --- .../Plugins/PluginLoader.cs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs index 01da1c54..c0aac87d 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs @@ -363,9 +363,10 @@ namespace PepperDash.Essentials { try { - if (typeof(IPluginDeviceFactory).IsAssignableFrom(type)) + if (typeof (IPluginDeviceFactory).IsAssignableFrom(type)) { - var plugin = (IPluginDeviceFactory)Crestron.SimplSharp.Reflection.Activator.CreateInstance(type); + var plugin = + (IPluginDeviceFactory) Crestron.SimplSharp.Reflection.Activator.CreateInstance(type); LoadCustomPlugin(plugin, loadedAssembly); } else @@ -378,18 +379,30 @@ namespace PepperDash.Essentials } } } + catch (NotSupportedException e) + { + //this happens for dlls that aren't PD dlls, like ports of Mono classes into S#. Swallowing. + + } catch (Exception e) { Debug.Console(2, "Load Plugin not found. {0}.{2} is not a plugin factory. Exception: {1}", - loadedAssembly.Name, e, type.Name); - continue; + loadedAssembly.Name, e.Message, type.Name); } } } + catch (TypeLoadException e) + { + Debug.Console(0, Debug.ErrorLogLevel.Warning, "Unable to load assembly {0}: {1}", + loadedAssembly.Name, e.Message); + Debug.Console(2, e.StackTrace); + } catch (Exception e) { - Debug.Console(2, "Error Loading Assembly: {0} Exception: {1} ", loadedAssembly.Name, e); + Debug.Console(0, Debug.ErrorLogLevel.Warning, "Error Loading assembly {0}: {1}", + loadedAssembly.Name, e.Message); + Debug.Console(2, "{0}", e.StackTrace); continue; } } From 8cfd58bb7e25c4476d21cee2d06e4420022b02e7 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Thu, 8 Apr 2021 14:21:32 -0600 Subject: [PATCH 8/8] Fix error printing for plugin loading --- .../Plugins/PluginLoader.cs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs index c0aac87d..7192c667 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs @@ -358,7 +358,19 @@ namespace PepperDash.Essentials try { var assy = loadedAssembly.Assembly; - var types = assy.GetTypes(); + CType[] types = {}; + try + { + types = assy.GetTypes(); + } + catch (TypeLoadException e) + { + Debug.Console(0, Debug.ErrorLogLevel.Warning, "Unable to get types for assembly {0}: {1}", + loadedAssembly.Name, e.Message); + Debug.Console(2, e.StackTrace); + continue; + } + foreach (var type in types) { try @@ -382,7 +394,7 @@ namespace PepperDash.Essentials catch (NotSupportedException e) { //this happens for dlls that aren't PD dlls, like ports of Mono classes into S#. Swallowing. - + } catch (Exception e) { @@ -392,12 +404,6 @@ namespace PepperDash.Essentials } } - catch (TypeLoadException e) - { - Debug.Console(0, Debug.ErrorLogLevel.Warning, "Unable to load assembly {0}: {1}", - loadedAssembly.Name, e.Message); - Debug.Console(2, e.StackTrace); - } catch (Exception e) { Debug.Console(0, Debug.ErrorLogLevel.Warning, "Error Loading assembly {0}: {1}",